Fix the service cann't rebinded after the service died
The Content Capture remote service needs to rebind afeter died. But the service entered an error state, causing the reconnection to be ignored. When service died, the state should be changed to waiting the new connection. Bug: 184786235 Test: atest CtsContentCaptureServiceTestCases Change-Id: I2842b2aab0dcf82938b5c7a9f6afcf044f7f598e
This commit is contained in:
@@ -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