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

Commit 7423f439 authored by Wesley Wang's avatar Wesley Wang
Browse files

Move setup optimization mode to main thread

 - Due to unclear root cause of optimization mode being reset after
   reboot, update the setup logic from deferred background thread to
   main thread, to avoid any possible background task unexecuted case.

Bug: 241735485
Test: make SettingsRoboTests
Change-Id: I2de2181321712f89fadc04bf5000aea91a01485a
parent 82789d15
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -296,7 +296,6 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
                BatteryHistoricalLogUtil.getPackageNameWithUserId(
                        mBatteryOptimizeUtils.getPackageName(), UserHandle.myUserId()),
                mLogStringBuilder.toString());
        mBatteryOptimizeUtils.setAppUsageState(selectedPreference, Action.APPLY);
        Log.d(TAG, "Leave with mode: " + selectedPreference);
    }

@@ -424,6 +423,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
        updatePreferenceState(mUnrestrictedPreference, selectedKey);
        updatePreferenceState(mOptimizePreference, selectedKey);
        updatePreferenceState(mRestrictedPreference, selectedKey);
        mBatteryOptimizeUtils.setAppUsageState(getSelectedPreference(), Action.APPLY);
    }

    private void updatePreferenceState(SelectorWithWidgetPreference preference,
+2 −5
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.content.pm.UserInfo;
import android.os.AsyncTask;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.ArraySet;
@@ -227,10 +226,8 @@ public class BatteryOptimizeUtils {
                mode == MODE_RESTRICTED ? AppOpsManager.MODE_IGNORED : AppOpsManager.MODE_ALLOWED;
        final boolean allowListed = mode == MODE_UNRESTRICTED;

        AsyncTask.execute(() -> {
        setAppOptimizationModeInternal(context, appOpsManagerMode, allowListed, uid,
                packageName, batteryUtils, powerAllowlistBackend, action);
        });
    }

    private static void setAppOptimizationModeInternal(