From 5e3a56cd6a115b456e38a09f94a10db7cbe889f3 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 24 Mar 2022 11:20:05 +0100 Subject: [PATCH 1/3] rename properties to fit with a single naming convention --- .../e/drive/services/InitializerService.java | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 6b208015..15291935 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -52,10 +52,10 @@ public class InitializerService extends Service implements OnRemoteOperationList private final String TAG = InitializerService.class.getSimpleName(); private int existingRemoteFolderCounter; //Temporarily used to know if all remotePath exist - private List mSyncedFolders; - private OwnCloudClient mCloudClient; - private Handler mHandler; - private Account mAccount; + private List syncedFolders; + private OwnCloudClient cloudClient; + private Handler handler; + private Account account; private int restartFolderCreationCounter =0; @Override @@ -95,10 +95,10 @@ public class InitializerService extends Service implements OnRemoteOperationList Log.w(TAG, "Account's name not found. Neither in shared prefs nor in intent's extras"); stopSelf(); } else { - this.mAccount = CommonUtils.getAccount( accountName, accountType, AccountManager.get(this) ); + this.account = CommonUtils.getAccount( accountName, accountType, AccountManager.get(this) ); //Get OwnCloudlient - if (this.mAccount != null) { - this.mCloudClient = CommonUtils.getOwnCloudClient( this.mAccount, getApplicationContext()); + if (this.account != null) { + this.cloudClient = CommonUtils.getOwnCloudClient( this.account, getApplicationContext()); start(); } else { Log.w(TAG, "Got account is invalid."); @@ -116,18 +116,18 @@ public class InitializerService extends Service implements OnRemoteOperationList public void start() { Log.i(TAG, "start()"); - if (mCloudClient == null){ + if (cloudClient == null){ stopSelf(); return; } List syncCategories = new ArrayList<>(); - if (CommonUtils.isMediaSyncEnabled(mAccount)) { + if (CommonUtils.isMediaSyncEnabled(account)) { syncCategories.addAll(Arrays.asList(MEDIA_SYNCABLE_CATEGORIES)); } - if (CommonUtils.isSettingsSyncEnabled(mAccount)) { + if (CommonUtils.isSettingsSyncEnabled(account)) { syncCategories.addAll(Arrays.asList(SETTINGS_SYNCABLE_CATEGORIES)); } @@ -145,7 +145,7 @@ public class InitializerService extends Service implements OnRemoteOperationList private void getInitialSyncedFolders( List categories){ Log.i(TAG, "getInitialSyncedFolders"); - this.mSyncedFolders = new ArrayList<>(); + this.syncedFolders = new ArrayList<>(); for(int i=-1, size = categories.size(); ++i < size;){ final String DEVICE_SPECIFIC_PATH = PATH_SEPARATOR+"Devices"+PATH_SEPARATOR+ Build.BRAND+"_"+ Build.MODEL+"_" @@ -154,36 +154,36 @@ public class InitializerService extends Service implements OnRemoteOperationList case "Medias": break; case "Images": - mSyncedFolders.add( new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_DCIM), + syncedFolders.add( new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_DCIM), "/Photos/", true) ); - mSyncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_PICTURES), + syncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_PICTURES), "/Pictures/", true ) ); break; case "Movies": - mSyncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_MOVIES), + syncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_MOVIES), "/Movies/", true)); break; case "Music": - mSyncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_MUSIC), + syncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_MUSIC), "/Music/", true)); break; case "Ringtones": - mSyncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_RINGTONES), + syncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_RINGTONES), "/Ringtones/", true)); break; case "Documents": - mSyncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_DOCUMENTS), + syncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_DOCUMENTS), "/Documents/", true)); break; case "Podcasts": - mSyncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_PODCASTS), + syncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_PODCASTS), "/Podcasts/", true)); break; case "Rom settings": String remoteFolderPath = DEVICE_SPECIFIC_PATH+"/rom_settings/"; - mSyncedFolders.add( new SyncedFolder(categories.get(i), "/data/system/users/0/", remoteFolderPath, true, false, true, false) ); + syncedFolders.add( new SyncedFolder(categories.get(i), "/data/system/users/0/", remoteFolderPath, true, false, true, false) ); try{ - mSyncedFolders.add( new SyncedFolder( + syncedFolders.add( new SyncedFolder( categories.get(i), getFilesDir().getCanonicalPath()+PATH_SEPARATOR, remoteFolderPath+"app_list/", @@ -208,29 +208,29 @@ public class InitializerService extends Service implements OnRemoteOperationList Log.i(TAG, "createNextRemoteFolder()"); this.restartFolderCreationCounter = 0; - if (this.mSyncedFolders == null || this.mSyncedFolders.isEmpty() ){ + if (this.syncedFolders == null || this.syncedFolders.isEmpty() ){ this.stopSelf(); } //It means that there are still folders to create - if (this.existingRemoteFolderCounter < this.mSyncedFolders.size() ){ + if (this.existingRemoteFolderCounter < this.syncedFolders.size() ){ - if (this.mHandler == null ) this.mHandler = new Handler(); + if (this.handler == null ) this.handler = new Handler(); CreateInitialFolderRemoteOperation createFolderOperation = new CreateInitialFolderRemoteOperation( - this.mSyncedFolders.get( this.existingRemoteFolderCounter ), + this.syncedFolders.get( this.existingRemoteFolderCounter ), true, this); - createFolderOperation.execute(this.mCloudClient, this, this.mHandler); + createFolderOperation.execute(this.cloudClient, this, this.handler); - } else if (this.existingRemoteFolderCounter == this.mSyncedFolders.size() ){ + } else if (this.existingRemoteFolderCounter == this.syncedFolders.size() ){ doLastStep(); } else { - Log.e(TAG, "this.existingRemoteFolderCounter : "+this.existingRemoteFolderCounter+" > this.mSyncedFolders.size() : "+this.mSyncedFolders.size() ); + Log.e(TAG, "this.existingRemoteFolderCounter : "+this.existingRemoteFolderCounter+" > this.mSyncedFolders.size() : "+this.syncedFolders.size() ); this.stopSelf(); } } @@ -249,7 +249,7 @@ public class InitializerService extends Service implements OnRemoteOperationList if (this.restartFolderCreationCounter < 3) { Log.w( TAG, " restart operation" ); - operation.execute( this.mCloudClient, this, this.mHandler ); + operation.execute( this.cloudClient, this, this.handler); this.restartFolderCreationCounter+=1; } else { @@ -275,7 +275,7 @@ public class InitializerService extends Service implements OnRemoteOperationList Context.MODE_PRIVATE ) .edit() .putBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, true) - .putInt( INITIALFOLDERS_NUMBER, mSyncedFolders.size() ) + .putInt( INITIALFOLDERS_NUMBER, syncedFolders.size() ) .apply(); CommonUtils.registerPeriodicFullScanWorker(WorkManager.getInstance(appContext)); @@ -296,11 +296,11 @@ public class InitializerService extends Service implements OnRemoteOperationList @Override public void onDestroy() { super.onDestroy(); - this.mHandler = null; - this.mAccount = null; - this.mCloudClient = null; - if(this.mSyncedFolders != null) this.mSyncedFolders.clear(); - this.mSyncedFolders = null; + this.handler = null; + this.account = null; + this.cloudClient = null; + if(this.syncedFolders != null) this.syncedFolders.clear(); + this.syncedFolders = null; } @Nullable -- GitLab From c71009fa2e81c5487a27eebb99440f55d0850b83 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 24 Mar 2022 11:22:14 +0100 Subject: [PATCH 2/3] fix coding style for if/else and brackets --- .../e/drive/services/InitializerService.java | 92 +++++++++---------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index 15291935..bf1c5e06 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -25,7 +25,6 @@ import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -36,7 +35,6 @@ import foundation.e.drive.operations.CreateInitialFolderRemoteOperation; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; - import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR; import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; import static foundation.e.drive.utils.AppConstants.MEDIA_SYNCABLE_CATEGORIES; @@ -66,39 +64,39 @@ public class InitializerService extends Service implements OnRemoteOperationList } @Override - public int onStartCommand( Intent intent, int flags, int startId ) { + public int onStartCommand(Intent intent, int flags, int startId) { Log.i(TAG, "onStartCommand(...)"); CommonUtils.setServiceUnCaughtExceptionHandler(this); //Get account - SharedPreferences prefs = this.getSharedPreferences( AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE ); + SharedPreferences prefs = this.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); - if (prefs.getBoolean( AppConstants.INITIALIZATION_HAS_BEEN_DONE, false ) ) { + if (prefs.getBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false)) { Log.w(TAG, "Initializer has already been run"); } else { - String accountName = prefs.getString( AccountManager.KEY_ACCOUNT_NAME, "" ); - String accountType = prefs.getString( AccountManager.KEY_ACCOUNT_TYPE, "" ); + String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, ""); + String accountType = prefs.getString(AccountManager.KEY_ACCOUNT_TYPE, ""); - if ( accountName.isEmpty() && accountType.isEmpty() && intent.getExtras() != null ) { + if (accountName.isEmpty() && accountType.isEmpty() && intent.getExtras() != null) { - accountName = intent.getExtras().getString( AccountManager.KEY_ACCOUNT_NAME, "" ); - accountType = intent.getExtras().getString( AccountManager.KEY_ACCOUNT_TYPE, "" ); + accountName = intent.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME, ""); + accountType = intent.getExtras().getString(AccountManager.KEY_ACCOUNT_TYPE, ""); - prefs.edit().putString( AccountManager.KEY_ACCOUNT_NAME, accountName ) - .putString( AccountManager.KEY_ACCOUNT_TYPE, accountType ) + prefs.edit().putString(AccountManager.KEY_ACCOUNT_NAME, accountName) + .putString(AccountManager.KEY_ACCOUNT_TYPE, accountType) .apply(); } - if (accountName.isEmpty() ) { + if (accountName.isEmpty()) { Log.w(TAG, "Account's name not found. Neither in shared prefs nor in intent's extras"); stopSelf(); } else { - this.account = CommonUtils.getAccount( accountName, accountType, AccountManager.get(this) ); + this.account = CommonUtils.getAccount(accountName, accountType, AccountManager.get(this)); //Get OwnCloudlient if (this.account != null) { - this.cloudClient = CommonUtils.getOwnCloudClient( this.account, getApplicationContext()); + this.cloudClient = CommonUtils.getOwnCloudClient(this.account, getApplicationContext()); start(); } else { Log.w(TAG, "Got account is invalid."); @@ -116,7 +114,7 @@ public class InitializerService extends Service implements OnRemoteOperationList public void start() { Log.i(TAG, "start()"); - if (cloudClient == null){ + if (cloudClient == null) { stopSelf(); return; } @@ -142,22 +140,22 @@ public class InitializerService extends Service implements OnRemoteOperationList * Return a list of SyncedFolder * @param categories categories indicating which syncedFolder to create */ - private void getInitialSyncedFolders( List categories){ + private void getInitialSyncedFolders(List categories) { Log.i(TAG, "getInitialSyncedFolders"); this.syncedFolders = new ArrayList<>(); - for(int i=-1, size = categories.size(); ++i < size;){ + for(int i=-1, size = categories.size(); ++i < size;) { final String DEVICE_SPECIFIC_PATH = PATH_SEPARATOR+"Devices"+PATH_SEPARATOR+ Build.BRAND+"_"+ Build.MODEL+"_" + Build.SERIAL; - switch ( categories.get(i) ){ + switch (categories.get(i)) { case "Medias": break; case "Images": - syncedFolders.add( new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_DCIM), - "/Photos/", true) ); + syncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_DCIM), + "/Photos/", true)); syncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_PICTURES), - "/Pictures/", true ) ); + "/Pictures/", true)); break; case "Movies": syncedFolders.add(new SyncedFolder(categories.get(i), getExternalFolder(Environment.DIRECTORY_MOVIES), @@ -181,56 +179,56 @@ public class InitializerService extends Service implements OnRemoteOperationList break; case "Rom settings": String remoteFolderPath = DEVICE_SPECIFIC_PATH+"/rom_settings/"; - syncedFolders.add( new SyncedFolder(categories.get(i), "/data/system/users/0/", remoteFolderPath, true, false, true, false) ); + syncedFolders.add(new SyncedFolder(categories.get(i), "/data/system/users/0/", remoteFolderPath, true, false, true, false)); try{ - syncedFolders.add( new SyncedFolder( + syncedFolders.add(new SyncedFolder( categories.get(i), getFilesDir().getCanonicalPath()+PATH_SEPARATOR, remoteFolderPath+"app_list/", true, false, true, - false) ); - } catch (Exception e){ Log.e(TAG, e.toString()); } + false)); + } catch (Exception e) { Log.e(TAG, e.toString()); } break; } } } - private String getExternalFolder(String directory){ + private String getExternalFolder(String directory) { return CommonUtils.getLocalPath(Environment.getExternalStoragePublicDirectory(directory))+ PATH_SEPARATOR; } /** * Start to createSyncedFolder in the cloud */ - private void CreateNextRemoteFolder(){ + private void CreateNextRemoteFolder() { Log.i(TAG, "createNextRemoteFolder()"); this.restartFolderCreationCounter = 0; - if (this.syncedFolders == null || this.syncedFolders.isEmpty() ){ + if (this.syncedFolders == null || this.syncedFolders.isEmpty()) { this.stopSelf(); } //It means that there are still folders to create - if (this.existingRemoteFolderCounter < this.syncedFolders.size() ){ + if (this.existingRemoteFolderCounter < this.syncedFolders.size()) { - if (this.handler == null ) this.handler = new Handler(); + if (this.handler == null) this.handler = new Handler(); CreateInitialFolderRemoteOperation createFolderOperation = new CreateInitialFolderRemoteOperation( - this.syncedFolders.get( this.existingRemoteFolderCounter ), + this.syncedFolders.get(this.existingRemoteFolderCounter), true, this); createFolderOperation.execute(this.cloudClient, this, this.handler); - } else if (this.existingRemoteFolderCounter == this.syncedFolders.size() ){ + } else if (this.existingRemoteFolderCounter == this.syncedFolders.size()) { doLastStep(); } else { - Log.e(TAG, "this.existingRemoteFolderCounter : "+this.existingRemoteFolderCounter+" > this.mSyncedFolders.size() : "+this.syncedFolders.size() ); + Log.e(TAG, "this.existingRemoteFolderCounter : "+this.existingRemoteFolderCounter+" > this.mSyncedFolders.size() : "+this.syncedFolders.size()); this.stopSelf(); } } @@ -238,18 +236,18 @@ public class InitializerService extends Service implements OnRemoteOperationList @Override public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { Log.i(TAG, "onRemoteOperationFinish()"); - if (operation instanceof CreateInitialFolderRemoteOperation){ + if (operation instanceof CreateInitialFolderRemoteOperation) { - if (result.isSuccess() || result.getCode() == RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS){ + if (result.isSuccess() || result.getCode() == RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS) { this.existingRemoteFolderCounter+=1; CreateNextRemoteFolder(); - } else if (result.getHttpCode() == 423 || result.getHttpCode() == 409){//file locked or conflict in result - Log.e( TAG, result.getLogMessage() ); + } else if (result.getHttpCode() == 423 || result.getHttpCode() == 409) {//file locked or conflict in result + Log.e(TAG, result.getLogMessage()); if (this.restartFolderCreationCounter < 3) { - Log.w( TAG, " restart operation" ); - operation.execute( this.cloudClient, this, this.handler); + Log.w(TAG, " restart operation"); + operation.execute(this.cloudClient, this, this.handler); this.restartFolderCreationCounter+=1; } else { @@ -258,7 +256,7 @@ public class InitializerService extends Service implements OnRemoteOperationList } } else { - Log.e(TAG, result.getLogMessage()+" "+result.getHttpCode() ); + Log.e(TAG, result.getLogMessage()+" "+result.getHttpCode()); stopSelf(); } } @@ -268,20 +266,20 @@ public class InitializerService extends Service implements OnRemoteOperationList /** * Function to check if all remote folder have been created **/ - private void doLastStep(){ + private void doLastStep() { Log.i(TAG, "doLastStep()"); final Context appContext = getApplicationContext(); - appContext.getSharedPreferences( AppConstants.SHARED_PREFERENCE_NAME, - Context.MODE_PRIVATE ) + appContext.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, + Context.MODE_PRIVATE) .edit() .putBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, true) - .putInt( INITIALFOLDERS_NUMBER, syncedFolders.size() ) + .putInt(INITIALFOLDERS_NUMBER, syncedFolders.size()) .apply(); CommonUtils.registerPeriodicFullScanWorker(WorkManager.getInstance(appContext)); //all folder have been created - ((EdriveApplication) this.getApplication() ).startRecursiveFileObserver(); + ((EdriveApplication) this.getApplication()).startRecursiveFileObserver(); Intent SynchronizationServiceIntent = new Intent(getApplicationContext(), foundation.e.drive.services.SynchronizationService.class); startService(SynchronizationServiceIntent); @@ -299,7 +297,7 @@ public class InitializerService extends Service implements OnRemoteOperationList this.handler = null; this.account = null; this.cloudClient = null; - if(this.syncedFolders != null) this.syncedFolders.clear(); + if (this.syncedFolders != null) this.syncedFolders.clear(); this.syncedFolders = null; } -- GitLab From 11d96bd80356072d100cd5faf6ad4bbfd773c704 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 24 Mar 2022 11:25:25 +0100 Subject: [PATCH 3/3] remove useless comments and spaces --- .../e/drive/services/InitializerService.java | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java index bf1c5e06..ef08ccb2 100644 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ b/app/src/main/java/foundation/e/drive/services/InitializerService.java @@ -71,9 +71,7 @@ public class InitializerService extends Service implements OnRemoteOperationList //Get account SharedPreferences prefs = this.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); - if (prefs.getBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false)) { - Log.w(TAG, "Initializer has already been run"); } else { String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, ""); @@ -107,11 +105,6 @@ public class InitializerService extends Service implements OnRemoteOperationList return super.onStartCommand(intent, flags, startId); } - - /** - * start to do its job - */ - public void start() { Log.i(TAG, "start()"); if (cloudClient == null) { @@ -134,7 +127,7 @@ public class InitializerService extends Service implements OnRemoteOperationList this.existingRemoteFolderCounter = 0; CreateNextRemoteFolder(); - } + } /** * Return a list of SyncedFolder @@ -190,7 +183,7 @@ public class InitializerService extends Service implements OnRemoteOperationList true, false)); } catch (Exception e) { Log.e(TAG, e.toString()); } - break; + break; } } } @@ -199,9 +192,6 @@ public class InitializerService extends Service implements OnRemoteOperationList return CommonUtils.getLocalPath(Environment.getExternalStoragePublicDirectory(directory))+ PATH_SEPARATOR; } - /** - * Start to createSyncedFolder in the cloud - */ private void CreateNextRemoteFolder() { Log.i(TAG, "createNextRemoteFolder()"); this.restartFolderCreationCounter = 0; @@ -212,7 +202,6 @@ public class InitializerService extends Service implements OnRemoteOperationList //It means that there are still folders to create if (this.existingRemoteFolderCounter < this.syncedFolders.size()) { - if (this.handler == null) this.handler = new Handler(); CreateInitialFolderRemoteOperation createFolderOperation = @@ -224,9 +213,7 @@ public class InitializerService extends Service implements OnRemoteOperationList createFolderOperation.execute(this.cloudClient, this, this.handler); } else if (this.existingRemoteFolderCounter == this.syncedFolders.size()) { - doLastStep(); - } else { Log.e(TAG, "this.existingRemoteFolderCounter : "+this.existingRemoteFolderCounter+" > this.mSyncedFolders.size() : "+this.syncedFolders.size()); this.stopSelf(); @@ -249,12 +236,10 @@ public class InitializerService extends Service implements OnRemoteOperationList Log.w(TAG, " restart operation"); operation.execute(this.cloudClient, this, this.handler); this.restartFolderCreationCounter+=1; - } else { Log.e(TAG, "Remote folder's creation failed due to conflict with server"); stopSelf(); } - } else { Log.e(TAG, result.getLogMessage()+" "+result.getHttpCode()); stopSelf(); -- GitLab