Hook up hibernation eligibility to exemption toggle
Use hibernation eligibility API to determine whether toggle should be enabled or disabled for an app. For apps that are already exempt from hibernation by the system, the toggle is disabled and unchecked. Bug: 200087723 Test: manual Test: atest AppHibernationIntegrationTest Change-Id: I36a1eafc2bb90a92bcbdc4bf32041426d6377fd4
This commit is contained in:
@@ -27,6 +27,8 @@ import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
|
||||
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.eq;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -43,6 +45,7 @@ import androidx.preference.SwitchPreference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -68,6 +71,7 @@ public class HibernationSwitchPreferenceControllerTest {
|
||||
|
||||
private HibernationSwitchPreferenceController mController;
|
||||
private Context mContext;
|
||||
private String mOriginalPreSFlagValue;
|
||||
|
||||
@Before
|
||||
public void setUp() throws PackageManager.NameNotFoundException {
|
||||
@@ -89,6 +93,16 @@ public class HibernationSwitchPreferenceControllerTest {
|
||||
"true", true /* makeDefault */);
|
||||
mController = new HibernationSwitchPreferenceController(mContext, KEY);
|
||||
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
|
||||
@@ -124,43 +138,37 @@ public class HibernationSwitchPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_exemptedByDefaultPackage_shouldNotCheck() {
|
||||
public void isPackageHibernationExemptByUser_preSAppShouldBeExemptByDefault() {
|
||||
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(false);
|
||||
assertTrue(mController.isPackageHibernationExemptByUser());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_exemptedPackageOverrideByUser_shouldCheck() {
|
||||
public void isPackageHibernationExemptByUser_preSAppShouldNotBeExemptWithUserSetting() {
|
||||
when(mAppOpsManager.unsafeCheckOpNoThrow(
|
||||
eq(OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED), anyInt(), eq(EXEMPTED_PACKAGE_NAME)))
|
||||
.thenReturn(MODE_ALLOWED);
|
||||
mController.setPackage(EXEMPTED_PACKAGE_NAME);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setChecked(true);
|
||||
assertFalse(mController.isPackageHibernationExemptByUser());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_unexemptedPackageOverrideByUser_shouldNotCheck() {
|
||||
public void isPackageHibernationExemptByUser_SAppShouldBeExemptWithUserSetting() {
|
||||
when(mAppOpsManager.unsafeCheckOpNoThrow(
|
||||
eq(OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED), anyInt(), eq(UNEXEMPTED_PACKAGE_NAME)))
|
||||
.thenReturn(MODE_IGNORED);
|
||||
mController.setPackage(UNEXEMPTED_PACKAGE_NAME);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setChecked(false);
|
||||
assertTrue(mController.isPackageHibernationExemptByUser());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_exemptedByDefaultPackageOverriddenByPreSFlag_shouldCheck() {
|
||||
public void isPackageHibernationExemptByUser_preSAppShouldNotBeExemptByDefaultWithPreSFlag() {
|
||||
DeviceConfig.setProperty(NAMESPACE_APP_HIBERNATION, PROPERTY_HIBERNATION_TARGETS_PRE_S_APPS,
|
||||
"true", true /* makeDefault */);
|
||||
when(mAppOpsManager.unsafeCheckOpNoThrow(
|
||||
@@ -168,8 +176,6 @@ public class HibernationSwitchPreferenceControllerTest {
|
||||
.thenReturn(MODE_DEFAULT);
|
||||
mController.setPackage(EXEMPTED_PACKAGE_NAME);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setChecked(true);
|
||||
assertFalse(mController.isPackageHibernationExemptByUser());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user