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

Commit 87a17d01 authored by Lei Yu's avatar Lei Yu Committed by Android (Google) Code Review
Browse files

Merge "Add action to open the anomaly detail page"

parents 0bb26fef 1b472be8
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -22,11 +22,14 @@ import android.content.Context;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;

import com.android.internal.util.CollectionUtils;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.fuelgauge.batterytip.AppInfo;

import java.util.ArrayList;
import java.util.List;

/**
@@ -37,7 +40,7 @@ public class RestrictAppPreferenceController extends BasePreferenceController {
    static final String KEY_RESTRICT_APP = "restricted_app";

    private AppOpsManager mAppOpsManager;
    private List<AppOpsManager.PackageOps> mPackageOps;
    private List<AppInfo> mAppInfos;
    private SettingsActivity mSettingsActivity;
    private InstrumentedPreferenceFragment mPreferenceFragment;

@@ -62,9 +65,17 @@ public class RestrictAppPreferenceController extends BasePreferenceController {
    public void updateState(Preference preference) {
        super.updateState(preference);

        mPackageOps = mAppOpsManager.getPackagesForOps(
        final List<AppOpsManager.PackageOps> packageOpsList = mAppOpsManager.getPackagesForOps(
                new int[]{AppOpsManager.OP_RUN_ANY_IN_BACKGROUND});
        final int num = mPackageOps != null ? mPackageOps.size() : 0;
        final int num = CollectionUtils.size(packageOpsList);
        mAppInfos = new ArrayList<>();

        for (int i = 0; i < num; i++) {
            final AppOpsManager.PackageOps packageOps = packageOpsList.get(i);
            mAppInfos.add(new AppInfo.Builder()
                    .setPackageName(packageOps.getPackageName())
                    .build());
        }

        // Enable the preference if some apps already been restricted, otherwise disable it
        preference.setEnabled(num > 0);
@@ -78,7 +89,7 @@ public class RestrictAppPreferenceController extends BasePreferenceController {
        if (getPreferenceKey().equals(preference.getKey())) {
            // start fragment
            RestrictedAppDetails.startRestrictedAppDetails(mSettingsActivity, mPreferenceFragment,
                    mPackageOps);
                    mAppInfos);
            return true;
        }

+15 −11
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings.fuelgauge;

import android.app.AppOpsManager;
import android.app.Fragment;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -35,6 +36,7 @@ import com.android.settings.Utils;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.fuelgauge.batterytip.AppInfo;
import com.android.settings.widget.AppCheckBoxPreference;
import com.android.settingslib.core.AbstractPreferenceController;

@@ -47,11 +49,12 @@ public class RestrictedAppDetails extends DashboardFragment {

    public static final String TAG = "RestrictedAppDetails";

    private static final String EXTRA_PACKAGE_OPS_LIST = "package_ops_list";
    @VisibleForTesting
    static final String EXTRA_APP_INFO_LIST = "app_info_list";
    private static final String KEY_PREF_RESTRICTED_APP_LIST = "restrict_app_list";

    @VisibleForTesting
    List<AppOpsManager.PackageOps> mPackageOpsList;
    List<AppInfo> mAppInfos;
    @VisibleForTesting
    IconDrawableFactory mIconDrawableFactory;
    @VisibleForTesting
@@ -62,9 +65,9 @@ public class RestrictedAppDetails extends DashboardFragment {
    PackageManager mPackageManager;

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

        new SubSettingLauncher(caller)
                .setDestination(RestrictedAppDetails.class.getName())
@@ -80,7 +83,7 @@ public class RestrictedAppDetails extends DashboardFragment {
        final Context context = getContext();

        mRestrictedAppListGroup = (PreferenceGroup) findPreference(KEY_PREF_RESTRICTED_APP_LIST);
        mPackageOpsList = getArguments().getParcelableArrayList(EXTRA_PACKAGE_OPS_LIST);
        mAppInfos = getArguments().getParcelableArrayList(EXTRA_APP_INFO_LIST);
        mPackageManager = context.getPackageManager();
        mIconDrawableFactory = IconDrawableFactory.newInstance(context);
        mBatteryUtils = BatteryUtils.getInstance(context);
@@ -119,19 +122,20 @@ public class RestrictedAppDetails extends DashboardFragment {
        mRestrictedAppListGroup.removeAll();
        final Context context = getPrefContext();

        for (int i = 0, size = mPackageOpsList.size(); i < size; i++) {
        for (int i = 0, size = mAppInfos.size(); i < size; i++) {
            final CheckBoxPreference checkBoxPreference = new AppCheckBoxPreference(context);
            final AppOpsManager.PackageOps packageOps = mPackageOpsList.get(i);
            final AppInfo appInfo = mAppInfos.get(i);
            try {
                final ApplicationInfo applicationInfo = mPackageManager.getApplicationInfo(
                        packageOps.getPackageName(), 0 /* flags */);
                        appInfo.packageName, 0 /* flags */);
                checkBoxPreference.setChecked(true);
                checkBoxPreference.setTitle(mPackageManager.getApplicationLabel(applicationInfo));
                checkBoxPreference.setKey(packageOps.getPackageName());
                checkBoxPreference.setKey(appInfo.packageName);
                checkBoxPreference.setIcon(
                        Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager,
                                packageOps.getPackageName(),
                                UserHandle.getUserId(packageOps.getUid())));
                                appInfo.packageName,
                                UserHandle.getUserId(
                                        mBatteryUtils.getPackageUid(appInfo.packageName))));
                checkBoxPreference.setOnPreferenceChangeListener((pref, value) -> {
                    // change the toggle
                    final int mode = (Boolean) value ? AppOpsManager.MODE_IGNORED
+3 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.view.LayoutInflater;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController.BatteryTipListener;
import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
@@ -141,7 +142,8 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
            return;
        }
        final BatteryTipAction action = BatteryTipUtils.getActionForBatteryTip(mBatteryTip,
                (SettingsActivity) getActivity(), this);
                (SettingsActivity) getActivity(),
                (InstrumentedPreferenceFragment) getTargetFragment());
        if (action != null) {
            action.handlePositiveAction();
        }
