Merge "Call noteAppRestrictionChanged when toggling restrictions/exemptions" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
83da3f0041
@@ -558,6 +558,11 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
ActivityManager am = (ActivityManager) mActivity.getSystemService(
|
ActivityManager am = (ActivityManager) mActivity.getSystemService(
|
||||||
Context.ACTIVITY_SERVICE);
|
Context.ACTIVITY_SERVICE);
|
||||||
Log.d(TAG, "Stopping package " + pkgName);
|
Log.d(TAG, "Stopping package " + pkgName);
|
||||||
|
if (android.app.Flags.appRestrictionsApi()) {
|
||||||
|
am.noteAppRestrictionEnabled(pkgName, mAppEntry.info.uid,
|
||||||
|
ActivityManager.RESTRICTION_LEVEL_FORCE_STOPPED, true,
|
||||||
|
ActivityManager.RESTRICTION_REASON_USER, "settings", 0L);
|
||||||
|
}
|
||||||
am.forceStopPackage(pkgName);
|
am.forceStopPackage(pkgName);
|
||||||
int userId = UserHandle.getUserId(mAppEntry.info.uid);
|
int userId = UserHandle.getUserId(mAppEntry.info.uid);
|
||||||
mState.invalidatePackage(pkgName, userId);
|
mState.invalidatePackage(pkgName, userId);
|
||||||
|
|||||||
@@ -345,9 +345,9 @@ public class BatteryOptimizeUtils {
|
|||||||
try {
|
try {
|
||||||
batteryUtils.setForceAppStandby(uid, packageName, appStandbyMode);
|
batteryUtils.setForceAppStandby(uid, packageName, appStandbyMode);
|
||||||
if (allowListed) {
|
if (allowListed) {
|
||||||
powerAllowlistBackend.addApp(packageName);
|
powerAllowlistBackend.addApp(packageName, uid);
|
||||||
} else {
|
} else {
|
||||||
powerAllowlistBackend.removeApp(packageName);
|
powerAllowlistBackend.removeApp(packageName, uid);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Error cases, set standby mode as -1 for logging.
|
// Error cases, set standby mode as -1 for logging.
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.fuelgauge;
|
package com.android.settings.fuelgauge;
|
||||||
|
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -386,6 +387,14 @@ public class BatteryUtils {
|
|||||||
// Control whether app could run in the background if it is pre O app
|
// Control whether app could run in the background if it is pre O app
|
||||||
mAppOpsManager.setMode(AppOpsManager.OP_RUN_IN_BACKGROUND, uid, packageName, mode);
|
mAppOpsManager.setMode(AppOpsManager.OP_RUN_IN_BACKGROUND, uid, packageName, mode);
|
||||||
}
|
}
|
||||||
|
// Notify system of reason for change
|
||||||
|
if (isForceAppStandbyEnabled(uid, packageName) != (mode == AppOpsManager.MODE_IGNORED)) {
|
||||||
|
mContext.getSystemService(ActivityManager.class).noteAppRestrictionEnabled(
|
||||||
|
packageName, uid, ActivityManager.RESTRICTION_LEVEL_BACKGROUND_RESTRICTED,
|
||||||
|
mode == AppOpsManager.MODE_IGNORED,
|
||||||
|
ActivityManager.RESTRICTION_REASON_USER,
|
||||||
|
"settings", 0);
|
||||||
|
}
|
||||||
// Control whether app could run jobs in the background
|
// Control whether app could run jobs in the background
|
||||||
mAppOpsManager.setMode(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, uid, packageName, mode);
|
mAppOpsManager.setMode(AppOpsManager.OP_RUN_ANY_IN_BACKGROUND, uid, packageName, mode);
|
||||||
|
|
||||||
|
|||||||
@@ -142,9 +142,9 @@ public class HighPowerDetail extends InstrumentedDialogFragment
|
|||||||
if (newValue) {
|
if (newValue) {
|
||||||
mBatteryUtils.setForceAppStandby(
|
mBatteryUtils.setForceAppStandby(
|
||||||
mPackageUid, mPackageName, AppOpsManager.MODE_ALLOWED);
|
mPackageUid, mPackageName, AppOpsManager.MODE_ALLOWED);
|
||||||
mBackend.addApp(mPackageName);
|
mBackend.addApp(mPackageName, mPackageUid);
|
||||||
} else {
|
} else {
|
||||||
mBackend.removeApp(mPackageName);
|
mBackend.removeApp(mPackageName, mPackageUid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.spa.app.appinfo
|
package com.android.settings.spa.app.appinfo
|
||||||
|
|
||||||
|
import android.app.ActivityManager
|
||||||
import android.app.settings.SettingsEnums
|
import android.app.settings.SettingsEnums
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
@@ -154,6 +155,13 @@ class PackageInfoPresenter(
|
|||||||
logAction(SettingsEnums.ACTION_APP_FORCE_STOP)
|
logAction(SettingsEnums.ACTION_APP_FORCE_STOP)
|
||||||
coroutineScope.launch(Dispatchers.Default) {
|
coroutineScope.launch(Dispatchers.Default) {
|
||||||
Log.d(TAG, "Stopping package $packageName")
|
Log.d(TAG, "Stopping package $packageName")
|
||||||
|
if (android.app.Flags.appRestrictionsApi()) {
|
||||||
|
val uid = userPackageManager.getPackageUid(packageName, 0)
|
||||||
|
context.activityManager.noteAppRestrictionEnabled(
|
||||||
|
packageName, uid,
|
||||||
|
ActivityManager.RESTRICTION_LEVEL_FORCE_STOPPED, true,
|
||||||
|
ActivityManager.RESTRICTION_REASON_USER, "settings", 0)
|
||||||
|
}
|
||||||
context.activityManager.forceStopPackageAsUser(packageName, userId)
|
context.activityManager.forceStopPackageAsUser(packageName, userId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -206,8 +206,8 @@ public class BatteryOptimizeUtilsTest {
|
|||||||
TimeUnit.SECONDS.sleep(1);
|
TimeUnit.SECONDS.sleep(1);
|
||||||
|
|
||||||
verify(mMockBatteryUtils, never()).setForceAppStandby(anyInt(), anyString(), anyInt());
|
verify(mMockBatteryUtils, never()).setForceAppStandby(anyInt(), anyString(), anyInt());
|
||||||
verify(mMockBackend, never()).addApp(anyString());
|
verify(mMockBackend, never()).addApp(anyString(), anyInt());
|
||||||
verify(mMockBackend, never()).removeApp(anyString());
|
verify(mMockBackend, never()).removeApp(anyString(), anyInt());
|
||||||
verifyNoInteractions(mObserver);
|
verifyNoInteractions(mObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,9 +358,9 @@ public class BatteryOptimizeUtilsTest {
|
|||||||
private void verifySetAppOptimizationMode(int appStandbyMode, boolean allowListed) {
|
private void verifySetAppOptimizationMode(int appStandbyMode, boolean allowListed) {
|
||||||
verify(mMockBatteryUtils).setForceAppStandby(UID, PACKAGE_NAME, appStandbyMode);
|
verify(mMockBatteryUtils).setForceAppStandby(UID, PACKAGE_NAME, appStandbyMode);
|
||||||
if (allowListed) {
|
if (allowListed) {
|
||||||
verify(mMockBackend).addApp(PACKAGE_NAME);
|
verify(mMockBackend).addApp(PACKAGE_NAME, UID);
|
||||||
} else {
|
} else {
|
||||||
verify(mMockBackend).removeApp(PACKAGE_NAME);
|
verify(mMockBackend).removeApp(PACKAGE_NAME, UID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user