From 86bcd37b8f11e62752571b8cfe885946f5d92637 Mon Sep 17 00:00:00 2001 From: hupeng3 Date: Tue, 10 May 2022 12:33:08 +0800 Subject: Toast: Fix JE caused by service not bind Before calling unbindService, we need to call bindService, but there are some logic problems in DisplayHashController, which cause this problem to occur. Add the control variable mBound. Bug: 232001919 Test: atest DisplayHashManagerTest Signed-off-by: hupeng3 Change-Id: I84cd1542af345d5078ef40ab282d2d405e967e8e --- .../core/java/com/android/server/wm/DisplayHashController.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayHashController.java b/services/core/java/com/android/server/wm/DisplayHashController.java index 64a57588113c..543d4ad6b507 100644 --- a/services/core/java/com/android/server/wm/DisplayHashController.java +++ b/services/core/java/com/android/server/wm/DisplayHashController.java @@ -369,9 +369,6 @@ public class DisplayHashController { if (mServiceConnection == null) { if (DEBUG) Slog.v(TAG, "creating connection"); - // Create the connection - mServiceConnection = new DisplayHashingServiceConnection(); - final ComponentName component = getServiceComponentName(); if (DEBUG) Slog.v(TAG, "binding to: " + component); if (component != null) { @@ -379,6 +376,8 @@ public class DisplayHashController { intent.setComponent(component); final long token = Binder.clearCallingIdentity(); try { + // Create the connection + mServiceConnection = new DisplayHashingServiceConnection(); mContext.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); if (DEBUG) Slog.v(TAG, "bound"); } finally { @@ -387,7 +386,9 @@ public class DisplayHashController { } } - mServiceConnection.runCommandLocked(command); + if (mServiceConnection != null) { + mServiceConnection.runCommandLocked(command); + } } } -- cgit v1.2.3-59-g8ed1b