Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
- v3.0.1-beta
  • Loading branch information
zhwanng committed Jun 29, 2024
1 parent 15bd1a2 commit f5100de
Show file tree
Hide file tree
Showing 62 changed files with 2,051 additions and 1,389 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
compileSdk rootProject.ext.compileSdkVersion

versionCode 150
versionName "3.0.0-beta"
versionName "3.0.1-beta"
multiDexEnabled true

resValue "string", "authorities", defaultConfig.applicationId + '.debug.cameraupload.provider'
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
android:name=".util.GlideCache"
android:value="AppGlideModule" />

<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync"
tools:node="merge" />

<activity
android:name=".ui.SplashActivity"
android:exported="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ private Constants() {
throw new IllegalStateException("Constants class"); //NON-NLS(1)
}

public static final String APP_PACKAGE = "com.seafile.seadroid2";


public static final int PERIODIC_SCAN_INTERVALS = 1000 * 60 * 30; //30 mins
public static final int PERIODIC_SCAN_INTERVALS = 1000 * 60 * 5; //5m
public static final int PASSWORD_MINIMUM_LENGTH = 8;
public static final String URL_PRIVACY = "https://www.seafile.com/privacy/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,37 @@ public interface FileTransferDAO {
@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_source = :feature and data_status = 0 order by created_at asc limit 1")
List<FileTransferEntity> getOnePendingTransferSync(String related_account, TransferAction transfer_action, TransferDataSource feature);

@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_status = 0 order by created_at asc limit :limit")
List<FileTransferEntity> getListPendingTransferSync(String related_account, TransferAction transfer_action, int limit);
@Query("select COUNT(*) from file_transfer_list where related_account = :related_account and transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_source = :feature and data_status = 0")
int countPendingTransferSync(String related_account, TransferAction transfer_action, TransferDataSource feature);


@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_status = 0 order by created_at asc limit :limit offset :offset")
List<FileTransferEntity> getPagePendingListTransferSync(String related_account, TransferAction transfer_action, int limit, int offset);

@Query("select * from file_transfer_list where transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_source = :feature and data_status = 0 order by created_at asc limit 1")
List<FileTransferEntity> getOnePendingTransferAllAccountSync(TransferAction transfer_action, TransferDataSource feature);

@Query("select * from file_transfer_list where related_account = :related_account and is_auto_transfer = 1 and transfer_action = 'DOWNLOAD' and transfer_status in ('IN_PROGRESS', 'WAITING') and data_status = 0 order by created_at asc limit 10")
List<FileTransferEntity> getPendingDownloadListByActionSync(String related_account);

@Query("select * from file_transfer_list where related_account = :related_account and is_auto_transfer = 1 and transfer_action = 'DOWNLOAD' and transfer_status in ('IN_PROGRESS', 'WAITING') and data_status = 0 order by created_at asc limit 1")
List<FileTransferEntity> getOnePendingDownloadByActionSync(String related_account);


@Query("select COUNT(*) from file_transfer_list where related_account = :related_account and is_auto_transfer = 1 and transfer_action = 'DOWNLOAD' and transfer_status in ('IN_PROGRESS', 'WAITING') and data_status = 0")
@Query("select COUNT(*) from file_transfer_list where related_account = :related_account and is_auto_transfer = 1 and transfer_action = 'DOWNLOAD' and transfer_status in ('IN_PROGRESS', 'WAITING') and data_status = 0")
int countPendingDownloadListSync(String related_account);


@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'UPLOAD' and data_source in ('FOLDER_BACKUP','FILE_BACKUP','ALBUM_BACKUP') and data_status = 0 order by created_at desc")
Single<List<FileTransferEntity>> getUploadListAsync(String related_account);

@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'UPLOAD' and data_source in ('FOLDER_BACKUP','FILE_BACKUP','ALBUM_BACKUP') and data_status = 0 order by created_at desc limit :limit offset :offset")
List<FileTransferEntity> getPageUploadListSync(String related_account, int limit, int offset);


