Skip to content

Commit

Permalink
fix and update
Browse files Browse the repository at this point in the history
- Refactored logic when transferring a large number of files
- trust all certs
zhwanng committed Jun 19, 2024
1 parent 26a36b5 commit 15bd1a2
Showing 49 changed files with 646 additions and 328 deletions.
45 changes: 39 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -3,11 +3,12 @@ plugins {
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
}
def pid = 'com.seafile.seadroid2'

android {

defaultConfig {
applicationId 'com.seafile.seadroid2'
applicationId pid
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
compileSdk rootProject.ext.compileSdkVersion
@@ -89,8 +90,9 @@ android {
applicationVariants.all { variant ->
variant.outputs.all { output ->
if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
if (variant.name == "debug")
if (variant.name == "debug") {
outputFileName = "seafile-debug-" + defaultConfig.versionName + ".apk"
}
}
}
}
@@ -110,15 +112,47 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
applicationVariants.all { variant ->
variant.outputs.all { output ->
if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
if (variant.name == "release") {
outputFileName = "seafile-" + defaultConfig.versionName + ".apk"
if (variant.name == "release") {
if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
def versionName = defaultConfig.versionName

def outputFileName = "${versionName}_snapshot_build_temp.apk"
outputFileName = outputFileName.replace(" ", "_")
output.outputFileName = outputFileName

variant.assemble.doLast {

def buildCountFile = file("$rootDir/build_count.txt")
def buildCount = 0
if (buildCountFile.exists()) {
buildCount = buildCountFile.text.toInteger()
}

buildCount++
buildCountFile.text = buildCount.toString()

if (versionName.contains("-")) {
def prefix = versionName.substring(0, versionName.indexOf("-"))
def suffix = versionName.substring(versionName.indexOf("-") + 1)
versionName = prefix + "(" + suffix + ")"
}

def newOutputFileName = "seafile_${versionName}_build${versionCode}_snapshot${buildCount}.apk"
newOutputFileName = newOutputFileName.replace(" ", "_").replace("-", "_")
def apkFile = output.outputFile
def newApkFile = new File(apkFile.parent, newOutputFileName)

if (apkFile.exists()) {
apkFile.renameTo(newApkFile)
}
}
}
}
}
}
}
}

bundle {
density {
enableSplit true
@@ -253,7 +287,6 @@ android {
// implementation "io.noties.markwon:syntax-highlight:$markwon_version"



implementation 'com.madgag.spongycastle:core:1.54.0.0'
implementation 'com.madgag.spongycastle:prov:1.54.0.0'

2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -266,7 +266,7 @@
<!-- android:name=".ui.camera_upload.MediaSchedulerService"-->
<!-- android:permission="android.permission.BIND_JOB_SERVICE" />-->
<service
android:name=".framework.worker.FileSyncService"
android:name=".framework.file_monitor.FileSyncService"
android:exported="false" />

<receiver
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
import android.content.Context;

import com.seafile.seadroid2.gesturelock.AppLockManager;
import com.seafile.seadroid2.monitor.ActivityMonitor;
import com.seafile.seadroid2.framework.monitor.ActivityMonitor;
import com.seafile.seadroid2.framework.notification.base.NotificationUtils;
import com.seafile.seadroid2.framework.util.CrashHandler;

7 changes: 4 additions & 3 deletions app/src/main/java/com/seafile/seadroid2/SeafException.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.seafile.seadroid2;

import android.content.Context;

import com.google.common.base.MoreObjects;

public class SeafException extends Exception {
@@ -11,7 +9,10 @@ public class SeafException extends Exception {
public static final int HTTP_ABOVE_QUOTA = 443;

private int code;
public static final SeafException SUCCESS = new SeafException(-1, "success");
public static final int CODE_SUCCESS = -1;
public static final int CODE_ERROR = 0;

public static final SeafException SUCCESS = new SeafException(CODE_SUCCESS, "success");

public static final SeafException unknownException = new SeafException(1, "Unknown Error");
public static final SeafException networkException = new SeafException(2, "Network Error");
20 changes: 20 additions & 0 deletions app/src/main/java/com/seafile/seadroid2/config/Constants.java
Original file line number Diff line number Diff line change
@@ -66,4 +66,24 @@ private DP() {
public static final int DP_16 = SizeUtils.dp2px(16);
public static final int DP_32 = SizeUtils.dp2px(32);
}

/**
* <pre>
* {@code
* data status
* 0: normal,
* -1: deleted,
* -2: hidden,
* -3: locked,
* -4: locked and hidden.
* }
* </pre>
*/
public static class DataStatus {
public static final int NORMAL = 0;
public static final int DELETED = -1;
public static final int HIDDEN = -2;
public static final int LOCKED = -3;
public static final int LOCKED_AND_HIDDEN = -4;
}
}
7 changes: 7 additions & 0 deletions app/src/main/java/com/seafile/seadroid2/config/RepoType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.seafile.seadroid2.config;

public class RepoType {
public static final String TYPE_MINE = "mine";
public static final String TYPE_SHARED = "shared";
public static final String TYPE_GROUP = "group";
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.seafile.seadroid2.framework.data.db;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;

import com.seafile.seadroid2.SeadroidApplication;
import com.seafile.seadroid2.framework.data.db.dao.CertCacheDAO;
@@ -28,7 +31,7 @@
CertEntity.class,
FileTransferEntity.class,
StarredModel.class
}, version = 1, exportSchema = false)
}, version = 2, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
private static final String DATABASE_NAME = "seafile_room.db";
private static volatile AppDatabase _instance;
@@ -39,23 +42,38 @@ public static AppDatabase getInstance() {
if (_instance == null) {
_instance = Room
.databaseBuilder(SeadroidApplication.getAppContext(), AppDatabase.class, DATABASE_NAME)
.addMigrations(MIGRATION_1_2)
.build();
}
}
}
return _instance;
}

