Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fdcf2e73 authored by Daniel Bright's avatar Daniel Bright
Browse files

Created typed class for the pin result

The initial goal was to remove PhoneConstants.  But in doing so, it made sense to replace
an int[] array as a return type with a strongly typed class called PinResult.

Bug: 147774309
Test: SystemUITests
Change-Id: I42f2141f9378fc4f7a6f11af6073d38f917528bc
parent 843cd473
Loading
Loading
Loading
Loading
+25 −21
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.keyguard;
package com.android.keyguard;


import android.annotation.NonNull;
import android.app.AlertDialog;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.Dialog;
@@ -26,6 +27,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Color;
import android.telephony.PinResult;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
@@ -35,7 +37,6 @@ import android.view.View;
import android.view.WindowManager;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ImageView;


import com.android.internal.telephony.PhoneConstants;
import com.android.systemui.Dependency;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.R;


@@ -139,11 +140,11 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {


        // Sending empty PIN here to query the number of remaining PIN attempts
        // Sending empty PIN here to query the number of remaining PIN attempts
        new CheckSimPin("", mSubId) {
        new CheckSimPin("", mSubId) {
            void onSimCheckResponse(final int result, final int attemptsRemaining) {
            void onSimCheckResponse(final PinResult result) {
                Log.d(LOG_TAG, "onSimCheckResponse " + " dummy One result" + result +
                Log.d(LOG_TAG, "onSimCheckResponse " + " dummy One result "
                        " attemptsRemaining=" + attemptsRemaining);
                        + result.toString());
                if (attemptsRemaining >= 0) {
                if (result.getAttemptsRemaining() >= 0) {
                    mRemainingAttempts = attemptsRemaining;
                    mRemainingAttempts = result.getAttemptsRemaining();
                    setLockedSimMessage();
                    setLockedSimMessage();
                }
                }
            }
            }
@@ -251,7 +252,7 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
            mSubId = subId;
            mSubId = subId;
        }
        }


        abstract void onSimCheckResponse(final int result, final int attemptsRemaining);
        abstract void onSimCheckResponse(@NonNull PinResult result);


        @Override
        @Override
        public void run() {
        public void run() {
@@ -261,23 +262,23 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
            TelephonyManager telephonyManager =
            TelephonyManager telephonyManager =
                    ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE))
                    ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE))
                            .createForSubscriptionId(mSubId);
                            .createForSubscriptionId(mSubId);
            final int[] result = telephonyManager.supplyPinReportResult(mPin);
            final PinResult result = telephonyManager.supplyPinReportPinResult(mPin);
            if (result == null || result.length == 0) {
            if (result == null) {
                Log.e(TAG, "Error result for supplyPinReportResult.");
                Log.e(TAG, "Error result for supplyPinReportResult.");
                post(new Runnable() {
                post(new Runnable() {
                    @Override
                    @Override
                    public void run() {
                    public void run() {
                        onSimCheckResponse(PhoneConstants.PIN_GENERAL_FAILURE, -1);
                        onSimCheckResponse(PinResult.getDefaultFailedResult());
                    }
                    }
                });
                });
            } else {
            } else {
                if (DEBUG) {
                if (DEBUG) {
                    Log.v(TAG, "supplyPinReportResult returned: " + result[0] + " " + result[1]);
                    Log.v(TAG, "supplyPinReportResult returned: " + result.toString());
                }
                }
                post(new Runnable() {
                post(new Runnable() {
                    @Override
                    @Override
                    public void run() {
                    public void run() {
                        onSimCheckResponse(result[0], result[1]);
                        onSimCheckResponse(result);
                    }
                    }
                });
                });
            }
            }
