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

Commit 88910dec authored by Hui Yu's avatar Hui Yu
Browse files

FGS background start restriction.

1. Background started foreground service shall not have
while-in-use permissions including location, camera and
microphone. Many exemptions have been applied including:
--FGS started by widget.
--FGS started by notification.
--FGS started by IME or other visible app.
--FGS started by ROOT_UID, SYSTEM_UID, NFC_UID.

2. Add a phenotype key KEY_DEFAULT_BACKGROUND_FGS_STARTS_RESTRICTION_ENABLED
to turn on/off this feature (default is on).

3. In dogfood, if a background started FGS with while-in-use permission
(any of location/camera/microphone) run into this restriction, the FGS
will not been granted these permission. we show a toast message to
alert user and ask them to write a bugreport using instruction at
go/r-bg-fgs-restriction. So we can have a statistic how many apps will
be impacted by this feature.
These is a flag Settings.Global.FOREGROUND_SERVICE_STARTS_LOGGING_ENABLED
to turn on/off the toast message (default is on, in dogfood)

Bug: 136219221
Test: atest android.app.cts.ActivityManagerProcessStateTest
atest android.app.cts.ActivityManagerApi29Test.java
atest android.app.cts.ActivityManagerFgsBgStartTest

Change-Id: Ibc8aaa6839a69136f9311bfacdbab9705b31b6a7
parent 06b1d062
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -77,6 +77,8 @@ package android.app {
    method @RequiresPermission(android.Manifest.permission.CHANGE_CONFIGURATION) public void scheduleApplicationInfoChanged(java.util.List<java.lang.String>, int);
    method @RequiresPermission("android.permission.MANAGE_USERS") public boolean switchUser(@NonNull android.os.UserHandle);
    field public static final int PROCESS_CAPABILITY_ALL = 7; // 0x7
    field public static final int PROCESS_CAPABILITY_ALL_EXPLICIT = 1; // 0x1
    field public static final int PROCESS_CAPABILITY_ALL_IMPLICIT = 6; // 0x6
    field public static final int PROCESS_CAPABILITY_FOREGROUND_CAMERA = 2; // 0x2
    field public static final int PROCESS_CAPABILITY_FOREGROUND_LOCATION = 1; // 0x1
    field public static final int PROCESS_CAPABILITY_FOREGROUND_MICROPHONE = 4; // 0x4
+16 −0
Original line number Diff line number Diff line
@@ -602,6 +602,22 @@ public class ActivityManager {
    public static final int PROCESS_CAPABILITY_ALL = PROCESS_CAPABILITY_FOREGROUND_LOCATION
            | PROCESS_CAPABILITY_FOREGROUND_CAMERA
            | PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;
    /**
     * All explicit capabilities. These are capabilities that need to be specified from manifest
     * file.
     * @hide
     */
    @TestApi
    public static final int PROCESS_CAPABILITY_ALL_EXPLICIT =
            PROCESS_CAPABILITY_FOREGROUND_LOCATION;

    /**
     * All implicit capabilities. There are capabilities that process automatically have.
     * @hide
     */
    @TestApi
    public static final int PROCESS_CAPABILITY_ALL_IMPLICIT = PROCESS_CAPABILITY_FOREGROUND_CAMERA
            | PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;

    // NOTE: If PROCESS_STATEs are added, then new fields must be added
    // to frameworks/base/core/proto/android/app/enums.proto and the following method must
+6 −0
Original line number Diff line number Diff line
@@ -377,4 +377,10 @@ public abstract class ActivityManagerInternal {
     * uid, false otherwise
     */
    public abstract boolean isUidCurrentlyInstrumented(int uid);

    /**
     * Show a debug toast, asking user to file a bugreport.
     */
    // TODO: remove this toast after feature development is done
    public abstract void showWhileInUseDebugToast(int uid, int op, int mode);
}
+9 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.app;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.util.SparseArray;
import android.util.SparseIntArray;

import com.android.internal.util.function.HexFunction;
@@ -82,4 +83,12 @@ public abstract class AppOpsManagerInternal {
     * access to app ops for their user.
     */
    public abstract void setDeviceAndProfileOwners(SparseIntArray owners);

    /**
     * Update if the list of AppWidget becomes visible/invisible.
     * @param uidPackageNames uid to packageName map.
     * @param visible true for visible, false for invisible.
     */
    public abstract void updateAppWidgetVisibility(SparseArray<String> uidPackageNames,
            boolean visible);
}
+9 −0
Original line number Diff line number Diff line
@@ -11100,6 +11100,15 @@ public final class Settings {
        public static final String ACTIVITY_STARTS_LOGGING_ENABLED
                = "activity_starts_logging_enabled";
        /**
         * Feature flag to enable or disable the foreground service starts logging feature.
         * Type: int (0 for false, 1 for true)
         * Default: 1
         * @hide
         */
        public static final String FOREGROUND_SERVICE_STARTS_LOGGING_ENABLED =
                "foreground_service_starts_logging_enabled";
        /**
         * @hide
         * @see com.android.server.appbinding.AppBindingConstants
Loading