Loading src/java/com/android/internal/telephony/CarrierServiceBindHelper.java +22 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } Loading Loading @@ -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 + "]"; Loading tests/telephonytests/src/com/android/internal/telephony/CarrierServiceBindHelperTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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))); } } Loading
src/java/com/android/internal/telephony/CarrierServiceBindHelper.java +22 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } Loading Loading @@ -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 + "]"; Loading
tests/telephonytests/src/com/android/internal/telephony/CarrierServiceBindHelperTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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))); } }