Merge "Fixes how unbindService works" am: b7682d401f

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1564532

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I16e115505e4b3c2ac0c9fe78e82b704cb1ce4ceb
This commit is contained in:
Tianjie Xu
2021-01-29 23:31:30 +00:00
committed by Automerger Merge Worker

View File

@@ -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();
}
mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mBinder = IResumeOnRebootService.Stub.asInterface(service);
connectionLatch.countDown();
}
@Override
public void onServiceDisconnected(ComponentName name) {
}
},
@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);