Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 657c80a3 authored by Hall Liu's avatar Hall Liu Committed by android-build-merger
Browse files

Merge "Unbind MBMS service after calling close"

am: d0056373

Change-Id: I9392f5d1c2922d373b0aef812cbc43ba1ef05848
parents 051f9b8e d0056373
Loading
Loading
Loading
Loading
+63 −50
Original line number Diff line number Diff line
@@ -243,6 +243,7 @@ public class MbmsDownloadSession implements AutoCloseable {
    };

    private AtomicReference<IMbmsDownloadService> mService = new AtomicReference<>(null);
    private ServiceConnection mServiceConnection;
    private final InternalDownloadSessionCallback mInternalCallback;
    private final Map<DownloadStatusListener, InternalDownloadStatusListener>
            mInternalDownloadStatusListeners = new HashMap<>();
@@ -318,8 +319,7 @@ public class MbmsDownloadSession implements AutoCloseable {
    }

    private int bindAndInitialize() {
        return MbmsUtils.startBinding(mContext, MBMS_DOWNLOAD_SERVICE_ACTION,
                new ServiceConnection() {
        mServiceConnection = new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                IMbmsDownloadService downloadService =
@@ -367,7 +367,18 @@ public class MbmsDownloadSession implements AutoCloseable {
                sIsInitialized.set(false);
                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() {
        try {
            IMbmsDownloadService downloadService = mService.get();
            if (downloadService == null) {
            if (downloadService == null || mServiceConnection == null) {
                Log.i(LOG_TAG, "Service already dead");
                return;
            }
            downloadService.dispose(mSubscriptionId);
            mContext.unbindService(mServiceConnection);
        } catch (RemoteException e) {
            // Ignore
            Log.i(LOG_TAG, "Remote exception while disposing of service");
        } finally {
            mService.set(null);
            sIsInitialized.set(false);
            mServiceConnection = null;
            mInternalCallback.stop();
        }
    }
+67 −54
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ public class MbmsGroupCallSession implements AutoCloseable {
    };

    private InternalGroupCallSessionCallback mInternalCallback;
    private ServiceConnection mServiceConnection;
    private Set<GroupCall> mKnownActiveGroupCalls = new ArraySet<>();

    private final Context mContext;
@@ -163,7 +164,7 @@ public class MbmsGroupCallSession implements AutoCloseable {
    public void close() {
        try {
            IMbmsGroupCallService groupCallService = mService.get();
            if (groupCallService == null) {
            if (groupCallService == null || mServiceConnection == null) {
                // Ignore and return, assume already disposed.
                return;
            }
@@ -172,11 +173,13 @@ public class MbmsGroupCallSession implements AutoCloseable {
                s.getCallback().stop();
            }
            mKnownActiveGroupCalls.clear();
            mContext.unbindService(mServiceConnection);
        } catch (RemoteException e) {
            // Ignore for now
        } finally {
            mService.set(null);
            sIsInitialized.set(false);
            mServiceConnection = null;
            mInternalCallback.stop();
        }
    }
@@ -244,8 +247,7 @@ public class MbmsGroupCallSession implements AutoCloseable {
    }

    private int bindAndInitialize() {
        return MbmsUtils.startBinding(mContext, MBMS_GROUP_CALL_SERVICE_ACTION,
                new ServiceConnection() {
        mServiceConnection = new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                IMbmsGroupCallService groupCallService =
@@ -297,6 +299,17 @@ public class MbmsGroupCallSession implements AutoCloseable {
                sIsInitialized.set(false);
                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);
    }
}
+66 −53
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ public class MbmsStreamingSession implements AutoCloseable {
    };

    private InternalStreamingSessionCallback mInternalCallback;
    private ServiceConnection mServiceConnection;
    private Set<StreamingService> mKnownActiveStreamingServices = new ArraySet<>();

    private final Context mContext;
@@ -168,7 +169,7 @@ public class MbmsStreamingSession implements AutoCloseable {
    public void close() {
        try {
            IMbmsStreamingService streamingService = mService.get();
            if (streamingService == null) {
            if (streamingService == null || mServiceConnection == null) {
                // Ignore and return, assume already disposed.
                return;
            }
@@ -177,11 +178,13 @@ public class MbmsStreamingSession implements AutoCloseable {
                s.getCallback().stop();
            }
            mKnownActiveStreamingServices.clear();
            mContext.unbindService(mServiceConnection);
        } catch (RemoteException e) {
            // Ignore for now
        } finally {
            mService.set(null);
            sIsInitialized.set(false);
            mServiceConnection = null;
            mInternalCallback.stop();
        }
    }
@@ -286,8 +289,7 @@ public class MbmsStreamingSession implements AutoCloseable {
    }

    private int bindAndInitialize() {
        return MbmsUtils.startBinding(mContext, MBMS_STREAMING_SERVICE_ACTION,
                new ServiceConnection() {
        mServiceConnection = new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                IMbmsStreamingService streamingService =
@@ -338,7 +340,18 @@ public class MbmsStreamingSession implements AutoCloseable {
                sIsInitialized.set(false);
                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) {