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 <hp121520@gmail.com>
Change-Id: I84cd1542af345d5078ef40ab282d2d405e967e8e
This commit is contained in:
hupeng3
2022-05-10 12:33:08 +08:00
parent aca9b26c93
commit 86bcd37b8f

View File

@@ -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);
}
}
}