Loading src/java/com/android/internal/telephony/CarrierSignalAgent.java +103 −9 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.internal.telephony; import static android.telephony.CarrierConfigManager.KEY_CARRIER_APP_NO_WAKE_SIGNAL_CONFIG_STRING_ARRAY; import static android.telephony.CarrierConfigManager.KEY_CARRIER_APP_WAKE_SIGNAL_CONFIG_STRING_ARRAY; import android.annotation.Nullable; import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.ComponentName; Loading @@ -28,6 +29,7 @@ import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.Network; import android.os.AsyncResult; import android.os.Build; import android.os.Handler; import android.os.Message; import android.os.PersistableBundle; Loading @@ -35,6 +37,7 @@ import android.os.UserHandle; import android.telephony.CarrierConfigManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.data.ApnSetting; import android.text.TextUtils; import android.util.LocalLog; import android.util.Log; Loading @@ -50,6 +53,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; /** * This class act as an CarrierSignalling Agent. Loading Loading @@ -98,13 +102,30 @@ public class CarrierSignalAgent extends Handler { /** * This is a list of supported signals from CarrierSignalAgent */ private final Set<String> mCarrierSignalList = new HashSet<>(Arrays.asList( private static final Set<String> VALID_CARRIER_SIGNAL_ACTIONS = new HashSet<>(Arrays.asList( TelephonyManager.ACTION_CARRIER_SIGNAL_PCO_VALUE, TelephonyManager.ACTION_CARRIER_SIGNAL_REDIRECTED, TelephonyManager.ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED, TelephonyManager.ACTION_CARRIER_SIGNAL_RESET, TelephonyManager.ACTION_CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE)); private static final Map<String, String> NEW_ACTION_TO_COMPAT_MAP = new HashMap<String, String>() {{ put(TelephonyManager.ACTION_CARRIER_SIGNAL_PCO_VALUE, TelephonyIntents.ACTION_CARRIER_SIGNAL_PCO_VALUE); put(TelephonyManager.ACTION_CARRIER_SIGNAL_REDIRECTED, TelephonyIntents.ACTION_CARRIER_SIGNAL_REDIRECTED); put(TelephonyManager.ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED, TelephonyIntents.ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED); put(TelephonyManager.ACTION_CARRIER_SIGNAL_RESET, TelephonyIntents.ACTION_CARRIER_SIGNAL_RESET); put(TelephonyManager.ACTION_CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE, TelephonyIntents.ACTION_CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE); }}; private static final Map<String, String> COMPAT_ACTION_TO_NEW_MAP = NEW_ACTION_TO_COMPAT_MAP .entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey)); private final LocalLog mErrorLocalLog = new LocalLog(20); private final BroadcastReceiver mReceiver = new BroadcastReceiver() { Loading Loading @@ -251,10 +272,16 @@ public class CarrierSignalAgent extends Handler { } String[] signals = splitStr[1].split(CARRIER_SIGNAL_DELIMITER); for (String s : signals) { if (!mCarrierSignalList.contains(s)) { if (!VALID_CARRIER_SIGNAL_ACTIONS.contains(s)) { // It could be a legacy action in the com.android.internal.telephony // namespace. If that's the case, translate it to the new actions. if (COMPAT_ACTION_TO_NEW_MAP.containsKey(s)) { s = COMPAT_ACTION_TO_NEW_MAP.get(s); } else { loge("Invalid signal name: " + s); continue; } } Set<ComponentName> componentList = newCachedWakeSignalConfigs.get(s); if (componentList == null) { componentList = new HashSet<>(); Loading Loading @@ -301,7 +328,13 @@ public class CarrierSignalAgent extends Handler { final PackageManager packageManager = mPhone.getContext().getPackageManager(); for (ComponentName name : receivers) { Intent signal = new Intent(intent); if (wakeup) { signal.setComponent(name); } else { // Explicit intents won't reach dynamically registered receivers -- set the package // instead. signal.setPackage(name.getPackageName()); } if (wakeup && packageManager.queryBroadcastReceivers(signal, PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) { Loading @@ -320,11 +353,22 @@ public class CarrierSignalAgent extends Handler { signal.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); if (!wakeup) signal.setFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES); Intent compatIntent = null; try { mPhone.getContext().sendBroadcastAsUser(signal, UserHandle.ALL); if (mPhone.getContext().getPackageManager() .getApplicationInfo(name.getPackageName(), 0).targetSdkVersion <= Build.VERSION_CODES.R) { compatIntent = createCompatIntent(signal); } } catch (PackageManager.NameNotFoundException e) { // ignore, don't do anything special for compatibility } try { Intent intentToSend = compatIntent == null ? signal : compatIntent; mPhone.getContext().sendBroadcastAsUser(intentToSend, UserHandle.ALL); if (DBG) { log("Sending signal " + signal.getAction() + ((signal.getComponent() != null) ? " to the carrier signal receiver: " + signal.getComponent() : "")); log("Sending signal " + intentToSend.getAction() + " to the carrier signal receiver: " + intentToSend.getComponent()); } } catch (ActivityNotFoundException e) { loge("Send broadcast failed: " + e); Loading Loading @@ -356,6 +400,56 @@ public class CarrierSignalAgent extends Handler { } } private static @Nullable Intent createCompatIntent(Intent original) { String compatAction = NEW_ACTION_TO_COMPAT_MAP.get(original.getAction()); if (compatAction == null) { Rlog.i(LOG_TAG, "intent action " + original.getAction() + " does not have a" + " compat alternative for component " + original.getComponent()); return null; } Intent compatIntent = new Intent(original); compatIntent.setAction(compatAction); for (String extraKey : original.getExtras().keySet()) { switch (extraKey) { case TelephonyManager.EXTRA_REDIRECTION_URL: compatIntent.putExtra(TelephonyIntents.EXTRA_REDIRECTION_URL, original.getStringExtra(TelephonyManager.EXTRA_REDIRECTION_URL)); break; case TelephonyManager.EXTRA_DATA_FAIL_CAUSE: compatIntent.putExtra(TelephonyIntents.EXTRA_ERROR_CODE, original.getIntExtra(TelephonyManager.EXTRA_DATA_FAIL_CAUSE, -1)); break; case TelephonyManager.EXTRA_PCO_ID: compatIntent.putExtra(TelephonyIntents.EXTRA_PCO_ID, original.getIntExtra(TelephonyManager.EXTRA_PCO_ID, -1)); break; case TelephonyManager.EXTRA_PCO_VALUE: compatIntent.putExtra(TelephonyIntents.EXTRA_PCO_VALUE, original.getByteArrayExtra(TelephonyManager.EXTRA_PCO_VALUE)); break; case TelephonyManager.EXTRA_DEFAULT_NETWORK_AVAILABLE: compatIntent.putExtra(TelephonyIntents.EXTRA_DEFAULT_NETWORK_AVAILABLE, original.getBooleanExtra( TelephonyManager.EXTRA_DEFAULT_NETWORK_AVAILABLE, false)); break; case TelephonyManager.EXTRA_APN_TYPE: int apnType = original.getIntExtra(TelephonyManager.EXTRA_APN_TYPE, ApnSetting.TYPE_DEFAULT); compatIntent.putExtra(TelephonyIntents.EXTRA_APN_TYPE_INT, apnType); compatIntent.putExtra(TelephonyIntents.EXTRA_APN_TYPE, ApnSetting.getApnTypesStringFromBitmask(apnType)); break; case TelephonyManager.EXTRA_APN_PROTOCOL: int apnProtocol = original.getIntExtra(TelephonyManager.EXTRA_APN_PROTOCOL, -1); compatIntent.putExtra(TelephonyIntents.EXTRA_APN_PROTOCOL_INT, apnProtocol); compatIntent.putExtra(TelephonyIntents.EXTRA_APN_PROTOCOL, ApnSetting.getProtocolStringFromInt(apnProtocol)); break; } } return compatIntent; } private void log(String s) { Rlog.d(LOG_TAG, "[" + mPhone.getPhoneId() + "]" + s); } Loading src/java/com/android/internal/telephony/dataconnection/DcTracker.java +6 −11 Original line number Diff line number Diff line Loading @@ -3023,10 +3023,8 @@ public class DcTracker extends Handler { value[0] = (byte) pcoVal; final Intent intent = new Intent(TelephonyManager.ACTION_CARRIER_SIGNAL_PCO_VALUE); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE, "default"); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE_INT, TYPE_DEFAULT); intent.putExtra(TelephonyManager.EXTRA_APN_PROTOCOL, "IPV4V6"); intent.putExtra(TelephonyManager.EXTRA_APN_PROTOCOL_INT, PROTOCOL_IPV4V6); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE, TYPE_DEFAULT); intent.putExtra(TelephonyManager.EXTRA_APN_PROTOCOL, PROTOCOL_IPV4V6); intent.putExtra(TelephonyManager.EXTRA_PCO_ID, 0xFF00); intent.putExtra(TelephonyManager.EXTRA_PCO_VALUE, value); mPhone.getCarrierSignalAgent().notifyCarrierSignalReceivers(intent); Loading @@ -3051,9 +3049,8 @@ public class DcTracker extends Handler { // Compose broadcast intent send to the specific carrier signaling receivers Intent intent = new Intent(TelephonyManager .ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED); intent.putExtra(TelephonyManager.EXTRA_ERROR_CODE, cause); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE, apnContext.getApnType()); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE_INT, intent.putExtra(TelephonyManager.EXTRA_DATA_FAIL_CAUSE, cause); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE, ApnSetting.getApnTypesBitmaskFromString(apnContext.getApnType())); mPhone.getCarrierSignalAgent().notifyCarrierSignalReceivers(intent); Loading Loading @@ -4797,11 +4794,9 @@ public class DcTracker extends Handler { String apnType = apnContext.getApnType(); final Intent intent = new Intent(TelephonyManager.ACTION_CARRIER_SIGNAL_PCO_VALUE); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE, apnType); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE_INT, intent.putExtra(TelephonyManager.EXTRA_APN_TYPE, ApnSetting.getApnTypesBitmaskFromString(apnType)); intent.putExtra(TelephonyManager.EXTRA_APN_PROTOCOL, pcoData.bearerProto); intent.putExtra(TelephonyManager.EXTRA_APN_PROTOCOL_INT, intent.putExtra(TelephonyManager.EXTRA_APN_PROTOCOL, ApnSetting.getProtocolIntFromString(pcoData.bearerProto)); intent.putExtra(TelephonyManager.EXTRA_PCO_ID, pcoData.pcoId); intent.putExtra(TelephonyManager.EXTRA_PCO_VALUE, pcoData.contents); Loading tests/telephonytests/src/com/android/internal/telephony/CarrierSignalAgentTest.java +200 −11 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
src/java/com/android/internal/telephony/CarrierSignalAgent.java +103 −9 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.internal.telephony; import static android.telephony.CarrierConfigManager.KEY_CARRIER_APP_NO_WAKE_SIGNAL_CONFIG_STRING_ARRAY; import static android.telephony.CarrierConfigManager.KEY_CARRIER_APP_WAKE_SIGNAL_CONFIG_STRING_ARRAY; import android.annotation.Nullable; import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.ComponentName; Loading @@ -28,6 +29,7 @@ import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.Network; import android.os.AsyncResult; import android.os.Build; import android.os.Handler; import android.os.Message; import android.os.PersistableBundle; Loading @@ -35,6 +37,7 @@ import android.os.UserHandle; import android.telephony.CarrierConfigManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.data.ApnSetting; import android.text.TextUtils; import android.util.LocalLog; import android.util.Log; Loading @@ -50,6 +53,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; /** * This class act as an CarrierSignalling Agent. Loading Loading @@ -98,13 +102,30 @@ public class CarrierSignalAgent extends Handler { /** * This is a list of supported signals from CarrierSignalAgent */ private final Set<String> mCarrierSignalList = new HashSet<>(Arrays.asList( private static final Set<String> VALID_CARRIER_SIGNAL_ACTIONS = new HashSet<>(Arrays.asList( TelephonyManager.ACTION_CARRIER_SIGNAL_PCO_VALUE, TelephonyManager.ACTION_CARRIER_SIGNAL_REDIRECTED, TelephonyManager.ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED, TelephonyManager.ACTION_CARRIER_SIGNAL_RESET, TelephonyManager.ACTION_CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE)); private static final Map<String, String> NEW_ACTION_TO_COMPAT_MAP = new HashMap<String, String>() {{ put(TelephonyManager.ACTION_CARRIER_SIGNAL_PCO_VALUE, TelephonyIntents.ACTION_CARRIER_SIGNAL_PCO_VALUE); put(TelephonyManager.ACTION_CARRIER_SIGNAL_REDIRECTED, TelephonyIntents.ACTION_CARRIER_SIGNAL_REDIRECTED); put(TelephonyManager.ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED, TelephonyIntents.ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED); put(TelephonyManager.ACTION_CARRIER_SIGNAL_RESET, TelephonyIntents.ACTION_CARRIER_SIGNAL_RESET); put(TelephonyManager.ACTION_CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE, TelephonyIntents.ACTION_CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE); }}; private static final Map<String, String> COMPAT_ACTION_TO_NEW_MAP = NEW_ACTION_TO_COMPAT_MAP .entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey)); private final LocalLog mErrorLocalLog = new LocalLog(20); private final BroadcastReceiver mReceiver = new BroadcastReceiver() { Loading Loading @@ -251,10 +272,16 @@ public class CarrierSignalAgent extends Handler { } String[] signals = splitStr[1].split(CARRIER_SIGNAL_DELIMITER); for (String s : signals) { if (!mCarrierSignalList.contains(s)) { if (!VALID_CARRIER_SIGNAL_ACTIONS.contains(s)) { // It could be a legacy action in the com.android.internal.telephony // namespace. If that's the case, translate it to the new actions. if (COMPAT_ACTION_TO_NEW_MAP.containsKey(s)) { s = COMPAT_ACTION_TO_NEW_MAP.get(s); } else { loge("Invalid signal name: " + s); continue; } } Set<ComponentName> componentList = newCachedWakeSignalConfigs.get(s); if (componentList == null) { componentList = new HashSet<>(); Loading Loading @@ -301,7 +328,13 @@ public class CarrierSignalAgent extends Handler { final PackageManager packageManager = mPhone.getContext().getPackageManager(); for (ComponentName name : receivers) { Intent signal = new Intent(intent); if (wakeup) { signal.setComponent(name); } else { // Explicit intents won't reach dynamically registered receivers -- set the package // instead. signal.setPackage(name.getPackageName()); } if (wakeup && packageManager.queryBroadcastReceivers(signal, PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) { Loading @@ -320,11 +353,22 @@ public class CarrierSignalAgent extends Handler { signal.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); if (!wakeup) signal.setFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES); Intent compatIntent = null; try { mPhone.getContext().sendBroadcastAsUser(signal, UserHandle.ALL); if (mPhone.getContext().getPackageManager() .getApplicationInfo(name.getPackageName(), 0).targetSdkVersion <= Build.VERSION_CODES.R) { compatIntent = createCompatIntent(signal); } } catch (PackageManager.NameNotFoundException e) { // ignore, don't do anything special for compatibility } try { Intent intentToSend = compatIntent == null ? signal : compatIntent; mPhone.getContext().sendBroadcastAsUser(intentToSend, UserHandle.ALL); if (DBG) { log("Sending signal " + signal.getAction() + ((signal.getComponent() != null) ? " to the carrier signal receiver: " + signal.getComponent() : "")); log("Sending signal " + intentToSend.getAction() + " to the carrier signal receiver: " + intentToSend.getComponent()); } } catch (ActivityNotFoundException e) { loge("Send broadcast failed: " + e); Loading Loading @@ -356,6 +400,56 @@ public class CarrierSignalAgent extends Handler { } } private static @Nullable Intent createCompatIntent(Intent original) { String compatAction = NEW_ACTION_TO_COMPAT_MAP.get(original.getAction()); if (compatAction == null) { Rlog.i(LOG_TAG, "intent action " + original.getAction() + " does not have a" + " compat alternative for component " + original.getComponent()); return null; } Intent compatIntent = new Intent(original); compatIntent.setAction(compatAction); for (String extraKey : original.getExtras().keySet()) { switch (extraKey) { case TelephonyManager.EXTRA_REDIRECTION_URL: compatIntent.putExtra(TelephonyIntents.EXTRA_REDIRECTION_URL, original.getStringExtra(TelephonyManager.EXTRA_REDIRECTION_URL)); break; case TelephonyManager.EXTRA_DATA_FAIL_CAUSE: compatIntent.putExtra(TelephonyIntents.EXTRA_ERROR_CODE, original.getIntExtra(TelephonyManager.EXTRA_DATA_FAIL_CAUSE, -1)); break; case TelephonyManager.EXTRA_PCO_ID: compatIntent.putExtra(TelephonyIntents.EXTRA_PCO_ID, original.getIntExtra(TelephonyManager.EXTRA_PCO_ID, -1)); break; case TelephonyManager.EXTRA_PCO_VALUE: compatIntent.putExtra(TelephonyIntents.EXTRA_PCO_VALUE, original.getByteArrayExtra(TelephonyManager.EXTRA_PCO_VALUE)); break; case TelephonyManager.EXTRA_DEFAULT_NETWORK_AVAILABLE: compatIntent.putExtra(TelephonyIntents.EXTRA_DEFAULT_NETWORK_AVAILABLE, original.getBooleanExtra( TelephonyManager.EXTRA_DEFAULT_NETWORK_AVAILABLE, false)); break; case TelephonyManager.EXTRA_APN_TYPE: int apnType = original.getIntExtra(TelephonyManager.EXTRA_APN_TYPE, ApnSetting.TYPE_DEFAULT); compatIntent.putExtra(TelephonyIntents.EXTRA_APN_TYPE_INT, apnType); compatIntent.putExtra(TelephonyIntents.EXTRA_APN_TYPE, ApnSetting.getApnTypesStringFromBitmask(apnType)); break; case TelephonyManager.EXTRA_APN_PROTOCOL: int apnProtocol = original.getIntExtra(TelephonyManager.EXTRA_APN_PROTOCOL, -1); compatIntent.putExtra(TelephonyIntents.EXTRA_APN_PROTOCOL_INT, apnProtocol); compatIntent.putExtra(TelephonyIntents.EXTRA_APN_PROTOCOL, ApnSetting.getProtocolStringFromInt(apnProtocol)); break; } } return compatIntent; } private void log(String s) { Rlog.d(LOG_TAG, "[" + mPhone.getPhoneId() + "]" + s); } Loading
src/java/com/android/internal/telephony/dataconnection/DcTracker.java +6 −11 Original line number Diff line number Diff line Loading @@ -3023,10 +3023,8 @@ public class DcTracker extends Handler { value[0] = (byte) pcoVal; final Intent intent = new Intent(TelephonyManager.ACTION_CARRIER_SIGNAL_PCO_VALUE); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE, "default"); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE_INT, TYPE_DEFAULT); intent.putExtra(TelephonyManager.EXTRA_APN_PROTOCOL, "IPV4V6"); intent.putExtra(TelephonyManager.EXTRA_APN_PROTOCOL_INT, PROTOCOL_IPV4V6); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE, TYPE_DEFAULT); intent.putExtra(TelephonyManager.EXTRA_APN_PROTOCOL, PROTOCOL_IPV4V6); intent.putExtra(TelephonyManager.EXTRA_PCO_ID, 0xFF00); intent.putExtra(TelephonyManager.EXTRA_PCO_VALUE, value); mPhone.getCarrierSignalAgent().notifyCarrierSignalReceivers(intent); Loading @@ -3051,9 +3049,8 @@ public class DcTracker extends Handler { // Compose broadcast intent send to the specific carrier signaling receivers Intent intent = new Intent(TelephonyManager .ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED); intent.putExtra(TelephonyManager.EXTRA_ERROR_CODE, cause); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE, apnContext.getApnType()); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE_INT, intent.putExtra(TelephonyManager.EXTRA_DATA_FAIL_CAUSE, cause); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE, ApnSetting.getApnTypesBitmaskFromString(apnContext.getApnType())); mPhone.getCarrierSignalAgent().notifyCarrierSignalReceivers(intent); Loading Loading @@ -4797,11 +4794,9 @@ public class DcTracker extends Handler { String apnType = apnContext.getApnType(); final Intent intent = new Intent(TelephonyManager.ACTION_CARRIER_SIGNAL_PCO_VALUE); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE, apnType); intent.putExtra(TelephonyManager.EXTRA_APN_TYPE_INT, intent.putExtra(TelephonyManager.EXTRA_APN_TYPE, ApnSetting.getApnTypesBitmaskFromString(apnType)); intent.putExtra(TelephonyManager.EXTRA_APN_PROTOCOL, pcoData.bearerProto); intent.putExtra(TelephonyManager.EXTRA_APN_PROTOCOL_INT, intent.putExtra(TelephonyManager.EXTRA_APN_PROTOCOL, ApnSetting.getProtocolIntFromString(pcoData.bearerProto)); intent.putExtra(TelephonyManager.EXTRA_PCO_ID, pcoData.pcoId); intent.putExtra(TelephonyManager.EXTRA_PCO_VALUE, pcoData.contents); Loading
tests/telephonytests/src/com/android/internal/telephony/CarrierSignalAgentTest.java +200 −11 File changed.Preview size limit exceeded, changes collapsed. Show changes