Merge "Expose PinResult and ICC PIN/PUK APIs as SystemApi"
diff --git a/api/system-current.txt b/api/system-current.txt
index e94a3b2..348f050 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -11500,6 +11500,18 @@
field public static final int PHYSICAL_CELL_ID_UNKNOWN = -1; // 0xffffffff
}
+ public final class PinResult implements android.os.Parcelable {
+ method public int describeContents();
+ method public int getAttemptsRemaining();
+ method public int getResult();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.telephony.PinResult> CREATOR;
+ field public static final int PIN_RESULT_TYPE_ABORTED = 3; // 0x3
+ field public static final int PIN_RESULT_TYPE_FAILURE = 2; // 0x2
+ field public static final int PIN_RESULT_TYPE_INCORRECT = 1; // 0x1
+ field public static final int PIN_RESULT_TYPE_SUCCESS = 0; // 0x0
+ }
+
public final class PreciseCallState implements android.os.Parcelable {
ctor public PreciseCallState(int, int, int, int, int);
method public int describeContents();
@@ -11843,6 +11855,7 @@
public class TelephonyManager {
method @Deprecated @RequiresPermission(android.Manifest.permission.CALL_PHONE) public void call(String, String);
+ method @NonNull @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.telephony.PinResult changeIccLockPin(@NonNull String, @NonNull String);
method public int checkCarrierPrivilegesForPackage(String);
method public int checkCarrierPrivilegesForPackageAnyPhone(String);
method public void dial(String);
@@ -11947,6 +11960,7 @@
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataActivationState(int);
method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataEnabled(int, boolean);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataRoamingEnabled(boolean);
+ method @NonNull @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.telephony.PinResult setIccLockEnabled(boolean, @NonNull String);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setMobileDataPolicyEnabledStatus(int, boolean);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setMultiSimCarrierRestriction(boolean);
method public int setNrDualConnectivityState(int);
@@ -11962,10 +11976,12 @@
method @Deprecated public void setVisualVoicemailEnabled(android.telecom.PhoneAccountHandle, boolean);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setVoiceActivationState(int);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void shutdownAllRadios();
+ method @NonNull @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.telephony.PinResult supplyIccLockPin(@NonNull String);
+ method @NonNull @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.telephony.PinResult supplyIccLockPuk(@NonNull String, @NonNull String);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean supplyPin(String);
- method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int[] supplyPinReportResult(String);
+ method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int[] supplyPinReportResult(String);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean supplyPuk(String, String);
- method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int[] supplyPukReportResult(String, String);
+ method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int[] supplyPukReportResult(String, String);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean switchSlots(int[]);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void toggleRadioOnOff();
method @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public void updateOtaEmergencyNumberDbFilePath(@NonNull android.os.ParcelFileDescriptor);
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index d380560..0d0fe56 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -10341,6 +10341,18 @@
field public static final int PHYSICAL_CELL_ID_UNKNOWN = -1; // 0xffffffff
}
+ public final class PinResult implements android.os.Parcelable {
+ method public int describeContents();
+ method public int getAttemptsRemaining();
+ method public int getResult();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.telephony.PinResult> CREATOR;
+ field public static final int PIN_RESULT_TYPE_ABORTED = 3; // 0x3
+ field public static final int PIN_RESULT_TYPE_FAILURE = 2; // 0x2
+ field public static final int PIN_RESULT_TYPE_INCORRECT = 1; // 0x1
+ field public static final int PIN_RESULT_TYPE_SUCCESS = 0; // 0x0
+ }
+
public final class PreciseCallState implements android.os.Parcelable {
ctor public PreciseCallState(int, int, int, int, int);
method public int describeContents();
@@ -10684,6 +10696,7 @@
public class TelephonyManager {
method @Deprecated @RequiresPermission(android.Manifest.permission.CALL_PHONE) public void call(String, String);
+ method @NonNull @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.telephony.PinResult changeIccLockPin(@NonNull String, @NonNull String);
method public int checkCarrierPrivilegesForPackage(String);
method public int checkCarrierPrivilegesForPackageAnyPhone(String);
method public void dial(String);
@@ -10788,6 +10801,7 @@
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataActivationState(int);
method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataEnabled(int, boolean);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataRoamingEnabled(boolean);
+ method @NonNull @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.telephony.PinResult setIccLockEnabled(boolean, @NonNull String);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setMobileDataPolicyEnabledStatus(int, boolean);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setMultiSimCarrierRestriction(boolean);
method public int setNrDualConnectivityState(int);
@@ -10803,10 +10817,12 @@
method @Deprecated public void setVisualVoicemailEnabled(android.telecom.PhoneAccountHandle, boolean);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setVoiceActivationState(int);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void shutdownAllRadios();
+ method @NonNull @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.telephony.PinResult supplyIccLockPin(@NonNull String);
+ method @NonNull @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.telephony.PinResult supplyIccLockPuk(@NonNull String, @NonNull String);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean supplyPin(String);
- method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int[] supplyPinReportResult(String);
+ method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int[] supplyPinReportResult(String);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean supplyPuk(String, String);
- method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int[] supplyPukReportResult(String, String);
+ method @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int[] supplyPukReportResult(String, String);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean switchSlots(int[]);
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void toggleRadioOnOff();
method @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public void updateOtaEmergencyNumberDbFilePath(@NonNull android.os.ParcelFileDescriptor);
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinViewController.java
index cc8bf4f..2cdd7f1 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinViewController.java
@@ -154,8 +154,8 @@
}
mView.resetPasswordText(true /* animate */,
/* announce */
- result.getType() != PinResult.PIN_RESULT_TYPE_SUCCESS);
- if (result.getType() == PinResult.PIN_RESULT_TYPE_SUCCESS) {
+ result.getResult() != PinResult.PIN_RESULT_TYPE_SUCCESS);
+ if (result.getResult() == PinResult.PIN_RESULT_TYPE_SUCCESS) {
mKeyguardUpdateMonitor.reportSimUnlocked(mSubId);
mRemainingAttempts = -1;
mShowDefaultMessage = true;
@@ -163,7 +163,7 @@
true, KeyguardUpdateMonitor.getCurrentUser());
} else {
mShowDefaultMessage = false;
- if (result.getType() == PinResult.PIN_RESULT_TYPE_INCORRECT) {
+ if (result.getResult() == PinResult.PIN_RESULT_TYPE_INCORRECT) {
if (result.getAttemptsRemaining() <= 2) {
// this is getting critical - show dialog
getSimRemainingAttemptsDialog(
@@ -289,20 +289,14 @@
@Override
public void run() {
if (DEBUG) {
- Log.v(TAG, "call supplyPinReportResultForSubscriber(subid=" + mSubId + ")");
+ Log.v(TAG, "call supplyIccLockPin(subid=" + mSubId + ")");
}
- TelephonyManager telephonyManager =
- mTelephonyManager.createForSubscriptionId(mSubId);
- final PinResult result = telephonyManager.supplyPinReportPinResult(mPin);
- if (result == null) {
- Log.e(TAG, "Error result for supplyPinReportResult.");
- mView.post(() -> onSimCheckResponse(PinResult.getDefaultFailedResult()));
- } else {
- if (DEBUG) {
- Log.v(TAG, "supplyPinReportResult returned: " + result.toString());
- }
- mView.post(() -> onSimCheckResponse(result));
+ TelephonyManager telephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
+ final PinResult result = telephonyManager.supplyIccLockPin(mPin);
+ if (DEBUG) {
+ Log.v(TAG, "supplyIccLockPin returned: " + result.toString());
}
+ mView.post(() -> onSimCheckResponse(result));
}
}
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukViewController.java
index a873749..adb4c13 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukViewController.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukViewController.java
@@ -267,8 +267,8 @@
}
mView.resetPasswordText(true /* animate */,
/* announce */
- result.getType() != PinResult.PIN_RESULT_TYPE_SUCCESS);
- if (result.getType() == PinResult.PIN_RESULT_TYPE_SUCCESS) {
+ result.getResult() != PinResult.PIN_RESULT_TYPE_SUCCESS);
+ if (result.getResult() == PinResult.PIN_RESULT_TYPE_SUCCESS) {
mKeyguardUpdateMonitor.reportSimUnlocked(mSubId);
mRemainingAttempts = -1;
mShowDefaultMessage = true;
@@ -277,7 +277,7 @@
true, KeyguardUpdateMonitor.getCurrentUser());
} else {
mShowDefaultMessage = false;
- if (result.getType() == PinResult.PIN_RESULT_TYPE_INCORRECT) {
+ if (result.getResult() == PinResult.PIN_RESULT_TYPE_INCORRECT) {
// show message
mMessageAreaController.setMessage(mView.getPukPasswordErrorMessage(
result.getAttemptsRemaining(), false,
@@ -390,23 +390,15 @@
@Override
public void run() {
- if (DEBUG) Log.v(TAG, "call supplyPukReportResult()");
- TelephonyManager telephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
- final PinResult result = telephonyManager.supplyPukReportPinResult(mPuk, mPin);
- if (result == null) {
- Log.e(TAG, "Error result for supplyPukReportResult.");
- mView.post(() -> onSimLockChangedResponse(PinResult.getDefaultFailedResult()));
- } else {
- if (DEBUG) {
- Log.v(TAG, "supplyPukReportResult returned: " + result.toString());
- }
- mView.post(new Runnable() {
- @Override
- public void run() {
- onSimLockChangedResponse(result);
- }
- });
+ if (DEBUG) {
+ Log.v(TAG, "call supplyIccLockPuk(subid=" + mSubId + ")");
}
+ TelephonyManager telephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
+ final PinResult result = telephonyManager.supplyIccLockPuk(mPuk, mPin);
+ if (DEBUG) {
+ Log.v(TAG, "supplyIccLockPuk returned: " + result.toString());
+ }
+ mView.post(() -> onSimLockChangedResponse(result));
}
}
diff --git a/telephony/java/android/telephony/PinResult.java b/telephony/java/android/telephony/PinResult.java
index c2a4f33..b8c1ffe 100644
--- a/telephony/java/android/telephony/PinResult.java
+++ b/telephony/java/android/telephony/PinResult.java
@@ -19,6 +19,7 @@
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
@@ -27,10 +28,16 @@
import java.util.Objects;
/**
- * Holds the result from a pin attempt.
+ * Holds the result from a PIN attempt.
+ *
+ * @see TelephonyManager#supplyIccLockPin
+ * @see TelephonyManager#supplyIccLockPuk
+ * @see TelephonyManager#setIccLockEnabled
+ * @see TelephonyManager#changeIccLockPin
*
* @hide
*/
+@SystemApi
public final class PinResult implements Parcelable {
/** @hide */
@IntDef({
@@ -64,24 +71,24 @@
private static final PinResult sFailedResult =
new PinResult(PinResult.PIN_RESULT_TYPE_FAILURE, -1);
- private final @PinResultType int mType;
+ private final @PinResultType int mResult;
private final int mAttemptsRemaining;
/**
- * Returns either success, incorrect or failure.
+ * Returns the result of the PIN attempt.
*
- * @see #PIN_RESULT_TYPE_SUCCESS
- * @see #PIN_RESULT_TYPE_INCORRECT
- * @see #PIN_RESULT_TYPE_FAILURE
- * @return The result type of the pin attempt.
+ * @return The result of the PIN attempt.
*/
- public @PinResultType int getType() {
- return mType;
+ public @PinResultType int getResult() {
+ return mResult;
}
/**
- * The number of pin attempts remaining.
+ * Returns the number of PIN attempts remaining.
+ * This will be set when {@link #getResult} is {@link #PIN_RESULT_TYPE_INCORRECT}.
+ * Indicates the number of attempts at entering the PIN before the SIM will be locked and
+ * require a PUK unlock to be performed.
*
* @return Number of attempts remaining.
*/
@@ -89,22 +96,32 @@
return mAttemptsRemaining;
}
+ /**
+ * Used to indicate a failed PIN attempt result.
+ *
+ * @return default PinResult for failure.
+ *
+ * @hide
+ */
@NonNull
public static PinResult getDefaultFailedResult() {
return sFailedResult;
}
/**
- * PinResult constructor
+ * PinResult constructor.
*
- * @param type The type of pin result.
+ * @param result The pin result value.
* @see #PIN_RESULT_TYPE_SUCCESS
* @see #PIN_RESULT_TYPE_INCORRECT
* @see #PIN_RESULT_TYPE_FAILURE
+ * @see #PIN_RESULT_TYPE_ABORTED
* @param attemptsRemaining Number of pin attempts remaining.
+ *
+ * @hide
*/
- public PinResult(@PinResultType int type, int attemptsRemaining) {
- mType = type;
+ public PinResult(@PinResultType int result, int attemptsRemaining) {
+ mResult = result;
mAttemptsRemaining = attemptsRemaining;
}
@@ -114,7 +131,7 @@
* @hide
*/
private PinResult(Parcel in) {
- mType = in.readInt();
+ mResult = in.readInt();
mAttemptsRemaining = in.readInt();
}
@@ -124,11 +141,11 @@
@NonNull
@Override
public String toString() {
- return "type: " + getType() + ", attempts remaining: " + getAttemptsRemaining();
+ return "result: " + getResult() + ", attempts remaining: " + getAttemptsRemaining();
}
/**
- * Required to be Parcelable
+ * Describe the contents of this object.
*/
@Override
public int describeContents() {
@@ -136,15 +153,17 @@
}
/**
- * Required to be Parcelable
+ * Write this object to a Parcel.
*/
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
- out.writeInt(mType);
+ out.writeInt(mResult);
out.writeInt(mAttemptsRemaining);
}
- /** Required to be Parcelable */
+ /**
+ * Parcel creator class.
+ */
public static final @NonNull Parcelable.Creator<PinResult> CREATOR = new Creator<PinResult>() {
public PinResult createFromParcel(Parcel in) {
return new PinResult(in);
@@ -156,7 +175,7 @@
@Override
public int hashCode() {
- return Objects.hash(mAttemptsRemaining, mType);
+ return Objects.hash(mAttemptsRemaining, mResult);
}
@Override
@@ -171,7 +190,7 @@
return false;
}
PinResult other = (PinResult) obj;
- return (mType == other.mType
+ return (mResult == other.mResult
&& mAttemptsRemaining == other.mAttemptsRemaining);
}
}
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index e65b641..2c9e20d 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -8871,9 +8871,13 @@
return false;
}
- /** @hide */
+ /**
+ * @deprecated use {@link #supplyIccLockPin(String)} instead.
+ * @hide
+ */
@SystemApi
@RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
+ @Deprecated
public int[] supplyPinReportResult(String pin) {
try {
ITelephony telephony = getITelephony();
@@ -8885,65 +8889,91 @@
return new int[0];
}
- /** @hide */
+ /**
+ * @deprecated use {@link #supplyIccLockPuk(String, String)} instead.
+ * @hide
+ */
@SystemApi
@RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
+ @Deprecated
public int[] supplyPukReportResult(String puk, String pin) {
try {
ITelephony telephony = getITelephony();
if (telephony != null)
return telephony.supplyPukReportResultForSubscriber(getSubId(), puk, pin);
} catch (RemoteException e) {
- Log.e(TAG, "Error calling ITelephony#]", e);
+ Log.e(TAG, "Error calling ITelephony#supplyPukReportResultForSubscriber", e);
}
return new int[0];
}
/**
- * Used when the user attempts to enter their pin.
+ * Supplies a PIN to unlock the ICC and returns the corresponding {@link PinResult}.
+ * Used when the user enters their ICC unlock PIN to attempt an unlock.
*
- * @param pin The user entered pin.
- * @return The result of the pin.
+ * @param pin The user entered PIN.
+ * @return The result of the PIN.
+ * @throws SecurityException if the caller doesn't have the permission.
+ * @throws IllegalStateException if the Telephony process is not currently available.
+ *
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling
+ * app has carrier privileges (see {@link #hasCarrierPrivileges}).
*
* @hide
*/
- @Nullable
+ @SystemApi
+ @NonNull
@RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
- public PinResult supplyPinReportPinResult(@NonNull String pin) {
+ public PinResult supplyIccLockPin(@NonNull String pin) {
try {
ITelephony telephony = getITelephony();
if (telephony != null) {
int[] result = telephony.supplyPinReportResultForSubscriber(getSubId(), pin);
return new PinResult(result[0], result[1]);
+ } else {
+ throw new IllegalStateException("telephony service is null.");
}
} catch (RemoteException e) {
- Log.e(TAG, "Error calling ITelephony#supplyPinReportResultForSubscriber", e);
+ Log.e(TAG, "Error calling ITelephony#supplyIccLockPin", e);
+ e.rethrowFromSystemServer();
}
- return null;
+ return PinResult.getDefaultFailedResult();
}
/**
- * Used when the user attempts to enter the puk or their pin.
+ * Supplies a PUK and PIN to unlock the ICC and returns the corresponding {@link PinResult}.
+ * Used when the user enters their ICC unlock PUK and PIN to attempt an unlock.
*
- * @param puk The product unblocking key.
- * @param pin The user entered pin.
- * @return The result of the pin.
+ * @param puk The product unlocking key.
+ * @param pin The user entered PIN.
+ * @return The result of the PUK and PIN.
+ * @throws SecurityException if the caller doesn't have the permission.
+ * @throws IllegalStateException if the Telephony process is not currently available.
+ *
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling
+ * app has carrier privileges (see {@link #hasCarrierPrivileges}).
*
* @hide
*/
- @Nullable
+ @SystemApi
+ @NonNull
@RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
- public PinResult supplyPukReportPinResult(@NonNull String puk, @NonNull String pin) {
+ public PinResult supplyIccLockPuk(@NonNull String puk, @NonNull String pin) {
try {
ITelephony telephony = getITelephony();
if (telephony != null) {
int[] result = telephony.supplyPukReportResultForSubscriber(getSubId(), puk, pin);
return new PinResult(result[0], result[1]);
+ } else {
+ throw new IllegalStateException("telephony service is null.");
}
} catch (RemoteException e) {
- Log.e(TAG, "Error calling ITelephony#]", e);
+ Log.e(TAG, "Error calling ITelephony#supplyIccLockPuk", e);
+ e.rethrowFromSystemServer();
}
- return null;
+ return PinResult.getDefaultFailedResult();
}
/**
@@ -13628,18 +13658,22 @@
}
/**
- * The IccLock state or password was changed successfully.
+ * Indicates that the ICC PIN lock state or PIN was changed successfully.
* @hide
*/
public static final int CHANGE_ICC_LOCK_SUCCESS = Integer.MAX_VALUE;
/**
- * Check whether ICC pin lock is enabled.
- * This is a sync call which returns the cached pin enabled state.
+ * Check whether ICC PIN lock is enabled.
+ * This is a sync call which returns the cached PIN enabled state.
*
- * @return {@code true} if ICC lock enabled, {@code false} if ICC lock disabled.
- *
+ * @return {@code true} if ICC PIN lock enabled, {@code false} if disabled.
* @throws SecurityException if the caller doesn't have the permission.
+ * @throws IllegalStateException if the Telephony process is not currently available.
+ *
+ * <p>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}).
*
* @hide
*/
@@ -13651,81 +13685,97 @@
ITelephony telephony = getITelephony();
if (telephony != null) {
return telephony.isIccLockEnabled(getSubId());
+ } else {
+ throw new IllegalStateException("telephony service is null.");
}
} catch (RemoteException e) {
Log.e(TAG, "isIccLockEnabled RemoteException", e);
+ e.rethrowFromSystemServer();
}
return false;
}
/**
- * Set the ICC pin lock enabled or disabled.
+ * Enable or disable the ICC PIN lock.
*
- * If enable/disable ICC pin lock successfully, a value of {@link Integer#MAX_VALUE} is
- * returned.
- * If an incorrect old password is specified, the return value will indicate how many more
- * attempts the user can make to change the password before the SIM is locked.
- * Using PUK code to unlock SIM if enter the incorrect old password 3 times.
- *
- * @param enabled "true" for locked, "false" for unlocked.
- * @param password needed to change the ICC pin state, aka. Pin1
- * @return an integer representing the status of IccLock enabled or disabled in the following
- * three cases:
- * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
- * successfully.
- * - Positive number and zero for remaining password attempts.
- * - Negative number for other failure cases (such like enabling/disabling PIN failed).
- *
+ * @param enabled "true" for locked, "false" for unlocked.
+ * @param pin needed to change the ICC PIN lock, aka. Pin1.
+ * @return the result of enabling or disabling the ICC PIN lock.
* @throws SecurityException if the caller doesn't have the permission.
+ * @throws IllegalStateException if the Telephony process is not currently available.
+ *
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling
+ * app has carrier privileges (see {@link #hasCarrierPrivileges}).
*
* @hide
*/
+ @SystemApi
+ @NonNull
@RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
- public int setIccLockEnabled(boolean enabled, @NonNull String password) {
- checkNotNull(password, "setIccLockEnabled password can't be null.");
+ public PinResult setIccLockEnabled(boolean enabled, @NonNull String pin) {
+ checkNotNull(pin, "setIccLockEnabled pin can't be null.");
try {
ITelephony telephony = getITelephony();
if (telephony != null) {
- return telephony.setIccLockEnabled(getSubId(), enabled, password);
+ int result = telephony.setIccLockEnabled(getSubId(), enabled, pin);
+ if (result == CHANGE_ICC_LOCK_SUCCESS) {
+ return new PinResult(PinResult.PIN_RESULT_TYPE_SUCCESS, 0);
+ } else if (result < 0) {
+ return PinResult.getDefaultFailedResult();
+ } else {
+ return new PinResult(PinResult.PIN_RESULT_TYPE_INCORRECT, result);
+ }
+ } else {
+ throw new IllegalStateException("telephony service is null.");
}
} catch (RemoteException e) {
Log.e(TAG, "setIccLockEnabled RemoteException", e);
+ e.rethrowFromSystemServer();
}
- return 0;
+ return PinResult.getDefaultFailedResult();
}
/**
- * Change the ICC password used in ICC pin lock.
+ * Change the ICC lock PIN.
*
- * If the password was changed successfully, a value of {@link Integer#MAX_VALUE} is returned.
- * If an incorrect old password is specified, the return value will indicate how many more
- * attempts the user can make to change the password before the SIM is locked.
- * Using PUK code to unlock SIM if enter the incorrect old password 3 times.
- *
- * @param oldPassword is the old password
- * @param newPassword is the new password
- * @return an integer representing the status of IccLock changed in the following three cases:
- * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
- * - Positive number and zero for remaining password attempts.
- * - Negative number for other failure cases (such like enabling/disabling PIN failed).
- *
+ * @param oldPin is the old PIN
+ * @param newPin is the new PIN
+ * @return The result of changing the ICC lock PIN.
* @throws SecurityException if the caller doesn't have the permission.
+ * @throws IllegalStateException if the Telephony process is not currently available.
+ *
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling
+ * app has carrier privileges (see {@link #hasCarrierPrivileges}).
*
* @hide
*/
+ @SystemApi
+ @NonNull
@RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
- public int changeIccLockPassword(@NonNull String oldPassword, @NonNull String newPassword) {
- checkNotNull(oldPassword, "changeIccLockPassword oldPassword can't be null.");
- checkNotNull(newPassword, "changeIccLockPassword newPassword can't be null.");
+ public PinResult changeIccLockPin(@NonNull String oldPin, @NonNull String newPin) {
+ checkNotNull(oldPin, "changeIccLockPin oldPin can't be null.");
+ checkNotNull(newPin, "changeIccLockPin newPin can't be null.");
try {
ITelephony telephony = getITelephony();
if (telephony != null) {
- return telephony.changeIccLockPassword(getSubId(), oldPassword, newPassword);
+ int result = telephony.changeIccLockPassword(getSubId(), oldPin, newPin);
+ if (result == CHANGE_ICC_LOCK_SUCCESS) {
+ return new PinResult(PinResult.PIN_RESULT_TYPE_SUCCESS, 0);
+ } else if (result < 0) {
+ return PinResult.getDefaultFailedResult();
+ } else {
+ return new PinResult(PinResult.PIN_RESULT_TYPE_INCORRECT, result);
+ }
+ } else {
+ throw new IllegalStateException("telephony service is null.");
}
} catch (RemoteException e) {
- Log.e(TAG, "changeIccLockPassword RemoteException", e);
+ Log.e(TAG, "changeIccLockPin RemoteException", e);
+ e.rethrowFromSystemServer();
}
- return 0;
+ return PinResult.getDefaultFailedResult();
}
/**