static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
//drop table
database.execSQL("DROP TABLE IF EXISTS repos");

// create table
database.execSQL("CREATE TABLE repos (repo_id TEXT NOT NULL, repo_name TEXT, type TEXT, group_id INTEGER NOT NULL DEFAULT 0, group_name TEXT, owner_name TEXT, owner_email TEXT, owner_contact_email TEXT, modifier_email TEXT, modifier_name TEXT, modifier_contact_email TEXT, related_account TEXT, last_modified TEXT, encrypted INTEGER NOT NULL DEFAULT 0, size INTEGER NOT NULL DEFAULT 0, starred INTEGER NOT NULL DEFAULT 0, permission TEXT, monitored INTEGER NOT NULL DEFAULT 0, is_admin INTEGER NOT NULL DEFAULT 0, salt TEXT, status TEXT, last_modified_long INTEGER NOT NULL DEFAULT 0, root TEXT, magic TEXT, random_key TEXT, enc_version INTEGER NOT NULL DEFAULT 0, file_count INTEGER NOT NULL DEFAULT 0,v INTEGER NOT NULL DEFAULT 1,data_status INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(repo_id, group_id))");
}
};


public abstract RepoDAO repoDao();

public abstract DirentDAO direntDao();

public abstract StarredDirentDAO starredDirentDAO();

public abstract EncKeyCacheDAO encKeyCacheDAO();

public abstract CertCacheDAO certDAO();

public abstract FolderBackupMonitorDAO folderBackupMonitorDAO();

public abstract FileTransferDAO fileTransferDAO();

}
Original file line number Diff line number Diff line change
@@ -29,11 +29,11 @@ public interface FileTransferDAO {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(FileTransferEntity entity);

@Query("DELETE FROM file_transfer_list where transfer_action = :transfer_action")
void deleteAllByAction(TransferAction transfer_action);
@Query("DELETE FROM file_transfer_list where related_account = :related_account and transfer_action = :transfer_action")
void deleteAllByAction(String related_account, TransferAction transfer_action);

@Query("DELETE FROM file_transfer_list where transfer_action = :transfer_action")
Completable deleteAllByActionAsync(TransferAction transfer_action);
@Query("DELETE FROM file_transfer_list where related_account = :related_account and transfer_action = :transfer_action")
Completable deleteAllByActionAsync(String related_account, TransferAction transfer_action);

@Query("DELETE FROM file_transfer_list where uid = :uid")
Completable deleteAsyncById(String uid);
@@ -72,6 +72,9 @@ public interface FileTransferDAO {
@Query("update file_transfer_list set transfer_status = 'CANCELLED', transfer_result = :result where data_source = 'FILE_BACKUP' and transfer_status in ('IN_PROGRESS','WAITING')")
void cancelWithFileBackup(TransferResult result);

@Query("update file_transfer_list set transfer_status = 'CANCELLED', transfer_result = 'CANCELLED', data_status = -1, transferred_size = 0 where data_source in ('FILE_BACKUP','FOLDER_BACKUP')")
void cancelAllWithFileBackup();

@Query("select * from file_transfer_list where related_account = :related_account and data_source in ( :feats ) and data_status = 0 order by created_at asc")
Single<List<FileTransferEntity>> getListByFeatAsync(String related_account, List<TransferDataSource> feats);

@@ -85,9 +88,17 @@ public interface FileTransferDAO {
@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")
@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")
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);

@@ -110,20 +121,23 @@ 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")
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 related_account = :related_account and transfer_action = :transferAction and full_path = :full_path and data_status = 0 order by created_at")
List<FileTransferEntity> getListByFullPathsSync(String related_account, TransferAction transferAction, String full_path);
List<FileTransferEntity> getListByFullPathSync(String related_account, TransferAction transferAction, String full_path);

@Query("select COUNT(*) from file_transfer_list where repo_id = :repoId and full_path = :fullPath and transfer_action = :transfer_action and data_source = :feature and data_status = 0 ")
int checkOneByFullPath(String repoId, String fullPath, TransferAction transfer_action, TransferDataSource feature);


@RawQuery
int updateEntityStatus(SupportSQLiteQuery query);

@Query("select COUNT(*) from file_transfer_list where related_account = :related_account and transfer_action = :transferAction and data_source = :feature and transfer_status in (:transferStatus) and data_status = 0 order by created_at asc")
Single<Integer> getCount(String related_account, TransferAction transferAction, TransferDataSource feature, List<TransferStatus> transferStatus);


}
Original file line number Diff line number Diff line change
@@ -14,14 +14,15 @@
import com.seafile.seadroid2.framework.datastore.sp.SettingsManager;
import com.seafile.seadroid2.framework.util.Utils;

@Entity(tableName = "repos")
@Entity(tableName = "repos",primaryKeys = {"repo_id","group_id"})
public class RepoModel extends BaseModel {
@PrimaryKey

@NonNull
public String repo_id = "";
public String repo_name; //repo_name

public String type; //mine\group\shared

public long group_id;
public String group_name;

Original file line number Diff line number Diff line change
@@ -24,17 +24,9 @@ public class BaseModel {
*/
public int v = 1;


/**
* <pre>
* {@code
* data status
* 0: normal,
* -1: deleted,
* -2: hidden,
* -3: locked,
* -4: locked and hidden.
* }
* </pre>
* @see com.seafile.seadroid2.config.Constants.DataStatus
*/
public int data_status = 0;

Loading

0 comments on commit 15bd1a2

Please sign in to comment.