Snap for 8151064 from d74f060971 to tm-release
Change-Id: Id208853ed5cea20a1345b49535faac90f6a71d36
This commit is contained in:
@@ -20,6 +20,8 @@ import static android.app.AppOpsManager.MODE_ALLOWED;
|
|||||||
import static android.app.AppOpsManager.MODE_DEFAULT;
|
import static android.app.AppOpsManager.MODE_DEFAULT;
|
||||||
import static android.app.AppOpsManager.MODE_IGNORED;
|
import static android.app.AppOpsManager.MODE_IGNORED;
|
||||||
import static android.app.AppOpsManager.OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED;
|
import static android.app.AppOpsManager.OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED;
|
||||||
|
import static android.permission.PermissionControllerManager.HIBERNATION_ELIGIBILITY_EXEMPT_BY_SYSTEM;
|
||||||
|
import static android.permission.PermissionControllerManager.HIBERNATION_ELIGIBILITY_UNKNOWN;
|
||||||
import static android.provider.DeviceConfig.NAMESPACE_APP_HIBERNATION;
|
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_APP_HIBERNATION_ENABLED;
|
||||||
@@ -29,6 +31,7 @@ import android.app.AppOpsManager;
|
|||||||
import android.apphibernation.AppHibernationManager;
|
import android.apphibernation.AppHibernationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.permission.PermissionControllerManager;
|
||||||
import android.provider.DeviceConfig;
|
import android.provider.DeviceConfig;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
@@ -51,7 +54,10 @@ public final class HibernationSwitchPreferenceController extends AppInfoPreferen
|
|||||||
private static final String TAG = "HibernationSwitchPrefController";
|
private static final String TAG = "HibernationSwitchPrefController";
|
||||||
private String mPackageName;
|
private String mPackageName;
|
||||||
private final AppOpsManager mAppOpsManager;
|
private final AppOpsManager mAppOpsManager;
|
||||||
|
private final PermissionControllerManager mPermissionControllerManager;
|
||||||
private int mPackageUid;
|
private int mPackageUid;
|
||||||
|
private boolean mHibernationEligibilityLoaded;
|
||||||
|
private int mHibernationEligibility = HIBERNATION_ELIGIBILITY_UNKNOWN;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean mIsPackageSet;
|
boolean mIsPackageSet;
|
||||||
private boolean mIsPackageExemptByDefault;
|
private boolean mIsPackageExemptByDefault;
|
||||||
@@ -60,6 +66,7 @@ public final class HibernationSwitchPreferenceController extends AppInfoPreferen
|
|||||||
String preferenceKey) {
|
String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
mAppOpsManager = context.getSystemService(AppOpsManager.class);
|
mAppOpsManager = context.getSystemService(AppOpsManager.class);
|
||||||
|
mPermissionControllerManager = context.getSystemService(PermissionControllerManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||||
@@ -109,10 +116,27 @@ public final class HibernationSwitchPreferenceController extends AppInfoPreferen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isAppEligibleForHibernation() {
|
||||||
|
return mHibernationEligibilityLoaded
|
||||||
|
&& mHibernationEligibility != HIBERNATION_ELIGIBILITY_EXEMPT_BY_SYSTEM
|
||||||
|
&& mHibernationEligibility != HIBERNATION_ELIGIBILITY_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
super.updateState(preference);
|
super.updateState(preference);
|
||||||
((SwitchPreference) preference).setChecked(!isPackageHibernationExemptByUser());
|
((SwitchPreference) preference).setChecked(isAppEligibleForHibernation()
|
||||||
|
&& !isPackageHibernationExemptByUser());
|
||||||
|
preference.setEnabled(isAppEligibleForHibernation());
|
||||||
|
if (!mHibernationEligibilityLoaded) {
|
||||||
|
mPermissionControllerManager.getHibernationEligibility(mPackageName,
|
||||||
|
mContext.getMainExecutor(),
|
||||||
|
eligibility -> {
|
||||||
|
mHibernationEligibility = eligibility;
|
||||||
|
mHibernationEligibilityLoaded = true;
|
||||||
|
updateState(preference);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|||||||
@@ -16,19 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings.display.darkmode;
|
package com.android.settings.display.darkmode;
|
||||||
|
|
||||||
|
import static android.provider.Settings.ACTION_BEDTIME_SETTINGS;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
/** Manages Digital Wellbeing bedtime settings' intents. */
|
/** Manages Digital Wellbeing bedtime settings' intents. */
|
||||||
public final class BedtimeSettings {
|
public final class BedtimeSettings {
|
||||||
@VisibleForTesting
|
|
||||||
public static final String ACTION_BEDTIME_SETTINGS = "android.settings.BEDTIME_SETTINGS";
|
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final PackageManager mPackageManager;
|
private final PackageManager mPackageManager;
|
||||||
private final String mWellbeingPackage;
|
private final String mWellbeingPackage;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.testutils;
|
package com.android.settings.testutils;
|
||||||
|
|
||||||
import static com.android.settings.display.darkmode.BedtimeSettings.ACTION_BEDTIME_SETTINGS;
|
import static android.provider.Settings.ACTION_BEDTIME_SETTINGS;
|
||||||
|
|
||||||
import static org.robolectric.Shadows.shadowOf;
|
import static org.robolectric.Shadows.shadowOf;
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
|||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@@ -89,6 +88,7 @@ public class UserDetailsSettingsTest {
|
|||||||
private static final String KEY_ENABLE_TELEPHONY = "enable_calling";
|
private static final String KEY_ENABLE_TELEPHONY = "enable_calling";
|
||||||
private static final String KEY_REMOVE_USER = "remove_user";
|
private static final String KEY_REMOVE_USER = "remove_user";
|
||||||
private static final String KEY_APP_AND_CONTENT_ACCESS = "app_and_content_access";
|
private static final String KEY_APP_AND_CONTENT_ACCESS = "app_and_content_access";
|
||||||
|
private static final String KEY_APP_COPYING = "app_copying";
|
||||||
|
|
||||||
private static final int DIALOG_CONFIRM_REMOVE = 1;
|
private static final int DIALOG_CONFIRM_REMOVE = 1;
|
||||||
|
|
||||||
@@ -105,6 +105,8 @@ public class UserDetailsSettingsTest {
|
|||||||
private Preference mRemoveUserPref;
|
private Preference mRemoveUserPref;
|
||||||
@Mock
|
@Mock
|
||||||
private Preference mAppAndContentAccessPref;
|
private Preference mAppAndContentAccessPref;
|
||||||
|
@Mock
|
||||||
|
private Preference mAppCopyingPref;
|
||||||
|
|
||||||
private FragmentActivity mActivity;
|
private FragmentActivity mActivity;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@@ -145,6 +147,7 @@ public class UserDetailsSettingsTest {
|
|||||||
doReturn(mRemoveUserPref).when(mFragment).findPreference(KEY_REMOVE_USER);
|
doReturn(mRemoveUserPref).when(mFragment).findPreference(KEY_REMOVE_USER);
|
||||||
doReturn(mAppAndContentAccessPref)
|
doReturn(mAppAndContentAccessPref)
|
||||||
.when(mFragment).findPreference(KEY_APP_AND_CONTENT_ACCESS);
|
.when(mFragment).findPreference(KEY_APP_AND_CONTENT_ACCESS);
|
||||||
|
doReturn(mAppCopyingPref).when(mFragment).findPreference(KEY_APP_COPYING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -163,7 +166,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_userSelected_shouldSetupSwitchPref() {
|
public void initialize_userSelected_shouldSetupSwitchPref() {
|
||||||
setupSelectedUser();
|
setupSelectedUser();
|
||||||
doReturn("Switch to " + mUserInfo.name)
|
doReturn("Switch to " + mUserInfo.name)
|
||||||
@@ -179,7 +181,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_guestSelected_shouldSetupSwitchPref() {
|
public void initialize_guestSelected_shouldSetupSwitchPref() {
|
||||||
setupSelectedGuest();
|
setupSelectedGuest();
|
||||||
doReturn("Switch to " + mUserInfo.name)
|
doReturn("Switch to " + mUserInfo.name)
|
||||||
@@ -195,7 +196,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_userSelected_shouldNotShowAppAndContentPref() {
|
public void initialize_userSelected_shouldNotShowAppAndContentPref() {
|
||||||
setupSelectedUser();
|
setupSelectedUser();
|
||||||
|
|
||||||
@@ -205,7 +205,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_guestSelected_shouldNotShowAppAndContentPref() {
|
public void initialize_guestSelected_shouldNotShowAppAndContentPref() {
|
||||||
setupSelectedGuest();
|
setupSelectedGuest();
|
||||||
|
|
||||||
@@ -259,7 +258,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_adminWithTelephony_shouldShowPhonePreference() {
|
public void initialize_adminWithTelephony_shouldShowPhonePreference() {
|
||||||
setupSelectedUser();
|
setupSelectedUser();
|
||||||
doReturn(true).when(mTelephonyManager).isVoiceCapable();
|
doReturn(true).when(mTelephonyManager).isVoiceCapable();
|
||||||
@@ -272,7 +270,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_adminNoTelephony_shouldNotShowPhonePreference() {
|
public void initialize_adminNoTelephony_shouldNotShowPhonePreference() {
|
||||||
setupSelectedUser();
|
setupSelectedUser();
|
||||||
doReturn(false).when(mTelephonyManager).isVoiceCapable();
|
doReturn(false).when(mTelephonyManager).isVoiceCapable();
|
||||||
@@ -306,7 +303,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_adminSelectsSecondaryUser_shouldShowRemovePreference() {
|
public void initialize_adminSelectsSecondaryUser_shouldShowRemovePreference() {
|
||||||
setupSelectedUser();
|
setupSelectedUser();
|
||||||
mUserManager.setIsAdminUser(true);
|
mUserManager.setIsAdminUser(true);
|
||||||
@@ -319,7 +315,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_adminSelectsNewRestrictedUser_shouldOpenAppContentScreen() {
|
public void initialize_adminSelectsNewRestrictedUser_shouldOpenAppContentScreen() {
|
||||||
setupSelectedRestrictedUser();
|
setupSelectedRestrictedUser();
|
||||||
mUserManager.setIsAdminUser(true);
|
mUserManager.setIsAdminUser(true);
|
||||||
@@ -342,7 +337,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_adminSelectsRestrictedUser_shouldSetupPreferences() {
|
public void initialize_adminSelectsRestrictedUser_shouldSetupPreferences() {
|
||||||
setupSelectedRestrictedUser();
|
setupSelectedRestrictedUser();
|
||||||
mUserManager.setIsAdminUser(true);
|
mUserManager.setIsAdminUser(true);
|
||||||
@@ -361,7 +355,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_adminSelectsExistingRestrictedUser_shouldNotStartAppAndContentAccess() {
|
public void initialize_adminSelectsExistingRestrictedUser_shouldNotStartAppAndContentAccess() {
|
||||||
setupSelectedRestrictedUser();
|
setupSelectedRestrictedUser();
|
||||||
mUserManager.setIsAdminUser(true);
|
mUserManager.setIsAdminUser(true);
|
||||||
@@ -373,7 +366,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_adminSelectsGuest_shouldShowRemovePreference() {
|
public void initialize_adminSelectsGuest_shouldShowRemovePreference() {
|
||||||
setupSelectedGuest();
|
setupSelectedGuest();
|
||||||
mUserManager.setIsAdminUser(true);
|
mUserManager.setIsAdminUser(true);
|
||||||
@@ -396,7 +388,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_disallowRemoveUserRestriction_shouldNotShowRemovePreference() {
|
public void initialize_disallowRemoveUserRestriction_shouldNotShowRemovePreference() {
|
||||||
setupSelectedUser();
|
setupSelectedUser();
|
||||||
mUserManager.setIsAdminUser(true);
|
mUserManager.setIsAdminUser(true);
|
||||||
@@ -408,7 +399,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_userHasCallRestriction_shouldSetPhoneSwitchUnChecked() {
|
public void initialize_userHasCallRestriction_shouldSetPhoneSwitchUnChecked() {
|
||||||
setupSelectedUser();
|
setupSelectedUser();
|
||||||
mUserManager.setIsAdminUser(true);
|
mUserManager.setIsAdminUser(true);
|
||||||
@@ -421,7 +411,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_noCallRestriction_shouldSetPhoneSwitchChecked() {
|
public void initialize_noCallRestriction_shouldSetPhoneSwitchChecked() {
|
||||||
setupSelectedUser();
|
setupSelectedUser();
|
||||||
mUserManager.setIsAdminUser(true);
|
mUserManager.setIsAdminUser(true);
|
||||||
@@ -432,7 +421,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_guestSelected_noCallRestriction_shouldSetPhonePreference() {
|
public void initialize_guestSelected_noCallRestriction_shouldSetPhonePreference() {
|
||||||
setupSelectedGuest();
|
setupSelectedGuest();
|
||||||
mUserManager.setIsAdminUser(true);
|
mUserManager.setIsAdminUser(true);
|
||||||
@@ -444,7 +432,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_guestSelected_callRestriction_shouldSetPhonePreference() {
|
public void initialize_guestSelected_callRestriction_shouldSetPhonePreference() {
|
||||||
setupSelectedGuest();
|
setupSelectedGuest();
|
||||||
mUserManager.setIsAdminUser(true);
|
mUserManager.setIsAdminUser(true);
|
||||||
@@ -457,7 +444,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_switchUserDisallowed_shouldSetAdminDisabledOnSwitchPreference() {
|
public void initialize_switchUserDisallowed_shouldSetAdminDisabledOnSwitchPreference() {
|
||||||
setupSelectedUser();
|
setupSelectedUser();
|
||||||
mUserCapabilities.mDisallowSwitchUser = true;
|
mUserCapabilities.mDisallowSwitchUser = true;
|
||||||
@@ -473,7 +459,6 @@ public class UserDetailsSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void initialize_switchUserAllowed_shouldSetSwitchPreferenceEnabled() {
|
public void initialize_switchUserAllowed_shouldSetSwitchPreferenceEnabled() {
|
||||||
setupSelectedUser();
|
setupSelectedUser();
|
||||||
mUserCapabilities.mDisallowSwitchUser = false;
|
mUserCapabilities.mDisallowSwitchUser = false;
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
@@ -43,6 +45,7 @@ import androidx.preference.SwitchPreference;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -68,6 +71,7 @@ public class HibernationSwitchPreferenceControllerTest {
|
|||||||
|
|
||||||
private HibernationSwitchPreferenceController mController;
|
private HibernationSwitchPreferenceController mController;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private String mOriginalPreSFlagValue;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws PackageManager.NameNotFoundException {
|
public void setUp() throws PackageManager.NameNotFoundException {
|
||||||
@@ -89,6 +93,16 @@ public class HibernationSwitchPreferenceControllerTest {
|
|||||||
"true", true /* makeDefault */);
|
"true", true /* makeDefault */);
|
||||||
mController = new HibernationSwitchPreferenceController(mContext, KEY);
|
mController = new HibernationSwitchPreferenceController(mContext, KEY);
|
||||||
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||||
|
|
||||||
|
mOriginalPreSFlagValue = DeviceConfig.getProperty(NAMESPACE_APP_HIBERNATION,
|
||||||
|
PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void cleanUp() {
|
||||||
|
// Restore original device config values.
|
||||||
|
DeviceConfig.setProperty(NAMESPACE_APP_HIBERNATION, PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS,
|
||||||
|
mOriginalPreSFlagValue, true /* makeDefault */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -124,43 +138,37 @@ public class HibernationSwitchPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_exemptedByDefaultPackage_shouldNotCheck() {
|
public void isPackageHibernationExemptByUser_preSAppShouldBeExemptByDefault() {
|
||||||
when(mAppOpsManager.unsafeCheckOpNoThrow(
|
when(mAppOpsManager.unsafeCheckOpNoThrow(
|
||||||
eq(OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED), anyInt(), eq(EXEMPTED_PACKAGE_NAME)))
|
eq(OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED), anyInt(), eq(EXEMPTED_PACKAGE_NAME)))
|
||||||
.thenReturn(MODE_DEFAULT);
|
.thenReturn(MODE_DEFAULT);
|
||||||
mController.setPackage(EXEMPTED_PACKAGE_NAME);
|
mController.setPackage(EXEMPTED_PACKAGE_NAME);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
assertTrue(mController.isPackageHibernationExemptByUser());
|
||||||
|
|
||||||
verify(mPreference).setChecked(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_exemptedPackageOverrideByUser_shouldCheck() {
|
public void isPackageHibernationExemptByUser_preSAppShouldNotBeExemptWithUserSetting() {
|
||||||
when(mAppOpsManager.unsafeCheckOpNoThrow(
|
when(mAppOpsManager.unsafeCheckOpNoThrow(
|
||||||
eq(OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED), anyInt(), eq(EXEMPTED_PACKAGE_NAME)))
|
eq(OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED), anyInt(), eq(EXEMPTED_PACKAGE_NAME)))
|
||||||
.thenReturn(MODE_ALLOWED);
|
.thenReturn(MODE_ALLOWED);
|
||||||
mController.setPackage(EXEMPTED_PACKAGE_NAME);
|
mController.setPackage(EXEMPTED_PACKAGE_NAME);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
assertFalse(mController.isPackageHibernationExemptByUser());
|
||||||
|
|
||||||
verify(mPreference).setChecked(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_unexemptedPackageOverrideByUser_shouldNotCheck() {
|
public void isPackageHibernationExemptByUser_SAppShouldBeExemptWithUserSetting() {
|
||||||
when(mAppOpsManager.unsafeCheckOpNoThrow(
|
when(mAppOpsManager.unsafeCheckOpNoThrow(
|
||||||
eq(OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED), anyInt(), eq(UNEXEMPTED_PACKAGE_NAME)))
|
eq(OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED), anyInt(), eq(UNEXEMPTED_PACKAGE_NAME)))
|
||||||
.thenReturn(MODE_IGNORED);
|
.thenReturn(MODE_IGNORED);
|
||||||
mController.setPackage(UNEXEMPTED_PACKAGE_NAME);
|
mController.setPackage(UNEXEMPTED_PACKAGE_NAME);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
assertTrue(mController.isPackageHibernationExemptByUser());
|
||||||
|
|
||||||
verify(mPreference).setChecked(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_exemptedByDefaultPackageOverriddenByPreSFlag_shouldCheck() {
|
public void isPackageHibernationExemptByUser_preSAppShouldNotBeExemptByDefaultWithPreSFlag() {
|
||||||
DeviceConfig.setProperty(NAMESPACE_APP_HIBERNATION, PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS,
|
DeviceConfig.setProperty(NAMESPACE_APP_HIBERNATION, PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS,
|
||||||
"true", true /* makeDefault */);
|
"true", true /* makeDefault */);
|
||||||
when(mAppOpsManager.unsafeCheckOpNoThrow(
|
when(mAppOpsManager.unsafeCheckOpNoThrow(
|
||||||
@@ -168,8 +176,6 @@ public class HibernationSwitchPreferenceControllerTest {
|
|||||||
.thenReturn(MODE_DEFAULT);
|
.thenReturn(MODE_DEFAULT);
|
||||||
mController.setPackage(EXEMPTED_PACKAGE_NAME);
|
mController.setPackage(EXEMPTED_PACKAGE_NAME);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
assertFalse(mController.isPackageHibernationExemptByUser());
|
||||||
|
|
||||||
verify(mPreference).setChecked(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user