Merge "Unbind MBMS service after calling close"
am: d00563735f
Change-Id: I9392f5d1c2922d373b0aef812cbc43ba1ef05848
This commit is contained in:
@@ -243,6 +243,7 @@ public class MbmsDownloadSession implements AutoCloseable {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private AtomicReference<IMbmsDownloadService> mService = new AtomicReference<>(null);
|
private AtomicReference<IMbmsDownloadService> mService = new AtomicReference<>(null);
|
||||||
|
private ServiceConnection mServiceConnection;
|
||||||
private final InternalDownloadSessionCallback mInternalCallback;
|
private final InternalDownloadSessionCallback mInternalCallback;
|
||||||
private final Map<DownloadStatusListener, InternalDownloadStatusListener>
|
private final Map<DownloadStatusListener, InternalDownloadStatusListener>
|
||||||
mInternalDownloadStatusListeners = new HashMap<>();
|
mInternalDownloadStatusListeners = new HashMap<>();
|
||||||
@@ -318,8 +319,7 @@ public class MbmsDownloadSession implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int bindAndInitialize() {
|
private int bindAndInitialize() {
|
||||||
return MbmsUtils.startBinding(mContext, MBMS_DOWNLOAD_SERVICE_ACTION,
|
mServiceConnection = new ServiceConnection() {
|
||||||
new ServiceConnection() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
IMbmsDownloadService downloadService =
|
IMbmsDownloadService downloadService =
|
||||||
@@ -367,7 +367,18 @@ public class MbmsDownloadSession implements AutoCloseable {
|
|||||||
sIsInitialized.set(false);
|
sIsInitialized.set(false);
|
||||||
mService.set(null);
|
mService.set(null);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
@Override
|
||||||
|
public void onNullBinding(ComponentName name) {
|
||||||
|
Log.w(LOG_TAG, "bindAndInitialize: Remote service returned null");
|
||||||
|
sendErrorToApp(MbmsErrors.ERROR_MIDDLEWARE_LOST,
|
||||||
|
"Middleware service binding returned null");
|
||||||
|
sIsInitialized.set(false);
|
||||||
|
mService.set(null);
|
||||||
|
mContext.unbindService(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return MbmsUtils.startBinding(mContext, MBMS_DOWNLOAD_SERVICE_ACTION, mServiceConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -965,17 +976,19 @@ public class MbmsDownloadSession implements AutoCloseable {
|
|||||||
public void close() {
|
public void close() {
|
||||||
try {
|
try {
|
||||||
IMbmsDownloadService downloadService = mService.get();
|
IMbmsDownloadService downloadService = mService.get();
|
||||||
if (downloadService == null) {
|
if (downloadService == null || mServiceConnection == null) {
|
||||||
Log.i(LOG_TAG, "Service already dead");
|
Log.i(LOG_TAG, "Service already dead");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
downloadService.dispose(mSubscriptionId);
|
downloadService.dispose(mSubscriptionId);
|
||||||
|
mContext.unbindService(mServiceConnection);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// Ignore
|
// Ignore
|
||||||
Log.i(LOG_TAG, "Remote exception while disposing of service");
|
Log.i(LOG_TAG, "Remote exception while disposing of service");
|
||||||
} finally {
|
} finally {
|
||||||
mService.set(null);
|
mService.set(null);
|
||||||
sIsInitialized.set(false);
|
sIsInitialized.set(false);
|
||||||
|
mServiceConnection = null;
|
||||||
mInternalCallback.stop();
|
mInternalCallback.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ public class MbmsGroupCallSession implements AutoCloseable {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private InternalGroupCallSessionCallback mInternalCallback;
|
private InternalGroupCallSessionCallback mInternalCallback;
|
||||||
|
private ServiceConnection mServiceConnection;
|
||||||
private Set<GroupCall> mKnownActiveGroupCalls = new ArraySet<>();
|
private Set<GroupCall> mKnownActiveGroupCalls = new ArraySet<>();
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
@@ -163,7 +164,7 @@ public class MbmsGroupCallSession implements AutoCloseable {
|
|||||||
public void close() {
|
public void close() {
|
||||||
try {
|
try {
|
||||||
IMbmsGroupCallService groupCallService = mService.get();
|
IMbmsGroupCallService groupCallService = mService.get();
|
||||||
if (groupCallService == null) {
|
if (groupCallService == null || mServiceConnection == null) {
|
||||||
// Ignore and return, assume already disposed.
|
// Ignore and return, assume already disposed.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -172,11 +173,13 @@ public class MbmsGroupCallSession implements AutoCloseable {
|
|||||||
s.getCallback().stop();
|
s.getCallback().stop();
|
||||||
}
|
}
|
||||||
mKnownActiveGroupCalls.clear();
|
mKnownActiveGroupCalls.clear();
|
||||||
|
mContext.unbindService(mServiceConnection);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// Ignore for now
|
// Ignore for now
|
||||||
} finally {
|
} finally {
|
||||||
mService.set(null);
|
mService.set(null);
|
||||||
sIsInitialized.set(false);
|
sIsInitialized.set(false);
|
||||||
|
mServiceConnection = null;
|
||||||
mInternalCallback.stop();
|
mInternalCallback.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,8 +247,7 @@ public class MbmsGroupCallSession implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int bindAndInitialize() {
|
private int bindAndInitialize() {
|
||||||
return MbmsUtils.startBinding(mContext, MBMS_GROUP_CALL_SERVICE_ACTION,
|
mServiceConnection = new ServiceConnection() {
|
||||||
new ServiceConnection() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
IMbmsGroupCallService groupCallService =
|
IMbmsGroupCallService groupCallService =
|
||||||
@@ -297,6 +299,17 @@ public class MbmsGroupCallSession implements AutoCloseable {
|
|||||||
sIsInitialized.set(false);
|
sIsInitialized.set(false);
|
||||||
mService.set(null);
|
mService.set(null);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
@Override
|
||||||
|
public void onNullBinding(ComponentName name) {
|
||||||
|
Log.w(LOG_TAG, "bindAndInitialize: Remote service returned null");
|
||||||
|
mInternalCallback.onError(MbmsErrors.ERROR_MIDDLEWARE_LOST,
|
||||||
|
"Middleware service binding returned null");
|
||||||
|
sIsInitialized.set(false);
|
||||||
|
mService.set(null);
|
||||||
|
mContext.unbindService(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return MbmsUtils.startBinding(mContext, MBMS_GROUP_CALL_SERVICE_ACTION, mServiceConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ public class MbmsStreamingSession implements AutoCloseable {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private InternalStreamingSessionCallback mInternalCallback;
|
private InternalStreamingSessionCallback mInternalCallback;
|
||||||
|
private ServiceConnection mServiceConnection;
|
||||||
private Set<StreamingService> mKnownActiveStreamingServices = new ArraySet<>();
|
private Set<StreamingService> mKnownActiveStreamingServices = new ArraySet<>();
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
@@ -168,7 +169,7 @@ public class MbmsStreamingSession implements AutoCloseable {
|
|||||||
public void close() {
|
public void close() {
|
||||||
try {
|
try {
|
||||||
IMbmsStreamingService streamingService = mService.get();
|
IMbmsStreamingService streamingService = mService.get();
|
||||||
if (streamingService == null) {
|
if (streamingService == null || mServiceConnection == null) {
|
||||||
// Ignore and return, assume already disposed.
|
// Ignore and return, assume already disposed.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -177,11 +178,13 @@ public class MbmsStreamingSession implements AutoCloseable {
|
|||||||
s.getCallback().stop();
|
s.getCallback().stop();
|
||||||
}
|
}
|
||||||
mKnownActiveStreamingServices.clear();
|
mKnownActiveStreamingServices.clear();
|
||||||
|
mContext.unbindService(mServiceConnection);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// Ignore for now
|
// Ignore for now
|
||||||
} finally {
|
} finally {
|
||||||
mService.set(null);
|
mService.set(null);
|
||||||
sIsInitialized.set(false);
|
sIsInitialized.set(false);
|
||||||
|
mServiceConnection = null;
|
||||||
mInternalCallback.stop();
|
mInternalCallback.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,8 +289,7 @@ public class MbmsStreamingSession implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int bindAndInitialize() {
|
private int bindAndInitialize() {
|
||||||
return MbmsUtils.startBinding(mContext, MBMS_STREAMING_SERVICE_ACTION,
|
mServiceConnection = new ServiceConnection() {
|
||||||
new ServiceConnection() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
IMbmsStreamingService streamingService =
|
IMbmsStreamingService streamingService =
|
||||||
@@ -338,7 +340,18 @@ public class MbmsStreamingSession implements AutoCloseable {
|
|||||||
sIsInitialized.set(false);
|
sIsInitialized.set(false);
|
||||||
mService.set(null);
|
mService.set(null);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
@Override
|
||||||
|
public void onNullBinding(ComponentName name) {
|
||||||
|
Log.w(LOG_TAG, "bindAndInitialize: Remote service returned null");
|
||||||
|
sendErrorToApp(MbmsErrors.ERROR_MIDDLEWARE_LOST,
|
||||||
|
"Middleware service binding returned null");
|
||||||
|
sIsInitialized.set(false);
|
||||||
|
mService.set(null);
|
||||||
|
mContext.unbindService(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return MbmsUtils.startBinding(mContext, MBMS_STREAMING_SERVICE_ACTION, mServiceConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendErrorToApp(int errorCode, String message) {
|
private void sendErrorToApp(int errorCode, String message) {
|
||||||
|
|||||||
Reference in New Issue
Block a user