Loading src/java/com/android/internal/telephony/Phone.java +85 −18 Original line number Diff line number Diff line Loading @@ -95,9 +95,11 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; Loading Loading @@ -419,7 +421,7 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { protected SimulatedRadioControl mSimulatedRadioControl; private boolean mUnitTestMode; private Map<Integer, Long> mAllowedNetworkTypesForReasons = new HashMap<>(); private final CarrierPrivilegesTracker mCarrierPrivilegesTracker; protected VoiceCallSessionStats mVoiceCallSessionStats; Loading Loading @@ -1715,6 +1717,23 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { } } private @TelephonyManager.NetworkTypeBitMask long getAllowedNetworkTypes() { long allowedNetworkTypes = TelephonyManager.getAllNetworkTypesBitmask(); if (SubscriptionController.getInstance() != null) { String result = SubscriptionController.getInstance().getSubscriptionProperty( getSubId(), SubscriptionManager.ALLOWED_NETWORK_TYPES); if (result != null) { try { allowedNetworkTypes = Long.parseLong(result); } catch (NumberFormatException err) { Rlog.e(LOG_TAG, "allowedNetworkTypes NumberFormat exception"); } } } return allowedNetworkTypes; } /** * Set the properties by matching the carrier string in * a string-array resource Loading Loading @@ -2032,6 +2051,16 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { editor.apply(); } private @TelephonyManager.NetworkTypeBitMask long getAllowedNetworkTypesForAllReasons() { long allowedNetworkTypes = TelephonyManager.getAllNetworkTypesBitmask(); synchronized (mAllowedNetworkTypesForReasons) { for (long networkTypes: mAllowedNetworkTypesForReasons.values()) { allowedNetworkTypes = allowedNetworkTypes & networkTypes; } } return allowedNetworkTypes; } public void setVoiceCallForwardingFlag(int line, boolean enable, String number) { setCallForwardingIndicatorInSharedPref(enable); IccRecords r = getIccRecords(); Loading Loading @@ -2146,6 +2175,55 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { mCi.setCdmaSubscriptionSource(cdmaSubscriptionType, response); } /** * Get the effective allowed network types on the device. * @return effective network type */ public @TelephonyManager.NetworkTypeBitMask long getEffectiveAllowedNetworkTypes() { long allowedNetworkTypes = getAllowedNetworkTypes(); return allowedNetworkTypes & getAllowedNetworkTypesForAllReasons(); } /** * Get the allowed network types for a certain reason. * @param reason reason to configure allowed network types * @return the allowed network types. */ public @TelephonyManager.NetworkTypeBitMask long getAllowedNetworkTypes( @TelephonyManager.AllowedNetworkTypesReason int reason) { synchronized (mAllowedNetworkTypesForReasons) { switch (reason) { case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER: return mAllowedNetworkTypesForReasons.getOrDefault( TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, TelephonyManager.getAllNetworkTypesBitmask()); default: Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); return TelephonyManager.getAllNetworkTypesBitmask(); } } } /** * Requests to set the allowed network types for a specific reason * @param reason reason to configure allowed network type * @param networkTypes one of the network types */ public void setAllowedNetworkTypes(@TelephonyManager.AllowedNetworkTypesReason int reason, @TelephonyManager.NetworkTypeBitMask long networkTypes) { synchronized (mAllowedNetworkTypesForReasons) { switch (reason) { case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER: mAllowedNetworkTypesForReasons.put( TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, networkTypes); break; default: Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); break; } } } /** * Requests to set the preferred network type for searching and registering * (CS/PS domain, RAT, and operation mode) Loading @@ -2158,21 +2236,7 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { int modemRaf = getRadioAccessFamily(); int rafFromType = RadioAccessFamily.getRafFromNetworkType(networkType); long allowedNetworkTypes = -1; if (SubscriptionController.getInstance() != null) { String result = SubscriptionController.getInstance().getSubscriptionProperty( getSubId(), SubscriptionManager.ALLOWED_NETWORK_TYPES); if (result != null) { try { allowedNetworkTypes = Long.parseLong(result); } catch (NumberFormatException err) { Rlog.d(LOG_TAG, "allowedNetworkTypes NumberFormat exception"); } } } long allowedNetworkTypes = getAllowedNetworkTypes(); if (modemRaf == RadioAccessFamily.RAF_UNKNOWN || rafFromType == RadioAccessFamily.RAF_UNKNOWN) { Rlog.d(LOG_TAG, "setPreferredNetworkType: Abort, unknown RAF: " Loading @@ -2187,13 +2251,16 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { return; } int filteredRaf = (int) (rafFromType & modemRaf & allowedNetworkTypes); int filteredRaf = (int) (rafFromType & modemRaf & allowedNetworkTypes & getAllowedNetworkTypesForAllReasons()); int filteredType = RadioAccessFamily.getNetworkTypeFromRaf(filteredRaf); long powerAllowedNetworkTypes = getAllowedNetworkTypes( TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER); Rlog.d(LOG_TAG, "setPreferredNetworkType: networkType = " + networkType + " modemRaf = " + modemRaf + " rafFromType = " + rafFromType + " allowedNetworkTypes = " + allowedNetworkTypes + " power allowedNetworkTypes = " + powerAllowedNetworkTypes + " filteredType = " + filteredType); mCi.setPreferredNetworkType(filteredType, response); Loading Loading
src/java/com/android/internal/telephony/Phone.java +85 −18 Original line number Diff line number Diff line Loading @@ -95,9 +95,11 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; Loading Loading @@ -419,7 +421,7 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { protected SimulatedRadioControl mSimulatedRadioControl; private boolean mUnitTestMode; private Map<Integer, Long> mAllowedNetworkTypesForReasons = new HashMap<>(); private final CarrierPrivilegesTracker mCarrierPrivilegesTracker; protected VoiceCallSessionStats mVoiceCallSessionStats; Loading Loading @@ -1715,6 +1717,23 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { } } private @TelephonyManager.NetworkTypeBitMask long getAllowedNetworkTypes() { long allowedNetworkTypes = TelephonyManager.getAllNetworkTypesBitmask(); if (SubscriptionController.getInstance() != null) { String result = SubscriptionController.getInstance().getSubscriptionProperty( getSubId(), SubscriptionManager.ALLOWED_NETWORK_TYPES); if (result != null) { try { allowedNetworkTypes = Long.parseLong(result); } catch (NumberFormatException err) { Rlog.e(LOG_TAG, "allowedNetworkTypes NumberFormat exception"); } } } return allowedNetworkTypes; } /** * Set the properties by matching the carrier string in * a string-array resource Loading Loading @@ -2032,6 +2051,16 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { editor.apply(); } private @TelephonyManager.NetworkTypeBitMask long getAllowedNetworkTypesForAllReasons() { long allowedNetworkTypes = TelephonyManager.getAllNetworkTypesBitmask(); synchronized (mAllowedNetworkTypesForReasons) { for (long networkTypes: mAllowedNetworkTypesForReasons.values()) { allowedNetworkTypes = allowedNetworkTypes & networkTypes; } } return allowedNetworkTypes; } public void setVoiceCallForwardingFlag(int line, boolean enable, String number) { setCallForwardingIndicatorInSharedPref(enable); IccRecords r = getIccRecords(); Loading Loading @@ -2146,6 +2175,55 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { mCi.setCdmaSubscriptionSource(cdmaSubscriptionType, response); } /** * Get the effective allowed network types on the device. * @return effective network type */ public @TelephonyManager.NetworkTypeBitMask long getEffectiveAllowedNetworkTypes() { long allowedNetworkTypes = getAllowedNetworkTypes(); return allowedNetworkTypes & getAllowedNetworkTypesForAllReasons(); } /** * Get the allowed network types for a certain reason. * @param reason reason to configure allowed network types * @return the allowed network types. */ public @TelephonyManager.NetworkTypeBitMask long getAllowedNetworkTypes( @TelephonyManager.AllowedNetworkTypesReason int reason) { synchronized (mAllowedNetworkTypesForReasons) { switch (reason) { case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER: return mAllowedNetworkTypesForReasons.getOrDefault( TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, TelephonyManager.getAllNetworkTypesBitmask()); default: Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); return TelephonyManager.getAllNetworkTypesBitmask(); } } } /** * Requests to set the allowed network types for a specific reason * @param reason reason to configure allowed network type * @param networkTypes one of the network types */ public void setAllowedNetworkTypes(@TelephonyManager.AllowedNetworkTypesReason int reason, @TelephonyManager.NetworkTypeBitMask long networkTypes) { synchronized (mAllowedNetworkTypesForReasons) { switch (reason) { case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER: mAllowedNetworkTypesForReasons.put( TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, networkTypes); break; default: Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); break; } } } /** * Requests to set the preferred network type for searching and registering * (CS/PS domain, RAT, and operation mode) Loading @@ -2158,21 +2236,7 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { int modemRaf = getRadioAccessFamily(); int rafFromType = RadioAccessFamily.getRafFromNetworkType(networkType); long allowedNetworkTypes = -1; if (SubscriptionController.getInstance() != null) { String result = SubscriptionController.getInstance().getSubscriptionProperty( getSubId(), SubscriptionManager.ALLOWED_NETWORK_TYPES); if (result != null) { try { allowedNetworkTypes = Long.parseLong(result); } catch (NumberFormatException err) { Rlog.d(LOG_TAG, "allowedNetworkTypes NumberFormat exception"); } } } long allowedNetworkTypes = getAllowedNetworkTypes(); if (modemRaf == RadioAccessFamily.RAF_UNKNOWN || rafFromType == RadioAccessFamily.RAF_UNKNOWN) { Rlog.d(LOG_TAG, "setPreferredNetworkType: Abort, unknown RAF: " Loading @@ -2187,13 +2251,16 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { return; } int filteredRaf = (int) (rafFromType & modemRaf & allowedNetworkTypes); int filteredRaf = (int) (rafFromType & modemRaf & allowedNetworkTypes & getAllowedNetworkTypesForAllReasons()); int filteredType = RadioAccessFamily.getNetworkTypeFromRaf(filteredRaf); long powerAllowedNetworkTypes = getAllowedNetworkTypes( TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER); Rlog.d(LOG_TAG, "setPreferredNetworkType: networkType = " + networkType + " modemRaf = " + modemRaf + " rafFromType = " + rafFromType + " allowedNetworkTypes = " + allowedNetworkTypes + " power allowedNetworkTypes = " + powerAllowedNetworkTypes + " filteredType = " + filteredType); mCi.setPreferredNetworkType(filteredType, response); Loading