diff options
| author | 2021-01-30 00:52:01 +0000 | |
|---|---|---|
| committer | 2021-01-30 00:52:01 +0000 | |
| commit | e4f83a107b368ddeae1c532051ccc9c226da6cee (patch) | |
| tree | e3a68c47343bf277c27262ff71b2fd357437445d | |
| parent | 0afd2d9f27805b206908c0ffe8ed6a82bf998e5d (diff) | |
| parent | e3100d711134b94df7f59278a7a1854be62019e0 (diff) | |
Merge "Fixes how unbindService works" am: b7682d401f am: 3339f21560 am: e3100d7111
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1564532
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: Ib3d3939345cf4aefd63172eb56c1a8b99acd3df0
| -rw-r--r-- | services/core/java/com/android/server/locksettings/ResumeOnRebootServiceProvider.java | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/services/core/java/com/android/server/locksettings/ResumeOnRebootServiceProvider.java b/services/core/java/com/android/server/locksettings/ResumeOnRebootServiceProvider.java index 8399f54764e0..a1e18bd5a6bd 100644 --- a/services/core/java/com/android/server/locksettings/ResumeOnRebootServiceProvider.java +++ b/services/core/java/com/android/server/locksettings/ResumeOnRebootServiceProvider.java @@ -106,6 +106,8 @@ public class ResumeOnRebootServiceProvider { private final Context mContext; private final ComponentName mComponentName; private IResumeOnRebootService mBinder; + @Nullable + ServiceConnection mServiceConnection; private ResumeOnRebootServiceConnection(Context context, @NonNull ComponentName componentName) { @@ -115,17 +117,9 @@ public class ResumeOnRebootServiceProvider { /** Unbind from the service */ public void unbindService() { - mContext.unbindService(new ServiceConnection() { - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - } - - @Override - public void onServiceDisconnected(ComponentName name) { - mBinder = null; - - } - }); + if (mServiceConnection != null) { + mContext.unbindService(mServiceConnection); + } } /** Bind to the service */ @@ -134,17 +128,19 @@ public class ResumeOnRebootServiceProvider { CountDownLatch connectionLatch = new CountDownLatch(1); Intent intent = new Intent(); intent.setComponent(mComponentName); - final boolean success = mContext.bindServiceAsUser(intent, new ServiceConnection() { - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - mBinder = IResumeOnRebootService.Stub.asInterface(service); - connectionLatch.countDown(); - } - - @Override - public void onServiceDisconnected(ComponentName name) { - } - }, + mServiceConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + mBinder = IResumeOnRebootService.Stub.asInterface(service); + connectionLatch.countDown(); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + mBinder = null; + } + }; + final boolean success = mContext.bindServiceAsUser(intent, mServiceConnection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, BackgroundThread.getHandler(), UserHandle.SYSTEM); |