Merge "Add intdef for Telephony network type constants"

This commit is contained in:
Hall Liu
2018-09-25 22:45:39 +00:00
committed by Gerrit Code Review

View File

@@ -2089,10 +2089,37 @@ public class TelephonyManager {
/** Max network type number. Update as new types are added. Don't add negative types. {@hide} */ /** Max network type number. Update as new types are added. Don't add negative types. {@hide} */
public static final int MAX_NETWORK_TYPE = NETWORK_TYPE_LTE_CA; public static final int MAX_NETWORK_TYPE = NETWORK_TYPE_LTE_CA;
/** @hide */
@IntDef({
NETWORK_TYPE_UNKNOWN,
NETWORK_TYPE_GPRS,
NETWORK_TYPE_EDGE,
NETWORK_TYPE_UMTS,
NETWORK_TYPE_CDMA,
NETWORK_TYPE_EVDO_0,
NETWORK_TYPE_EVDO_A,
NETWORK_TYPE_1xRTT,
NETWORK_TYPE_HSDPA,
NETWORK_TYPE_HSUPA,
NETWORK_TYPE_HSPA,
NETWORK_TYPE_IDEN,
NETWORK_TYPE_EVDO_B,
NETWORK_TYPE_LTE,
NETWORK_TYPE_EHRPD,
NETWORK_TYPE_HSPAP,
NETWORK_TYPE_GSM,
NETWORK_TYPE_TD_SCDMA,
NETWORK_TYPE_IWLAN,
NETWORK_TYPE_LTE_CA,
})
@Retention(RetentionPolicy.SOURCE)
public @interface NetworkType{}
/** /**
* @return the NETWORK_TYPE_xxxx for current data connection. * @return the NETWORK_TYPE_xxxx for current data connection.
*/ */
public int getNetworkType() { public @NetworkType int getNetworkType() {
try { try {
ITelephony telephony = getITelephony(); ITelephony telephony = getITelephony();
if (telephony != null) { if (telephony != null) {
@@ -2147,7 +2174,7 @@ public class TelephonyManager {
// This can happen when the ITelephony interface is not up yet. // This can happen when the ITelephony interface is not up yet.
return NETWORK_TYPE_UNKNOWN; return NETWORK_TYPE_UNKNOWN;
} }
} catch(RemoteException ex) { } catch (RemoteException ex) {
// This shouldn't happen in the normal case // This shouldn't happen in the normal case
return NETWORK_TYPE_UNKNOWN; return NETWORK_TYPE_UNKNOWN;
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
@@ -2187,7 +2214,7 @@ public class TelephonyManager {
*/ */
@SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public int getDataNetworkType() { public @NetworkType int getDataNetworkType() {
return getDataNetworkType(getSubId(SubscriptionManager.getDefaultDataSubscriptionId())); return getDataNetworkType(getSubId(SubscriptionManager.getDefaultDataSubscriptionId()));
} }
@@ -2227,7 +2254,7 @@ public class TelephonyManager {
*/ */
@SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public int getVoiceNetworkType() { public @NetworkType int getVoiceNetworkType() {
return getVoiceNetworkType(getSubId()); return getVoiceNetworkType(getSubId());
} }