From e0de018109a1480a130591648f9f921c527d38a5 Mon Sep 17 00:00:00 2001 From: Michael Groover Date: Tue, 23 Jun 2020 19:45:14 -0700 Subject: [PATCH] Add additional info to device ID docs in TelephonyManager and Build Android 10 introduced additional restrictions to access persistent device identifiers. This commit updates the javadocs for TelephonyManager and Build to provide additional details regarding the requirements and how to check if these requirements are met. Fixes: 158471988 Test: m docs -j Change-Id: I02932a22ecc5b761aa1a92d59d09d31863c34235 --- core/java/android/os/Build.java | 25 +- .../android/telephony/TelephonyManager.java | 256 +++++++++++++----- 2 files changed, 204 insertions(+), 77 deletions(-) diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java index ef2a8a122e956..b36aeb89c02a4 100755 --- a/core/java/android/os/Build.java +++ b/core/java/android/os/Build.java @@ -133,12 +133,23 @@ public class Build { * key attestation to obtain * proof of the device's original identifiers. * - *

Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or - * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier - * privileges (see {@link android.telephony.TelephonyManager#hasCarrierPrivileges}). The profile - * owner is an app that owns a managed profile on the device; for more details see Work profiles. Profile owner - * access is deprecated and will be removed in a future release. + *

Starting with API level 29, persistent device identifiers are guarded behind additional + * restrictions, and apps are recommended to use resettable identifiers (see Best practices for unique identifiers). This method can be invoked if one of + * the following requirements is met: + *

* *

If the calling app does not meet one of these requirements then this method will behave * as follows: @@ -150,7 +161,7 @@ public class Build { * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or * higher, then a SecurityException is thrown. * - * * + * * @return The serial number if specified. */ @SuppressAutoDoc // No support for device / profile owner. diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index fadebaa7bb8a1..09dcc1ef4395d 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -38,6 +38,7 @@ import android.annotation.SystemService; import android.annotation.TestApi; import android.annotation.WorkerThread; import android.app.PendingIntent; +import android.app.role.RoleManager; import android.compat.Compatibility; import android.compat.annotation.ChangeId; import android.compat.annotation.EnabledAfter; @@ -1885,12 +1886,23 @@ public class TelephonyManager { * Returns the unique device ID, for example, the IMEI for GSM and the MEID * or ESN for CDMA phones. Return null if device ID is not available. * - *

Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or - * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier - * privileges (see {@link #hasCarrierPrivileges}) on any active subscription. The profile owner - * is an app that owns a managed profile on the device; for more details see Work profiles. Profile owner - * access is deprecated and will be removed in a future release. + *

Starting with API level 29, persistent device identifiers are guarded behind additional + * restrictions, and apps are recommended to use resettable identifiers (see Best practices for unique identifiers). This method can be invoked if one of + * the following requirements is met: + *

* *

If the calling app does not meet one of these requirements then this method will behave * as follows: @@ -1927,12 +1939,23 @@ public class TelephonyManager { * Returns the unique device ID of a subscription, for example, the IMEI for * GSM and the MEID for CDMA phones. Return null if device ID is not available. * - *

Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or - * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier - * privileges (see {@link #hasCarrierPrivileges}) on any active subscription. The profile owner - * is an app that owns a managed profile on the device; for more details see Work profiles. Profile owner - * access is deprecated and will be removed in a future release. + *

Starting with API level 29, persistent device identifiers are guarded behind additional + * restrictions, and apps are recommended to use resettable identifiers (see Best practices for unique identifiers). This method can be invoked if one of + * the following requirements is met: + *

* *

If the calling app does not meet one of these requirements then this method will behave * as follows: @@ -1985,18 +2008,23 @@ public class TelephonyManager { * Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not * available. * - *

This API requires one of the following: + *

Starting with API level 29, persistent device identifiers are guarded behind additional + * restrictions, and apps are recommended to use resettable identifiers (see Best practices for unique identifiers). This method can be invoked if one of + * the following requirements is met: *

- *

The profile owner is an app that owns a managed profile on the device; for more details - * see Work profiles. - * Access by profile owners is deprecated and will be removed in a future release. * *

If the calling app does not meet one of these requirements then this method will behave * as follows: @@ -2058,12 +2086,23 @@ public class TelephonyManager { /** * Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. * - *

Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or - * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier - * privileges (see {@link #hasCarrierPrivileges}) on any active subscription. The profile owner - * is an app that owns a managed profile on the device; for more details see Work profiles. Profile owner - * access is deprecated and will be removed in a future release. + *

Starting with API level 29, persistent device identifiers are guarded behind additional + * restrictions, and apps are recommended to use resettable identifiers (see Best practices for unique identifiers). This method can be invoked if one of + * the following requirements is met: + *

* *

If the calling app does not meet one of these requirements then this method will behave * as follows: @@ -2085,12 +2124,23 @@ public class TelephonyManager { /** * Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. * - *

Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or - * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier - * privileges (see {@link #hasCarrierPrivileges}) on any active subscription. The profile owner - * is an app that owns a managed profile on the device; for more details see Work profiles. Profile owner - * access is deprecated and will be removed in a future release. + *

Starting with API level 29, persistent device identifiers are guarded behind additional + * restrictions, and apps are recommended to use resettable identifiers (see Best practices for unique identifiers). This method can be invoked if one of + * the following requirements is met: + *

* *

If the calling app does not meet one of these requirements then this method will behave * as follows: @@ -2158,12 +2208,25 @@ public class TelephonyManager { /** * Returns the Network Access Identifier (NAI). Return null if NAI is not available. * - *

Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or - * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier - * privileges (see {@link #hasCarrierPrivileges}). The profile owner is an app that owns a - * managed profile on the device; for more details see Work profiles. Profile owner - * access is deprecated and will be removed in a future release. + *

Starting with API level 29, persistent device identifiers are guarded behind additional + * restrictions, and apps are recommended to use resettable identifiers (see Best practices for unique identifiers). This method can be invoked if one of + * the following requirements is met: + *

+ * + *

If the calling app does not meet one of these requirements then this method will behave + * as follows: * *