summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Sarah Chin <sarahchin@google.com> 2020-11-23 17:50:19 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2020-11-23 17:50:19 +0000
commit2391403601d22eabe00e20bfaf3ca0084827affc (patch)
tree47a78fcc227fac14899689ba46a9e15167f1b067
parent6d7e4c43d65dc0d880fb1f496de11f3c085918a1 (diff)
parentcafa63af2bed5ed0a543a3cc6e33bc5feacf76b1 (diff)
Merge "Expose PinResult and ICC PIN/PUK APIs as SystemApi"
-rw-r--r--core/api/system-current.txt20
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardSimPinView.java31
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardSimPukView.java33
-rw-r--r--telephony/java/android/telephony/PinResult.java63
-rw-r--r--telephony/java/android/telephony/TelephonyManager.java174
5 files changed, 189 insertions, 132 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index c780c5c75e59..f6b1d0627312 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -9745,6 +9745,18 @@ package android.telephony {
field @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final int LISTEN_VOICE_ACTIVATION_STATE = 131072; // 0x20000
}
+ 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();
@@ -10088,6 +10100,7 @@ package android.telephony {
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);
@@ -10192,6 +10205,7 @@ package android.telephony {
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);
@@ -10207,10 +10221,12 @@ package android.telephony {
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/KeyguardSimPinView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinView.java
index 1c47aa0151f0..1f22d48561f2 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPinView.java
@@ -257,31 +257,16 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
@Override
public void run() {
if (DEBUG) {
- Log.v(TAG, "call supplyPinReportResultForSubscriber(subid=" + mSubId + ")");
+ Log.v(TAG, "call supplyIccLockPin(subid=" + mSubId + ")");
}
TelephonyManager telephonyManager =
((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE))
.createForSubscriptionId(mSubId);
- final PinResult result = telephonyManager.supplyPinReportPinResult(mPin);
- if (result == null) {
- Log.e(TAG, "Error result for supplyPinReportResult.");
- post(new Runnable() {
- @Override
- public void run() {
- onSimCheckResponse(PinResult.getDefaultFailedResult());
- }
- });
- } else {
- if (DEBUG) {
- Log.v(TAG, "supplyPinReportResult returned: " + result.toString());
- }
- post(new Runnable() {
- @Override
- public void run() {
- onSimCheckResponse(result);
- }
- });
+ final PinResult result = telephonyManager.supplyIccLockPin(mPin);
+ if (DEBUG) {
+ Log.v(TAG, "supplyIccLockPin returned: " + result.toString());
}
+ post(() -> onSimCheckResponse(result));
}
}
@@ -341,8 +326,8 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
}
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) {
Dependency.get(KeyguardUpdateMonitor.class)
.reportSimUnlocked(mSubId);
mRemainingAttempts = -1;
@@ -352,7 +337,7 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
}
} 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(
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukView.java
index 4c5e7ee5ebe0..48161f1a38c5 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSimPukView.java
@@ -319,30 +319,17 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {
@Override
public void run() {
- if (DEBUG) Log.v(TAG, "call supplyPukReportResult()");
+ if (DEBUG) {
+ Log.v(TAG, "call supplyIccLockPuk(subid=" + mSubId + ")");
+ }
TelephonyManager telephonyManager =
((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE))
.createForSubscriptionId(mSubId);
- final PinResult result = telephonyManager.supplyPukReportPinResult(mPuk, mPin);
- if (result == null) {
- Log.e(TAG, "Error result for supplyPukReportResult.");
- post(new Runnable() {
- @Override
- public void run() {
- onSimLockChangedResponse(PinResult.getDefaultFailedResult());
- }
- });
- } else {
- if (DEBUG) {
- Log.v(TAG, "supplyPukReportResult returned: " + result.toString());
- }
- post(new Runnable() {
- @Override
- public void run() {
- onSimLockChangedResponse(result);
- }
- });
+ final PinResult result = telephonyManager.supplyIccLockPuk(mPuk, mPin);
+ if (DEBUG) {
+ Log.v(TAG, "supplyIccLockPuk returned: " + result.toString());
}
+ post(() -> onSimLockChangedResponse(result));
}
}
@@ -415,8 +402,8 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {
}
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) {
Dependency.get(KeyguardUpdateMonitor.class)
.reportSimUnlocked(mSubId);
mRemainingAttempts = -1;
@@ -427,7 +414,7 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {
}
} else {
mShowDefaultMessage = false;
- if (result.getType() == PinResult.PIN_RESULT_TYPE_INCORRECT) {
+ if (result.getResult() == PinResult.PIN_RESULT_TYPE_INCORRECT) {
// show message
mSecurityMessageDisplay.setMessage(getPukPasswordErrorMessage(
result.getAttemptsRemaining(), false));
diff --git a/telephony/java/android/telephony/PinResult.java b/telephony/java/android/telephony/PinResult.java
index c2a4f33e95b9..b8c1ffe58371 100644
--- a/telephony/java/android/telephony/PinResult.java
+++ b/telephony/java/android/telephony/PinResult.java
@@ -19,6 +19,7 @@ package android.telephony;
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 com.android.internal.telephony.PhoneConstants;
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 @@ public final class PinResult implements Parcelable {
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 @@ public final class PinResult implements Parcelable {
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 @@ public final class PinResult implements Parcelable {
* @hide
*/
private PinResult(Parcel in) {
- mType = in.readInt();
+ mResult = in.readInt();
mAttemptsRemaining = in.readInt();
}
@@ -124,11 +141,11 @@ public final class PinResult implements Parcelable {
@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 @@ public final class PinResult implements Parcelable {
}
/**
- * 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 @@ public final class PinResult implements Parcelable {
@Override
public int hashCode() {
- return Objects.hash(mAttemptsRemaining, mType);
+ return Objects.hash(mAttemptsRemaining, mResult);
}
@Override
@@ -171,7 +190,7 @@ public final class PinResult implements Parcelable {
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 92dc2fffe6e2..4a7118ec3590 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -8825,9 +8825,13 @@ public class TelephonyManager {
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();
@@ -8839,65 +8843,91 @@ public class TelephonyManager {
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();
}
/**
@@ -13462,18 +13492,22 @@ public class TelephonyManager {
}
/**
- * 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.
- *
- * @return {@code true} if ICC lock enabled, {@code false} if ICC lock disabled.
+ * Check whether ICC PIN lock is enabled.
+ * This is a sync call which returns the cached PIN enabled state.
*
+ * @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
*/
@@ -13485,81 +13519,97 @@ public class TelephonyManager {
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.
- *
- * 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).
+ * Enable or disable the ICC PIN lock.
*
+ * @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.
- *
- * 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).
+ * Change the ICC lock PIN.
*
+ * @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();
}
/**