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

Commit 1d128c38 authored by Jordan Liu's avatar Jordan Liu Committed by Gerrit Code Review
Browse files

Merge "Only unbind if bind() returned success"

parents 98debea0 391ef4c3
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -69,6 +69,9 @@ public class CarrierServiceBindHelper {
    public SparseArray<String> mLastSimState = new SparseArray<>();
    private final PackageChangeReceiver mPackageMonitor = new CarrierServicePackageMonitor();

    // whether we have successfully bound to the service
    private boolean mServiceBound = false;

    private BroadcastReceiver mUserUnlockedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
@@ -279,6 +282,7 @@ public class CarrierServiceBindHelper {
                                Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE,
                                (r) -> mHandler.post(r),
                                connection)) {
                    mServiceBound = true;
                    return;
                }

@@ -333,11 +337,12 @@ public class CarrierServiceBindHelper {
            carrierServiceClass = null;

            // Actually unbind
            if (connection != null && connection.connected) {
            if (mServiceBound) {
                log("Unbinding from carrier app");
                mServiceBound = false;
                mContext.unbindService(connection);
            } else {
                log("Already unbound, skipping unbindService call");
                log("Not bound, skipping unbindService call");
            }
            connection = null;
            mUnbindScheduledUptimeMillis = -1;
+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ public class CarrierServiceBindHelperTest extends TelephonyTest {
    }

    @Test
    public void testUnbindWhenNotConnected() throws Exception {
    public void testUnbindWhenNotBound() throws Exception {
        mCarrierServiceBindHelper = new CarrierServiceBindHelper(mContext);

        // Try unbinding without binding and make sure we don't throw an Exception