Remove the feature flag for forced_app_standby

The forced-app-standby or background-restriction feature is now a stable
feature that has been in multiple releases. The code for toggling it on
or off is no longer required.

Test: atest CtsAlarmManagerTestCases:BackgroundRestrictedAlarmsTest
Test: atest FrameworksMockingServicesTests:AppStateTrackerTest
Test: atest CtsJobSchedulerTestCases:JobThrottlingTest
Test: Manually test that background restriction UI works as expected.

Bug: 265350615
Change-Id: I109dd97f9918e97ab2406b99ce15bd991071b7c7
This commit is contained in:
Suprabh Shukla
2023-01-18 22:25:44 -08:00
parent 83eb599a8f
commit 0da993900e
6 changed files with 11 additions and 102 deletions

View File

@@ -157,18 +157,12 @@ public class AppStateTrackerImpl implements AppStateTracker {
@GuardedBy("mLock")
boolean mForceAllAppStandbyForSmallBattery;
/**
* True if the forced app standby feature is enabled in settings
*/
@GuardedBy("mLock")
boolean mForcedAppStandbyEnabled;
/**
* A lock-free set of (uid, packageName) pairs in background restricted mode.
*
* <p>
* It's bascially shadowing the {@link #mRunAnyRestrictedPackages} together with
* the {@link #mForcedAppStandbyEnabled} - mutations on them would result in copy-on-write.
* It's basically shadowing the {@link #mRunAnyRestrictedPackages}, any mutations on it would
* result in copy-on-write.
* </p>
*/
volatile Set<Pair<Integer, String>> mBackgroundRestrictedUidPackages = Collections.emptySet();
@@ -200,10 +194,9 @@ public class AppStateTrackerImpl implements AppStateTracker {
int TEMP_EXEMPTION_LIST_CHANGED = 5;
int EXEMPTED_BUCKET_CHANGED = 6;
int FORCE_ALL_CHANGED = 7;
int FORCE_APP_STANDBY_FEATURE_FLAG_CHANGED = 8;
int IS_UID_ACTIVE_CACHED = 9;
int IS_UID_ACTIVE_RAW = 10;
int IS_UID_ACTIVE_CACHED = 8;
int IS_UID_ACTIVE_RAW = 9;
}
private final StatLogger mStatLogger = new StatLogger(new String[] {
@@ -215,7 +208,6 @@ public class AppStateTrackerImpl implements AppStateTracker {
"TEMP_EXEMPTION_LIST_CHANGED",
"EXEMPTED_BUCKET_CHANGED",
"FORCE_ALL_CHANGED",
"FORCE_APP_STANDBY_FEATURE_FLAG_CHANGED",
"IS_UID_ACTIVE_CACHED",
"IS_UID_ACTIVE_RAW",
@@ -228,18 +220,10 @@ public class AppStateTrackerImpl implements AppStateTracker {
}
void register() {
mContext.getContentResolver().registerContentObserver(
Settings.Global.getUriFor(Settings.Global.FORCED_APP_STANDBY_ENABLED),
false, this);
mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(
Settings.Global.FORCED_APP_STANDBY_FOR_SMALL_BATTERY_ENABLED), false, this);
}
boolean isForcedAppStandbyEnabled() {
return injectGetGlobalSettingInt(Settings.Global.FORCED_APP_STANDBY_ENABLED, 1) == 1;
}
boolean isForcedAppStandbyForSmallBatteryEnabled() {
return injectGetGlobalSettingInt(
Settings.Global.FORCED_APP_STANDBY_FOR_SMALL_BATTERY_ENABLED, 0) == 1;
@@ -247,21 +231,7 @@ public class AppStateTrackerImpl implements AppStateTracker {
@Override
public void onChange(boolean selfChange, Uri uri) {
if (Settings.Global.getUriFor(Settings.Global.FORCED_APP_STANDBY_ENABLED).equals(uri)) {
final boolean enabled = isForcedAppStandbyEnabled();
synchronized (mLock) {
if (mForcedAppStandbyEnabled == enabled) {
return;
}
mForcedAppStandbyEnabled = enabled;
updateBackgroundRestrictedUidPackagesLocked();
if (DEBUG) {
Slog.d(TAG, "Forced app standby feature flag changed: "
+ mForcedAppStandbyEnabled);
}
}
mHandler.notifyForcedAppStandbyFeatureFlagChanged();
} else if (Settings.Global.getUriFor(
if (Settings.Global.getUriFor(
Settings.Global.FORCED_APP_STANDBY_FOR_SMALL_BATTERY_ENABLED).equals(uri)) {
final boolean enabled = isForcedAppStandbyForSmallBatteryEnabled();
synchronized (mLock) {
@@ -515,7 +485,6 @@ public class AppStateTrackerImpl implements AppStateTracker {
mFlagsObserver = new FeatureFlagsObserver();
mFlagsObserver.register();
mForcedAppStandbyEnabled = mFlagsObserver.isForcedAppStandbyEnabled();
mForceAllAppStandbyForSmallBattery =
mFlagsObserver.isForcedAppStandbyForSmallBatteryEnabled();
mStandbyTracker = new StandbyTracker();
@@ -636,14 +605,10 @@ public class AppStateTrackerImpl implements AppStateTracker {
/**
* Update the {@link #mBackgroundRestrictedUidPackages} upon mutations on
* {@link #mRunAnyRestrictedPackages} or {@link #mForcedAppStandbyEnabled}.
* {@link #mRunAnyRestrictedPackages}.
*/
@GuardedBy("mLock")
private void updateBackgroundRestrictedUidPackagesLocked() {
if (!mForcedAppStandbyEnabled) {
mBackgroundRestrictedUidPackages = Collections.emptySet();
return;
}
Set<Pair<Integer, String>> fasUidPkgs = new ArraySet<>();
for (int i = 0, size = mRunAnyRestrictedPackages.size(); i < size; i++) {
fasUidPkgs.add(mRunAnyRestrictedPackages.valueAt(i));
@@ -821,13 +786,14 @@ public class AppStateTrackerImpl implements AppStateTracker {
private class MyHandler extends Handler {
private static final int MSG_UID_ACTIVE_STATE_CHANGED = 0;
// Unused ids 1, 2.
private static final int MSG_RUN_ANY_CHANGED = 3;
private static final int MSG_ALL_UNEXEMPTED = 4;
private static final int MSG_ALL_EXEMPTION_LIST_CHANGED = 5;
private static final int MSG_TEMP_EXEMPTION_LIST_CHANGED = 6;
private static final int MSG_FORCE_ALL_CHANGED = 7;
private static final int MSG_USER_REMOVED = 8;
private static final int MSG_FORCE_APP_STANDBY_FEATURE_FLAG_CHANGED = 9;
// Unused id 9.
private static final int MSG_EXEMPTED_BUCKET_CHANGED = 10;
private static final int MSG_AUTO_RESTRICTED_BUCKET_FEATURE_FLAG_CHANGED = 11;
@@ -867,11 +833,6 @@ public class AppStateTrackerImpl implements AppStateTracker {
obtainMessage(MSG_FORCE_ALL_CHANGED).sendToTarget();
}
public void notifyForcedAppStandbyFeatureFlagChanged() {
removeMessages(MSG_FORCE_APP_STANDBY_FEATURE_FLAG_CHANGED);
obtainMessage(MSG_FORCE_APP_STANDBY_FEATURE_FLAG_CHANGED).sendToTarget();
}
public void notifyExemptedBucketChanged() {
removeMessages(MSG_EXEMPTED_BUCKET_CHANGED);
obtainMessage(MSG_EXEMPTED_BUCKET_CHANGED).sendToTarget();
@@ -966,22 +927,6 @@ public class AppStateTrackerImpl implements AppStateTracker {
mStatLogger.logDurationStat(Stats.FORCE_ALL_CHANGED, start);
return;
case MSG_FORCE_APP_STANDBY_FEATURE_FLAG_CHANGED:
// Feature flag for forced app standby changed.
final boolean unblockAlarms;
synchronized (mLock) {
unblockAlarms = !mForcedAppStandbyEnabled;
}
for (Listener l : cloneListeners()) {
l.updateAllJobs();
if (unblockAlarms) {
l.unblockAllUnrestrictedAlarms();
}
}
mStatLogger.logDurationStat(
Stats.FORCE_APP_STANDBY_FEATURE_FLAG_CHANGED, start);
return;
case MSG_USER_REMOVED:
handleUserRemoved(msg.arg1);
return;
@@ -1164,8 +1109,7 @@ public class AppStateTrackerImpl implements AppStateTracker {
// If apps will be put into restricted standby bucket automatically on user-forced
// app standby, instead of blocking alarms completely, let the restricted standby bucket
// policy take care of it.
return (mForcedAppStandbyEnabled
&& !mActivityManagerInternal.isBgAutoRestrictedBucketFeatureFlagEnabled()
return (!mActivityManagerInternal.isBgAutoRestrictedBucketFeatureFlagEnabled()
&& isRunAnyRestrictedLocked(uid, packageName));
}
}
@@ -1210,8 +1154,7 @@ public class AppStateTrackerImpl implements AppStateTracker {
// If apps will be put into restricted standby bucket automatically on user-forced
// app standby, instead of blocking jobs completely, let the restricted standby bucket
// policy take care of it.
if (mForcedAppStandbyEnabled
&& !mActivityManagerInternal.isBgAutoRestrictedBucketFeatureFlagEnabled()
if (!mActivityManagerInternal.isBgAutoRestrictedBucketFeatureFlagEnabled()
&& isRunAnyRestrictedLocked(uid, packageName)) {
return true;
}
@@ -1321,8 +1264,6 @@ public class AppStateTrackerImpl implements AppStateTracker {
pw.println("Current AppStateTracker State:");
pw.increaseIndent();
pw.println("Forced App Standby Feature enabled: " + mForcedAppStandbyEnabled);
pw.print("Force all apps standby: ");
pw.println(isForceAllAppsStandbyEnabled());
@@ -1400,8 +1341,6 @@ public class AppStateTrackerImpl implements AppStateTracker {
synchronized (mLock) {
final long token = proto.start(fieldId);
proto.write(AppStateTrackerProto.FORCED_APP_STANDBY_FEATURE_ENABLED,
mForcedAppStandbyEnabled);
proto.write(AppStateTrackerProto.FORCE_ALL_APPS_STANDBY,
isForceAllAppsStandbyEnabled());
proto.write(AppStateTrackerProto.IS_SMALL_BATTERY_DEVICE, isSmallBatteryDevice());

View File

@@ -5379,9 +5379,7 @@ public class AlarmManagerService extends SystemService {
@Override
public void unblockAllUnrestrictedAlarms() {
// Called when:
// 1. Power exemption list changes,
// 2. User FAS feature is disabled.
// Called when the power exemption list changes.
synchronized (mLock) {
sendAllUnrestrictedPendingBackgroundAlarmsLocked();
}

View File

@@ -14549,15 +14549,6 @@ public final class Settings {
public static final String APP_AUTO_RESTRICTION_ENABLED =
"app_auto_restriction_enabled";
/**
* Feature flag to enable or disable the Forced App Standby feature.
* Type: int (0 for false, 1 for true)
* Default: 1
* @hide
*/
@Readable
public static final String FORCED_APP_STANDBY_ENABLED = "forced_app_standby_enabled";
/**
* Whether or not to enable Forced App Standby on small battery devices.
* Type: int (0 for false, 1 for true)

View File

@@ -227,9 +227,6 @@ class SettingsProtoDumpUtil {
dumpSetting(s, p,
Settings.Global.APP_AUTO_RESTRICTION_ENABLED,
GlobalSettingsProto.App.AUTO_RESTRICTION_ENABLED);
dumpSetting(s, p,
Settings.Global.FORCED_APP_STANDBY_ENABLED,
GlobalSettingsProto.App.FORCED_APP_STANDBY_ENABLED);
dumpSetting(s, p,
Settings.Global.FORCED_APP_STANDBY_FOR_SMALL_BATTERY_ENABLED,
GlobalSettingsProto.App.FORCED_APP_STANDBY_FOR_SMALL_BATTERY_ENABLED);

View File

@@ -285,7 +285,6 @@ public class SettingsBackupTest {
Settings.Global.FANCY_IME_ANIMATIONS,
Settings.Global.ONE_HANDED_KEYGUARD_SIDE,
Settings.Global.FORCE_ALLOW_ON_EXTERNAL,
Settings.Global.FORCED_APP_STANDBY_ENABLED,
Settings.Global.FORCED_APP_STANDBY_FOR_SMALL_BATTERY_ENABLED,
Settings.Global.WIFI_ON_WHEN_PROXY_DISCONNECTED,
Settings.Global.FSTRIM_MANDATORY_INTERVAL,

View File

@@ -37,7 +37,6 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
import androidx.test.InstrumentationRegistry;
@@ -165,18 +164,6 @@ public class BackgroundRestrictionsTest {
awaitJobStart(DEFAULT_WAIT_TIMEOUT));
}
@FlakyTest
@Test
public void testFeatureFlag() throws Exception {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.FORCED_APP_STANDBY_ENABLED, 0);
scheduleAndAssertJobStarted();
setAppOpsModeAllowed(false);
mIActivityManager.makePackageIdle(TEST_APP_PACKAGE, UserHandle.USER_CURRENT);
assertFalse("Job stopped even when feature flag was disabled",
awaitJobStop(DEFAULT_WAIT_TIMEOUT, JobParameters.STOP_REASON_UNDEFINED));
}
@After
public void tearDown() throws Exception {
final Intent cancelJobsIntent = new Intent(TestJobActivity.ACTION_CANCEL_JOBS);
@@ -187,8 +174,6 @@ public class BackgroundRestrictionsTest {
Thread.sleep(500); // To avoid race with register in the next setUp
setAppOpsModeAllowed(true);
setPowerExemption(false);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.FORCED_APP_STANDBY_ENABLED, 1);
}
private void setPowerExemption(boolean exempt) throws RemoteException {