Loading src/java/com/android/internal/telephony/CarrierActionAgent.java +28 −20 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.os.Registrant; import android.os.RegistrantList; import android.provider.Settings; import android.telephony.Rlog; import android.telephony.TelephonyManager; import android.util.LocalLog; import android.util.Log; Loading Loading @@ -56,6 +57,8 @@ public class CarrierActionAgent extends Handler { public static final int CARRIER_ACTION_SET_METERED_APNS_ENABLED = 0; public static final int CARRIER_ACTION_SET_RADIO_ENABLED = 1; public static final int CARRIER_ACTION_RESET = 2; public static final int EVENT_APM_SETTINGS_CHANGED = 3; public static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 4; /** Member variables */ private final Phone mPhone; Loading @@ -77,37 +80,31 @@ public class CarrierActionAgent extends Handler { final String action = intent.getAction(); final String iccState = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)){ if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(iccState) || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(iccState)) { if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(iccState)) { sendEmptyMessage(CARRIER_ACTION_RESET); String mobileData = Settings.Global.MOBILE_DATA; if (TelephonyManager.getDefault().getSimCount() != 1) { mobileData = mobileData + mPhone.getSubId(); } } } }; private class SettingsObserver extends ContentObserver { SettingsObserver() { super(null); } @Override public void onChange(boolean selfChange) { if (Settings.Global.getInt(mPhone.getContext().getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0) { mSettingsObserver.observe(Settings.Global.getUriFor(mobileData), EVENT_MOBILE_DATA_SETTINGS_CHANGED); mSettingsObserver.observe( Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), EVENT_APM_SETTINGS_CHANGED); } else if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(iccState)) { sendEmptyMessage(CARRIER_ACTION_RESET); mSettingsObserver.unobserve(); } } } }; /** Constructor */ public CarrierActionAgent(Phone phone) { mPhone = phone; mPhone.getContext().registerReceiver(mReceiver, new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED)); mSettingsObserver = new SettingsObserver(); mPhone.getContext().getContentResolver().registerContentObserver( Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), false, mSettingsObserver); mSettingsObserver = new SettingsObserver(mPhone.getContext(), this); if (DBG) log("Creating CarrierActionAgent"); } Loading Loading @@ -137,6 +134,17 @@ public class CarrierActionAgent extends Handler { mPhone.getCarrierSignalAgent().notifyCarrierSignalReceivers( new Intent(TelephonyIntents.ACTION_CARRIER_SIGNAL_RESET)); break; case EVENT_APM_SETTINGS_CHANGED: log("EVENT_APM_SETTINGS_CHANGED"); if ((Settings.Global.getInt(mPhone.getContext().getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0)) { sendEmptyMessage(CARRIER_ACTION_RESET); } break; case EVENT_MOBILE_DATA_SETTINGS_CHANGED: log("EVENT_MOBILE_DATA_SETTINGS_CHANGED"); if (!mPhone.getDataEnabled()) sendEmptyMessage(CARRIER_ACTION_RESET); break; default: loge("Unknown carrier action: " + msg.what); } Loading tests/telephonytests/src/com/android/internal/telephony/CarrierActionAgentTest.java +23 −3 Original line number Diff line number Diff line Loading @@ -20,14 +20,18 @@ import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.anyLong; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import android.content.Intent; import android.database.ContentObserver; import android.net.Uri; import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.provider.Settings; import android.provider.Telephony; import android.telephony.CarrierConfigManager; import android.test.mock.MockContentResolver; import android.test.suitebuilder.annotation.SmallTest; Loading Loading @@ -95,16 +99,32 @@ public class CarrierActionAgentTest extends TelephonyTest { @Test @SmallTest public void testCarrierActionResetOnAPM() { // setting observer register at sim loading final Intent intent = new Intent(TelephonyIntents.ACTION_SIM_STATE_CHANGED); intent.putExtra(IccCardConstants.INTENT_KEY_ICC_STATE, IccCardConstants.INTENT_VALUE_ICC_LOADED); mContext.sendBroadcast(intent); waitForMs(100); // carrier actions triggered from sim loading ArgumentCaptor<Message> message = ArgumentCaptor.forClass(Message.class); verify(mDataActionHandler).sendMessageAtTime(message.capture(), anyLong()); assertEquals(DATA_CARRIER_ACTION_EVENT, message.getValue().what); verify(mRadioActionHandler).sendMessageAtTime(message.capture(), anyLong()); assertEquals(RADIO_CARRIER_ACTION_EVENT, message.getValue().what); // simulate APM change from off -> on Settings.Global.putInt(mFakeContentResolver, Settings.Global.AIRPLANE_MODE_ON, 1); mFakeContentResolver.notifyChange( Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), null); waitForMs(200); ArgumentCaptor<Message> message = ArgumentCaptor.forClass(Message.class); verify(mDataActionHandler).sendMessageAtTime(message.capture(), anyLong()); // carrier actions triggered from APM verify(mDataActionHandler, times(2)).sendMessageAtTime(message.capture(), anyLong()); assertEquals(DATA_CARRIER_ACTION_EVENT, message.getValue().what); verify(mRadioActionHandler).sendMessageAtTime(message.capture(), anyLong()); verify(mRadioActionHandler, times(2)).sendMessageAtTime(message.capture(), anyLong()); assertEquals(RADIO_CARRIER_ACTION_EVENT, message.getValue().what); } Loading Loading
src/java/com/android/internal/telephony/CarrierActionAgent.java +28 −20 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.os.Registrant; import android.os.RegistrantList; import android.provider.Settings; import android.telephony.Rlog; import android.telephony.TelephonyManager; import android.util.LocalLog; import android.util.Log; Loading Loading @@ -56,6 +57,8 @@ public class CarrierActionAgent extends Handler { public static final int CARRIER_ACTION_SET_METERED_APNS_ENABLED = 0; public static final int CARRIER_ACTION_SET_RADIO_ENABLED = 1; public static final int CARRIER_ACTION_RESET = 2; public static final int EVENT_APM_SETTINGS_CHANGED = 3; public static final int EVENT_MOBILE_DATA_SETTINGS_CHANGED = 4; /** Member variables */ private final Phone mPhone; Loading @@ -77,37 +80,31 @@ public class CarrierActionAgent extends Handler { final String action = intent.getAction(); final String iccState = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)){ if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(iccState) || IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(iccState)) { if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(iccState)) { sendEmptyMessage(CARRIER_ACTION_RESET); String mobileData = Settings.Global.MOBILE_DATA; if (TelephonyManager.getDefault().getSimCount() != 1) { mobileData = mobileData + mPhone.getSubId(); } } } }; private class SettingsObserver extends ContentObserver { SettingsObserver() { super(null); } @Override public void onChange(boolean selfChange) { if (Settings.Global.getInt(mPhone.getContext().getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0) { mSettingsObserver.observe(Settings.Global.getUriFor(mobileData), EVENT_MOBILE_DATA_SETTINGS_CHANGED); mSettingsObserver.observe( Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), EVENT_APM_SETTINGS_CHANGED); } else if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(iccState)) { sendEmptyMessage(CARRIER_ACTION_RESET); mSettingsObserver.unobserve(); } } } }; /** Constructor */ public CarrierActionAgent(Phone phone) { mPhone = phone; mPhone.getContext().registerReceiver(mReceiver, new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED)); mSettingsObserver = new SettingsObserver(); mPhone.getContext().getContentResolver().registerContentObserver( Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), false, mSettingsObserver); mSettingsObserver = new SettingsObserver(mPhone.getContext(), this); if (DBG) log("Creating CarrierActionAgent"); } Loading Loading @@ -137,6 +134,17 @@ public class CarrierActionAgent extends Handler { mPhone.getCarrierSignalAgent().notifyCarrierSignalReceivers( new Intent(TelephonyIntents.ACTION_CARRIER_SIGNAL_RESET)); break; case EVENT_APM_SETTINGS_CHANGED: log("EVENT_APM_SETTINGS_CHANGED"); if ((Settings.Global.getInt(mPhone.getContext().getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0)) { sendEmptyMessage(CARRIER_ACTION_RESET); } break; case EVENT_MOBILE_DATA_SETTINGS_CHANGED: log("EVENT_MOBILE_DATA_SETTINGS_CHANGED"); if (!mPhone.getDataEnabled()) sendEmptyMessage(CARRIER_ACTION_RESET); break; default: loge("Unknown carrier action: " + msg.what); } Loading
tests/telephonytests/src/com/android/internal/telephony/CarrierActionAgentTest.java +23 −3 Original line number Diff line number Diff line Loading @@ -20,14 +20,18 @@ import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.anyLong; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import android.content.Intent; import android.database.ContentObserver; import android.net.Uri; import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.provider.Settings; import android.provider.Telephony; import android.telephony.CarrierConfigManager; import android.test.mock.MockContentResolver; import android.test.suitebuilder.annotation.SmallTest; Loading Loading @@ -95,16 +99,32 @@ public class CarrierActionAgentTest extends TelephonyTest { @Test @SmallTest public void testCarrierActionResetOnAPM() { // setting observer register at sim loading final Intent intent = new Intent(TelephonyIntents.ACTION_SIM_STATE_CHANGED); intent.putExtra(IccCardConstants.INTENT_KEY_ICC_STATE, IccCardConstants.INTENT_VALUE_ICC_LOADED); mContext.sendBroadcast(intent); waitForMs(100); // carrier actions triggered from sim loading ArgumentCaptor<Message> message = ArgumentCaptor.forClass(Message.class); verify(mDataActionHandler).sendMessageAtTime(message.capture(), anyLong()); assertEquals(DATA_CARRIER_ACTION_EVENT, message.getValue().what); verify(mRadioActionHandler).sendMessageAtTime(message.capture(), anyLong()); assertEquals(RADIO_CARRIER_ACTION_EVENT, message.getValue().what); // simulate APM change from off -> on Settings.Global.putInt(mFakeContentResolver, Settings.Global.AIRPLANE_MODE_ON, 1); mFakeContentResolver.notifyChange( Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), null); waitForMs(200); ArgumentCaptor<Message> message = ArgumentCaptor.forClass(Message.class); verify(mDataActionHandler).sendMessageAtTime(message.capture(), anyLong()); // carrier actions triggered from APM verify(mDataActionHandler, times(2)).sendMessageAtTime(message.capture(), anyLong()); assertEquals(DATA_CARRIER_ACTION_EVENT, message.getValue().what); verify(mRadioActionHandler).sendMessageAtTime(message.capture(), anyLong()); verify(mRadioActionHandler, times(2)).sendMessageAtTime(message.capture(), anyLong()); assertEquals(RADIO_CARRIER_ACTION_EVENT, message.getValue().what); } Loading