Unhibernate an app when a user exempts it

When an app is exempted from hibernation, we unhibernate as well. This
prevents confusing situations where a user may return to the "Unused
Apps" page and sees that the app is still there even after exemption.

Bug: 205641871
Test: atest HibernationSwitchPreferenceControllerTest
Change-Id: I4f98a2212eefdb6c456a0de36d428021b262cca3
This commit is contained in:
Kevin Han
2021-11-09 16:47:35 -08:00
parent fcb067b577
commit 39f038137e
2 changed files with 23 additions and 1 deletions

View File

@@ -26,6 +26,7 @@ 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.apphibernation.AppHibernationManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.provider.DeviceConfig;
@@ -134,8 +135,15 @@ public final class HibernationSwitchPreferenceController extends AppInfoPreferen
@Override
public boolean onPreferenceChange(Preference preference, Object isChecked) {
try {
final boolean checked = (boolean) isChecked;
mAppOpsManager.setUidMode(OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED, mPackageUid,
(boolean) isChecked ? MODE_ALLOWED : MODE_IGNORED);
checked ? MODE_ALLOWED : MODE_IGNORED);
if (!checked) {
final AppHibernationManager ahm =
mContext.getSystemService(AppHibernationManager.class);
ahm.setHibernatingForUser(mPackageName, false);
ahm.setHibernatingGlobally(mPackageName, false);
}
} catch (RuntimeException e) {
return false;
}