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

Commit d330a6cc authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Invalidate caches when locale changes.

When loading roots for the first time, we're okay using any cached
data from the system, but if the locale changes we need to
force-refresh everything.

Now that we're always using the system cache, we have a nice strong
signal for "empty" versus "not cached" results, so we don't need to
wait around for the first loading pass to finish.

Add logic to invalidate system cache when locale changes, and fix
locking bug.

Bug: 27977906
Change-Id: Ic50083eff360bea887799583f6c9f02c129eec91
parent fa1832e4
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ public class DocumentsApplication extends Application {
        final int memoryClassBytes = am.getMemoryClass() * 1024 * 1024;

        mRoots = new RootsCache(this);
        mRoots.updateAsync();
        mRoots.updateAsync(false);

        mThumbnails = new ThumbnailCache(memoryClassBytes / 4);

@@ -105,7 +105,7 @@ public class DocumentsApplication extends Application {
                final String packageName = data.getSchemeSpecificPart();
                mRoots.updatePackageAsync(packageName);
            } else {
                mRoots.updateAsync();
                mRoots.updateAsync(true);
            }
        }
    };
+15 −22
Original line number Diff line number Diff line
@@ -122,7 +122,7 @@ public class RootsCache {
    /**
     * Gather roots from all known storage providers.
     */
    public void updateAsync() {
    public void updateAsync(boolean forceRefreshAll) {

        // NOTE: This method is called when the UI language changes.
        // For that reason we update our RecentsRoot to reflect
@@ -139,14 +139,15 @@ public class RootsCache {
                | Root.FLAG_SUPPORTS_CREATE));
        assert(mRecentsRoot.availableBytes == -1);

        new UpdateTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        new UpdateTask(forceRefreshAll, null)
                .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }

    /**
     * Gather roots from storage providers belonging to given package name.
     */
    public void updatePackageAsync(String packageName) {
        new UpdateTask(packageName).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        new UpdateTask(false, packageName).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }

    /**
@@ -223,23 +224,22 @@ public class RootsCache {
    }

    private class UpdateTask extends AsyncTask<Void, Void, Void> {
        private final boolean mForceRefreshAll;
        private final String mForceRefreshPackage;

        private final Multimap<String, RootInfo> mTaskRoots = ArrayListMultimap.create();
        private final HashSet<String> mTaskStoppedAuthorities = new HashSet<>();

        /**
         * Update all roots.
         */
        public UpdateTask() {
            this(null);
        }

        /**
         * Force update roots belonging to given package name. Other roots will
         * be copied from cached {@link #mRoots} values.
         * Create task to update roots cache.
         *
         * @param forceRefreshAll when true, all previously cached values for
         *            all packages should be ignored.
         * @param forceRefreshPackage when non-null, all previously cached
         *            values for this specific package should be ignored.
         */
        public UpdateTask(String forceRefreshPackage) {
        public UpdateTask(boolean forceRefreshAll, String forceRefreshPackage) {
            mForceRefreshAll = forceRefreshAll;
            mForceRefreshPackage = forceRefreshPackage;
        }

@@ -247,14 +247,6 @@ public class RootsCache {
        protected Void doInBackground(Void... params) {
            final long start = SystemClock.elapsedRealtime();

            if (mForceRefreshPackage != null) {
                // We must have previously cached values to fill in non-matching
                // packages, so wait around for successful first load.
                if (!waitForFirstLoad()) {
                    return null;
                }
            }

            mTaskRoots.put(mRecentsRoot.authority, mRecentsRoot);

            final ContentResolver resolver = mContext.getContentResolver();
@@ -300,7 +292,8 @@ public class RootsCache {
                return;
            }

            final boolean forceRefresh = Objects.equals(mForceRefreshPackage, info.packageName);
            final boolean forceRefresh = mForceRefreshAll
                    || Objects.equals(info.packageName, mForceRefreshPackage);
            mTaskRoots.putAll(info.authority, loadRootsForAuthority(mContext.getContentResolver(),
                    info.authority, forceRefresh));
        }