Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9e245762 authored by Alan Stokes's avatar Alan Stokes
Browse files

Cleanup background activity starts for release.

This removes the parts of the feature that were only needed in beta
releases:
- Toast when a start is or would be blocked.
- Configurable whitelist of exempt apps.
- Global setting to disable.

Not to be submitted until after beta 5 is cut.

Bug: 131747138
Test: atest BackgroundActivityLaunchTest
Test: atest RootWindowContainerTests
Test: atest WmTests:ActivityStarterTests
Test: atest CtsWindowManagerDeviceTestCases:ActivityStarterTests
Test: atest CtsAppTestCases:.ServiceTest

Change-Id: I3d8b9c72c8fac86b93ac57a8a1988f4133043af8
parent b730e365
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -286,7 +286,6 @@ public abstract class ActivityManagerInternal {
    public abstract boolean isActivityStartsLoggingEnabled();
    /** Returns true if the background activity starts is enabled. */
    public abstract boolean isBackgroundActivityStartsEnabled();
    public abstract boolean isPackageNameWhitelistedForBgActivityStarts(String packageName);
    public abstract void reportCurKeyguardUsageEvent(boolean keyguardShowing);

    /** Input dispatch timeout to a window, start the ANR process. */
+1 −11
Original line number Diff line number Diff line
@@ -11648,16 +11648,6 @@ public final class Settings {
        public static final String ACTIVITY_STARTS_LOGGING_ENABLED
                = "activity_starts_logging_enabled";
        /**
         * Feature flag to enable or disable the background activity starts.
         * When disabled, apps aren't allowed to start activities unless they're in the foreground.
         * Type: int (0 for false, 1 for true)
         * Default: 1
         * @hide
         */
        public static final String BACKGROUND_ACTIVITY_STARTS_ENABLED =
                "background_activity_starts_enabled";
        /**
         * @hide
         * @see com.android.server.appbinding.AppBindingConstants
+0 −7
Original line number Diff line number Diff line
@@ -4308,13 +4308,6 @@
    <!-- Title text to append when the display is secure.  [CHAR LIMIT=30] -->
    <string name="display_manager_overlay_display_secure_suffix">, secure</string>

    <!-- Activity starter -->
    <!-- Toast message for blocking background activity starts feature running in permissive mode -->
    <string name="activity_starter_block_bg_activity_starts_permissive">This background activity start from <xliff:g id="packageName" example="com.example">%1$s</xliff:g> will be blocked in future Q builds. See g.co/dev/bgblock.</string>

    <!-- Toast message for blocking background activity starts feature running in enforcing mode -->
    <string name="activity_starter_block_bg_activity_starts_enforcing">Background activity start from <xliff:g id="packageName" example="com.example">%1$s</xliff:g> blocked. See g.co/dev/bgblock. </string>

    <!-- Keyguard strings -->
    <!-- Message shown in pattern unlock after some number of unsuccessful attempts -->
    <string name="kg_forgot_pattern_button_text">Forgot Pattern</string>
+0 −1
Original line number Diff line number Diff line
@@ -131,7 +131,6 @@ public class SettingsBackupTest {
                    Settings.Global.AUTOFILL_MAX_VISIBLE_DATASETS,
                    Settings.Global.AUTOMATIC_POWER_SAVE_MODE,
                    Settings.Global.AVERAGE_TIME_TO_DISCHARGE,
                    Settings.Global.BACKGROUND_ACTIVITY_STARTS_ENABLED,
                    Settings.Global.BATTERY_CHARGING_STATE_UPDATE_DELAY,
                    Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME,
                    Settings.Global.BROADCAST_BG_CONSTANTS,
+4 −52
Original line number Diff line number Diff line
@@ -30,8 +30,6 @@ import android.provider.DeviceConfig.OnPropertiesChangedListener;
import android.provider.DeviceConfig.Properties;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.TextUtils.SimpleStringSplitter;
import android.util.ArraySet;
import android.util.KeyValueListParser;
import android.util.Slog;

@@ -125,13 +123,6 @@ final class ActivityManagerConstants extends ContentObserver {
    private static final String KEY_DEFAULT_BACKGROUND_ACTIVITY_STARTS_ENABLED =
            "default_background_activity_starts_enabled";

    /**
     * The packages temporarily whitelisted to be able to start activities from background.
     * The list of packages is {@code ":"} colon delimited.
     */
    private static final String KEY_BACKGROUND_ACTIVITY_STARTS_PACKAGE_NAMES_WHITELIST =
            "background_activity_starts_package_names_whitelist";


    // Maximum number of cached processes we will allow.
    public int MAX_CACHED_PROCESSES = DEFAULT_MAX_CACHED_PROCESSES;
@@ -263,8 +254,6 @@ final class ActivityManagerConstants extends ContentObserver {
    // If not set explicitly the default is controlled by DeviceConfig.
    volatile boolean mFlagBackgroundActivityStartsEnabled;

    volatile ArraySet<String> mPackageNamesWhitelistedForBgActivityStarts = new ArraySet<>();

    private final ActivityManagerService mService;
    private ContentResolver mResolver;
    private final KeyValueListParser mParser = new KeyValueListParser(',');
@@ -309,10 +298,6 @@ final class ActivityManagerConstants extends ContentObserver {
    private static final Uri ACTIVITY_STARTS_LOGGING_ENABLED_URI = Settings.Global.getUriFor(
                Settings.Global.ACTIVITY_STARTS_LOGGING_ENABLED);

    private static final Uri BACKGROUND_ACTIVITY_STARTS_ENABLED_URI =
                Settings.Global.getUriFor(
                        Settings.Global.BACKGROUND_ACTIVITY_STARTS_ENABLED);

    private static final Uri ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS_URI =
            Settings.Global.getUriFor(Settings.Global.ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS);

@@ -329,7 +314,6 @@ final class ActivityManagerConstants extends ContentObserver {
                                updateMaxCachedProcesses();
                                break;
                            case KEY_DEFAULT_BACKGROUND_ACTIVITY_STARTS_ENABLED:
                            case KEY_BACKGROUND_ACTIVITY_STARTS_PACKAGE_NAMES_WHITELIST:
                                updateBackgroundActivityStarts();
                                break;
                            default:
@@ -356,7 +340,6 @@ final class ActivityManagerConstants extends ContentObserver {
        mResolver = resolver;
        mResolver.registerContentObserver(ACTIVITY_MANAGER_CONSTANTS_URI, false, this);
        mResolver.registerContentObserver(ACTIVITY_STARTS_LOGGING_ENABLED_URI, false, this);
        mResolver.registerContentObserver(BACKGROUND_ACTIVITY_STARTS_ENABLED_URI, false, this);
        if (mSystemServerAutomaticHeapDumpEnabled) {
            mResolver.registerContentObserver(ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS_URI,
                    false, this);
@@ -393,8 +376,6 @@ final class ActivityManagerConstants extends ContentObserver {
            updateConstants();
        } else if (ACTIVITY_STARTS_LOGGING_ENABLED_URI.equals(uri)) {
            updateActivityStartsLoggingEnabled();
        } else if (BACKGROUND_ACTIVITY_STARTS_ENABLED_URI.equals(uri)) {
            updateBackgroundActivityStarts();
        } else if (ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS_URI.equals(uri)) {
            updateEnableAutomaticSystemServerHeapDumps();
        }
@@ -485,39 +466,10 @@ final class ActivityManagerConstants extends ContentObserver {
    }

    private void updateBackgroundActivityStarts() {
        String whitelistedPackageNames = null;
        int settingsValue = Settings.Global.getInt(mResolver,
                Settings.Global.BACKGROUND_ACTIVITY_STARTS_ENABLED, -1);

        // If the user has explicitly enabled or disabled, that affects all apps.
        // Otherwise we take the default state and whitelist from DeviceConfig.
        if (settingsValue >= 0) {
            mFlagBackgroundActivityStartsEnabled = settingsValue != 0;
        } else {
            boolean enabledInDeviceConfig = DeviceConfig.getBoolean(
        mFlagBackgroundActivityStartsEnabled = DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
                KEY_DEFAULT_BACKGROUND_ACTIVITY_STARTS_ENABLED,
                /*defaultValue*/ false);
            mFlagBackgroundActivityStartsEnabled = enabledInDeviceConfig;
            if (!enabledInDeviceConfig) {
                whitelistedPackageNames = DeviceConfig.getProperty(
                        DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
                        KEY_BACKGROUND_ACTIVITY_STARTS_PACKAGE_NAMES_WHITELIST);
            }
        }
        if (TextUtils.isEmpty(whitelistedPackageNames)) {
            if (!mPackageNamesWhitelistedForBgActivityStarts.isEmpty()) {
                mPackageNamesWhitelistedForBgActivityStarts = new ArraySet<>();
            }
        } else {
            ArraySet<String> newSet = new ArraySet<>();
            SimpleStringSplitter splitter = new SimpleStringSplitter(':');
            splitter.setString(whitelistedPackageNames);
            while (splitter.hasNext()) {
                newSet.add(splitter.next());
            }
            mPackageNamesWhitelistedForBgActivityStarts = newSet;
        }
    }

    private void updateEnableAutomaticSystemServerHeapDumps() {
Loading