Merge "Fix the service cann't rebinded after the service died" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c85f9a62b5
@@ -88,7 +88,7 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
|
||||
private final int mBindingFlags;
|
||||
protected I mService;
|
||||
|
||||
private boolean mBinding;
|
||||
private boolean mConnecting;
|
||||
private boolean mDestroyed;
|
||||
private boolean mServiceDied;
|
||||
private boolean mCompleted;
|
||||
@@ -228,7 +228,7 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
|
||||
if (mService != null) {
|
||||
mService.asBinder().unlinkToDeath(this, 0);
|
||||
}
|
||||
mBinding = false;
|
||||
mConnecting = true;
|
||||
mService = null;
|
||||
mServiceDied = true;
|
||||
cancelScheduledUnbind();
|
||||
@@ -435,10 +435,10 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
|
||||
}
|
||||
|
||||
private void handleEnsureBound() {
|
||||
if (handleIsBound() || mBinding) return;
|
||||
if (handleIsBound() || mConnecting) return;
|
||||
|
||||
if (mVerbose) Slog.v(mTag, "ensureBound()");
|
||||
mBinding = true;
|
||||
mConnecting = true;
|
||||
|
||||
final int flags = Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE
|
||||
| Context.BIND_INCLUDE_CAPABILITIES | mBindingFlags;
|
||||
@@ -448,7 +448,7 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
|
||||
|
||||
if (!willBind) {
|
||||
Slog.w(mTag, "could not bind to " + mIntent + " using flags " + flags);
|
||||
mBinding = false;
|
||||
mConnecting = false;
|
||||
|
||||
if (!mServiceDied) {
|
||||
handleBinderDied();
|
||||
@@ -457,10 +457,10 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
|
||||
}
|
||||
|
||||
private void handleEnsureUnbound() {
|
||||
if (!handleIsBound() && !mBinding) return;
|
||||
if (!handleIsBound() && !mConnecting) return;
|
||||
|
||||
if (mVerbose) Slog.v(mTag, "ensureUnbound()");
|
||||
mBinding = false;
|
||||
mConnecting = false;
|
||||
if (handleIsBound()) {
|
||||
handleOnConnectedStateChangedInternal(false);
|
||||
if (mService != null) {
|
||||
@@ -476,12 +476,12 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
if (mVerbose) Slog.v(mTag, "onServiceConnected()");
|
||||
if (mDestroyed || !mBinding) {
|
||||
if (mDestroyed || !mConnecting) {
|
||||
// This is abnormal. Unbinding the connection has been requested already.
|
||||
Slog.wtf(mTag, "onServiceConnected() was dispatched after unbindService.");
|
||||
return;
|
||||
}
|
||||
mBinding = false;
|
||||
mConnecting = false;
|
||||
try {
|
||||
service.linkToDeath(AbstractRemoteService.this, 0);
|
||||
} catch (RemoteException re) {
|
||||
@@ -496,7 +496,7 @@ public abstract class AbstractRemoteService<S extends AbstractRemoteService<S, I
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
if (mVerbose) Slog.v(mTag, "onServiceDisconnected()");
|
||||
mBinding = true;
|
||||
mConnecting = true;
|
||||
mService = null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user