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

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

Fix issue #21816660 (app standby), work on issue #20882522 (voice interact)

Issue #21816660: More app standby abuse prevention

We now apply the same rules for deciding when an app has counted
as active when the screen is on as when the screen is off; the only
change this really means is that we don't immediately count foreground
services as making an app active both screen on as well as the
existing behavior for screen off.

Also small fix to how we switch into voice interaction mode that
guarantees we immediately switch to the screen on state.

Issue #20882522 VI: voice interactor service not restarted

This fixes some problems in the framework, allowing it to be
correctly restarted (and rolled by to the default voice interactor
if appropriate).  There are still some problems in system UI that
leave things broken in some cases.

Also small fix to how we switch into voice interaction mode that
guarantees we immediately switch to the screen on state.

Change-Id: Ie4fd098a2f5174a2c94f36d30427fb2a9db3d835
parent 285cb414
Loading
Loading
Loading
Loading
+18 −23
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import static com.android.server.am.ActivityManagerDebugConfig.*;
import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID;
import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK;
import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE;
import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV;
import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_PINNABLE;
import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
@@ -10338,11 +10337,12 @@ public final class ActivityManagerService extends ActivityManagerNative
    void startRunningVoiceLocked(IVoiceInteractionSession session, int targetUid) {
        mVoiceWakeLock.setWorkSource(new WorkSource(targetUid));
        if (mRunningVoice == null || mRunningVoice.asBinder() != session.asBinder()) {
            if (mRunningVoice == null) {
            boolean wasRunningVoice = mRunningVoice != null;
            mRunningVoice = session;
            if (!wasRunningVoice) {
                mVoiceWakeLock.acquire();
                updateSleepIfNeededLocked();
            }
            mRunningVoice = session;
        }
    }
@@ -18595,13 +18595,9 @@ public final class ActivityManagerService extends ActivityManagerNative
            return;
        }
        boolean isInteraction;
        if (!mSleeping) {
            isInteraction = app.curProcState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
            app.fgInteractionTime = 0;
        } else {
            // If the display is off, we are going to be more restrictive about what we consider
            // to be an app interaction.  Being the top activity doesn't count, nor do generally
            // foreground services.
        // To avoid some abuse patterns, we are going to be careful about what we consider
        // to be an app interaction.  Being the top activity doesn't count while the display
        // is sleeping, nor do short foreground services.
        if (app.curProcState <= ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
            isInteraction = true;
            app.fgInteractionTime = 0;
@@ -18618,7 +18614,6 @@ public final class ActivityManagerService extends ActivityManagerNative
                    <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
            app.fgInteractionTime = 0;
        }
        }
        if (isInteraction && !app.reportedInteraction) {
            String[] packages = app.getPackageList();
            if (packages != null) {
+71 −38
Original line number Diff line number Diff line
@@ -853,7 +853,38 @@ public class VoiceInteractionManagerService extends SystemService {
        PackageMonitor mPackageMonitor = new PackageMonitor() {
            @Override
            public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
                return super.onHandleForceStop(intent, packages, uid, doit);
                if (DEBUG) Slog.d(TAG, "onHandleForceStop uid=" + uid + " doit=" + doit);

                int userHandle = UserHandle.getUserId(uid);
                ComponentName curInteractor = getCurInteractor(userHandle);
                ComponentName curRecognizer = getCurRecognizer(userHandle);
                boolean hit = false;
                for (String pkg : packages) {
                    if (curInteractor != null && pkg.equals(curInteractor.getPackageName())) {
                        hit = true;
                        break;
                    } else if (curRecognizer != null
                            && pkg.equals(curRecognizer.getPackageName())) {
                        hit = true;
                        break;
                    }
                }
                if (hit && doit) {
                    // The user is force stopping our current interactor/recognizer.
                    // Clear the current settings and restore default state.
                    synchronized (VoiceInteractionManagerService.this) {
                        mSoundTriggerHelper.stopAllRecognitions();
                        if (mImpl != null) {
                            mImpl.shutdownLocked();
                            mImpl = null;
                        }
                        setCurInteractor(null, userHandle);
                        setCurRecognizer(null, userHandle);
                        initForUser(userHandle);
                        switchImplementationIfNeededLocked(true);
                    }
                }
                return hit;
            }

            @Override
@@ -865,6 +896,7 @@ public class VoiceInteractionManagerService extends SystemService {
                int userHandle = getChangingUserId();
                if (DEBUG) Slog.d(TAG, "onSomePackagesChanged user=" + userHandle);

                synchronized (VoiceInteractionManagerService.this) {
                    ComponentName curInteractor = getCurInteractor(userHandle);
                    ComponentName curRecognizer = getCurRecognizer(userHandle);
                    if (curRecognizer == null) {
@@ -912,6 +944,7 @@ public class VoiceInteractionManagerService extends SystemService {
                                userHandle), userHandle);
                    }
                }
            }
        };
    }
}