Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4794163 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

669 list pwa fix

parent 5aa533e3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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" />
+0 −1
Original line number Diff line number Diff line
@@ -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";

+10 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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()
@@ -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);

+9 −7
Original line number Diff line number Diff line
@@ -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);
@@ -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);

@@ -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"));
@@ -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()) {
+17 −13
Original line number Diff line number Diff line
@@ -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;
@@ -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;
    }

    /**
@@ -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;
    }


@@ -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;
    }

    /**