summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Fengjiang Li <fengjial@google.com> 2024-06-12 22:18:49 +0000
committer Fengjiang Li <fengjial@google.com> 2024-06-14 21:56:26 +0000
commitc1274bdd5301b74ef502f9416f7df6cc3e37c018 (patch)
tree6e50f4c0dc83cc83c9e9d8f7bec2333b26ec5c07
parentb915c239278e363000b2c4668e33170f4bf00612 (diff)
[Launcher Jank] Avoid making ContentResolver binder calls from GestureNavigationSettingsObserver
Test: manual Flag: NONE performance change Bug: 333772683 Change-Id: Iffb50e296902d5017ad615cea2588719e38bcecf
-rw-r--r--core/java/com/android/internal/policy/GestureNavigationSettingsObserver.java76
-rw-r--r--packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java9
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/LightBarTransitionsController.java4
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/LightBarTransitionsControllerTest.java7
-rw-r--r--services/core/java/com/android/server/wm/DisplayPolicy.java2
5 files changed, 60 insertions, 38 deletions
diff --git a/core/java/com/android/internal/policy/GestureNavigationSettingsObserver.java b/core/java/com/android/internal/policy/GestureNavigationSettingsObserver.java
index f1ed3bed5d89..b7e68bacd143 100644
--- a/core/java/com/android/internal/policy/GestureNavigationSettingsObserver.java
+++ b/core/java/com/android/internal/policy/GestureNavigationSettingsObserver.java
@@ -36,11 +36,13 @@ public class GestureNavigationSettingsObserver extends ContentObserver {
private Context mContext;
private Runnable mOnChangeRunnable;
private Handler mMainHandler;
+ private Handler mBgHandler;
- public GestureNavigationSettingsObserver(Handler handler, Context context,
- Runnable onChangeRunnable) {
- super(handler);
- mMainHandler = handler;
+ public GestureNavigationSettingsObserver(
+ Handler mainHandler, Handler bgHandler, Context context, Runnable onChangeRunnable) {
+ super(mainHandler);
+ mMainHandler = mainHandler;
+ mBgHandler = bgHandler;
mContext = context;
mOnChangeRunnable = onChangeRunnable;
}
@@ -60,45 +62,51 @@ public class GestureNavigationSettingsObserver extends ContentObserver {
* Registers the observer for all users.
*/
public void register() {
- ContentResolver r = mContext.getContentResolver();
- r.registerContentObserver(
- Settings.Secure.getUriFor(Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT),
- false, this, UserHandle.USER_ALL);
- r.registerContentObserver(
- Settings.Secure.getUriFor(Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT),
- false, this, UserHandle.USER_ALL);
- r.registerContentObserver(
- Settings.Secure.getUriFor(Settings.Secure.USER_SETUP_COMPLETE),
- false, this, UserHandle.USER_ALL);
- DeviceConfig.addOnPropertiesChangedListener(
- DeviceConfig.NAMESPACE_SYSTEMUI,
- runnable -> mMainHandler.post(runnable),
- mOnPropertiesChangedListener);
+ mBgHandler.post(() -> {
+ ContentResolver r = mContext.getContentResolver();
+ r.registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT),
+ false, this, UserHandle.USER_ALL);
+ r.registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT),
+ false, this, UserHandle.USER_ALL);
+ r.registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.USER_SETUP_COMPLETE),
+ false, this, UserHandle.USER_ALL);
+ DeviceConfig.addOnPropertiesChangedListener(
+ DeviceConfig.NAMESPACE_SYSTEMUI,
+ runnable -> mMainHandler.post(runnable),
+ mOnPropertiesChangedListener);
+ });
}
/**
* Registers the observer for the calling user.
*/
public void registerForCallingUser() {
- ContentResolver r = mContext.getContentResolver();
- r.registerContentObserver(
- Settings.Secure.getUriFor(Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT),
- false, this);
- r.registerContentObserver(
- Settings.Secure.getUriFor(Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT),
- false, this);
- r.registerContentObserver(
- Settings.Secure.getUriFor(Settings.Secure.USER_SETUP_COMPLETE),
- false, this);
- DeviceConfig.addOnPropertiesChangedListener(
- DeviceConfig.NAMESPACE_SYSTEMUI,
- runnable -> mMainHandler.post(runnable),
- mOnPropertiesChangedListener);
+ mBgHandler.post(() -> {
+ ContentResolver r = mContext.getContentResolver();
+ r.registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT),
+ false, this);
+ r.registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT),
+ false, this);
+ r.registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.USER_SETUP_COMPLETE),
+ false, this);
+ DeviceConfig.addOnPropertiesChangedListener(
+ DeviceConfig.NAMESPACE_SYSTEMUI,
+ runnable -> mMainHandler.post(runnable),
+ mOnPropertiesChangedListener);
+ });
}
public void unregister() {
- mContext.getContentResolver().unregisterContentObserver(this);
- DeviceConfig.removeOnPropertiesChangedListener(mOnPropertiesChangedListener);
+ mBgHandler.post(() -> {
+ mContext.getContentResolver().unregisterContentObserver(this);
+ DeviceConfig.removeOnPropertiesChangedListener(mOnPropertiesChangedListener);
+ });
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java
index 99c95b54a4ca..c9be9938ef74 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgeBackGestureHandler.java
@@ -45,6 +45,7 @@ import android.graphics.Rect;
import android.graphics.Region;
import android.hardware.input.InputManager;
import android.icu.text.SimpleDateFormat;
+import android.os.Handler;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemProperties;
@@ -410,6 +411,7 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
PluginManager pluginManager,
@BackPanelUiThread UiThreadContext uiThreadContext,
@Background Executor backgroundExecutor,
+ @Background Handler bgHandler,
UserTracker userTracker,
NavigationModeController navigationModeController,
BackPanelController.Factory backPanelControllerFactory,
@@ -473,7 +475,8 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
ViewConfiguration.getLongPressTimeout());
mGestureNavigationSettingsObserver = new GestureNavigationSettingsObserver(
- mUiThreadContext.getHandler(), mContext, this::onNavigationSettingsChanged);
+ mUiThreadContext.getHandler(), bgHandler, mContext,
+ this::onNavigationSettingsChanged);
updateCurrentUserResources();
}
@@ -1316,6 +1319,7 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
private final PluginManager mPluginManager;
private final UiThreadContext mUiThreadContext;
private final Executor mBackgroundExecutor;
+ private final Handler mBgHandler;
private final UserTracker mUserTracker;
private final NavigationModeController mNavigationModeController;
private final BackPanelController.Factory mBackPanelControllerFactory;
@@ -1336,6 +1340,7 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
PluginManager pluginManager,
@BackPanelUiThread UiThreadContext uiThreadContext,
@Background Executor backgroundExecutor,
+ @Background Handler bgHandler,
UserTracker userTracker,
NavigationModeController navigationModeController,
BackPanelController.Factory backPanelControllerFactory,
@@ -1354,6 +1359,7 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
mPluginManager = pluginManager;
mUiThreadContext = uiThreadContext;
mBackgroundExecutor = backgroundExecutor;
+ mBgHandler = bgHandler;
mUserTracker = userTracker;
mNavigationModeController = navigationModeController;
mBackPanelControllerFactory = backPanelControllerFactory;
@@ -1378,6 +1384,7 @@ public class EdgeBackGestureHandler implements PluginListener<NavigationEdgeBack
mPluginManager,
mUiThreadContext,
mBackgroundExecutor,
+ mBgHandler,
mUserTracker,
mNavigationModeController,
mBackPanelControllerFactory,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/LightBarTransitionsController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/LightBarTransitionsController.java
index 2235035fe5aa..d2a1c4402b93 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/LightBarTransitionsController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/LightBarTransitionsController.java
@@ -29,6 +29,7 @@ import androidx.annotation.VisibleForTesting;
import com.android.app.animation.Interpolators;
import com.android.internal.policy.GestureNavigationSettingsObserver;
import com.android.systemui.Dumpable;
+import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.statusbar.CommandQueue;
@@ -124,6 +125,7 @@ public class LightBarTransitionsController implements Dumpable {
@AssistedInject
public LightBarTransitionsController(
Context context,
+ @Background Handler bgHandler,
@Assisted DarkIntensityApplier applier,
CommandQueue commandQueue,
KeyguardStateController keyguardStateController,
@@ -140,7 +142,7 @@ public class LightBarTransitionsController implements Dumpable {
mContext = context;
mDisplayId = mContext.getDisplayId();
mGestureNavigationSettingsObserver = new GestureNavigationSettingsObserver(
- mHandler, mContext, this::onNavigationSettingsChanged);
+ mHandler, bgHandler, mContext, this::onNavigationSettingsChanged);
mGestureNavigationSettingsObserver.register();
onNavigationSettingsChanged();
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/LightBarTransitionsControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/LightBarTransitionsControllerTest.java
index 43c19b833646..7dfdb9228936 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/LightBarTransitionsControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/LightBarTransitionsControllerTest.java
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import android.os.Handler;
import android.testing.TestableLooper;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -58,14 +59,16 @@ public class LightBarTransitionsControllerTest extends SysuiTestCase {
private KeyguardStateController mKeyguardStateController;
@Mock
private StatusBarStateController mStatusBarStateController;
+ @Mock
+ private Handler mBgHandler;
private LightBarTransitionsController mLightBarTransitionsController;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
- mLightBarTransitionsController = new LightBarTransitionsController(mContext, mApplier,
- new CommandQueue(mContext, new FakeDisplayTracker(mContext)),
+ mLightBarTransitionsController = new LightBarTransitionsController(mContext,
+ mBgHandler, mApplier, new CommandQueue(mContext, new FakeDisplayTracker(mContext)),
mKeyguardStateController, mStatusBarStateController);
}
diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java
index 2f2395502e4b..4a59fc2a8f15 100644
--- a/services/core/java/com/android/server/wm/DisplayPolicy.java
+++ b/services/core/java/com/android/server/wm/DisplayPolicy.java
@@ -128,6 +128,7 @@ import android.window.ClientWindowFrames;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.os.BackgroundThread;
import com.android.internal.policy.ForceShowNavBarSettingsObserver;
import com.android.internal.policy.GestureNavigationSettingsObserver;
import com.android.internal.policy.ScreenDecorationsUtils;
@@ -673,6 +674,7 @@ public class DisplayPolicy {
mService.mHighRefreshRateDenylist);
mGestureNavigationSettingsObserver = new GestureNavigationSettingsObserver(mHandler,
+ BackgroundThread.getHandler(),
mContext, () -> {
synchronized (mLock) {
onConfigurationChanged();