@@ -330,17 +331,18 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
        if (mCheckSimPinThread == null) {
        if (mCheckSimPinThread == null) {
            mCheckSimPinThread = new CheckSimPin(mPasswordEntry.getText(), mSubId) {
            mCheckSimPinThread = new CheckSimPin(mPasswordEntry.getText(), mSubId) {
                @Override
                @Override
                void onSimCheckResponse(final int result, final int attemptsRemaining) {
                void onSimCheckResponse(final PinResult result) {
                    post(new Runnable() {
                    post(new Runnable() {
                        @Override
                        @Override
                        public void run() {
                        public void run() {
                            mRemainingAttempts = attemptsRemaining;
                            mRemainingAttempts = result.getAttemptsRemaining();
                            if (mSimUnlockProgressDialog != null) {
                            if (mSimUnlockProgressDialog != null) {
                                mSimUnlockProgressDialog.hide();
                                mSimUnlockProgressDialog.hide();
                            }
                            }
                            resetPasswordText(true /* animate */,
                            resetPasswordText(true /* animate */,
                                    result != PhoneConstants.PIN_RESULT_SUCCESS /* announce */);
                                    /* announce */
                            if (result == PhoneConstants.PIN_RESULT_SUCCESS) {
                                    result.getType() != PinResult.PIN_RESULT_TYPE_SUCCESS);
                            if (result.getType() == PinResult.PIN_RESULT_TYPE_SUCCESS) {
                                Dependency.get(KeyguardUpdateMonitor.class)
                                Dependency.get(KeyguardUpdateMonitor.class)
                                        .reportSimUnlocked(mSubId);
                                        .reportSimUnlocked(mSubId);
                                mRemainingAttempts = -1;
                                mRemainingAttempts = -1;
@@ -350,14 +352,16 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
                                }
                                }
                            } else {
                            } else {
                                mShowDefaultMessage = false;
                                mShowDefaultMessage = false;
                                if (result == PhoneConstants.PIN_PASSWORD_INCORRECT) {
                                if (result.getType() == PinResult.PIN_RESULT_TYPE_INCORRECT) {
                                    if (attemptsRemaining <= 2) {
                                    if (result.getAttemptsRemaining() <= 2) {
                                        // this is getting critical - show dialog
                                        // this is getting critical - show dialog
                                        getSimRemainingAttemptsDialog(attemptsRemaining).show();
                                        getSimRemainingAttemptsDialog(
                                                result.getAttemptsRemaining()).show();
                                    } else {
                                    } else {
                                        // show message
                                        // show message
                                        mSecurityMessageDisplay.setMessage(
                                        mSecurityMessageDisplay.setMessage(
                                                getPinPasswordErrorMessage(attemptsRemaining, false));
                                                getPinPasswordErrorMessage(
                                                        result.getAttemptsRemaining(), false));
                                    }
                                    }
                                } else {
                                } else {
                                    // "PIN operation failed!" - no idea what this was and no way to
                                    // "PIN operation failed!" - no idea what this was and no way to
@@ -367,7 +371,7 @@ public class KeyguardSimPinView extends KeyguardPinBasedInputView {
                                }
                                }
                                if (DEBUG) Log.d(LOG_TAG, "verifyPasswordAndUnlock "
                                if (DEBUG) Log.d(LOG_TAG, "verifyPasswordAndUnlock "
                                        + " CheckSimPin.onSimCheckResponse: " + result
                                        + " CheckSimPin.onSimCheckResponse: " + result
                                        + " attemptsRemaining=" + attemptsRemaining);
                                        + " attemptsRemaining=" + result.getAttemptsRemaining());
                            }
                            }
                            mCallback.userActivity();
                            mCallback.userActivity();
                            mCheckSimPinThread = null;
                            mCheckSimPinThread = null;
+31 −24
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.keyguard;
package com.android.keyguard;


import android.annotation.NonNull;
import android.app.Activity;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Dialog;
@@ -25,6 +26,7 @@ import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Color;
import android.telephony.PinResult;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
@@ -34,7 +36,6 @@ import android.view.View;
import android.view.WindowManager;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ImageView;


import com.android.internal.telephony.PhoneConstants;
import com.android.systemui.Dependency;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.R;


@@ -191,13 +192,16 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {


        // Sending empty PUK here to query the number of remaining PIN attempts
        // Sending empty PUK here to query the number of remaining PIN attempts
        new CheckSimPuk("", "", mSubId) {
        new CheckSimPuk("", "", mSubId) {
            void onSimLockChangedResponse(final int result, final int attemptsRemaining) {
            void onSimLockChangedResponse(final PinResult result) {
                Log.d(LOG_TAG, "onSimCheckResponse " + " dummy One result" + result +
                if (result == null) Log.e(LOG_TAG, "onSimCheckResponse, pin result is NULL");
                        " attemptsRemaining=" + attemptsRemaining);
                else {
                if (attemptsRemaining >= 0) {
                    Log.d(LOG_TAG, "onSimCheckResponse " + " dummy One result "
                    mRemainingAttempts = attemptsRemaining;
                            + result.toString());
                    if (result.getAttemptsRemaining() >= 0) {
                        mRemainingAttempts = result.getAttemptsRemaining();
                        mSecurityMessageDisplay.setMessage(
                        mSecurityMessageDisplay.setMessage(
                            getPukPasswordErrorMessage(attemptsRemaining, true));
                                getPukPasswordErrorMessage(result.getAttemptsRemaining(), true));
                    }
                }
                }
            }
            }
        }.start();
        }.start();
@@ -311,7 +315,7 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {
            mSubId = subId;
            mSubId = subId;
        }
        }


        abstract void onSimLockChangedResponse(final int result, final int attemptsRemaining);
        abstract void onSimLockChangedResponse(@NonNull PinResult result);


        @Override
        @Override
        public void run() {
        public void run() {
@@ -319,23 +323,23 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {
            TelephonyManager telephonyManager =
            TelephonyManager telephonyManager =
                    ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE))
                    ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE))
                            .createForSubscriptionId(mSubId);
                            .createForSubscriptionId(mSubId);
            final int[] result = telephonyManager.supplyPukReportResult(mPuk, mPin);
            final PinResult result = telephonyManager.supplyPukReportPinResult(mPuk, mPin);
            if (result == null || result.length == 0) {
            if (result == null) {
                Log.e(TAG, "Error result for supplyPukReportResult.");
                Log.e(TAG, "Error result for supplyPukReportResult.");
                post(new Runnable() {
                post(new Runnable() {
                    @Override
                    @Override
                    public void run() {
                    public void run() {
                        onSimLockChangedResponse(PhoneConstants.PIN_GENERAL_FAILURE, -1);
                        onSimLockChangedResponse(PinResult.getDefaultFailedResult());
                    }
                    }
                });
                });
            } else {
            } else {
                if (DEBUG) {
                if (DEBUG) {
                    Log.v(TAG, "supplyPukReportResult returned: " + result[0] + " " + result[1]);
                    Log.v(TAG, "supplyPukReportResult returned: " + result.toString());
                }
                }
                post(new Runnable() {
                post(new Runnable() {
                    @Override
                    @Override
                    public void run() {
                    public void run() {
                        onSimLockChangedResponse(result[0], result[1]);
                        onSimLockChangedResponse(result);
                    }
                    }
                });
                });
            }
            }
@@ -402,7 +406,7 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {
        if (mCheckSimPukThread == null) {
        if (mCheckSimPukThread == null) {
            mCheckSimPukThread = new CheckSimPuk(mPukText, mPinText, mSubId) {
            mCheckSimPukThread = new CheckSimPuk(mPukText, mPinText, mSubId) {
                @Override
                @Override
                void onSimLockChangedResponse(final int result, final int attemptsRemaining) {
                void onSimLockChangedResponse(final PinResult result) {
                    post(new Runnable() {
                    post(new Runnable() {
                        @Override
                        @Override
                        public void run() {
                        public void run() {
@@ -410,29 +414,32 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {
                                mSimUnlockProgressDialog.hide();
                                mSimUnlockProgressDialog.hide();
                            }
                            }
                            resetPasswordText(true /* animate */,
                            resetPasswordText(true /* animate */,
                                    result != PhoneConstants.PIN_RESULT_SUCCESS /* announce */);
                                    /* announce */
                            if (result == PhoneConstants.PIN_RESULT_SUCCESS) {
                                    result.getType() != PinResult.PIN_RESULT_TYPE_SUCCESS);
                            if (result.getType() == PinResult.PIN_RESULT_TYPE_SUCCESS) {
                                Dependency.get(KeyguardUpdateMonitor.class)
                                Dependency.get(KeyguardUpdateMonitor.class)
                                        .reportSimUnlocked(mSubId);
                                        .reportSimUnlocked(mSubId);
                                mRemainingAttempts = -1;
                                mRemainingAttempts = -1;
                                mShowDefaultMessage = true;
                                mShowDefaultMessage = true;
                                if (mCallback != null) {
                                if (mCallback != null) {
                                    mCallback.dismiss(true, KeyguardUpdateMonitor.getCurrentUser());
                                    mCallback.dismiss(true,
                                            KeyguardUpdateMonitor.getCurrentUser());
                                }
                                }
                            } else {
                            } else {
                                mShowDefaultMessage = false;
                                mShowDefaultMessage = false;
                                if (result == PhoneConstants.PIN_PASSWORD_INCORRECT) {
                                if (result.getType() == PinResult.PIN_RESULT_TYPE_INCORRECT) {
                                    // show message
                                    // show message
                                    mSecurityMessageDisplay.setMessage(getPukPasswordErrorMessage(
                                    mSecurityMessageDisplay.setMessage(getPukPasswordErrorMessage(
                                            attemptsRemaining, false));
                                            result.getAttemptsRemaining(), false));
                                    if (attemptsRemaining <= 2) {
                                    if (result.getAttemptsRemaining() <= 2) {
                                        // this is getting critical - show dialog
                                        // this is getting critical - show dialog
                                        getPukRemainingAttemptsDialog(attemptsRemaining).show();
                                        getPukRemainingAttemptsDialog(
                                                result.getAttemptsRemaining()).show();
                                    } else {
                                    } else {
                                        // show message
                                        // show message
                                        mSecurityMessageDisplay.setMessage(
                                        mSecurityMessageDisplay.setMessage(
                                                getPukPasswordErrorMessage(
                                                getPukPasswordErrorMessage(
                                                attemptsRemaining, false));
                                                        result.getAttemptsRemaining(), false));
                                    }
                                    }
                                } else {
                                } else {
                                    mSecurityMessageDisplay.setMessage(getContext().getString(
                                    mSecurityMessageDisplay.setMessage(getContext().getString(
@@ -440,7 +447,7 @@ public class KeyguardSimPukView extends KeyguardPinBasedInputView {
                                }
                                }
                                if (DEBUG) Log.d(LOG_TAG, "verifyPasswordAndUnlock "
                                if (DEBUG) Log.d(LOG_TAG, "verifyPasswordAndUnlock "
                                        + " UpdateSim.onSimCheckResponse: "
                                        + " UpdateSim.onSimCheckResponse: "
                                        + " attemptsRemaining=" + attemptsRemaining);
                                        + " attemptsRemaining=" + result.getAttemptsRemaining());
                                mStateMachine.reset();
                                mStateMachine.reset();
                            }
                            }
                            mCheckSimPukThread = null;
                            mCheckSimPukThread = null;