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

Commit 2b268200 authored by Jordan Liu's avatar Jordan Liu
Browse files

Do no try to unbind if not connected

Bug: 145661922
Test: atest CarrierServiceBindHelperTest#testUnbindWhenNotConnected
Change-Id: Ia727fdc623d703e372d2a29f5b582369b3df9d4f
parent b9072fec
Loading
Loading
Loading
Loading
+22 −4
Original line number Diff line number Diff line
@@ -86,12 +86,14 @@ public class CarrierServiceBindHelper {
    };

    private static final int EVENT_REBIND = 0;
    private static final int EVENT_PERFORM_IMMEDIATE_UNBIND = 1;
    @VisibleForTesting
    public static final int EVENT_PERFORM_IMMEDIATE_UNBIND = 1;
    @VisibleForTesting
    public static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 2;

    @UnsupportedAppUsage
    private Handler mHandler = new Handler() {
    @VisibleForTesting
    public Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            int phoneId;
@@ -331,8 +333,12 @@ public class CarrierServiceBindHelper {
            carrierServiceClass = null;

            // Actually unbind
            if (connection != null && connection.connected) {
                log("Unbinding from carrier app");
                mContext.unbindService(connection);
            } else {
                log("Already unbound, skipping unbindService call");
            }
            connection = null;
            mUnbindScheduledUptimeMillis = -1;
        }
@@ -369,6 +375,18 @@ public class CarrierServiceBindHelper {
            connected = false;
        }

        @Override
        public void onBindingDied(ComponentName name) {
            log("Binding from carrier app died: " + name.flattenToString());
            connected = false;
        }

        @Override
        public void onNullBinding(ComponentName name) {
            log("Null binding from carrier app: " + name.flattenToString());
            connected = false;
        }

        @Override
        public String toString() {
            return "CarrierServiceConnection[connected=" + connected + "]";
+12 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doReturn;

import android.os.Message;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -81,4 +82,15 @@ public class CarrierServiceBindHelperTest extends TelephonyTest {
        assertNotNull(mCarrierServiceBindHelper.mBindings.get(0));
        assertNotNull(mCarrierServiceBindHelper.mLastSimState.get(0));
    }

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

        // Try unbinding without binding and make sure we don't throw an Exception
        mCarrierServiceBindHelper.mHandler.handleMessage(
                Message.obtain(mCarrierServiceBindHelper.mHandler,
                        CarrierServiceBindHelper.EVENT_PERFORM_IMMEDIATE_UNBIND,
                        new Integer(0)));
    }
}