diff --git a/api/system-current.txt b/api/system-current.txt index cb4c4b7e37d8e..3983b51954944 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -10347,6 +10347,19 @@ package android.telephony { field public static final int LISTEN_VOICE_ACTIVATION_STATE = 131072; // 0x20000 } + public final class PinResult implements android.os.Parcelable { + ctor public PinResult(int, int); + method public int describeContents(); + method public int getAttemptsRemaining(); + method @NonNull public static android.telephony.PinResult getDefaultFailedResult(); + method public int getType(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; + 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(); @@ -10830,9 +10843,11 @@ package android.telephony { method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setVoiceActivationState(int); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void shutdownAllRadios(); 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 @Nullable @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.telephony.PinResult supplyPinReportPinResult(@NonNull 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 @Nullable @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public android.telephony.PinResult supplyPukReportPinResult(@NonNull String, @NonNull 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 public void updateServiceLocation(); diff --git a/telephony/java/android/telephony/PinResult.java b/telephony/java/android/telephony/PinResult.java new file mode 100644 index 0000000000000..683e85387c088 --- /dev/null +++ b/telephony/java/android/telephony/PinResult.java @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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; + +import com.android.internal.telephony.PhoneConstants; + +import java.util.Objects; + +/** + * Holds the result from a pin attempt. + * + * @hide + */ +@SystemApi +public final class PinResult implements Parcelable { + /** @hide */ + @IntDef({ + PIN_RESULT_TYPE_SUCCESS, + PIN_RESULT_TYPE_INCORRECT, + PIN_RESULT_TYPE_FAILURE, + }) + public @interface PinResultType {} + + /** + * Indicates that the pin attempt was a success. + */ + public static final int PIN_RESULT_TYPE_SUCCESS = PhoneConstants.PIN_RESULT_SUCCESS; + + /** + * Indicates that the pin attempt was incorrect. + */ + public static final int PIN_RESULT_TYPE_INCORRECT = PhoneConstants.PIN_PASSWORD_INCORRECT; + + /** + * Indicates that the pin attempt was a failure. + */ + public static final int PIN_RESULT_TYPE_FAILURE = PhoneConstants.PIN_GENERAL_FAILURE; + + private static final PinResult sFailedResult = + new PinResult(PinResult.PIN_RESULT_TYPE_FAILURE, -1); + + private final @PinResultType int mType; + + private final int mAttemptsRemaining; + + /** + * Returns either success, incorrect or failure. + * + * @see: #PIN_RESULT_TYPE_SUCCESS + * @see: #PIN_RESULT_TYPE_INCORRECT + * @see: #PIN_RESULT_TYPE_FAILURE + * @return The result type of the pin attempt. + */ + public @PinResultType int getType() { + return mType; + } + + /** + * The number of pin attempts remaining. + * + * @return Number of attempts remaining. + */ + public int getAttemptsRemaining() { + return mAttemptsRemaining; + } + + @NonNull + public static PinResult getDefaultFailedResult() { + return sFailedResult; + } + + /** + * PinResult constructor + * + * @param type The type of pin result. + * @see: #PIN_RESULT_TYPE_SUCCESS + * @see: #PIN_RESULT_TYPE_INCORRECT + * @see: #PIN_RESULT_TYPE_FAILURE + * @param attemptsRemaining Number of pin attempts remaining. + */ + public PinResult(@PinResultType int type, int attemptsRemaining) { + mType = type; + mAttemptsRemaining = attemptsRemaining; + } + + /** + * Construct a PinResult object from the given parcel. + * + * @hide + */ + private PinResult(Parcel in) { + mType = in.readInt(); + mAttemptsRemaining = in.readInt(); + } + + /** + * String representation of the Pin Result. + */ + @NonNull + @Override + public String toString() { + return "type: " + getType() + ", attempts remaining: " + getAttemptsRemaining(); + } + + /** + * Required to be Parcelable + */ + @Override + public int describeContents() { + return 0; + } + + /** + * Required to be Parcelable + */ + @Override + public void writeToParcel(@NonNull Parcel out, int flags) { + out.writeInt(mType); + out.writeInt(mAttemptsRemaining); + } + + /** Required to be Parcelable */ + public static final @NonNull Parcelable.Creator CREATOR = new Creator() { + public PinResult createFromParcel(Parcel in) { + return new PinResult(in); + } + public PinResult[] newArray(int size) { + return new PinResult[size]; + } + }; + + @Override + public int hashCode() { + return Objects.hash(mAttemptsRemaining, mType); + } + + @Override + public boolean equals(@Nullable Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PinResult other = (PinResult) obj; + return (mType == other.mType + && mAttemptsRemaining == other.mAttemptsRemaining); + } +} diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 4aedf67ac94b2..4c3cba536fecf 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -8547,9 +8547,13 @@ public class TelephonyManager { return false; } - /** @hide */ + /** + * @deprecated use {@link #supplyPinReportPinResult(String pin)} instead. + * + * @hide */ @SystemApi @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) + @Deprecated public int[] supplyPinReportResult(String pin) { try { ITelephony telephony = getITelephony(); @@ -8561,9 +8565,13 @@ public class TelephonyManager { return new int[0]; } - /** @hide */ + /** + * @deprecated use {@link #supplyPukReportPinResult(String puk, String pin)} instead. + * + * @hide */ @SystemApi @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) + @Deprecated public int[] supplyPukReportResult(String puk, String pin) { try { ITelephony telephony = getITelephony(); @@ -8575,6 +8583,55 @@ public class TelephonyManager { return new int[0]; } + /** + * Used when the user attempts to enter their pin. + * + * @param pin The user entered pin. + * @return The result of the pin. + * + * @hide + */ + @SystemApi + @Nullable + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) + public PinResult supplyPinReportPinResult(@NonNull String pin) { + try { + ITelephony telephony = getITelephony(); + if (telephony != null) { + int[] result = telephony.supplyPinReportResultForSubscriber(getSubId(), pin); + return new PinResult(result[0], result[1]); + } + } catch (RemoteException e) { + Log.e(TAG, "Error calling ITelephony#supplyPinReportResultForSubscriber", e); + } + return null; + } + + /** + * Used when the user attempts to enter the puk or their pin. + * + * @param puk The product unblocking key. + * @param pin The user entered pin. + * @return The result of the pin. + * + * @hide + */ + @SystemApi + @Nullable + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) + public PinResult supplyPukReportPinResult(@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]); + } + } catch (RemoteException e) { + Log.e(TAG, "Error calling ITelephony#]", e); + } + return null; + } + /** * Used to notify callers of * {@link TelephonyManager#sendUssdRequest(String, UssdResponseCallback, Handler)} when the