@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'DOWNLOAD' and data_status = 0 order by created_at desc")
Single<List<FileTransferEntity>> getDownloadListAsync(String related_account);

@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'DOWNLOAD' and data_status = 0 order by created_at desc limit :limit offset :offset")
List<FileTransferEntity> getPageDownloadListSync(String related_account, int limit, int offset);


@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'DOWNLOAD' and data_status = 0 order by created_at desc")
List<FileTransferEntity> getDownloadListSync(String related_account);

Expand All @@ -121,13 +128,16 @@ public interface FileTransferDAO {
@Query("select * from file_transfer_list where repo_id = :repoId and full_path IN(:fullPaths) and transfer_action = :transfer_action order by created_at asc")
Single<List<FileTransferEntity>> getListByFullPathsAsync(String repoId, List<String> fullPaths, TransferAction transfer_action);

@Query("select * from file_transfer_list where repo_id = :repoId and transfer_action = 'DOWNLOAD' and transfer_result = 'SUCCEEDED' and parent_path = :parent_path order by created_at asc")
@Query("select * from file_transfer_list where repo_id = :repoId and transfer_action = 'DOWNLOAD' and transfer_status = 'SUCCEEDED' and parent_path = :parent_path order by created_at asc")
Single<List<FileTransferEntity>> getDownloadedListByParentAsync(String repoId, String parent_path);


@Query("select * from file_transfer_list where repo_id = :repoId and full_path IN(:fullPaths) and transfer_action = :transfer_action order by created_at asc")
List<FileTransferEntity> getListByFullPathsSync(String repoId, List<String> fullPaths, TransferAction transfer_action);

@Query("select * from file_transfer_list where repo_id = :repoId and transfer_action = :transfer_action order by created_at asc limit :limit offset :offset")
List<FileTransferEntity> getPageListSync(String repoId, TransferAction transfer_action, int limit, int offset);

@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transferAction and full_path = :full_path and data_status = 0 order by created_at")
List<FileTransferEntity> getListByFullPathSync(String related_account, TransferAction transferAction, String full_path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,26 @@ public static File getLocalRepoFile(Account account, String repoId, String repoN
return new File(localPath);
}

/**
* Each repo is placed under [account-dir]/[repo-name].
* When a file is downloaded, it's placed in its repo, with its full path.
*/
public static File getLocalRepoPath(Account account, String repoId, String repoName) throws RuntimeException {
File file = getRepoDirMappingDataStore(account, repoId, repoName);


//build valid file path and name
String localPath = com.seafile.seadroid2.framework.util.FileUtils.buildValidFilePathName(file.getAbsolutePath());

File parentDir = new File(Utils.getParentPath(localPath));
if (!parentDir.exists()) {
parentDir.mkdirs();
}

return new File(localPath);
}


/**
* calculate if refresh time is expired, the expiration is 10 mins
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.CollectionUtils;
import com.blankj.utilcode.util.EncryptUtils;
import com.blankj.utilcode.util.GsonUtils;
import com.google.gson.reflect.TypeToken;
import com.seafile.seadroid2.account.Account;
Expand Down Expand Up @@ -113,8 +114,7 @@ public static void writeBackupPaths(List<String> paths) {
}

public static String readBackupPathStr() {
String confStr = DataStoreManager.getInstanceByUser(getCurrentAccount()).readString(SettingsManager.FOLDERS_BACKUP_SELECTED_PATH_KEY);
return confStr;
return DataStoreManager.getInstanceByUser(getCurrentAccount()).readString(SettingsManager.FOLDERS_BACKUP_SELECTED_PATH_KEY);
}

public static List<String> readBackupPaths() {
Expand All @@ -130,6 +130,28 @@ public static List<String> readBackupPaths() {
return CollectionUtils.isEmpty(list) ? CollectionUtils.newArrayList() : list;
}

public static long readBackupPathLastScanTime(String absPath) {
String k = SettingsManager.FOLDER_BACKUP_LAST_TIME_PREFIX + EncryptUtils.encryptMD5ToString(absPath);
return DataStoreManager
.getInstanceByUser(getCurrentAccount())
.readLong(k);
}

public static void writeBackupPathLastScanTime(String absPath) {
String k = SettingsManager.FOLDER_BACKUP_LAST_TIME_PREFIX + EncryptUtils.encryptMD5ToString(absPath);

DataStoreManager
.getInstanceByUser(getCurrentAccount())
.writeLong(k, System.currentTimeMillis());
}

public static void clearBackupPathLastScanTime(String absPath) {
String k = SettingsManager.FOLDER_BACKUP_LAST_TIME_PREFIX + EncryptUtils.encryptMD5ToString(absPath);

DataStoreManager
.getInstanceByUser(getCurrentAccount())
.removeByKey(k);
}

public static void writeSkipHiddenFiles(boolean isSkip) {
DataStoreManager.getInstanceByUser(getCurrentAccount()).writeBoolean(SettingsManager.FOLDER_BACKUP_SKIP_HIDDEN_FILES, isSkip);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,17 @@ public final class SettingsManager {
public static final String FOLDER_BACKUP_STATE = gAppContext.getString(R.string.key_folder_backup_state);

public static final String FOLDER_BACKUP_PATHS = "folder_backup_paths";

/**
* The last time the folder backup service was executed
*/
public static final String FOLDER_BACKUP_LAST_TIME = "folder_backup_last_time";

/**
* The last sync time for each backup folder
*/
public static final String FOLDER_BACKUP_LAST_TIME_PREFIX = "folder_backup_last_time_";

/**
* Is it necessary to filter hidden files when the folder backup service is turned on
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.CollectionUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.seafile.seadroid2.framework.datastore.DataManager;
import com.seafile.seadroid2.framework.datastore.StorageManager;
import com.seafile.seadroid2.framework.util.SLogs;
Expand All @@ -19,7 +20,6 @@
import com.seafile.seadroid2.framework.datastore.sp.FolderBackupManager;

import org.apache.commons.io.monitor.FileAlterationListener;
import org.apache.commons.io.monitor.FileAlterationMonitor;
import org.apache.commons.io.monitor.FileAlterationObserver;

import java.io.File;
Expand Down Expand Up @@ -117,10 +117,23 @@ public void onCreate() {

//file upload backup
BackgroundJobManagerImpl.getInstance().startFileUploadWorker();

startFolderMonitor();
if (!NetworkUtils.isRegisteredNetworkStatusChangedListener(networkStatusChangedListener)) {
NetworkUtils.registerNetworkStatusChangedListener(networkStatusChangedListener);
}
}

private final NetworkUtils.OnNetworkStatusChangedListener networkStatusChangedListener = new NetworkUtils.OnNetworkStatusChangedListener() {
@Override
public void onDisconnected() {
SLogs.e("disconnected: " + NetworkUtils.getNetworkType());
}

@Override
public void onConnected(NetworkUtils.NetworkType networkType) {
SLogs.e("connected: " + networkType);
}
};

private final FileFilter FILE_FILTER = file -> {

if (file.getAbsolutePath().startsWith(TEMP_FILE_DIR)) {
Expand All @@ -147,7 +160,7 @@ public void stopFolderMonitor() {
}
}

private void startFolderMonitor() {
public void startFolderMonitor() {
List<String> pathList = FolderBackupManager.readBackupPaths();

boolean isFound = pathList.stream().anyMatch(IGNORE_PATHS::contains);
Expand All @@ -159,7 +172,7 @@ private void startFolderMonitor() {
startFolderMonitor(pathList);
}

public void startFolderMonitor(List<String> pathList) {
private void startFolderMonitor(List<String> pathList) {
if (CollectionUtils.isEmpty(pathList)) {
return;
}
Expand Down Expand Up @@ -199,7 +212,7 @@ public void doBackup(String action, File file) {
// The file has changed: /storage/emulated/0/Android/media/com.seafile.seadroid2/Seafile
if (file.getAbsolutePath().startsWith(IGNORE_PATHS.get(0))) {
if ("change".equals(action)) {
BackgroundJobManagerImpl.getInstance().startDownloadCheckerWorker(file.getAbsolutePath());
BackgroundJobManagerImpl.getInstance().startDownloadedCheckerWorker(file.getAbsolutePath());
}
} else {
BackgroundJobManagerImpl.getInstance().scheduleFolderBackupScannerWorker(true);
Expand Down Expand Up @@ -273,6 +286,10 @@ public void onDestroy() {
if (mediaContentObserver != null) {
mediaContentObserver.unregister();
}

if (NetworkUtils.isRegisteredNetworkStatusChangedListener(networkStatusChangedListener)) {
NetworkUtils.unregisterNetworkStatusChangedListener(networkStatusChangedListener);
}
}

}
57 changes: 29 additions & 28 deletions app/src/main/java/com/seafile/seadroid2/framework/http/BaseIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

public abstract class BaseIO {

private final int DEFAULT_TIME_OUT = 60000;
private final int DEFAULT_TIME_OUT = 120000;
private final File cachePath = SeadroidApplication.getAppContext().getCacheDir();

//cache path
Expand Down Expand Up @@ -158,43 +158,44 @@ public OkHttpClient getClient() {
if (okHttpClient == null) {
synchronized (BaseIO.class) {
if (okHttpClient == null) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();

try {
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();


OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]);
builder.connectionSpecs(Arrays.asList(
ConnectionSpec.MODERN_TLS,
ConnectionSpec.COMPATIBLE_TLS,
ConnectionSpec.CLEARTEXT));
builder.cache(cache);

//cache control
builder.interceptors().add(REWRITE_CACHE_CONTROL_INTERCEPTOR);
builder.networkInterceptors().add(REWRITE_CACHE_CONTROL_INTERCEPTOR);

//add interceptors
List<Interceptor> interceptors = getInterceptors();
if (interceptors != null && !interceptors.isEmpty()) {
for (Interceptor i : interceptors) {
builder.interceptors().add(i);
}
}

//timeout
builder.writeTimeout(DEFAULT_TIME_OUT, TimeUnit.MILLISECONDS);
builder.readTimeout(DEFAULT_TIME_OUT, TimeUnit.MILLISECONDS);
builder.connectTimeout(DEFAULT_TIME_OUT, TimeUnit.MILLISECONDS);

okHttpClient = builder.build();
} catch (Exception e) {
e.printStackTrace();
}

builder.connectionSpecs(Arrays.asList(
ConnectionSpec.MODERN_TLS,
ConnectionSpec.COMPATIBLE_TLS,
ConnectionSpec.CLEARTEXT));
builder.cache(cache);

//cache control
builder.interceptors().add(REWRITE_CACHE_CONTROL_INTERCEPTOR);
builder.networkInterceptors().add(REWRITE_CACHE_CONTROL_INTERCEPTOR);

//add interceptors
List<Interceptor> interceptors = getInterceptors();
if (interceptors != null && !interceptors.isEmpty()) {
for (Interceptor i : interceptors) {
builder.interceptors().add(i);
}
}

//timeout
builder.writeTimeout(DEFAULT_TIME_OUT, TimeUnit.MILLISECONDS);
builder.readTimeout(DEFAULT_TIME_OUT, TimeUnit.MILLISECONDS);
builder.connectTimeout(DEFAULT_TIME_OUT, TimeUnit.MILLISECONDS);

okHttpClient = builder.build();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ public Intent getTransferIntent() {
}

@Override
public String getNotificationTitle() {
String uploading = context.getString(R.string.uploading);
String title = context.getString(R.string.settings_camera_upload_info_title);
return title + " " + uploading;
public String getDefaultTitle() {
return context.getString(R.string.settings_camera_upload_info_title);
}

@Override
public String getDefaultSubtitle() {
return context.getString(R.string.uploading);
}

@Override
Expand Down
Loading

0 comments on commit f5100de

Please sign in to comment.