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

Commit 252d4e1f authored by Lei Yu's avatar Lei Yu
Browse files

Fix bugs in auto restriction.

1. Dismiss this tip once user clicks it and goes to detail page.
2. In auto restriction, since apps are automatically restricted,
we need to remove apps in list that unrestricted by user.
3. Refactor the code to remove the unnecessary parameter(i.e.
SettingsActivity)

Bug: 78187414
Test: RunSettingsRoboTests
Change-Id: I1c950f7c55df35795641c2ea8579ce9e011dba28
parent 1257466d
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ public class RestrictAppPreferenceController extends BasePreferenceController {
    @VisibleForTesting
    List<AppInfo> mAppInfos;
    private AppOpsManager mAppOpsManager;
    private SettingsActivity mSettingsActivity;
    private InstrumentedPreferenceFragment mPreferenceFragment;
    private UserManager mUserManager;

@@ -53,10 +52,8 @@ public class RestrictAppPreferenceController extends BasePreferenceController {
        mUserManager = context.getSystemService(UserManager.class);
    }

    public RestrictAppPreferenceController(SettingsActivity settingsActivity,
            InstrumentedPreferenceFragment preferenceFragment) {
        this(settingsActivity.getApplicationContext());
        mSettingsActivity = settingsActivity;
    public RestrictAppPreferenceController(InstrumentedPreferenceFragment preferenceFragment) {
        this(preferenceFragment.getContext());
        mPreferenceFragment = preferenceFragment;
    }

@@ -83,7 +80,7 @@ public class RestrictAppPreferenceController extends BasePreferenceController {
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (getPreferenceKey().equals(preference.getKey())) {
            // start fragment
            RestrictedAppDetails.startRestrictedAppDetails(mSettingsActivity, mPreferenceFragment,
            RestrictedAppDetails.startRestrictedAppDetails(mPreferenceFragment,
                    mAppInfos);
            return true;
        }
+3 −3
Original line number Diff line number Diff line
@@ -67,12 +67,12 @@ public class RestrictedAppDetails extends DashboardFragment {
    private final FooterPreferenceMixin mFooterPreferenceMixin =
            new FooterPreferenceMixin(this, getLifecycle());

    public static void startRestrictedAppDetails(SettingsActivity caller,
            InstrumentedPreferenceFragment fragment, List<AppInfo> appInfos) {
    public static void startRestrictedAppDetails(InstrumentedPreferenceFragment fragment,
            List<AppInfo> appInfos) {
        final Bundle args = new Bundle();
        args.putParcelableList(EXTRA_APP_INFO_LIST, appInfos);

        new SubSettingLauncher(caller)
        new SubSettingLauncher(fragment.getContext())
                .setDestination(RestrictedAppDetails.class.getName())
                .setArguments(args)
                .setTitle(R.string.restricted_app_title)
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ public class SmartBatterySettings extends DashboardFragment {
        controllers.add(new SmartBatteryPreferenceController(context));
        if (settingsActivity != null && fragment != null) {
            controllers.add(
                    new RestrictAppPreferenceController(settingsActivity, fragment));
                    new RestrictAppPreferenceController(fragment));
        } else {
            controllers.add(new RestrictAppPreferenceController(context));
        }
+1 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ public class AnomalyDetectionJobService extends JobService {
                    .getFactory(this).getPowerUsageFeatureProvider(this);
            final MetricsFeatureProvider metricsFeatureProvider = FeatureFactory
                    .getFactory(this).getMetricsFeatureProvider();
            batteryUtils.initBatteryStatsHelper(batteryStatsHelper, null /* bundle */, userManager);

            for (JobWorkItem item = params.dequeueWork(); item != null;
                    item = params.dequeueWork()) {
+1 −2
Original line number Diff line number Diff line
@@ -101,8 +101,7 @@ public class BatteryTipUtils {
                }
            case BatteryTip.TipType.APP_RESTRICTION:
                if (batteryTip.getState() == BatteryTip.StateType.HANDLED) {
                    return new OpenRestrictAppFragmentAction(settingsActivity, fragment,
                            (RestrictAppTip) batteryTip);
                    return new OpenRestrictAppFragmentAction(fragment, (RestrictAppTip) batteryTip);
                } else {
                    return new RestrictAppAction(settingsActivity, (RestrictAppTip) batteryTip);
                }
Loading