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

Commit d2a77c24 authored by Zoltan Szatmary-Ban's avatar Zoltan Szatmary-Ban Committed by Android Git Automerger
Browse files

am 7602bc54: Merge "Register ActivityManagerService.PackageMonitor for all users." into lmp-dev

* commit '7602bc548c3c85e8958e899593cc1757d849d532':
  Register ActivityManagerService.PackageMonitor for all users.
parents f86afcd2 bdc07b69
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -2303,19 +2303,27 @@ public class ActivityManager {
     * call this method.
     * 
     * @param packageName The name of the package to be stopped.
     * @param userId The user for which the running package is to be stopped.
     * 
     * @hide This is not available to third party applications due to
     * it allowing them to break other applications by stopping their
     * services, removing their alarms, etc.
     */
    public void forceStopPackage(String packageName) {
    public void forceStopPackageAsUser(String packageName, int userId) {
        try {
            ActivityManagerNative.getDefault().forceStopPackage(packageName,
                    UserHandle.myUserId());
            ActivityManagerNative.getDefault().forceStopPackage(packageName, userId);
        } catch (RemoteException e) {
        }
    }

    /**
     * @see #forceStopPackageAsUser(String, int)
     * @hide
     */
    public void forceStopPackage(String packageName) {
        forceStopPackageAsUser(packageName, UserHandle.myUserId());
    }

    /**
     * Get the device configuration attributes.
     */
+19 −7
Original line number Diff line number Diff line
@@ -1986,9 +1986,12 @@ public final class ActivityManagerService extends ActivityManagerNative
        @Override
        public void onPackageRemoved(String packageName, int uid) {
            // Remove all tasks with activities in the specified package from the list of recent tasks
            final int eventUserId = getChangingUserId();
            synchronized (ActivityManagerService.this) {
                for (int i = mRecentTasks.size() - 1; i >= 0; i--) {
                    TaskRecord tr = mRecentTasks.get(i);
                    if (tr.userId != eventUserId) continue;
                    ComponentName cn = tr.intent.getComponent();
                    if (cn != null && cn.getPackageName().equals(packageName)) {
                        // If the package name matches, remove the task and kill the process
@@ -2006,28 +2009,36 @@ public final class ActivityManagerService extends ActivityManagerNative
        @Override
        public void onPackageModified(String packageName) {
            final int eventUserId = getChangingUserId();
            final PackageManager pm = mContext.getPackageManager();
            final ArrayList<Pair<Intent, Integer>> recentTaskIntents =
                    new ArrayList<Pair<Intent, Integer>>();
            final HashSet<ComponentName> componentsKnownToExist = new HashSet<ComponentName>();
            final ArrayList<Integer> tasksToRemove = new ArrayList<Integer>();
            // Copy the list of recent tasks so that we don't hold onto the lock on
            // ActivityManagerService for long periods while checking if components exist.
            synchronized (ActivityManagerService.this) {
                for (int i = mRecentTasks.size() - 1; i >= 0; i--) {
                    TaskRecord tr = mRecentTasks.get(i);
                    if (tr.userId != eventUserId) continue;
                    recentTaskIntents.add(new Pair<Intent, Integer>(tr.intent, tr.taskId));
                }
            }
            // Check the recent tasks and filter out all tasks with components that no longer exist.
            Intent tmpI = new Intent();
            for (int i = recentTaskIntents.size() - 1; i >= 0; i--) {
                Pair<Intent, Integer> p = recentTaskIntents.get(i);
                ComponentName cn = p.first.getComponent();
                if (cn != null && cn.getPackageName().equals(packageName)) {
                    if (componentsKnownToExist.contains(cn)) {
                        // If we know that the component still exists in the package, then skip
                        continue;
                    }
                    try {
                        // Add the task to the list to remove if the component no longer exists
                        tmpI.setComponent(cn);
                        if (pm.queryIntentActivities(tmpI, PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) {
                        ActivityInfo info = pm.getActivityInfo(cn, eventUserId);
                        if (info != null && info.isEnabled()) {
                            componentsKnownToExist.add(cn);
                        } else {
                            tasksToRemove.add(p.second);
                        }
                    } catch (Exception e) {}
@@ -2046,11 +2057,12 @@ public final class ActivityManagerService extends ActivityManagerNative
        @Override
        public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
            // Force stop the specified packages
            int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
            if (packages != null) {
                for (String pkg : packages) {
                    synchronized (ActivityManagerService.this) {
                        if (forceStopPackageLocked(pkg, -1, false, false, false, false, false, 0,
                                "finished booting")) {
                        if (forceStopPackageLocked(pkg, -1, false, false, false, false, false,
                                userId, "finished booting")) {
                            return true;
                        }
                    }
@@ -6269,7 +6281,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
        // Register receivers to handle package update events
        mPackageMonitor.register(mContext, Looper.getMainLooper(), false);
        mPackageMonitor.register(mContext, Looper.getMainLooper(), UserHandle.ALL, false);
        // Let system services know.
        mSystemServiceManager.startBootPhase(SystemService.PHASE_BOOT_COMPLETED);