Merge "Fixes how unbindService works"
This commit is contained in:
@@ -106,6 +106,8 @@ public class ResumeOnRebootServiceProvider {
|
|||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final ComponentName mComponentName;
|
private final ComponentName mComponentName;
|
||||||
private IResumeOnRebootService mBinder;
|
private IResumeOnRebootService mBinder;
|
||||||
|
@Nullable
|
||||||
|
ServiceConnection mServiceConnection;
|
||||||
|
|
||||||
private ResumeOnRebootServiceConnection(Context context,
|
private ResumeOnRebootServiceConnection(Context context,
|
||||||
@NonNull ComponentName componentName) {
|
@NonNull ComponentName componentName) {
|
||||||
@@ -115,17 +117,9 @@ public class ResumeOnRebootServiceProvider {
|
|||||||
|
|
||||||
/** Unbind from the service */
|
/** Unbind from the service */
|
||||||
public void unbindService() {
|
public void unbindService() {
|
||||||
mContext.unbindService(new ServiceConnection() {
|
if (mServiceConnection != null) {
|
||||||
@Override
|
mContext.unbindService(mServiceConnection);
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServiceDisconnected(ComponentName name) {
|
|
||||||
mBinder = null;
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Bind to the service */
|
/** Bind to the service */
|
||||||
@@ -134,17 +128,19 @@ public class ResumeOnRebootServiceProvider {
|
|||||||
CountDownLatch connectionLatch = new CountDownLatch(1);
|
CountDownLatch connectionLatch = new CountDownLatch(1);
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setComponent(mComponentName);
|
intent.setComponent(mComponentName);
|
||||||
final boolean success = mContext.bindServiceAsUser(intent, new ServiceConnection() {
|
mServiceConnection = new ServiceConnection() {
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
mBinder = IResumeOnRebootService.Stub.asInterface(service);
|
mBinder = IResumeOnRebootService.Stub.asInterface(service);
|
||||||
connectionLatch.countDown();
|
connectionLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceDisconnected(ComponentName name) {
|
public void onServiceDisconnected(ComponentName name) {
|
||||||
}
|
mBinder = null;
|
||||||
},
|
}
|
||||||
|
};
|
||||||
|
final boolean success = mContext.bindServiceAsUser(intent, mServiceConnection,
|
||||||
Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE,
|
Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE,
|
||||||
BackgroundThread.getHandler(), UserHandle.SYSTEM);
|
BackgroundThread.getHandler(), UserHandle.SYSTEM);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user