+3 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.support.v7.preference.PreferenceScreen;

import com.android.settings.SettingsActivity;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
@@ -48,14 +49,14 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
    PreferenceGroup mPreferenceGroup;
    @VisibleForTesting
    Context mPrefContext;
    PreferenceFragment mFragment;
    InstrumentedPreferenceFragment mFragment;

    public BatteryTipPreferenceController(Context context, String preferenceKey) {
        this(context, preferenceKey, null, null, null);
    }

    public BatteryTipPreferenceController(Context context, String preferenceKey,
            SettingsActivity settingsActivity, PreferenceFragment fragment,
            SettingsActivity settingsActivity, InstrumentedPreferenceFragment fragment,
            BatteryTipListener batteryTipListener) {
        super(context, preferenceKey);
        mBatteryTipListener = batteryTipListener;
+9 −3
Original line number Diff line number Diff line
@@ -17,11 +17,12 @@
package com.android.settings.fuelgauge.batterytip;

import android.app.Fragment;
import android.content.Context;

import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.fuelgauge.batterytip.actions.BatterySaverAction;
import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
import com.android.settings.fuelgauge.batterytip.actions.OpenRestrictAppFragmentAction;
import com.android.settings.fuelgauge.batterytip.actions.RestrictAppAction;
import com.android.settings.fuelgauge.batterytip.actions.SmartBatteryAction;
import com.android.settings.fuelgauge.batterytip.actions.UnrestrictAppAction;
@@ -42,14 +43,19 @@ public class BatteryTipUtils {
     * @return an action for {@code batteryTip}
     */
    public static BatteryTipAction getActionForBatteryTip(BatteryTip batteryTip,
            SettingsActivity settingsActivity, Fragment fragment) {
            SettingsActivity settingsActivity, InstrumentedPreferenceFragment fragment) {
        switch (batteryTip.getType()) {
            case BatteryTip.TipType.SMART_BATTERY_MANAGER:
                return new SmartBatteryAction(settingsActivity, fragment);
            case BatteryTip.TipType.BATTERY_SAVER:
                return new BatterySaverAction(settingsActivity);
            case BatteryTip.TipType.APP_RESTRICTION:
                if (batteryTip.getState() == BatteryTip.StateType.HANDLED) {
                    return new OpenRestrictAppFragmentAction(settingsActivity, fragment,
                            (RestrictAppTip) batteryTip);
                } else {
                    return new RestrictAppAction(settingsActivity, (RestrictAppTip) batteryTip);
                }
            case BatteryTip.TipType.REMOVE_APP_RESTRICTION:
                return new UnrestrictAppAction(settingsActivity, (UnrestrictAppTip) batteryTip);
            default:
Loading