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

Commit 5974577c authored by Beverly Tai's avatar Beverly Tai Committed by Automerger Merge Worker
Browse files

Merge "Fix ScreenDecorations user switch bug" into rvc-dev am: ec5dcbc2

Change-Id: Id7690a0876eb4010ac4c7e042811030949121bb0
parents a8ad785a ec5dcbc2
Loading
Loading
Loading
Loading
+15 −12
Original line number Diff line number Diff line
@@ -54,8 +54,10 @@ import android.graphics.Region;
import android.graphics.drawable.VectorDrawable;
import android.hardware.display.DisplayManager;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.HandlerThread;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings.Secure;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -298,13 +300,15 @@ public class ScreenDecorations extends SystemUI implements Tunable {
                        updateColorInversion(value);
                    }
                };
            }

                mColorInversionSetting.setListening(true);
                mColorInversionSetting.onChange(false);
            }

            IntentFilter filter = new IntentFilter();
            filter.addAction(Intent.ACTION_USER_SWITCHED);
            mBroadcastDispatcher.registerReceiverWithHandler(mIntentReceiver, filter, mHandler);
            mBroadcastDispatcher.registerReceiver(mUserSwitchIntentReceiver, filter,
                    new HandlerExecutor(mHandler), UserHandle.ALL);
            mIsRegistered = true;
        } else {
            mMainHandler.post(() -> mTunerService.removeTunable(this));
@@ -313,7 +317,7 @@ public class ScreenDecorations extends SystemUI implements Tunable {
                mColorInversionSetting.setListening(false);
            }

            mBroadcastDispatcher.unregisterReceiver(mIntentReceiver);
            mBroadcastDispatcher.unregisterReceiver(mUserSwitchIntentReceiver);
            mIsRegistered = false;
        }
    }
@@ -503,18 +507,17 @@ public class ScreenDecorations extends SystemUI implements Tunable {
        }
    }

    private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
    private final BroadcastReceiver mUserSwitchIntentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(Intent.ACTION_USER_SWITCHED)) {
                int newUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
                        ActivityManager.getCurrentUser());
            int newUserId = ActivityManager.getCurrentUser();
            if (DEBUG) {
                Log.d(TAG, "UserSwitched newUserId=" + newUserId);
            }
            // update color inversion setting to the new user
            mColorInversionSetting.setUserId(newUserId);
            updateColorInversion(mColorInversionSetting.getValue());
        }
        }
    };

    private void updateColorInversion(int colorsInvertedValue) {