Ensure hibernation exemption toggle uses pre-S flag
For dogfood, we want hibernation to target apps that target pre-S. This was done on the PermissionController side but the toggle in Settings did not visually reflect this policy, confusing dogfood/teamfood participants. This updates the default toggle position to consider whether the pre-S flag is on and then default to the "on" position for apps targeting pre-S if the flag was on for the device. Bug: 189260947 Test: atest HibernationSwitchPreferenceControllerTest Test: manual Change-Id: I9cd16e82e1eee4589cb17a356b6bf2e3297a8dd2
This commit is contained in:
@@ -161,6 +161,10 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
/** Whether or not app hibernation is enabled on the device **/
|
||||
public static final String PROPERTY_APP_HIBERNATION_ENABLED = "app_hibernation_enabled";
|
||||
|
||||
/** Whether or not app hibernation targets apps that target a pre-S SDK **/
|
||||
public static final String PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS =
|
||||
"app_hibernation_targets_pre_s_apps";
|
||||
|
||||
/** Whether or not Settings Shared Axis transition is enabled */
|
||||
public static final String SETTINGS_SHARED_AXIS_ENABLED = "settings_shared_axis_enabled";
|
||||
|
||||
|
@@ -23,6 +23,7 @@ import static android.app.AppOpsManager.OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED;
|
||||
import static android.provider.DeviceConfig.NAMESPACE_APP_HIBERNATION;
|
||||
|
||||
import static com.android.settings.Utils.PROPERTY_APP_HIBERNATION_ENABLED;
|
||||
import static com.android.settings.Utils.PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
@@ -95,8 +96,11 @@ public final class HibernationSwitchPreferenceController extends AppInfoPreferen
|
||||
: android.os.Build.VERSION_CODES.Q;
|
||||
try {
|
||||
mPackageUid = packageManager.getPackageUid(packageName, /* flags */ 0);
|
||||
mIsPackageExemptByDefault = packageManager.getTargetSdkVersion(packageName)
|
||||
<= maxTargetSdkVersionForExemptApps;
|
||||
mIsPackageExemptByDefault =
|
||||
hibernationTargetsPreSApps()
|
||||
? false
|
||||
: packageManager.getTargetSdkVersion(packageName)
|
||||
<= maxTargetSdkVersionForExemptApps;
|
||||
mIsPackageSet = true;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Slog.w(TAG, "Package [" + mPackageName + "] is not found!");
|
||||
@@ -142,4 +146,9 @@ public final class HibernationSwitchPreferenceController extends AppInfoPreferen
|
||||
return DeviceConfig.getBoolean(
|
||||
NAMESPACE_APP_HIBERNATION, PROPERTY_APP_HIBERNATION_ENABLED, false);
|
||||
}
|
||||
|
||||
private static boolean hibernationTargetsPreSApps() {
|
||||
return DeviceConfig.getBoolean(
|
||||
NAMESPACE_APP_HIBERNATION, PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS, false);
|
||||
}
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import static android.app.AppOpsManager.OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED;
|
||||
import static android.provider.DeviceConfig.NAMESPACE_APP_HIBERNATION;
|
||||
|
||||
import static com.android.settings.Utils.PROPERTY_APP_HIBERNATION_ENABLED;
|
||||
import static com.android.settings.Utils.PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS;
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
@@ -143,4 +144,18 @@ public class HibernationSwitchPreferenceControllerTest {
|
||||
|
||||
verify(mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_exemptedByDefaultPackageOverriddenByPreSFlag_shouldCheck() {
|
||||
DeviceConfig.setProperty(NAMESPACE_APP_HIBERNATION, PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS,
|
||||
"true", true /* makeDefault */);
|
||||
when(mAppOpsManager.unsafeCheckOpNoThrow(
|
||||
eq(OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED), anyInt(), eq(EXEMPTED_PACKAGE_NAME)))
|
||||
.thenReturn(MODE_DEFAULT);
|
||||
mController.setPackage(EXEMPTED_PACKAGE_NAME);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setChecked(true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user