Update language to comply with Android's inclusive language guidance
Refactor PowerWhitelistBackend to PowerAllowlistBackend See https://source.android.com/setup/contribute/respectful-code for reference Bug: 161896447 Test: robotest & manual Change-Id: I3d56e6dac1515b49a89f59c34edf403ecb891420
This commit is contained in:
@@ -21,20 +21,20 @@ import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||
import com.android.settingslib.applications.ApplicationsState.AppFilter;
|
||||
import com.android.settingslib.applications.ApplicationsState.CompoundFilter;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Connects data from the PowerWhitelistBackend to ApplicationsState.
|
||||
* Connects data from the PowerAllowlistBackend to ApplicationsState.
|
||||
*/
|
||||
public class AppStatePowerBridge extends AppStateBaseBridge {
|
||||
|
||||
private final PowerWhitelistBackend mBackend;
|
||||
private final PowerAllowlistBackend mBackend;
|
||||
|
||||
public AppStatePowerBridge(Context context, ApplicationsState appState, Callback callback) {
|
||||
super(appState, callback);
|
||||
mBackend = PowerWhitelistBackend.getInstance(context);
|
||||
mBackend = PowerAllowlistBackend.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,17 +43,17 @@ public class AppStatePowerBridge extends AppStateBaseBridge {
|
||||
final int N = apps.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
AppEntry app = apps.get(i);
|
||||
app.extraInfo = mBackend.isWhitelisted(app.info.packageName)
|
||||
app.extraInfo = mBackend.isAllowlisted(app.info.packageName)
|
||||
? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExtraInfo(AppEntry app, String pkg, int uid) {
|
||||
app.extraInfo = mBackend.isWhitelisted(pkg) ? Boolean.TRUE : Boolean.FALSE;
|
||||
app.extraInfo = mBackend.isAllowlisted(pkg) ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
|
||||
public static final AppFilter FILTER_POWER_WHITELISTED = new CompoundFilter(
|
||||
public static final AppFilter FILTER_POWER_ALLOWLISTED = new CompoundFilter(
|
||||
ApplicationsState.FILTER_WITHOUT_DISABLED_UNTIL_USED, new AppFilter() {
|
||||
@Override
|
||||
public void init() {
|
||||
|
@@ -35,8 +35,8 @@ import com.android.settingslib.applications.ApplicationsState;
|
||||
public class AppFilterRegistry {
|
||||
|
||||
@IntDef(value = {
|
||||
FILTER_APPS_POWER_WHITELIST,
|
||||
FILTER_APPS_POWER_WHITELIST_ALL,
|
||||
FILTER_APPS_POWER_ALLOWLIST,
|
||||
FILTER_APPS_POWER_ALLOWLIST_ALL,
|
||||
FILTER_APPS_ALL,
|
||||
FILTER_APPS_ENABLED,
|
||||
FILTER_APPS_INSTANT,
|
||||
@@ -56,8 +56,8 @@ public class AppFilterRegistry {
|
||||
|
||||
// Filter options used for displayed list of applications
|
||||
// Filters will appear sorted based on their value defined here.
|
||||
public static final int FILTER_APPS_POWER_WHITELIST = 0;
|
||||
public static final int FILTER_APPS_POWER_WHITELIST_ALL = 1;
|
||||
public static final int FILTER_APPS_POWER_ALLOWLIST = 0;
|
||||
public static final int FILTER_APPS_POWER_ALLOWLIST_ALL = 1;
|
||||
public static final int FILTER_APPS_RECENT = 2;
|
||||
public static final int FILTER_APPS_FREQUENT = 3;
|
||||
public static final int FILTER_APPS_ALL = 4;
|
||||
@@ -82,20 +82,20 @@ public class AppFilterRegistry {
|
||||
private AppFilterRegistry() {
|
||||
mFilters = new AppFilterItem[18];
|
||||
|
||||
// High power whitelist, on
|
||||
mFilters[FILTER_APPS_POWER_WHITELIST] = new AppFilterItem(
|
||||
// High power allowlist, on
|
||||
mFilters[FILTER_APPS_POWER_ALLOWLIST] = new AppFilterItem(
|
||||
new ApplicationsState.CompoundFilter(
|
||||
AppStatePowerBridge.FILTER_POWER_WHITELISTED,
|
||||
AppStatePowerBridge.FILTER_POWER_ALLOWLISTED,
|
||||
ApplicationsState.FILTER_ALL_ENABLED),
|
||||
FILTER_APPS_POWER_WHITELIST,
|
||||
FILTER_APPS_POWER_ALLOWLIST,
|
||||
R.string.high_power_filter_on);
|
||||
|
||||
// Without disabled until used
|
||||
mFilters[FILTER_APPS_POWER_WHITELIST_ALL] = new AppFilterItem(
|
||||
mFilters[FILTER_APPS_POWER_ALLOWLIST_ALL] = new AppFilterItem(
|
||||
new ApplicationsState.CompoundFilter(
|
||||
ApplicationsState.FILTER_WITHOUT_DISABLED_UNTIL_USED,
|
||||
ApplicationsState.FILTER_ALL_ENABLED),
|
||||
FILTER_APPS_POWER_WHITELIST_ALL,
|
||||
FILTER_APPS_POWER_ALLOWLIST_ALL,
|
||||
R.string.filter_all_apps);
|
||||
|
||||
// All apps
|
||||
@@ -200,7 +200,7 @@ public class AppFilterRegistry {
|
||||
case ManageApplications.LIST_TYPE_USAGE_ACCESS:
|
||||
return FILTER_APPS_USAGE_ACCESS;
|
||||
case ManageApplications.LIST_TYPE_HIGH_POWER:
|
||||
return FILTER_APPS_POWER_WHITELIST;
|
||||
return FILTER_APPS_POWER_ALLOWLIST;
|
||||
case ManageApplications.LIST_TYPE_OVERLAY:
|
||||
return FILTER_APPS_WITH_OVERLAY;
|
||||
case ManageApplications.LIST_TYPE_WRITE_SETTINGS:
|
||||
|
@@ -25,8 +25,8 @@ import static com.android.settings.applications.manageapplications.AppFilterRegi
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_FREQUENT;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_INSTANT;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_PERSONAL;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_POWER_WHITELIST;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_POWER_WHITELIST_ALL;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_POWER_ALLOWLIST;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_POWER_ALLOWLIST_ALL;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_RECENT;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_WORK;
|
||||
import static com.android.settings.search.actionbar.SearchMenuController.MENU_SEARCH;
|
||||
@@ -125,7 +125,7 @@ import com.android.settingslib.applications.ApplicationsState.AppFilter;
|
||||
import com.android.settingslib.applications.ApplicationsState.CompoundFilter;
|
||||
import com.android.settingslib.applications.ApplicationsState.VolumeFilter;
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
import com.android.settingslib.widget.settingsspinner.SettingsSpinnerAdapter;
|
||||
|
||||
@@ -479,7 +479,7 @@ public class ManageApplications extends InstrumentedFragment
|
||||
mFilterAdapter.enableFilter(FILTER_APPS_ALL);
|
||||
}
|
||||
if (mListType == LIST_TYPE_HIGH_POWER) {
|
||||
mFilterAdapter.enableFilter(FILTER_APPS_POWER_WHITELIST_ALL);
|
||||
mFilterAdapter.enableFilter(FILTER_APPS_POWER_ALLOWLIST_ALL);
|
||||
}
|
||||
|
||||
setCompositeFilter();
|
||||
@@ -1011,7 +1011,7 @@ public class ManageApplications extends InstrumentedFragment
|
||||
private boolean mHasReceivedBridgeCallback;
|
||||
private FileViewHolderController mExtraViewController;
|
||||
private SearchFilter mSearchFilter;
|
||||
private PowerWhitelistBackend mBackend;
|
||||
private PowerAllowlistBackend mBackend;
|
||||
|
||||
// This is to remember and restore the last scroll position when this
|
||||
// fragment is paused. We need this special handling because app entries are added gradually
|
||||
@@ -1036,7 +1036,7 @@ public class ManageApplications extends InstrumentedFragment
|
||||
mContext = manageApplications.getActivity();
|
||||
mIconDrawableFactory = IconDrawableFactory.newInstance(mContext);
|
||||
mAppFilter = appFilter;
|
||||
mBackend = PowerWhitelistBackend.getInstance(mContext);
|
||||
mBackend = PowerAllowlistBackend.getInstance(mContext);
|
||||
if (mManageApplications.mListType == LIST_TYPE_NOTIFICATION) {
|
||||
mExtraInfoBridge = new AppStateNotificationBridge(mContext, mState, this,
|
||||
manageApplications.mUsageStatsManager,
|
||||
@@ -1292,8 +1292,8 @@ public class ManageApplications extends InstrumentedFragment
|
||||
Log.d(TAG, "onRebuildComplete size=" + entries.size());
|
||||
}
|
||||
final int filterType = mAppFilter.getFilterType();
|
||||
if (filterType == FILTER_APPS_POWER_WHITELIST ||
|
||||
filterType == FILTER_APPS_POWER_WHITELIST_ALL) {
|
||||
if (filterType == FILTER_APPS_POWER_ALLOWLIST
|
||||
|| filterType == FILTER_APPS_POWER_ALLOWLIST_ALL) {
|
||||
entries = removeDuplicateIgnoringUser(entries);
|
||||
}
|
||||
mEntries = entries;
|
||||
@@ -1451,7 +1451,7 @@ public class ManageApplications extends InstrumentedFragment
|
||||
}
|
||||
ApplicationsState.AppEntry entry = mEntries.get(position);
|
||||
|
||||
return !mBackend.isSysWhitelisted(entry.info.packageName)
|
||||
return !mBackend.isSysAllowlisted(entry.info.packageName)
|
||||
&& !mBackend.isDefaultActiveApp(entry.info.packageName);
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,7 @@ import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||
|
||||
/**
|
||||
* Controller to control whether an app can run in the background
|
||||
@@ -54,18 +54,18 @@ public class BackgroundActivityPreferenceController extends AbstractPreferenceCo
|
||||
BatteryUtils mBatteryUtils;
|
||||
private InstrumentedPreferenceFragment mFragment;
|
||||
private String mTargetPackage;
|
||||
private PowerWhitelistBackend mPowerWhitelistBackend;
|
||||
private PowerAllowlistBackend mPowerAllowlistBackend;
|
||||
|
||||
public BackgroundActivityPreferenceController(Context context,
|
||||
InstrumentedPreferenceFragment fragment, int uid, String packageName) {
|
||||
this(context, fragment, uid, packageName, PowerWhitelistBackend.getInstance(context));
|
||||
this(context, fragment, uid, packageName, PowerAllowlistBackend.getInstance(context));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
BackgroundActivityPreferenceController(Context context, InstrumentedPreferenceFragment fragment,
|
||||
int uid, String packageName, PowerWhitelistBackend backend) {
|
||||
int uid, String packageName, PowerAllowlistBackend backend) {
|
||||
super(context);
|
||||
mPowerWhitelistBackend = backend;
|
||||
mPowerAllowlistBackend = backend;
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
mDpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||
@@ -84,8 +84,8 @@ public class BackgroundActivityPreferenceController extends AbstractPreferenceCo
|
||||
}
|
||||
final int mode = mAppOpsManager
|
||||
.checkOpNoThrow(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, mUid, mTargetPackage);
|
||||
final boolean whitelisted = mPowerWhitelistBackend.isWhitelisted(mTargetPackage);
|
||||
if (whitelisted || mode == AppOpsManager.MODE_ERRORED
|
||||
final boolean allowlisted = mPowerAllowlistBackend.isAllowlisted(mTargetPackage);
|
||||
if (allowlisted || mode == AppOpsManager.MODE_ERRORED
|
||||
|| Utils.isProfileOrDeviceOwner(mUserManager, mDpm, mTargetPackage)) {
|
||||
preference.setEnabled(false);
|
||||
} else {
|
||||
@@ -117,7 +117,7 @@ public class BackgroundActivityPreferenceController extends AbstractPreferenceCo
|
||||
}
|
||||
|
||||
public void updateSummary(Preference preference) {
|
||||
if (mPowerWhitelistBackend.isWhitelisted(mTargetPackage)) {
|
||||
if (mPowerAllowlistBackend.isAllowlisted(mTargetPackage)) {
|
||||
preference.setSummary(R.string.background_activity_summary_whitelisted);
|
||||
return;
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||
|
||||
/**
|
||||
* Controller that jumps to high power optimization fragment
|
||||
@@ -38,7 +38,7 @@ public class BatteryOptimizationPreferenceController extends AbstractPreferenceC
|
||||
private static final String KEY_BACKGROUND_ACTIVITY = "battery_optimization";
|
||||
|
||||
|
||||
private PowerWhitelistBackend mBackend;
|
||||
private PowerAllowlistBackend mBackend;
|
||||
private DashboardFragment mFragment;
|
||||
private SettingsActivity mSettingsActivity;
|
||||
private String mPackageName;
|
||||
@@ -49,12 +49,12 @@ public class BatteryOptimizationPreferenceController extends AbstractPreferenceC
|
||||
mFragment = fragment;
|
||||
mSettingsActivity = settingsActivity;
|
||||
mPackageName = packageName;
|
||||
mBackend = PowerWhitelistBackend.getInstance(mSettingsActivity);
|
||||
mBackend = PowerAllowlistBackend.getInstance(mSettingsActivity);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
BatteryOptimizationPreferenceController(SettingsActivity settingsActivity,
|
||||
DashboardFragment fragment, String packageName, PowerWhitelistBackend backend) {
|
||||
DashboardFragment fragment, String packageName, PowerAllowlistBackend backend) {
|
||||
super(settingsActivity);
|
||||
mFragment = fragment;
|
||||
mSettingsActivity = settingsActivity;
|
||||
@@ -69,8 +69,8 @@ public class BatteryOptimizationPreferenceController extends AbstractPreferenceC
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final boolean isWhitelisted = mBackend.isWhitelisted(mPackageName);
|
||||
preference.setSummary(isWhitelisted ? R.string.high_power_on : R.string.high_power_off);
|
||||
final boolean isAllowlisted = mBackend.isAllowlisted(mPackageName);
|
||||
preference.setSummary(isAllowlisted ? R.string.high_power_on : R.string.high_power_off);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -50,7 +50,7 @@ import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.fuelgauge.Estimate;
|
||||
import com.android.settingslib.fuelgauge.EstimateKt;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||
import com.android.settingslib.utils.PowerUtil;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
@@ -578,7 +578,7 @@ public class BatteryUtils {
|
||||
/**
|
||||
* Return {@code true} if we should hide anomaly app represented by {@code uid}
|
||||
*/
|
||||
public boolean shouldHideAnomaly(PowerWhitelistBackend powerWhitelistBackend, int uid,
|
||||
public boolean shouldHideAnomaly(PowerAllowlistBackend powerAllowlistBackend, int uid,
|
||||
AnomalyInfo anomalyInfo) {
|
||||
final String[] packageNames = mPackageManager.getPackagesForUid(uid);
|
||||
if (ArrayUtils.isEmpty(packageNames)) {
|
||||
@@ -586,7 +586,7 @@ public class BatteryUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
return isSystemUid(uid) || powerWhitelistBackend.isWhitelisted(packageNames)
|
||||
return isSystemUid(uid) || powerAllowlistBackend.isAllowlisted(packageNames)
|
||||
|| (isSystemApp(mPackageManager, packageNames) && !hasLauncherEntry(packageNames))
|
||||
|| (isExcessiveBackgroundAnomaly(anomalyInfo) && !isPreOApp(packageNames));
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ import com.android.settings.applications.AppInfoBase;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||
|
||||
public class HighPowerDetail extends InstrumentedDialogFragment implements OnClickListener,
|
||||
View.OnClickListener {
|
||||
@@ -46,7 +46,7 @@ public class HighPowerDetail extends InstrumentedDialogFragment implements OnCli
|
||||
private static final String ARG_DEFAULT_ON = "default_on";
|
||||
|
||||
@VisibleForTesting
|
||||
PowerWhitelistBackend mBackend;
|
||||
PowerAllowlistBackend mBackend;
|
||||
@VisibleForTesting
|
||||
BatteryUtils mBatteryUtils;
|
||||
@VisibleForTesting
|
||||
@@ -70,7 +70,7 @@ public class HighPowerDetail extends InstrumentedDialogFragment implements OnCli
|
||||
super.onCreate(savedInstanceState);
|
||||
final Context context = getContext();
|
||||
mBatteryUtils = BatteryUtils.getInstance(context);
|
||||
mBackend = PowerWhitelistBackend.getInstance(context);
|
||||
mBackend = PowerAllowlistBackend.getInstance(context);
|
||||
|
||||
mPackageName = getArguments().getString(AppInfoBase.ARG_PACKAGE_NAME);
|
||||
mPackageUid = getArguments().getInt(AppInfoBase.ARG_PACKAGE_UID);
|
||||
@@ -81,7 +81,7 @@ public class HighPowerDetail extends InstrumentedDialogFragment implements OnCli
|
||||
mLabel = mPackageName;
|
||||
}
|
||||
mDefaultOn = getArguments().getBoolean(ARG_DEFAULT_ON);
|
||||
mIsEnabled = mDefaultOn || mBackend.isWhitelisted(mPackageName);
|
||||
mIsEnabled = mDefaultOn || mBackend.isAllowlisted(mPackageName);
|
||||
}
|
||||
|
||||
public Checkable setup(View view, boolean on) {
|
||||
@@ -91,7 +91,7 @@ public class HighPowerDetail extends InstrumentedDialogFragment implements OnCli
|
||||
? R.string.ignore_optimizations_on_desc : R.string.ignore_optimizations_off_desc);
|
||||
view.setClickable(true);
|
||||
view.setOnClickListener(this);
|
||||
if (!on && mBackend.isSysWhitelisted(mPackageName)) {
|
||||
if (!on && mBackend.isSysAllowlisted(mPackageName)) {
|
||||
view.setEnabled(false);
|
||||
}
|
||||
return (Checkable) view;
|
||||
@@ -103,7 +103,7 @@ public class HighPowerDetail extends InstrumentedDialogFragment implements OnCli
|
||||
.setTitle(mLabel)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setView(R.layout.ignore_optimizations_content);
|
||||
if (!mBackend.isSysWhitelisted(mPackageName)) {
|
||||
if (!mBackend.isSysAllowlisted(mPackageName)) {
|
||||
b.setPositiveButton(R.string.done, this);
|
||||
}
|
||||
return b.create();
|
||||
@@ -137,7 +137,7 @@ public class HighPowerDetail extends InstrumentedDialogFragment implements OnCli
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
boolean newValue = mIsEnabled;
|
||||
boolean oldValue = mBackend.isWhitelisted(mPackageName);
|
||||
boolean oldValue = mBackend.isAllowlisted(mPackageName);
|
||||
if (newValue != oldValue) {
|
||||
logSpecialPermissionChange(newValue, mPackageName, getContext());
|
||||
if (newValue) {
|
||||
@@ -152,8 +152,8 @@ public class HighPowerDetail extends InstrumentedDialogFragment implements OnCli
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static void logSpecialPermissionChange(boolean whitelist, String packageName, Context context) {
|
||||
int logCategory = whitelist ? SettingsEnums.APP_SPECIAL_PERMISSION_BATTERY_DENY
|
||||
static void logSpecialPermissionChange(boolean allowlist, String packageName, Context context) {
|
||||
int logCategory = allowlist ? SettingsEnums.APP_SPECIAL_PERMISSION_BATTERY_DENY
|
||||
: SettingsEnums.APP_SPECIAL_PERMISSION_BATTERY_ALLOW;
|
||||
FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context, logCategory,
|
||||
packageName);
|
||||
@@ -173,16 +173,16 @@ public class HighPowerDetail extends InstrumentedDialogFragment implements OnCli
|
||||
}
|
||||
|
||||
public static CharSequence getSummary(Context context, String pkg) {
|
||||
return getSummary(context, PowerWhitelistBackend.getInstance(context), pkg);
|
||||
return getSummary(context, PowerAllowlistBackend.getInstance(context), pkg);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static CharSequence getSummary(Context context, PowerWhitelistBackend powerWhitelist,
|
||||
static CharSequence getSummary(Context context, PowerAllowlistBackend powerAllowlist,
|
||||
String pkg) {
|
||||
return context.getString(
|
||||
powerWhitelist.isSysWhitelisted(pkg) || powerWhitelist.isDefaultActiveApp(pkg)
|
||||
powerAllowlist.isSysAllowlisted(pkg) || powerAllowlist.isDefaultActiveApp(pkg)
|
||||
? R.string.high_power_system
|
||||
: powerWhitelist.isWhitelisted(pkg)
|
||||
: powerAllowlist.isAllowlisted(pkg)
|
||||
? R.string.high_power_on
|
||||
: R.string.high_power_off);
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -96,8 +96,8 @@ public class AnomalyDetectionJobService extends JobService {
|
||||
final BatteryUtils batteryUtils = BatteryUtils.getInstance(this);
|
||||
final ContentResolver contentResolver = getContentResolver();
|
||||
final UserManager userManager = getSystemService(UserManager.class);
|
||||
final PowerWhitelistBackend powerWhitelistBackend =
|
||||
PowerWhitelistBackend.getInstance(context);
|
||||
final PowerAllowlistBackend powerAllowlistBackend =
|
||||
PowerAllowlistBackend.getInstance(context);
|
||||
final PowerUsageFeatureProvider powerUsageFeatureProvider = FeatureFactory
|
||||
.getFactory(this).getPowerUsageFeatureProvider(this);
|
||||
final MetricsFeatureProvider metricsFeatureProvider = FeatureFactory
|
||||
@@ -105,7 +105,7 @@ public class AnomalyDetectionJobService extends JobService {
|
||||
|
||||
for (JobWorkItem item = dequeueWork(params); item != null; item = dequeueWork(params)) {
|
||||
saveAnomalyToDatabase(context, userManager,
|
||||
batteryDatabaseManager, batteryUtils, policy, powerWhitelistBackend,
|
||||
batteryDatabaseManager, batteryUtils, policy, powerAllowlistBackend,
|
||||
contentResolver, powerUsageFeatureProvider, metricsFeatureProvider,
|
||||
item.getIntent().getExtras());
|
||||
|
||||
@@ -127,7 +127,7 @@ public class AnomalyDetectionJobService extends JobService {
|
||||
@VisibleForTesting
|
||||
void saveAnomalyToDatabase(Context context, UserManager userManager,
|
||||
BatteryDatabaseManager databaseManager, BatteryUtils batteryUtils,
|
||||
BatteryTipPolicy policy, PowerWhitelistBackend powerWhitelistBackend,
|
||||
BatteryTipPolicy policy, PowerAllowlistBackend powerAllowlistBackend,
|
||||
ContentResolver contentResolver, PowerUsageFeatureProvider powerUsageFeatureProvider,
|
||||
MetricsFeatureProvider metricsFeatureProvider, Bundle bundle) {
|
||||
// The Example of intentDimsValue is: 35:{1:{1:{1:10013|}|}|}
|
||||
@@ -151,7 +151,7 @@ public class AnomalyDetectionJobService extends JobService {
|
||||
final String packageName = batteryUtils.getPackageName(uid);
|
||||
final long versionCode = batteryUtils.getAppLongVersionCode(packageName);
|
||||
final String versionedPackage = packageName + "/" + versionCode;
|
||||
if (batteryUtils.shouldHideAnomaly(powerWhitelistBackend, uid, anomalyInfo)) {
|
||||
if (batteryUtils.shouldHideAnomaly(powerAllowlistBackend, uid, anomalyInfo)) {
|
||||
metricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN,
|
||||
SettingsEnums.ACTION_ANOMALY_IGNORED,
|
||||
SettingsEnums.PAGE_UNKNOWN,
|
||||
|
@@ -393,7 +393,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
|
||||
p.setChecked(false);
|
||||
p.setTitle(app.activityName);
|
||||
p.setKey(getKeyForPackage(packageName));
|
||||
p.setSettingsEnabled(hasSettings && app.masterEntry == null);
|
||||
p.setSettingsEnabled(hasSettings && app.primaryEntry == null);
|
||||
p.setPersistent(false);
|
||||
p.setOnPreferenceChangeListener(this);
|
||||
p.setOnPreferenceClickListener(this);
|
||||
@@ -407,13 +407,13 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
|
||||
// able to toggle this app ON (it's ON by default and immutable).
|
||||
// Only do this for restricted profiles, not single-user restrictions
|
||||
// Also don't do this for secondary icons
|
||||
if (app.masterEntry == null) {
|
||||
if (app.primaryEntry == null) {
|
||||
requestRestrictionsForApp(packageName, p, false);
|
||||
}
|
||||
} else if (!mNewUser && isAppEnabledForUser(pi)) {
|
||||
p.setChecked(true);
|
||||
}
|
||||
if (app.masterEntry != null) {
|
||||
if (app.primaryEntry != null) {
|
||||
p.setImmutable(true);
|
||||
p.setChecked(mHelper.isPackageSelected(packageName));
|
||||
}
|
||||
@@ -436,13 +436,13 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
|
||||
// - Secondary entry that cannot see primary user accounts
|
||||
// - Primary entry that can see primary user accounts
|
||||
// Otherwise no summary is returned
|
||||
if (app.masterEntry != null) {
|
||||
if (app.primaryEntry != null) {
|
||||
if (mRestrictedProfile && pi.restrictedAccountType != null) {
|
||||
return getString(R.string.app_sees_restricted_accounts_and_controlled_by,
|
||||
app.masterEntry.activityName);
|
||||
app.primaryEntry.activityName);
|
||||
}
|
||||
return getString(R.string.user_restrictions_controlled_by,
|
||||
app.masterEntry.activityName);
|
||||
app.primaryEntry.activityName);
|
||||
} else if (pi.restrictedAccountType != null) {
|
||||
return getString(R.string.app_sees_restricted_accounts);
|
||||
}
|
||||
|
@@ -16,42 +16,24 @@
|
||||
|
||||
package com.android.settings.applications.manageapplications;
|
||||
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry
|
||||
.FILTER_APPS_ALL;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry
|
||||
.FILTER_APPS_INSTALL_SOURCES;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry
|
||||
.FILTER_APPS_POWER_WHITELIST;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry
|
||||
.FILTER_APPS_RECENT;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry
|
||||
.FILTER_APPS_USAGE_ACCESS;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry
|
||||
.FILTER_APPS_WITH_OVERLAY;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry
|
||||
.FILTER_APPS_WRITE_SETTINGS;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications
|
||||
.LIST_TYPE_GAMES;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications
|
||||
.LIST_TYPE_HIGH_POWER;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications
|
||||
.LIST_TYPE_MAIN;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications
|
||||
.LIST_TYPE_MANAGE_SOURCES;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications
|
||||
.LIST_TYPE_MOVIES;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications
|
||||
.LIST_TYPE_NOTIFICATION;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications
|
||||
.LIST_TYPE_OVERLAY;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications
|
||||
.LIST_TYPE_PHOTOGRAPHY;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications
|
||||
.LIST_TYPE_STORAGE;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications
|
||||
.LIST_TYPE_USAGE_ACCESS;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications
|
||||
.LIST_TYPE_WRITE_SETTINGS;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_ALL;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_INSTALL_SOURCES;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_POWER_ALLOWLIST;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_RECENT;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_USAGE_ACCESS;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_WITH_OVERLAY;
|
||||
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_WRITE_SETTINGS;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_GAMES;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_HIGH_POWER;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_MAIN;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_MANAGE_SOURCES;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_MOVIES;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_NOTIFICATION;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_OVERLAY;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_PHOTOGRAPHY;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_STORAGE;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_USAGE_ACCESS;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_WRITE_SETTINGS;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@@ -68,7 +50,7 @@ public class AppFilterRegistryTest {
|
||||
assertThat(registry.getDefaultFilterType(LIST_TYPE_USAGE_ACCESS))
|
||||
.isEqualTo(FILTER_APPS_USAGE_ACCESS);
|
||||
assertThat(registry.getDefaultFilterType(LIST_TYPE_HIGH_POWER))
|
||||
.isEqualTo(FILTER_APPS_POWER_WHITELIST);
|
||||
.isEqualTo(FILTER_APPS_POWER_ALLOWLIST);
|
||||
assertThat(registry.getDefaultFilterType(LIST_TYPE_OVERLAY))
|
||||
.isEqualTo(FILTER_APPS_WITH_OVERLAY);
|
||||
assertThat(registry.getDefaultFilterType(LIST_TYPE_WRITE_SETTINGS))
|
||||
|
@@ -40,7 +40,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowFragment;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -79,7 +79,7 @@ public class BackgroundActivityPreferenceControllerTest {
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private AdvancedPowerUsageDetail mFragment;
|
||||
@Mock
|
||||
private PowerWhitelistBackend mPowerWhitelistBackend;
|
||||
private PowerAllowlistBackend mPowerAllowlistBackend;
|
||||
private BackgroundActivityPreferenceController mController;
|
||||
private RestrictedPreference mPreference;
|
||||
private Context mShadowContext;
|
||||
@@ -103,7 +103,7 @@ public class BackgroundActivityPreferenceControllerTest {
|
||||
when(mPackageManager.getApplicationInfo(LOW_SDK_PACKAGE, PackageManager.GET_META_DATA))
|
||||
.thenReturn(mLowApplicationInfo);
|
||||
|
||||
when(mPowerWhitelistBackend.isWhitelisted(LOW_SDK_PACKAGE)).thenReturn(false);
|
||||
when(mPowerAllowlistBackend.isAllowlisted(LOW_SDK_PACKAGE)).thenReturn(false);
|
||||
mHighApplicationInfo.targetSdkVersion = Build.VERSION_CODES.O;
|
||||
mLowApplicationInfo.targetSdkVersion = Build.VERSION_CODES.L;
|
||||
|
||||
@@ -113,7 +113,7 @@ public class BackgroundActivityPreferenceControllerTest {
|
||||
mPreference = spy(new RestrictedPreference(mShadowContext, null /* attrs */));
|
||||
mPreference.setKey(BackgroundActivityPreferenceController.KEY_BACKGROUND_ACTIVITY);
|
||||
mController = spy(new BackgroundActivityPreferenceController(
|
||||
mContext, mFragment, UID_LOW_SDK, LOW_SDK_PACKAGE, mPowerWhitelistBackend));
|
||||
mContext, mFragment, UID_LOW_SDK, LOW_SDK_PACKAGE, mPowerAllowlistBackend));
|
||||
mController.mDpm = mDevicePolicyManagerWrapper;
|
||||
mController.mBatteryUtils = mBatteryUtils;
|
||||
}
|
||||
@@ -150,8 +150,8 @@ public class BackgroundActivityPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_whitelisted() {
|
||||
when(mPowerWhitelistBackend.isWhitelisted(LOW_SDK_PACKAGE)).thenReturn(true);
|
||||
public void updateState_allowlisted() {
|
||||
when(mPowerAllowlistBackend.isAllowlisted(LOW_SDK_PACKAGE)).thenReturn(true);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
assertThat(mPreference.getSummary()).isEqualTo(
|
||||
|
@@ -33,7 +33,7 @@ import androidx.preference.SwitchPreference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -46,8 +46,8 @@ import org.robolectric.RuntimeEnvironment;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BatteryOptimizationPreferenceControllerTest {
|
||||
|
||||
private static final String PKG_IN_WHITELIST = "com.pkg.in.whitelist";
|
||||
private static final String PKG_NOT_IN_WHITELIST = "com.pkg.not.in.whitelist";
|
||||
private static final String PKG_IN_ALLOWLIST = "com.pkg.in.allowlist";
|
||||
private static final String PKG_NOT_IN_ALLOWLIST = "com.pkg.not.in.allowlist";
|
||||
private static final String KEY_OPTIMIZATION = "battery_optimization";
|
||||
private static final String KEY_OTHER = "other";
|
||||
@Mock
|
||||
@@ -55,7 +55,7 @@ public class BatteryOptimizationPreferenceControllerTest {
|
||||
@Mock
|
||||
private DashboardFragment mFragment;
|
||||
@Mock
|
||||
private TestPowerWhitelistBackend mBackend;
|
||||
private TestPowerAllowlistBackend mBackend;
|
||||
|
||||
private BatteryOptimizationPreferenceController mController;
|
||||
private Preference mPreference;
|
||||
@@ -66,12 +66,12 @@ public class BatteryOptimizationPreferenceControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
doReturn(false).when(mBackend).isWhitelisted(PKG_NOT_IN_WHITELIST);
|
||||
doReturn(true).when(mBackend).isWhitelisted(PKG_IN_WHITELIST);
|
||||
doReturn(false).when(mBackend).isAllowlisted(PKG_NOT_IN_ALLOWLIST);
|
||||
doReturn(true).when(mBackend).isAllowlisted(PKG_IN_ALLOWLIST);
|
||||
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mController = spy(new BatteryOptimizationPreferenceController(mSettingsActivity, mFragment,
|
||||
PKG_NOT_IN_WHITELIST, mBackend));
|
||||
PKG_NOT_IN_ALLOWLIST, mBackend));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,10 +95,10 @@ public class BatteryOptimizationPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_appInWhitelist_showSummaryNotOptimized() {
|
||||
public void testUpdateState_appInAllowlist_showSummaryNotOptimized() {
|
||||
BatteryOptimizationPreferenceController controller =
|
||||
new BatteryOptimizationPreferenceController(mSettingsActivity, mFragment,
|
||||
PKG_IN_WHITELIST, mBackend);
|
||||
PKG_IN_ALLOWLIST, mBackend);
|
||||
|
||||
controller.updateState(mPreference);
|
||||
|
||||
@@ -106,7 +106,7 @@ public class BatteryOptimizationPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_appNotInWhitelist_showSummaryOptimized() {
|
||||
public void testUpdateState_appNotInAllowlist_showSummaryOptimized() {
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo(mContext.getString(R.string.high_power_off));
|
||||
@@ -115,9 +115,9 @@ public class BatteryOptimizationPreferenceControllerTest {
|
||||
/**
|
||||
* Create this test class so we could mock it
|
||||
*/
|
||||
public static class TestPowerWhitelistBackend extends PowerWhitelistBackend {
|
||||
public static class TestPowerAllowlistBackend extends PowerAllowlistBackend {
|
||||
|
||||
public TestPowerWhitelistBackend(Context context) {
|
||||
public TestPowerAllowlistBackend(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
|
@@ -63,7 +63,7 @@ import com.android.settings.fuelgauge.batterytip.BatteryDatabaseManager;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowThreadUtils;
|
||||
import com.android.settingslib.fuelgauge.Estimate;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
@@ -160,7 +160,7 @@ public class BatteryUtilsTest {
|
||||
@Mock
|
||||
private ApplicationInfo mLowApplicationInfo;
|
||||
@Mock
|
||||
private PowerWhitelistBackend mPowerWhitelistBackend;
|
||||
private PowerAllowlistBackend mPowerAllowlistBackend;
|
||||
@Mock
|
||||
private BatteryDatabaseManager mBatteryDatabaseManager;
|
||||
private AnomalyInfo mAnomalyInfo;
|
||||
@@ -642,7 +642,7 @@ public class BatteryUtilsTest {
|
||||
doReturn(new String[]{HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
|
||||
mHighApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
|
||||
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerWhitelistBackend, UID,
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerAllowlistBackend, UID,
|
||||
mAnomalyInfo)).isTrue();
|
||||
}
|
||||
|
||||
@@ -652,7 +652,7 @@ public class BatteryUtilsTest {
|
||||
doReturn(new String[]{HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
|
||||
mHighApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
|
||||
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerWhitelistBackend, UID,
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerAllowlistBackend, UID,
|
||||
mAnomalyInfo)).isTrue();
|
||||
}
|
||||
|
||||
@@ -661,16 +661,16 @@ public class BatteryUtilsTest {
|
||||
final int systemUid = Process.ROOT_UID;
|
||||
doReturn(new String[]{HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(systemUid);
|
||||
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerWhitelistBackend, systemUid,
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerAllowlistBackend, systemUid,
|
||||
mAnomalyInfo)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldHideAnomaly_AppInDozeList_returnTrue() {
|
||||
doReturn(new String[]{HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
|
||||
doReturn(true).when(mPowerWhitelistBackend).isWhitelisted(new String[]{HIGH_SDK_PACKAGE});
|
||||
doReturn(true).when(mPowerAllowlistBackend).isAllowlisted(new String[]{HIGH_SDK_PACKAGE});
|
||||
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerWhitelistBackend, UID,
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerAllowlistBackend, UID,
|
||||
mAnomalyInfo)).isTrue();
|
||||
}
|
||||
|
||||
@@ -678,7 +678,7 @@ public class BatteryUtilsTest {
|
||||
public void testShouldHideAnomaly_normalApp_returnFalse() {
|
||||
doReturn(new String[]{HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
|
||||
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerWhitelistBackend, UID,
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerAllowlistBackend, UID,
|
||||
mAnomalyInfo)).isFalse();
|
||||
}
|
||||
|
||||
@@ -687,7 +687,7 @@ public class BatteryUtilsTest {
|
||||
doReturn(new String[]{LOW_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
|
||||
mAnomalyInfo = new AnomalyInfo(INFO_EXCESSIVE);
|
||||
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerWhitelistBackend, UID,
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerAllowlistBackend, UID,
|
||||
mAnomalyInfo)).isFalse();
|
||||
}
|
||||
|
||||
@@ -696,7 +696,7 @@ public class BatteryUtilsTest {
|
||||
doReturn(new String[]{HIGH_SDK_PACKAGE}).when(mPackageManager).getPackagesForUid(UID);
|
||||
mAnomalyInfo = new AnomalyInfo(INFO_EXCESSIVE);
|
||||
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerWhitelistBackend, UID,
|
||||
assertThat(mBatteryUtils.shouldHideAnomaly(mPowerAllowlistBackend, UID,
|
||||
mAnomalyInfo)).isTrue();
|
||||
}
|
||||
|
||||
|
@@ -32,7 +32,7 @@ import android.content.DialogInterface;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -52,7 +52,7 @@ public class HighPowerDetailTest {
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private PowerWhitelistBackend mPowerWhitelistBackend;
|
||||
private PowerAllowlistBackend mPowerAllowlistBackend;
|
||||
@Mock
|
||||
private BatteryUtils mBatteryUtils;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class HighPowerDetailTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mFragment = spy(new HighPowerDetail());
|
||||
mFragment.mBackend = mPowerWhitelistBackend;
|
||||
mFragment.mBackend = mPowerAllowlistBackend;
|
||||
mFragment.mBatteryUtils = mBatteryUtils;
|
||||
mFragment.mPackageUid = TEST_UID;
|
||||
mFragment.mPackageName = TEST_PACKAGE;
|
||||
@@ -71,21 +71,21 @@ public class HighPowerDetailTest {
|
||||
|
||||
@Test
|
||||
public void logSpecialPermissionChange() {
|
||||
// Deny means app is whitelisted to opt out of power save restrictions
|
||||
// Deny means app is allowlisted to opt out of power save restrictions
|
||||
HighPowerDetail.logSpecialPermissionChange(true, "app", RuntimeEnvironment.application);
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_BATTERY_DENY), eq("app"));
|
||||
|
||||
// Allow means app is NOT whitelisted to opt out of power save restrictions
|
||||
// Allow means app is NOT allowlisted to opt out of power save restrictions
|
||||
HighPowerDetail.logSpecialPermissionChange(false, "app", RuntimeEnvironment.application);
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.APP_SPECIAL_PERMISSION_BATTERY_ALLOW), eq("app"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClick_appAddedToDozeWhitelist_getsUnrestricted() {
|
||||
public void onClick_appAddedToDozeAllowlist_getsUnrestricted() {
|
||||
mFragment.mIsEnabled = true;
|
||||
when(mPowerWhitelistBackend.isWhitelisted(TEST_PACKAGE)).thenReturn(false);
|
||||
when(mPowerAllowlistBackend.isAllowlisted(TEST_PACKAGE)).thenReturn(false);
|
||||
mFragment.onClick(null, DialogInterface.BUTTON_POSITIVE);
|
||||
verify(mBatteryUtils).setForceAppStandby(TEST_UID, TEST_PACKAGE,
|
||||
AppOpsManager.MODE_ALLOWED);
|
||||
@@ -93,9 +93,9 @@ public class HighPowerDetailTest {
|
||||
|
||||
@Test
|
||||
public void getSummary_defaultActivePackage_returnUnavailable() {
|
||||
doReturn(true).when(mPowerWhitelistBackend).isDefaultActiveApp(TEST_PACKAGE);
|
||||
doReturn(true).when(mPowerAllowlistBackend).isDefaultActiveApp(TEST_PACKAGE);
|
||||
|
||||
assertThat(HighPowerDetail.getSummary(mContext, mPowerWhitelistBackend, TEST_PACKAGE))
|
||||
assertThat(HighPowerDetail.getSummary(mContext, mPowerAllowlistBackend, TEST_PACKAGE))
|
||||
.isEqualTo(mContext.getString(R.string.high_power_system));
|
||||
}
|
||||
}
|
||||
|
@@ -36,7 +36,6 @@ import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.RuntimeEnvironment.application;
|
||||
|
||||
import android.app.JobSchedulerImpl;
|
||||
import android.app.StatsManager;
|
||||
@@ -59,8 +58,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
||||
import com.android.settings.testutils.shadow.ShadowPowerWhitelistBackend;
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -78,7 +76,7 @@ import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowConnectivityManager.class, ShadowPowerWhitelistBackend.class})
|
||||
@Config(shadows = {ShadowConnectivityManager.class})
|
||||
public class AnomalyDetectionJobServiceTest {
|
||||
private static final int UID = 12345;
|
||||
private static final String SYSTEM_PACKAGE = "com.android.system";
|
||||
@@ -95,7 +93,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
@Mock
|
||||
private BatteryUtils mBatteryUtils;
|
||||
@Mock
|
||||
private PowerWhitelistBackend mPowerWhitelistBackend;
|
||||
private PowerAllowlistBackend mPowerAllowlistBackend;
|
||||
@Mock
|
||||
private StatsDimensionsValue mStatsDimensionsValue;
|
||||
@Mock
|
||||
@@ -145,13 +143,13 @@ public class AnomalyDetectionJobServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveAnomalyToDatabase_systemWhitelisted_doNotSave() {
|
||||
public void saveAnomalyToDatabase_systemAllowlisted_doNotSave() {
|
||||
doReturn(UID).when(mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
|
||||
doReturn(true).when(mPowerWhitelistBackend).isWhitelisted(any(String[].class));
|
||||
doReturn(true).when(mPowerAllowlistBackend).isAllowlisted(any(String[].class));
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
|
||||
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
|
||||
mPowerWhitelistBackend, mContext.getContentResolver(),
|
||||
mPowerAllowlistBackend, mContext.getContentResolver(),
|
||||
mFeatureFactory.powerUsageFeatureProvider,
|
||||
mFeatureFactory.metricsFeatureProvider, mBundle);
|
||||
|
||||
@@ -165,14 +163,14 @@ public class AnomalyDetectionJobServiceTest {
|
||||
cookies.add(SUBSCRIBER_COOKIES_AUTO_RESTRICTION);
|
||||
mBundle.putStringArrayList(StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES, cookies);
|
||||
doReturn(SYSTEM_PACKAGE).when(mBatteryUtils).getPackageName(anyInt());
|
||||
doReturn(false).when(mPowerWhitelistBackend).isSysWhitelisted(SYSTEM_PACKAGE);
|
||||
doReturn(false).when(mPowerAllowlistBackend).isSysAllowlisted(SYSTEM_PACKAGE);
|
||||
doReturn(Process.FIRST_APPLICATION_UID).when(
|
||||
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
|
||||
doReturn(true).when(mBatteryUtils).shouldHideAnomaly(any(), anyInt(), any());
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
|
||||
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
|
||||
mPowerWhitelistBackend, mContext.getContentResolver(),
|
||||
mPowerAllowlistBackend, mContext.getContentResolver(),
|
||||
mFeatureFactory.powerUsageFeatureProvider,
|
||||
mFeatureFactory.metricsFeatureProvider, mBundle);
|
||||
|
||||
@@ -192,7 +190,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
|
||||
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
|
||||
mPowerWhitelistBackend, mContext.getContentResolver(),
|
||||
mPowerAllowlistBackend, mContext.getContentResolver(),
|
||||
mFeatureFactory.powerUsageFeatureProvider, mFeatureFactory.metricsFeatureProvider,
|
||||
mBundle);
|
||||
|
||||
@@ -207,7 +205,7 @@ public class AnomalyDetectionJobServiceTest {
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
|
||||
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
|
||||
mPowerWhitelistBackend, mContext.getContentResolver(),
|
||||
mPowerAllowlistBackend, mContext.getContentResolver(),
|
||||
mFeatureFactory.powerUsageFeatureProvider, mFeatureFactory.metricsFeatureProvider,
|
||||
mBundle);
|
||||
|
||||
@@ -221,13 +219,13 @@ public class AnomalyDetectionJobServiceTest {
|
||||
cookies.add(SUBSCRIBER_COOKIES_AUTO_RESTRICTION);
|
||||
mBundle.putStringArrayList(StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES, cookies);
|
||||
doReturn(SYSTEM_PACKAGE).when(mBatteryUtils).getPackageName(anyInt());
|
||||
doReturn(false).when(mPowerWhitelistBackend).isSysWhitelisted(SYSTEM_PACKAGE);
|
||||
doReturn(false).when(mPowerAllowlistBackend).isSysAllowlisted(SYSTEM_PACKAGE);
|
||||
doReturn(Process.FIRST_APPLICATION_UID).when(
|
||||
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
|
||||
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
|
||||
mPowerWhitelistBackend, mContext.getContentResolver(),
|
||||
mPowerAllowlistBackend, mContext.getContentResolver(),
|
||||
mFeatureFactory.powerUsageFeatureProvider, mFeatureFactory.metricsFeatureProvider,
|
||||
mBundle);
|
||||
|
||||
@@ -246,13 +244,13 @@ public class AnomalyDetectionJobServiceTest {
|
||||
cookies.add(SUBSCRIBER_COOKIES_NOT_AUTO_RESTRICTION);
|
||||
mBundle.putStringArrayList(StatsManager.EXTRA_STATS_BROADCAST_SUBSCRIBER_COOKIES, cookies);
|
||||
doReturn(SYSTEM_PACKAGE).when(mBatteryUtils).getPackageName(anyInt());
|
||||
doReturn(false).when(mPowerWhitelistBackend).isSysWhitelisted(SYSTEM_PACKAGE);
|
||||
doReturn(false).when(mPowerAllowlistBackend).isSysAllowlisted(SYSTEM_PACKAGE);
|
||||
doReturn(Process.FIRST_APPLICATION_UID).when(
|
||||
mAnomalyDetectionJobService).extractUidFromStatsDimensionsValue(any());
|
||||
|
||||
mAnomalyDetectionJobService.saveAnomalyToDatabase(mContext,
|
||||
mUserManager, mBatteryDatabaseManager, mBatteryUtils, mPolicy,
|
||||
mPowerWhitelistBackend, mContext.getContentResolver(),
|
||||
mPowerAllowlistBackend, mContext.getContentResolver(),
|
||||
mFeatureFactory.powerUsageFeatureProvider, mFeatureFactory.metricsFeatureProvider,
|
||||
mBundle);
|
||||
|
||||
|
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
@Implements(PowerWhitelistBackend.class)
|
||||
public class ShadowPowerWhitelistBackend {
|
||||
protected void __constructor__() {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user