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

Commit 44d39aee authored by Jing Ji's avatar Jing Ji
Browse files

Lock the CoreSettings in ActivityThread separately

To fix a deadlock between the locks 'mResourceManager' and LoadedApk

Bug: 175361185
Test: atest FrameworksServicesTests:CoreSettingsObserverTest
Test: atest FrameworksCoreTests:ActivityThreadTest
Test: atest CtsGpuToolsHostTestCases:CtsRootlessGpuDebugHostTest
Test: Manual - adb shell am refresh-settings-cache
Change-Id: I283e7edb51ea1305a4beb31a4e0b5c751ccb8607
parent 70829412
Loading
Loading
Loading
Loading
+22 −6
Original line number Diff line number Diff line
@@ -492,6 +492,11 @@ public final class ActivityThread extends ClientTransactionHandler {

    Bundle mCoreSettings = null;

    /**
     * The lock word for the {@link #mCoreSettings}.
     */
    private final Object mCoreSettingsLock = new Object();

    boolean mHasImeComponent = false;

    /** Activity client record, used for bookkeeping for the real {@link Activity} instance. */
@@ -4955,7 +4960,7 @@ public final class ActivityThread extends ClientTransactionHandler {
    }

    private void handleSetCoreSettings(Bundle coreSettings) {
        synchronized (mResourcesManager) {
        synchronized (mCoreSettingsLock) {
            mCoreSettings = coreSettings;
        }
        onCoreSettingsChange();
@@ -4971,6 +4976,8 @@ public final class ActivityThread extends ClientTransactionHandler {
    private boolean updateDebugViewAttributeState() {
        boolean previousState = View.sDebugViewAttributes;

        // mCoreSettings is only updated from the main thread, while this function is only called
        // from main thread as well, so no need to lock here.
        View.sDebugViewAttributesApplicationPackage = mCoreSettings.getString(
                Settings.Global.DEBUG_VIEW_ATTRIBUTES_APPLICATION_PACKAGE, "");
        String currentPackage = (mBoundApplication != null && mBoundApplication.appInfo != null)
@@ -6267,6 +6274,8 @@ public final class ActivityThread extends ClientTransactionHandler {
            }
        }

        // mCoreSettings is only updated from the main thread, while this function is only called
        // from main thread as well, so no need to lock here.
        GraphicsEnvironment.getInstance().setup(context, mCoreSettings);
        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
    }
@@ -6448,6 +6457,8 @@ public final class ActivityThread extends ClientTransactionHandler {
        }
        updateDefaultDensity();

        // mCoreSettings is only updated from the main thread, while this function is only called
        // from main thread as well, so no need to lock here.
        final String use24HourSetting = mCoreSettings.getString(Settings.System.TIME_12_24);
        Boolean is24Hr = null;
        if (use24HourSetting != null) {
@@ -7468,12 +7479,17 @@ public final class ActivityThread extends ClientTransactionHandler {
        }
    }

    public Bundle getCoreSettings() {
    /**
     * Caller should NEVER mutate the Bundle returned from here
     */
    Bundle getCoreSettings() {
        synchronized (mCoreSettingsLock) {
            return mCoreSettings;
        }
    }

    public int getIntCoreSetting(String key, int defaultValue) {
        synchronized (mResourcesManager) {
        synchronized (mCoreSettingsLock) {
            if (mCoreSettings != null) {
                return mCoreSettings.getInt(key, defaultValue);
            }
@@ -7485,7 +7501,7 @@ public final class ActivityThread extends ClientTransactionHandler {
     * Get the string value of the given key from core settings.
     */
    public String getStringCoreSetting(String key, String defaultValue) {
        synchronized (mResourcesManager) {
        synchronized (mCoreSettingsLock) {
            if (mCoreSettings != null) {
                return mCoreSettings.getString(key, defaultValue);
            }
@@ -7494,7 +7510,7 @@ public final class ActivityThread extends ClientTransactionHandler {
    }

    float getFloatCoreSetting(String key, float defaultValue) {
        synchronized (mResourcesManager) {
        synchronized (mCoreSettingsLock) {
            if (mCoreSettings != null) {
                return mCoreSettings.getFloat(key, defaultValue);
            }