Loading src/java/com/android/internal/telephony/CarrierSignalAgent.java +46 −51 Original line number Diff line number Diff line Loading @@ -20,11 +20,8 @@ import static android.telephony.CarrierConfigManager.KEY_CARRIER_APP_WAKE_SIGNAL import android.annotation.Nullable; import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.Network; Loading Loading @@ -125,25 +122,21 @@ public class CarrierSignalAgent extends Handler { private final LocalLog mErrorLocalLog = new LocalLog(16); private final BroadcastReceiver mReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DBG) log("CarrierSignalAgent receiver action: " + action); if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) { loadCarrierConfig(); } } }; private ConnectivityManager.NetworkCallback mNetworkCallback; /** Constructor */ public CarrierSignalAgent(Phone phone) { mPhone = phone; CarrierConfigManager carrierConfigManager = mPhone.getContext().getSystemService( CarrierConfigManager.class); loadCarrierConfig(); // reload configurations on CARRIER_CONFIG_CHANGED mPhone.getContext().registerReceiver(mReceiver, new IntentFilter(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); carrierConfigManager.registerCarrierConfigChangeListener( mPhone.getContext().getMainExecutor(), (slotIndex, subId, carrierId, specificCarrierId) -> { if (slotIndex == mPhone.getPhoneId()) { loadCarrierConfig(); } }); mPhone.getCarrierActionAgent().registerForCarrierAction( CarrierActionAgent.CARRIER_ACTION_REPORT_DEFAULT_NETWORK_STATUS, this, EVENT_REGISTER_DEFAULT_NETWORK_AVAIL, null, false); Loading Loading @@ -205,13 +198,16 @@ public class CarrierSignalAgent extends Handler { * load carrier config and cached the results into a hashMap action -> array list of components. */ private void loadCarrierConfig() { CarrierConfigManager configManager = (CarrierConfigManager) mPhone.getContext() .getSystemService(Context.CARRIER_CONFIG_SERVICE); PersistableBundle b = null; if (configManager != null) { b = configManager.getConfigForSubId(mPhone.getSubId()); PersistableBundle b = CarrierConfigManager.getCarrierConfigSubset( mPhone.getContext(), mPhone.getSubId(), KEY_CARRIER_APP_WAKE_SIGNAL_CONFIG_STRING_ARRAY, KEY_CARRIER_APP_NO_WAKE_SIGNAL_CONFIG_STRING_ARRAY); if (b.isEmpty()) { return; } if (b != null) { synchronized (mCachedWakeSignalConfigs) { log("Loading carrier config: " + KEY_CARRIER_APP_WAKE_SIGNAL_CONFIG_STRING_ARRAY); Map<String, Set<ComponentName>> config = parseAndCache( Loading Loading @@ -245,7 +241,6 @@ public class CarrierSignalAgent extends Handler { mCachedNoWakeSignalConfigs = config; } } } /** * Parse each config with the form {pakName./receiverName : signal1, signal2,.} and cached the Loading tests/telephonytests/src/com/android/internal/telephony/CarrierSignalAgentTest.java +35 −11 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Map; import java.util.Objects; import java.util.concurrent.Executor; import java.util.function.Function; import java.util.stream.Collectors; Loading @@ -70,6 +71,8 @@ public class CarrierSignalAgentTest extends TelephonyTest { private CarrierSignalAgent mCarrierSignalAgentUT; private PersistableBundle mBundle; private CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener; private static final String PCO_RECEIVER = "pak/PCO_RECEIVER"; private static final String DC_ERROR_RECEIVER = "pak/DC_ERROR_RECEIVER"; private static final String LEGACY_RECEIVER = "old.pkg/LEGACY_RECEIVER"; Loading Loading @@ -103,6 +106,7 @@ public class CarrierSignalAgentTest extends TelephonyTest { FAKE_DEFAULT_NETWORK_INTENT.putExtra( TelephonyManager.EXTRA_DEFAULT_NETWORK_AVAILABLE, true); } private static final int PHONE_ID = 0; // Mocked classes ResolveInfo mResolveInfo; Loading @@ -112,8 +116,17 @@ public class CarrierSignalAgentTest extends TelephonyTest { logd("CarrierSignalAgentTest +Setup!"); super.setUp(getClass().getSimpleName()); mResolveInfo = mock(ResolveInfo.class); doReturn((Executor) Runnable::run).when(mContext).getMainExecutor(); mBundle = mContextFixture.getCarrierConfigBundle(); when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mBundle); // Capture listener to emulate the carrier config change notification used later ArgumentCaptor<CarrierConfigManager.CarrierConfigChangeListener> listenerArgumentCaptor = ArgumentCaptor.forClass(CarrierConfigManager.CarrierConfigChangeListener.class); mCarrierSignalAgentUT = new CarrierSignalAgent(mPhone); verify(mCarrierConfigManager).registerCarrierConfigChangeListener(any(), listenerArgumentCaptor.capture()); mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(0); ComponentName legacyReceiverComponent = ComponentName.unflattenFromString(LEGACY_RECEIVER); ApplicationInfo fakeLegacyApplicationInfo = new ApplicationInfo(); Loading Loading @@ -159,9 +172,10 @@ public class CarrierSignalAgentTest extends TelephonyTest { verify(mContext, times(count)).sendBroadcast(mCaptorIntent.capture()); // Trigger carrier config reloading mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); count++; // Verify no broadcast has been sent due to no manifest receivers mCarrierSignalAgentUT.notifyCarrierSignalReceivers(intent); Loading Loading @@ -208,14 +222,16 @@ public class CarrierSignalAgentTest extends TelephonyTest { }); // Trigger carrier config reloading mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); // Verify broadcast has been sent to two different registered manifest receivers doReturn(new ArrayList<>(Arrays.asList(mResolveInfo))) .when(mPackageManager).queryBroadcastReceivers((Intent) any(), anyInt()); int broadcastCount = 1; int broadcastCount = 0; { mCarrierSignalAgentUT.notifyCarrierSignalReceivers(new Intent(FAKE_PCO_INTENT)); broadcastCount++; Loading Loading @@ -325,9 +341,10 @@ public class CarrierSignalAgentTest extends TelephonyTest { verify(mContext, times(count)).sendBroadcast(mCaptorIntent.capture()); // Trigger carrier config reloading mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); count++; // Verify broadcast has been sent to registered components mCarrierSignalAgentUT.notifyCarrierSignalReceivers(intent); Loading Loading @@ -362,9 +379,10 @@ public class CarrierSignalAgentTest extends TelephonyTest { argThat(o -> Objects.equals(o.getAction(), ACTION_CARRIER_SIGNAL_PCO_VALUE)), anyInt()); mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); count++; // Wake signal for PAK_PCO_RECEIVER mCarrierSignalAgentUT.notifyCarrierSignalReceivers( Loading Loading @@ -417,7 +435,9 @@ public class CarrierSignalAgentTest extends TelephonyTest { CarrierConfigManager.KEY_CARRIER_APP_WAKE_SIGNAL_CONFIG_STRING_ARRAY, new String[]{ PCO_RECEIVER + ":" + ACTION_CARRIER_SIGNAL_PCO_VALUE + "," + ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED }); mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); // verify no reset action on initial config load verify(mCarrierActionAgent, times(0)).sendMessageAtTime(any(Message.class), anyLong()); Loading @@ -427,7 +447,9 @@ public class CarrierSignalAgentTest extends TelephonyTest { CarrierConfigManager.KEY_CARRIER_APP_WAKE_SIGNAL_CONFIG_STRING_ARRAY, new String[]{ PCO_RECEIVER + ":" + ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED + "," + ACTION_CARRIER_SIGNAL_PCO_VALUE}); mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); // verify no reset action for the same config (different order) verify(mCarrierActionAgent, times(0)).sendMessageAtTime(any(Message.class), anyLong()); Loading @@ -437,7 +459,9 @@ public class CarrierSignalAgentTest extends TelephonyTest { CarrierConfigManager.KEY_CARRIER_APP_WAKE_SIGNAL_CONFIG_STRING_ARRAY, new String[]{ DC_ERROR_RECEIVER + ":" + ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED + "," + ACTION_CARRIER_SIGNAL_PCO_VALUE}); mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); // verify there is no reset action ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class); Loading Loading
src/java/com/android/internal/telephony/CarrierSignalAgent.java +46 −51 Original line number Diff line number Diff line Loading @@ -20,11 +20,8 @@ import static android.telephony.CarrierConfigManager.KEY_CARRIER_APP_WAKE_SIGNAL import android.annotation.Nullable; import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.Network; Loading Loading @@ -125,25 +122,21 @@ public class CarrierSignalAgent extends Handler { private final LocalLog mErrorLocalLog = new LocalLog(16); private final BroadcastReceiver mReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DBG) log("CarrierSignalAgent receiver action: " + action); if (action.equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) { loadCarrierConfig(); } } }; private ConnectivityManager.NetworkCallback mNetworkCallback; /** Constructor */ public CarrierSignalAgent(Phone phone) { mPhone = phone; CarrierConfigManager carrierConfigManager = mPhone.getContext().getSystemService( CarrierConfigManager.class); loadCarrierConfig(); // reload configurations on CARRIER_CONFIG_CHANGED mPhone.getContext().registerReceiver(mReceiver, new IntentFilter(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); carrierConfigManager.registerCarrierConfigChangeListener( mPhone.getContext().getMainExecutor(), (slotIndex, subId, carrierId, specificCarrierId) -> { if (slotIndex == mPhone.getPhoneId()) { loadCarrierConfig(); } }); mPhone.getCarrierActionAgent().registerForCarrierAction( CarrierActionAgent.CARRIER_ACTION_REPORT_DEFAULT_NETWORK_STATUS, this, EVENT_REGISTER_DEFAULT_NETWORK_AVAIL, null, false); Loading Loading @@ -205,13 +198,16 @@ public class CarrierSignalAgent extends Handler { * load carrier config and cached the results into a hashMap action -> array list of components. */ private void loadCarrierConfig() { CarrierConfigManager configManager = (CarrierConfigManager) mPhone.getContext() .getSystemService(Context.CARRIER_CONFIG_SERVICE); PersistableBundle b = null; if (configManager != null) { b = configManager.getConfigForSubId(mPhone.getSubId()); PersistableBundle b = CarrierConfigManager.getCarrierConfigSubset( mPhone.getContext(), mPhone.getSubId(), KEY_CARRIER_APP_WAKE_SIGNAL_CONFIG_STRING_ARRAY, KEY_CARRIER_APP_NO_WAKE_SIGNAL_CONFIG_STRING_ARRAY); if (b.isEmpty()) { return; } if (b != null) { synchronized (mCachedWakeSignalConfigs) { log("Loading carrier config: " + KEY_CARRIER_APP_WAKE_SIGNAL_CONFIG_STRING_ARRAY); Map<String, Set<ComponentName>> config = parseAndCache( Loading Loading @@ -245,7 +241,6 @@ public class CarrierSignalAgent extends Handler { mCachedNoWakeSignalConfigs = config; } } } /** * Parse each config with the form {pakName./receiverName : signal1, signal2,.} and cached the Loading
tests/telephonytests/src/com/android/internal/telephony/CarrierSignalAgentTest.java +35 −11 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Map; import java.util.Objects; import java.util.concurrent.Executor; import java.util.function.Function; import java.util.stream.Collectors; Loading @@ -70,6 +71,8 @@ public class CarrierSignalAgentTest extends TelephonyTest { private CarrierSignalAgent mCarrierSignalAgentUT; private PersistableBundle mBundle; private CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener; private static final String PCO_RECEIVER = "pak/PCO_RECEIVER"; private static final String DC_ERROR_RECEIVER = "pak/DC_ERROR_RECEIVER"; private static final String LEGACY_RECEIVER = "old.pkg/LEGACY_RECEIVER"; Loading Loading @@ -103,6 +106,7 @@ public class CarrierSignalAgentTest extends TelephonyTest { FAKE_DEFAULT_NETWORK_INTENT.putExtra( TelephonyManager.EXTRA_DEFAULT_NETWORK_AVAILABLE, true); } private static final int PHONE_ID = 0; // Mocked classes ResolveInfo mResolveInfo; Loading @@ -112,8 +116,17 @@ public class CarrierSignalAgentTest extends TelephonyTest { logd("CarrierSignalAgentTest +Setup!"); super.setUp(getClass().getSimpleName()); mResolveInfo = mock(ResolveInfo.class); doReturn((Executor) Runnable::run).when(mContext).getMainExecutor(); mBundle = mContextFixture.getCarrierConfigBundle(); when(mCarrierConfigManager.getConfigForSubId(anyInt(), any())).thenReturn(mBundle); // Capture listener to emulate the carrier config change notification used later ArgumentCaptor<CarrierConfigManager.CarrierConfigChangeListener> listenerArgumentCaptor = ArgumentCaptor.forClass(CarrierConfigManager.CarrierConfigChangeListener.class); mCarrierSignalAgentUT = new CarrierSignalAgent(mPhone); verify(mCarrierConfigManager).registerCarrierConfigChangeListener(any(), listenerArgumentCaptor.capture()); mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(0); ComponentName legacyReceiverComponent = ComponentName.unflattenFromString(LEGACY_RECEIVER); ApplicationInfo fakeLegacyApplicationInfo = new ApplicationInfo(); Loading Loading @@ -159,9 +172,10 @@ public class CarrierSignalAgentTest extends TelephonyTest { verify(mContext, times(count)).sendBroadcast(mCaptorIntent.capture()); // Trigger carrier config reloading mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); count++; // Verify no broadcast has been sent due to no manifest receivers mCarrierSignalAgentUT.notifyCarrierSignalReceivers(intent); Loading Loading @@ -208,14 +222,16 @@ public class CarrierSignalAgentTest extends TelephonyTest { }); // Trigger carrier config reloading mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); // Verify broadcast has been sent to two different registered manifest receivers doReturn(new ArrayList<>(Arrays.asList(mResolveInfo))) .when(mPackageManager).queryBroadcastReceivers((Intent) any(), anyInt()); int broadcastCount = 1; int broadcastCount = 0; { mCarrierSignalAgentUT.notifyCarrierSignalReceivers(new Intent(FAKE_PCO_INTENT)); broadcastCount++; Loading Loading @@ -325,9 +341,10 @@ public class CarrierSignalAgentTest extends TelephonyTest { verify(mContext, times(count)).sendBroadcast(mCaptorIntent.capture()); // Trigger carrier config reloading mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); count++; // Verify broadcast has been sent to registered components mCarrierSignalAgentUT.notifyCarrierSignalReceivers(intent); Loading Loading @@ -362,9 +379,10 @@ public class CarrierSignalAgentTest extends TelephonyTest { argThat(o -> Objects.equals(o.getAction(), ACTION_CARRIER_SIGNAL_PCO_VALUE)), anyInt()); mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); count++; // Wake signal for PAK_PCO_RECEIVER mCarrierSignalAgentUT.notifyCarrierSignalReceivers( Loading Loading @@ -417,7 +435,9 @@ public class CarrierSignalAgentTest extends TelephonyTest { CarrierConfigManager.KEY_CARRIER_APP_WAKE_SIGNAL_CONFIG_STRING_ARRAY, new String[]{ PCO_RECEIVER + ":" + ACTION_CARRIER_SIGNAL_PCO_VALUE + "," + ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED }); mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); // verify no reset action on initial config load verify(mCarrierActionAgent, times(0)).sendMessageAtTime(any(Message.class), anyLong()); Loading @@ -427,7 +447,9 @@ public class CarrierSignalAgentTest extends TelephonyTest { CarrierConfigManager.KEY_CARRIER_APP_WAKE_SIGNAL_CONFIG_STRING_ARRAY, new String[]{ PCO_RECEIVER + ":" + ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED + "," + ACTION_CARRIER_SIGNAL_PCO_VALUE}); mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); // verify no reset action for the same config (different order) verify(mCarrierActionAgent, times(0)).sendMessageAtTime(any(Message.class), anyLong()); Loading @@ -437,7 +459,9 @@ public class CarrierSignalAgentTest extends TelephonyTest { CarrierConfigManager.KEY_CARRIER_APP_WAKE_SIGNAL_CONFIG_STRING_ARRAY, new String[]{ DC_ERROR_RECEIVER + ":" + ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED + "," + ACTION_CARRIER_SIGNAL_PCO_VALUE}); mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); mCarrierConfigChangeListener.onCarrierConfigChanged(PHONE_ID, SubscriptionManager.INVALID_SUBSCRIPTION_ID, TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID); processAllMessages(); // verify there is no reset action ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class); Loading