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

Commit d67a78db authored by Christopher Tate's avatar Christopher Tate
Browse files

Don't rewrite package restrictions unconditionally in findPreferredActivity()

We've been forcing a rewrite of package restrictions when doing preferred-
activity lookups in most cases, even when the lookup was not actually making
any changes to the bookkeeping.  Now we only do so when something has
actually changed.  Flash drives everywhere rejoice.

Bug 17334180

Change-Id: Id8f20723002b7bbcc1d82ccde55df6ef727b64ba
parent f7255fcc
Loading
Loading
Loading
Loading
+100 −90
Original line number Diff line number Diff line
@@ -3035,6 +3035,8 @@ public class PackageManagerService extends IPackageManager.Stub {
                            (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0, userId)
                    : null;
            if (prefs != null && prefs.size() > 0) {
                boolean changed = false;
                try {
                    // First figure out how good the original match set is.
                    // We will only allow preferred activities that came
                    // from the same match quality.
@@ -3095,6 +3097,7 @@ public class PackageManagerService extends IPackageManager.Stub {
                            Slog.w(TAG, "Removing dangling preferred activity: "
                                    + pa.mPref.mComponent);
                            pir.removeFilter(pa);
                            changed = true;
                            continue;
                        }
                        for (int j=0; j<N; j++) {
@@ -3109,6 +3112,7 @@ public class PackageManagerService extends IPackageManager.Stub {
                            if (removeMatches) {
                                pir.removeFilter(pa);
                                changed = true;
                                if (DEBUG_PREFERRED) {
                                    Slog.v(TAG, "Removing match " + pa.mPref.mComponent);
                                }
@@ -3131,20 +3135,26 @@ public class PackageManagerService extends IPackageManager.Stub {
                                PreferredActivity lastChosen = new PreferredActivity(
                                        pa, pa.mPref.mMatch, null, pa.mPref.mComponent, false);
                                pir.addFilter(lastChosen);
                            mSettings.writePackageRestrictionsLPr(userId);
                                changed = true;
                                return null;
                            }
                            // Yay! Either the set matched or we're looking for the last chosen
                            if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Returning preferred activity: "
                                    + ri.activityInfo.packageName + "/" + ri.activityInfo.name);
                        mSettings.writePackageRestrictionsLPr(userId);
                            return ri;
                        }
                    }
                } finally {
                    if (changed) {
                        if (DEBUG_PREFERRED) {
                            Slog.v(TAG, "Preferred activity bookkeeping changed; writing restrictions");
                        }
                        mSettings.writePackageRestrictionsLPr(userId);
                    }
                }
            }
        }
        if (DEBUG_PREFERRED || debug) Slog.v(TAG, "No preferred activity to return");
        return null;
    }