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

Commit 4e6cef49 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Handle locale change and pacakge change in different way

- Stop using a custom callback from AM to detect locale changes
and use the LOCALE_CHANGED broadcast instead.

- This would open up a chance where a publisher app fetches
its won manifest shortcuts after a locale change but
ShortcutManager hasn't updated string resources.

- So instead, at every entry point from ShortcutManager, check
if the locale has changed, and if so, update all resources
(and reset throttling).

- Do the same for package change events too.  At every entry point
from ShortcutManager, check if the caller package has been updated,
or any target activities have been disabled.  If so, rescan the
caller package.

- We do *not* do the same check at the LauncherApps entry points,
because the launcher should use the callback to listen to
shortcut changes.

- Also stopped using PackageMonitor for now because we want to
set a higher priority and changing PackageMonitor at this point
seems too much for DR.

Bug 29895275
Bug 30123329

Change-Id: Ib4a2f626a936c7328e2cc032324f5c3d1c3b9122
parent f90128c6
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -67,10 +67,4 @@ public abstract class ShortcutServiceInternal {

    public abstract boolean hasShortcutHostPermission(int launcherUserId,
            @NonNull String callingPackage);

    /**
     * Called by AM when the system locale changes *within the AM lock*.  ABSOLUTELY do not take
     * any locks in this method.
     */
    public abstract void onSystemLocaleChangedNoLock();
}
+0 −10
Original line number Diff line number Diff line
@@ -140,7 +140,6 @@ import android.content.pm.PermissionInfo;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.ShortcutServiceInternal;
import android.content.pm.UserInfo;
import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
@@ -18862,15 +18861,6 @@ public final class ActivityManagerService extends ActivityManagerNative
                        null, AppOpsManager.OP_NONE, null, false, false,
                        MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
                if ((changes&ActivityInfo.CONFIG_LOCALE) != 0) {
                    // Tell the shortcut manager that the system locale changed.  It needs to know
                    // it before any other apps receive ACTION_LOCALE_CHANGED, which is why
                    // we "push" from here, rather than having the service listen to the broadcast.
                    final ShortcutServiceInternal shortcutService =
                            LocalServices.getService(ShortcutServiceInternal.class);
                    if (shortcutService != null) {
                        shortcutService.onSystemLocaleChangedNoLock();
                    }
                    intent = new Intent(Intent.ACTION_LOCALE_CHANGED);
                    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
                    if (!mProcessesReady) {
+57 −18
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.Preconditions;
import com.android.internal.util.XmlUtils;
import com.android.server.pm.ShortcutService.ShortcutOperation;
import com.android.server.pm.ShortcutService.Stats;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -437,8 +438,6 @@ class ShortcutPackage extends ShortcutPackageItem {
     * locale changes.
     */
    public int getApiCallCount() {
        mShortcutUser.resetThrottlingIfNeeded();

        final ShortcutService s = mShortcutUser.mService;

        // Reset the counter if:
@@ -598,7 +597,37 @@ class ShortcutPackage extends ShortcutPackageItem {
    }

    /**
     * Called when the package is updated or added.
     * @return false if any of the target activities are no longer enabled.
     */
    private boolean areAllActivitiesStillEnabled() {
        if (mShortcuts.size() == 0) {
            return true;
        }
        final ShortcutService s = mShortcutUser.mService;

        // Normally the number of target activities is 1 or so, so no need to use a complex
        // structure like a set.
        final ArrayList<ComponentName> checked = new ArrayList<>(4);

        for (int i = mShortcuts.size() - 1; i >= 0; i--) {
            final ShortcutInfo si = mShortcuts.valueAt(i);
            final ComponentName activity = si.getActivity();

            if (checked.contains(activity)) {
                continue; // Already checked.
            }
            checked.add(activity);

            if (!s.injectIsActivityEnabledAndExported(activity, getOwnerUserId())) {
                return false;
            }
        }
        return true;
    }

    /**
     * Called when the package may be added or updated, or its activities may be disabled, and
     * if so, rescan the package and do the necessary stuff.
     *
     * Add case:
     * - Publish manifest shortcuts.
@@ -606,24 +635,36 @@ class ShortcutPackage extends ShortcutPackageItem {
     * Update case:
     * - Re-publish manifest shortcuts.
     * - If there are shortcuts with resources (icons or strings), update their timestamps.
     * - Disable shortcuts whose target activities are disabled.
     *
     * @return TRUE if any shortcuts have been changed.
     */
    public boolean handlePackageAddedOrUpdated(boolean isNewApp, boolean forceRescan) {
        final PackageInfo pi = mShortcutUser.mService.getPackageInfo(
    public boolean rescanPackageIfNeeded(boolean isNewApp, boolean forceRescan) {
        final ShortcutService s = mShortcutUser.mService;
        final long start = s.injectElapsedRealtime();

        final PackageInfo pi;
        try {
            pi = mShortcutUser.mService.getPackageInfo(
                    getPackageName(), getPackageUserId());
            if (pi == null) {
                return false; // Shouldn't happen.
            }

            if (!isNewApp && !forceRescan) {
            // Make sure the version code or last update time has changed.
            // Otherwise, nothing to do.
            if (getPackageInfo().getVersionCode() >= pi.versionCode
                    && getPackageInfo().getLastUpdateTime() >= pi.lastUpdateTime) {
                // Return if the package hasn't changed, ie:
                // - version code hasn't change
                // - lastUpdateTime hasn't change
                // - all target activities are still enabled.
                if ((getPackageInfo().getVersionCode() >= pi.versionCode)
                        && (getPackageInfo().getLastUpdateTime() >= pi.lastUpdateTime)
                        && areAllActivitiesStillEnabled()) {
                    return false;
                }
            }
        } finally {
            s.logDurationStat(Stats.PACKAGE_UPDATE_CHECK, start);
        }

        // Now prepare to publish manifest shortcuts.
        List<ShortcutInfo> newManifestShortcutList = null;
@@ -654,8 +695,6 @@ class ShortcutPackage extends ShortcutPackageItem {

        getPackageInfo().updateVersionInfo(pi);

        final ShortcutService s = mShortcutUser.mService;

        boolean changed = false;

        // For existing shortcuts, update timestamps if they have any resources.
@@ -1001,7 +1040,7 @@ class ShortcutPackage extends ShortcutPackageItem {
            }
        }
        if (changed) {
            s.scheduleSaveUser(getPackageUserId());
            s.packageShortcutsChanged(getPackageName(), getPackageUserId());
        }
    }

+4 −0
Original line number Diff line number Diff line
@@ -48,6 +48,10 @@ abstract class ShortcutPackageItem {
        mPackageInfo = Preconditions.checkNotNull(packageInfo);
    }

    public ShortcutUser getUser() {
        return mShortcutUser;
    }

    /**
     * ID of the user who actually has this package running on.  For {@link ShortcutPackage},
     * this is the same thing as {@link #getOwnerUserId}, but if it's a {@link ShortcutLauncher} and
+115 −103

File changed.

Preview size limit exceeded, changes collapsed.

Loading