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

Commit 88d86fc0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix the shorcuts deletion issue in ShortcutService" into sc-dev am: 6efc0207

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13743106

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ibccd7726bd12a06544f79d8932bdf929d49286cb
parents a6e76d7f 6efc0207
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -362,6 +362,7 @@ public class ShortcutService extends IShortcutService.Stub {
    private List<Integer> mDirtyUserIds = new ArrayList<>();

    private final AtomicBoolean mBootCompleted = new AtomicBoolean();
    private final AtomicBoolean mShutdown = new AtomicBoolean();

    /**
     * Note we use a fine-grained lock for {@link #mUnlockedUsers} due to b/64303666.
@@ -498,6 +499,12 @@ public class ShortcutService extends IShortcutService.Stub {
        mContext.registerReceiverAsUser(mReceiver, UserHandle.ALL,
                localeFilter, null, mHandler);

        IntentFilter shutdownFilter = new IntentFilter();
        shutdownFilter.addAction(Intent.ACTION_SHUTDOWN);
        shutdownFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        mContext.registerReceiverAsUser(mShutdownReceiver, UserHandle.SYSTEM,
                shutdownFilter, null, mHandler);

        injectRegisterUidObserver(mUidObserver, ActivityManager.UID_OBSERVER_PROCSTATE
                | ActivityManager.UID_OBSERVER_GONE);

@@ -1162,6 +1169,9 @@ public class ShortcutService extends IShortcutService.Stub {
        if (DEBUG) {
            Slog.d(TAG, "saveDirtyInfo");
        }
        if (mShutdown.get()) {
            return;
        }
        try {
            synchronized (mLock) {
                for (int i = mDirtyUserIds.size() - 1; i >= 0; i--) {
@@ -3494,6 +3504,22 @@ public class ShortcutService extends IShortcutService.Stub {
        }
    };

    private final BroadcastReceiver mShutdownReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            // Since it cleans up the shortcut directory and rewrite the ShortcutPackageItems
            // in odrder during saveToXml(), it could lead to shortcuts missing when shutdown.
            // We need it so that it can finish up saving before shutdown.
            synchronized (mLock) {
                if (mHandler.hasCallbacks(mSaveDirtyInfoRunner)) {
                    mHandler.removeCallbacks(mSaveDirtyInfoRunner);
                    saveDirtyInfo();
                }
                mShutdown.set(true);
            }
        }
    };

    /**
     * Called when a user is unlocked.
     * - Check all known packages still exist, and otherwise perform cleanup.