Loading app/src/main/AndroidManifest.xml +1 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" /> <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" /> <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" /> <uses-permission android:name="foundation.e.pwaplayer.provider.READ_WRITE" /> <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission" /> Loading app/src/main/java/foundation/e/drive/utils/AppConstants.java +0 −1 Original line number Diff line number Diff line Loading @@ -28,7 +28,6 @@ public abstract class AppConstants { public static final String INITIALIZATION_HAS_BEEN_DONE = "initService_has_run"; public static final String INITIALFOLDERS_NUMBER = "initial_folder_number"; public static final String APPLICATIONS_LIST_FILE_NAME = "packages_list.csv"; public static final String APPLICATIONS_LIST_FILE_NAME_TMP = "tmp_packages_list.csv"; public static final String SHARED_PREFERENCE_NAME = "preferences"; public static final String KEY_LAST_SYNC_TIME = "lastSyncTimestamp"; Loading app/src/main/java/foundation/e/drive/work/FirstStartWorker.java +10 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ package foundation.e.drive.work; import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; import static foundation.e.drive.work.WorkRequestFactory.WorkType.ONE_TIME_APP_LIST; import static foundation.e.drive.work.WorkRequestFactory.WorkType.PERIODIC_SCAN; import android.content.Context; Loading Loading @@ -41,6 +42,9 @@ public class FirstStartWorker extends Worker { public Result doWork() { Timber.v("FirstStartWorker.doWork()"); final Context appContext = getApplicationContext(); generateFirstAppListFile(appContext); appContext.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE) .edit() Loading @@ -58,6 +62,12 @@ public class FirstStartWorker extends Worker { return Result.success(); } private void generateFirstAppListFile(@NonNull final Context context) { final WorkManager workManager = WorkManager.getInstance(context); workManager.enqueue(WorkRequestFactory.getOneTimeWorkRequest(ONE_TIME_APP_LIST, null)); } private void registerPeriodicWork(@NonNull final Context context) { final WorkManager workManager = WorkManager.getInstance(context); Loading app/src/main/java/foundation/e/drive/work/ListAppsWorker.java +9 −7 Original line number Diff line number Diff line Loading @@ -32,9 +32,10 @@ import timber.log.Timber; * @author vincent Bourgmayer */ public class ListAppsWorker extends Worker { private final static String PWA_PLAYER = "content://foundation.e.pwaplayer.provider/pwa"; private final static String SEPARATOR =","; private final static String PWA_SECTION_SEPARATOR = "\n---- PWAs ----\n"; private static final String PWA_PLAYER = "content://foundation.e.pwaplayer.provider/pwa"; private static final String SEPARATOR = ","; private static final String PWA_SECTION_SEPARATOR = "\n---- PWAs ----\n"; private static final String APPLICATIONS_LIST_FILE_NAME_TMP = ".tmp_packages_list.csv"; public ListAppsWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); Loading Loading @@ -66,6 +67,7 @@ public class ListAppsWorker extends Worker { } private void listPWAs(@NonNull final Context context, @NonNull final StringBuilder stringBuilder) { Timber.v("ListPWAs"); final Cursor cursor = context.getContentResolver().query( Uri.parse(PWA_PLAYER), null, null, null, null); Loading @@ -73,7 +75,7 @@ public class ListAppsWorker extends Worker { stringBuilder.append(PWA_SECTION_SEPARATOR); cursor.moveToFirst(); Timber.v("Writing list of PWA"); do { try { final String pwaTitle = cursor.getString(cursor.getColumnIndexOrThrow("title")); Loading @@ -95,12 +97,12 @@ public class ListAppsWorker extends Worker { } private boolean writeToFile(@NonNull final StringBuilder fileContents) { try (final FileOutputStream tmp = getApplicationContext().openFileOutput(AppConstants.APPLICATIONS_LIST_FILE_NAME_TMP, Context.MODE_PRIVATE); try (final FileOutputStream tmp = getApplicationContext().openFileOutput(APPLICATIONS_LIST_FILE_NAME_TMP, Context.MODE_PRIVATE); ) { tmp.write(fileContents.toString().getBytes()); final String filesDir = getApplicationContext().getFilesDir().getCanonicalPath() + PATH_SEPARATOR; final File tmp_file = new File(filesDir+AppConstants.APPLICATIONS_LIST_FILE_NAME_TMP); final File tmp_file = new File(filesDir + APPLICATIONS_LIST_FILE_NAME_TMP); final File real_file = new File(filesDir + AppConstants.APPLICATIONS_LIST_FILE_NAME); if (tmp_file.length() != real_file.length()) { Loading app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java +17 −13 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import androidx.work.Constraints; import androidx.work.Data; import androidx.work.NetworkType; import androidx.work.OneTimeWorkRequest; import androidx.work.OutOfQuotaPolicy; import androidx.work.PeriodicWorkRequest; import java.security.InvalidParameterException; Loading Loading @@ -122,13 +123,17 @@ public class WorkRequestFactory { } } /** * Create a workRequest to generate file which contains list of installed apps * @param expedited if request is expedited * @return the workRequest */ private static OneTimeWorkRequest createOneTimeAppListGenerationWorkRequest() { final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(ListAppsWorker.class) .setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) final OneTimeWorkRequest.Builder builder = new OneTimeWorkRequest.Builder(ListAppsWorker.class); return builder.setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) .addTag(AppConstants.WORK_GENERIC_TAG) .build(); return workRequest; } /** Loading @@ -140,13 +145,12 @@ public class WorkRequestFactory { private static OneTimeWorkRequest createOneTimeFullScanWorkRequest() { final Constraints constraints = createUnmeteredNetworkAndHighBatteryConstraints(); final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(FullScanWorker.class) .setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) final OneTimeWorkRequest.Builder builder = new OneTimeWorkRequest.Builder(FullScanWorker.class); return builder.setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) .setConstraints(constraints) .addTag(AppConstants.WORK_GENERIC_TAG) .build(); return workRequest; } Loading @@ -157,13 +161,13 @@ public class WorkRequestFactory { private static OneTimeWorkRequest createOneTimeGetUserInfoWorkRequest() { final Constraints constraints = createUnmeteredNetworkAndHighBatteryConstraints(); final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(AccountUserInfoWorker.class) .setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) final OneTimeWorkRequest.Builder builder = new OneTimeWorkRequest.Builder(AccountUserInfoWorker.class); return builder.setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) .addTag(AppConstants.WORK_GENERIC_TAG) .addTag(AppConstants.WORK_INITIALIZATION_TAG) .setConstraints(constraints) .build(); return workRequest; } /** Loading Loading
app/src/main/AndroidManifest.xml +1 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" /> <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" /> <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" /> <uses-permission android:name="foundation.e.pwaplayer.provider.READ_WRITE" /> <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission" /> Loading
app/src/main/java/foundation/e/drive/utils/AppConstants.java +0 −1 Original line number Diff line number Diff line Loading @@ -28,7 +28,6 @@ public abstract class AppConstants { public static final String INITIALIZATION_HAS_BEEN_DONE = "initService_has_run"; public static final String INITIALFOLDERS_NUMBER = "initial_folder_number"; public static final String APPLICATIONS_LIST_FILE_NAME = "packages_list.csv"; public static final String APPLICATIONS_LIST_FILE_NAME_TMP = "tmp_packages_list.csv"; public static final String SHARED_PREFERENCE_NAME = "preferences"; public static final String KEY_LAST_SYNC_TIME = "lastSyncTimestamp"; Loading
app/src/main/java/foundation/e/drive/work/FirstStartWorker.java +10 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ package foundation.e.drive.work; import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; import static foundation.e.drive.work.WorkRequestFactory.WorkType.ONE_TIME_APP_LIST; import static foundation.e.drive.work.WorkRequestFactory.WorkType.PERIODIC_SCAN; import android.content.Context; Loading Loading @@ -41,6 +42,9 @@ public class FirstStartWorker extends Worker { public Result doWork() { Timber.v("FirstStartWorker.doWork()"); final Context appContext = getApplicationContext(); generateFirstAppListFile(appContext); appContext.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE) .edit() Loading @@ -58,6 +62,12 @@ public class FirstStartWorker extends Worker { return Result.success(); } private void generateFirstAppListFile(@NonNull final Context context) { final WorkManager workManager = WorkManager.getInstance(context); workManager.enqueue(WorkRequestFactory.getOneTimeWorkRequest(ONE_TIME_APP_LIST, null)); } private void registerPeriodicWork(@NonNull final Context context) { final WorkManager workManager = WorkManager.getInstance(context); Loading
app/src/main/java/foundation/e/drive/work/ListAppsWorker.java +9 −7 Original line number Diff line number Diff line Loading @@ -32,9 +32,10 @@ import timber.log.Timber; * @author vincent Bourgmayer */ public class ListAppsWorker extends Worker { private final static String PWA_PLAYER = "content://foundation.e.pwaplayer.provider/pwa"; private final static String SEPARATOR =","; private final static String PWA_SECTION_SEPARATOR = "\n---- PWAs ----\n"; private static final String PWA_PLAYER = "content://foundation.e.pwaplayer.provider/pwa"; private static final String SEPARATOR = ","; private static final String PWA_SECTION_SEPARATOR = "\n---- PWAs ----\n"; private static final String APPLICATIONS_LIST_FILE_NAME_TMP = ".tmp_packages_list.csv"; public ListAppsWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); Loading Loading @@ -66,6 +67,7 @@ public class ListAppsWorker extends Worker { } private void listPWAs(@NonNull final Context context, @NonNull final StringBuilder stringBuilder) { Timber.v("ListPWAs"); final Cursor cursor = context.getContentResolver().query( Uri.parse(PWA_PLAYER), null, null, null, null); Loading @@ -73,7 +75,7 @@ public class ListAppsWorker extends Worker { stringBuilder.append(PWA_SECTION_SEPARATOR); cursor.moveToFirst(); Timber.v("Writing list of PWA"); do { try { final String pwaTitle = cursor.getString(cursor.getColumnIndexOrThrow("title")); Loading @@ -95,12 +97,12 @@ public class ListAppsWorker extends Worker { } private boolean writeToFile(@NonNull final StringBuilder fileContents) { try (final FileOutputStream tmp = getApplicationContext().openFileOutput(AppConstants.APPLICATIONS_LIST_FILE_NAME_TMP, Context.MODE_PRIVATE); try (final FileOutputStream tmp = getApplicationContext().openFileOutput(APPLICATIONS_LIST_FILE_NAME_TMP, Context.MODE_PRIVATE); ) { tmp.write(fileContents.toString().getBytes()); final String filesDir = getApplicationContext().getFilesDir().getCanonicalPath() + PATH_SEPARATOR; final File tmp_file = new File(filesDir+AppConstants.APPLICATIONS_LIST_FILE_NAME_TMP); final File tmp_file = new File(filesDir + APPLICATIONS_LIST_FILE_NAME_TMP); final File real_file = new File(filesDir + AppConstants.APPLICATIONS_LIST_FILE_NAME); if (tmp_file.length() != real_file.length()) { Loading
app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java +17 −13 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import androidx.work.Constraints; import androidx.work.Data; import androidx.work.NetworkType; import androidx.work.OneTimeWorkRequest; import androidx.work.OutOfQuotaPolicy; import androidx.work.PeriodicWorkRequest; import java.security.InvalidParameterException; Loading Loading @@ -122,13 +123,17 @@ public class WorkRequestFactory { } } /** * Create a workRequest to generate file which contains list of installed apps * @param expedited if request is expedited * @return the workRequest */ private static OneTimeWorkRequest createOneTimeAppListGenerationWorkRequest() { final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(ListAppsWorker.class) .setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) final OneTimeWorkRequest.Builder builder = new OneTimeWorkRequest.Builder(ListAppsWorker.class); return builder.setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) .addTag(AppConstants.WORK_GENERIC_TAG) .build(); return workRequest; } /** Loading @@ -140,13 +145,12 @@ public class WorkRequestFactory { private static OneTimeWorkRequest createOneTimeFullScanWorkRequest() { final Constraints constraints = createUnmeteredNetworkAndHighBatteryConstraints(); final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(FullScanWorker.class) .setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) final OneTimeWorkRequest.Builder builder = new OneTimeWorkRequest.Builder(FullScanWorker.class); return builder.setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) .setConstraints(constraints) .addTag(AppConstants.WORK_GENERIC_TAG) .build(); return workRequest; } Loading @@ -157,13 +161,13 @@ public class WorkRequestFactory { private static OneTimeWorkRequest createOneTimeGetUserInfoWorkRequest() { final Constraints constraints = createUnmeteredNetworkAndHighBatteryConstraints(); final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(AccountUserInfoWorker.class) .setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) final OneTimeWorkRequest.Builder builder = new OneTimeWorkRequest.Builder(AccountUserInfoWorker.class); return builder.setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES) .addTag(AppConstants.WORK_GENERIC_TAG) .addTag(AppConstants.WORK_INITIALIZATION_TAG) .setConstraints(constraints) .build(); return workRequest; } /** Loading