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

Commit c3af19a8 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Optimize bg check flow.

No longer need to look up the application info, target SDK is
explicitly passed in to the check.  For the external method, we
change this to just checked to see if background is completely
disabled, which doesn't need a target SDK check (and is the only
thing any of the current clients care about).

Now allow SystemUI to put targets of notification pending intents
on the temporary whitelist when they fire, so developers can avoid
dealing with background restrictions in this case (if the user
interacts with their notification, they will temporarily be
considered in the foreground).

Remove any thoughts of enforing restrictions on registerReceiver(),
so we don't need to deal with target SDK versions there (which can't
be done all that efficiently).

Also bring back the old "allow starts coming from foreground apps"
only for the MODE_IGNORE app op, since it should provide some
better compatibility.

Test: ran them.

Change-Id: Id4ea7f992d12ce4bd8e54f1dbaeb4a460a3dee59
parent c49f2e5d
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -520,17 +520,17 @@ public class ActivityManager {
    /** @hide Flag for registerUidObserver: report uid has become active. */
    /** @hide Flag for registerUidObserver: report uid has become active. */
    public static final int UID_OBSERVER_ACTIVE = 1<<3;
    public static final int UID_OBSERVER_ACTIVE = 1<<3;


    /** @hide Mode for {@link IActivityManager#getAppStartMode}: normal free-to-run operation. */
    /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: normal free-to-run operation. */
    public static final int APP_START_MODE_NORMAL = 0;
    public static final int APP_START_MODE_NORMAL = 0;


    /** @hide Mode for {@link IActivityManager#getAppStartMode}: delay running until later. */
    /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later. */
    public static final int APP_START_MODE_DELAYED = 1;
    public static final int APP_START_MODE_DELAYED = 1;


    /** @hide Mode for {@link IActivityManager#getAppStartMode}: delay running until later, with
    /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: delay running until later, with
     * rigid errors (throwing exception). */
     * rigid errors (throwing exception). */
    public static final int APP_START_MODE_DELAYED_RIGID = 2;
    public static final int APP_START_MODE_DELAYED_RIGID = 2;


    /** @hide Mode for {@link IActivityManager#getAppStartMode}: disable/cancel pending
    /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: disable/cancel pending
     * launches; this is the mode for ephemeral apps. */
     * launches; this is the mode for ephemeral apps. */
    public static final int APP_START_MODE_DISABLED = 3;
    public static final int APP_START_MODE_DISABLED = 3;


+2 −2
Original line number Original line Diff line number Diff line
@@ -1342,8 +1342,8 @@ class ContextImpl extends Context {
        }
        }
        try {
        try {
            final Intent intent = ActivityManager.getService().registerReceiver(
            final Intent intent = ActivityManager.getService().registerReceiver(
                    mMainThread.getApplicationThread(), mBasePackageName,
                    mMainThread.getApplicationThread(), mBasePackageName, rd, filter,
                    rd, filter, broadcastPermission, userId);
                    broadcastPermission, userId);
            if (intent != null) {
            if (intent != null) {
                intent.setExtrasClassLoader(getClassLoader());
                intent.setExtrasClassLoader(getClassLoader());
                intent.prepareToEnterProcess();
                intent.prepareToEnterProcess();
+1 −1
Original line number Original line Diff line number Diff line
@@ -475,7 +475,7 @@ interface IActivityManager {
    void suppressResizeConfigChanges(boolean suppress);
    void suppressResizeConfigChanges(boolean suppress);
    void moveTasksToFullscreenStack(int fromStackId, boolean onTop);
    void moveTasksToFullscreenStack(int fromStackId, boolean onTop);
    boolean moveTopActivityToPinnedStack(int stackId, in Rect bounds);
    boolean moveTopActivityToPinnedStack(int stackId, in Rect bounds);
    int getAppStartMode(int uid, in String packageName);
    boolean isAppStartModeDisabled(int uid, in String packageName);
    boolean unlockUser(int userid, in byte[] token, in byte[] secret,
    boolean unlockUser(int userid, in byte[] token, in byte[] secret,
            in IProgressListener listener);
            in IProgressListener listener);
    boolean isInMultiWindowMode(in IBinder token);
    boolean isInMultiWindowMode(in IBinder token);
+3 −0
Original line number Original line Diff line number Diff line
@@ -131,6 +131,9 @@
    <!-- Assist -->
    <!-- Assist -->
    <uses-permission android:name="android.permission.ACCESS_VOICE_INTERACTION_SERVICE" />
    <uses-permission android:name="android.permission.ACCESS_VOICE_INTERACTION_SERVICE" />


    <!-- Doze mode temp whitelisting for notification dispatching. -->
    <uses-permission android:name="android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST" />

    <!-- Listen for keyboard attachment / detachment -->
    <!-- Listen for keyboard attachment / detachment -->
    <uses-permission android:name="android.permission.TABLET_MODE" />
    <uses-permission android:name="android.permission.TABLET_MODE" />


+3 −4
Original line number Original line Diff line number Diff line
@@ -504,8 +504,8 @@ class AlarmManagerService extends SystemService {
            for (int i = alarms.size()-1; i >= 0; i--) {
            for (int i = alarms.size()-1; i >= 0; i--) {
                Alarm alarm = alarms.get(i);
                Alarm alarm = alarms.get(i);
                try {
                try {
                    if (alarm.uid == uid && ActivityManager.getService().getAppStartMode(
                    if (alarm.uid == uid && ActivityManager.getService().isAppStartModeDisabled(
                            uid, alarm.packageName) == ActivityManager.APP_START_MODE_DISABLED) {
                            uid, alarm.packageName)) {
                        alarms.remove(i);
                        alarms.remove(i);
                        didRemove = true;
                        didRemove = true;
                        if (alarm.alarmClock != null) {
                        if (alarm.alarmClock != null) {
@@ -1089,8 +1089,7 @@ class AlarmManagerService extends SystemService {
                operation, directReceiver, listenerTag, workSource, flags, alarmClock,
                operation, directReceiver, listenerTag, workSource, flags, alarmClock,
                callingUid, callingPackage);
                callingUid, callingPackage);
        try {
        try {
            if (ActivityManager.getService().getAppStartMode(callingUid, callingPackage)
            if (ActivityManager.getService().isAppStartModeDisabled(callingUid, callingPackage)) {
                    == ActivityManager.APP_START_MODE_DISABLED) {
                Slog.w(TAG, "Not setting alarm from " + callingUid + ":" + a
                Slog.w(TAG, "Not setting alarm from " + callingUid + ":" + a
                        + " -- package not allowed to start");
                        + " -- package not allowed to start");
                return;
                return;
Loading