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

Commit 49425d61 authored by Rubin Xu's avatar Rubin Xu Committed by Android (Google) Code Review
Browse files

Merge "Kill foreground apps when turning off work" into nyc-dev

parents da067dcb f8451b98
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -139,4 +139,9 @@ public abstract class ActivityManagerInternal {
     * minimized state.
     * minimized state.
     */
     */
    public abstract void notifyDockedStackMinimizedChanged(boolean minimized);
    public abstract void notifyDockedStackMinimizedChanged(boolean minimized);

    /**
     * Kill foreground apps from the specified user.
     */
    public abstract void killForegroundAppsForUser(int userHandle);
}
}
+30 −0
Original line number Original line Diff line number Diff line
@@ -20985,6 +20985,36 @@ public final class ActivityManagerService extends ActivityManagerNative
                mStackSupervisor.setDockedStackMinimized(minimized);
                mStackSupervisor.setDockedStackMinimized(minimized);
            }
            }
        }
        }
        @Override
        public void killForegroundAppsForUser(int userHandle) {
            synchronized (ActivityManagerService.this) {
                final ArrayList<ProcessRecord> procs = new ArrayList<>();
                final int NP = mProcessNames.getMap().size();
                for (int ip = 0; ip < NP; ip++) {
                    final SparseArray<ProcessRecord> apps = mProcessNames.getMap().valueAt(ip);
                    final int NA = apps.size();
                    for (int ia = 0; ia < NA; ia++) {
                        final ProcessRecord app = apps.valueAt(ia);
                        if (app.persistent) {
                            // We don't kill persistent processes.
                            continue;
                        }
                        if (app.removed) {
                            procs.add(app);
                        } else if (app.userId == userHandle && app.foregroundActivities) {
                            app.removed = true;
                            procs.add(app);
                        }
                    }
                }
                final int N = procs.size();
                for (int i = 0; i < N; i++) {
                    removeProcessLocked(procs.get(i), false, true, "kill all fg");
                }
            }
        }
    }
    }
    private final class SleepTokenImpl extends SleepToken {
    private final class SleepTokenImpl extends SleepToken {
+2 −0
Original line number Original line Diff line number Diff line
@@ -667,6 +667,8 @@ public class UserManagerService extends IUserManager.Stub {
            long identity = Binder.clearCallingIdentity();
            long identity = Binder.clearCallingIdentity();
            try {
            try {
                if (enableQuietMode) {
                if (enableQuietMode) {
                    LocalServices.getService(ActivityManagerInternal.class)
                            .killForegroundAppsForUser(userHandle);
                    ActivityManagerNative.getDefault().stopUser(userHandle, /* force */true, null);
                    ActivityManagerNative.getDefault().stopUser(userHandle, /* force */true, null);
                } else {
                } else {
                    ActivityManagerNative.getDefault().startUserInBackground(userHandle);
                    ActivityManagerNative.getDefault().startUserInBackground(userHandle);