diff --git a/api/system-current.txt b/api/system-current.txt index dfcae63f164e0..f049e6f248f0d 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -6097,6 +6097,7 @@ package android.telephony { method public boolean getEmergencyCallbackMode(); method public java.lang.String getIsimDomain(); method public int getPreferredNetworkType(int); + method public int getPreferredNetworkTypeBitmap(); method public int getRadioPowerState(); method public int getSimApplicationState(); method public int getSimCardState(); @@ -6125,6 +6126,7 @@ package android.telephony { method public void setDataActivationState(int); method public deprecated void setDataEnabled(int, boolean); method public void setDataRoamingEnabled(boolean); + method public boolean setPreferredNetworkTypeBitmap(int); method public boolean setRadio(boolean); method public boolean setRadioPower(boolean); method public void setSimPowerState(int); diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index c7df36b62a798..e5291cbb2f261 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -6382,8 +6382,9 @@ public class TelephonyManager { public @PrefNetworkMode int getPreferredNetworkType(int subId) { try { ITelephony telephony = getITelephony(); - if (telephony != null) + if (telephony != null) { return telephony.getPreferredNetworkType(subId); + } } catch (RemoteException ex) { Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); } catch (NullPointerException ex) { @@ -6392,6 +6393,37 @@ public class TelephonyManager { return -1; } + /** + * Get the preferred network type bitmap. + * + *

If this object has been created with {@link #createForSubscriptionId}, applies to the + * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} + * + *

Requires Permission: + * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} + * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). + * + * @return a 32-bit bitmap. + * + * @hide + */ + @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) + @SystemApi + public @NetworkTypeBitMask int getPreferredNetworkTypeBitmap() { + try { + ITelephony telephony = getITelephony(); + if (telephony != null) { + return RadioAccessFamily.getRafFromNetworkType( + telephony.getPreferredNetworkType(getSubId())); + } + } catch (RemoteException ex) { + Rlog.e(TAG, "getPreferredNetworkTypeBitmap RemoteException", ex); + } catch (NullPointerException ex) { + Rlog.e(TAG, "getPreferredNetworkTypeBitmap NPE", ex); + } + return 0; + } + /** * Sets the network selection mode to automatic. * @@ -6606,6 +6638,37 @@ public class TelephonyManager { return false; } + /** + * Set the preferred network type bitmap. + * + *

If this object has been created with {@link #createForSubscriptionId}, applies to the + * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} + * + *

Requires Permission: + * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling + * app has carrier privileges (see {@link #hasCarrierPrivileges}). + * + * @param networkTypeBitmap a 32-bit bitmap. + * @return true on success; false on any failure. + * @hide + */ + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) + @SystemApi + public boolean setPreferredNetworkTypeBitmap(@NetworkTypeBitMask int networkTypeBitmap) { + try { + ITelephony telephony = getITelephony(); + if (telephony != null) { + return telephony.setPreferredNetworkType( + getSubId(), RadioAccessFamily.getNetworkTypeFromRaf(networkTypeBitmap)); + } + } catch (RemoteException ex) { + Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); + } catch (NullPointerException ex) { + Rlog.e(TAG, "setPreferredNetworkType NPE", ex); + } + return false; + } + /** * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. *