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

Commit ce8e3fc1 authored by Songchun Fan's avatar Songchun Fan
Browse files

[SettingsProvider] skip caching in system server

The old implementation avoids closing the memory int array if the
process is the system process. However, this doesn't prevent the object
to be garbage collected. As a result, the array may be left open without
being properly closed.

This change skips sending the memory int array and index if the query
is from inside system server; should also addresses StrictMode complaints.

BUG: 277448672
Test: boots
Change-Id: I309ad3558a77d8e7d0c8a8d2c8f45db5a316c976
parent 0a2721fc
Loading
Loading
Loading
Loading
+56 −44
Original line number Diff line number Diff line
@@ -3036,9 +3036,7 @@ public final class Settings {
        public void destroy() {
            try {
                // If this process is the system server process, mArray is the same object as
                // the memory int array kept inside SettingsProvider, so skipping the close()
                if (!Settings.isInSystemServer() && !mArray.isClosed()) {
                if (!mArray.isClosed()) {
                    mArray.close();
                }
            } catch (IOException e) {
@@ -3218,8 +3216,9 @@ public final class Settings {
        @UnsupportedAppUsage
        public String getStringForUser(ContentResolver cr, String name, final int userHandle) {
            final boolean isSelf = (userHandle == UserHandle.myUserId());
            final boolean useCache = isSelf && !isInSystemServer();
            boolean needsGenerationTracker = false;
            if (isSelf) {
            if (useCache) {
                synchronized (NameValueCache.this) {
                    final GenerationTracker generationTracker = mGenerationTrackers.get(name);
                    if (generationTracker != null) {
@@ -3251,8 +3250,10 @@ public final class Settings {
                needsGenerationTracker = true;
            } else {
                if (DEBUG || LOCAL_LOGV) {
                    Log.v(TAG, "get setting for user " + userHandle
                            + " by user " + UserHandle.myUserId() + " so skipping cache");
                    Log.v(TAG, "get setting " + name + " for user " + userHandle + " by user "
                            + UserHandle.myUserId()
                            + (isInSystemServer() ? " in system_server" : "")
                            + " so skipping cache");
                }
            }
@@ -3365,10 +3366,13 @@ public final class Settings {
                                }
                            }
                        } else {
                            if (LOCAL_LOGV) Log.i(TAG, "call-query of user " + userHandle
                            if (DEBUG || LOCAL_LOGV) {
                                Log.i(TAG, "call-query of user " + userHandle
                                        + " by " + UserHandle.myUserId()
                                        + (isInSystemServer() ? " in system_server" : "")
                                        + " so not updating cache");
                            }
                        }
                        return value;
                    }
                    // If the response Bundle is null, we fall through
@@ -3440,12 +3444,14 @@ public final class Settings {
        public ArrayMap<String, String> getStringsForPrefix(ContentResolver cr, String prefix,
                List<String> names) {
            final boolean useCache = !isInSystemServer();
            String namespace = prefix.substring(0, prefix.length() - 1);
            Config.enforceReadPermission(namespace);
            ArrayMap<String, String> keyValues = new ArrayMap<>();
            int currentGeneration = -1;
            boolean needsGenerationTracker = false;
            if (useCache) {
                synchronized (NameValueCache.this) {
                    final GenerationTracker generationTracker = mGenerationTrackers.get(prefix);
                    if (generationTracker != null) {
@@ -3491,6 +3497,12 @@ public final class Settings {
                        needsGenerationTracker = true;
                    }
                }
            } else {
                if (DEBUG || LOCAL_LOGV) {
                    Log.v(TAG, "getting settings for prefix " + prefix + " in system_server"
                            + " so skipping cache");
                }
            }
            if (mCallListCommand == null) {
                // No list command specified, return empty map