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

Commit 74aaf54c authored by Rakesh Pallerla's avatar Rakesh Pallerla Committed by Linux Build Service Account
Browse files

Settings:PIN/PUK Lock and Status

- Added support for RUIM PIN locking
- Display message to indicate PIN/PUK status changes
Changes done to display retry counter on wrong entry of PIN1,
and message to indicate PIN1 enable/disable as per certain
carrier requirements.
- Process NOT_SUPPORTED response for pin lock checkbox
If RIL replies with REQUEST_NOT_SUPPORTED
when trying to enable or disable pin lock
process such response and display appropriate message.
-For some cards, ICC LOCK should be enabled
to change the password. In this case RIL_E_REQUEST_NOT_SUPPORTED
should be sent by RIL. On receiving this message
the Settings app should display Enable ICC LOCK message.
-Don't assume that the exception returned on a PIN operation
is a CommandException. Handle other types as well, like
RuntimeException
CRs-Fixed: 222544, 181380, 181401, 229819, 246807, 249863, 337001, 441001

Change-Id: I142137e44cc11a8a5d42b0e458d5654422c4c630
(cherry picked from commit a24b001dcfa5bb960283018670788e471fbe8199)
(cherry picked from commit 95795cf1d3928eacba57ec2954af066bba5d791c)
(cherry picked from commit 33b68c69a5b7f4b62b333d49d098ba6ce717afb7)
parent 4bfe03e4
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -1912,11 +1912,11 @@
    <string name="dialog_title_font_size">Font size</string>

    <!-- SIM lock settings title -->
    <string name="sim_lock_settings">SIM card lock settings</string>
    <string name="sim_lock_settings">SIM/RUIM card lock settings</string>
    <!-- Security & location settings screen, setting option name -->
    <string name="sim_lock_settings_category">Set up SIM card lock</string>
    <string name="sim_lock_settings_category">Set up SIM/RUIM card lock</string>
    <!-- Security & location settings screen, section heading for settings related to sim card locking -->
    <string name="sim_lock_settings_title">SIM card lock</string>
    <string name="sim_lock_settings_title">SIM/RUIM card lock</string>
    <!-- SIM card lock settings screen, setting check box label -->
    <string name="sim_pin_toggle">Lock SIM card</string>
    <!-- SIM card lock settings screen, setting option summary text when SIM lock check box is selected -->
@@ -1946,6 +1946,8 @@
    <string name="sim_bad_pin">Incorrect PIN</string>
    <!-- SIM card lock settings screen, SIM PIN dialog message when PINs don't match -->
    <string name="sim_pins_dont_match">PINs don\'t match</string>
    <!-- SIM card lock settings screen, SIM PIN dialog message when SIM card is absent-->
    <string name="sim_absent">No SIM/RUIM</string>
    <!-- SIM card lock settings screen, toast after not entering correct SIM PIN -->
    <string name="sim_change_failed">Can\'t change PIN.\nPossibly incorrect PIN.</string>
    <!-- SIM card lock settings screen, SIM PIN dialog message when the entered PIN is correct-->
@@ -1956,6 +1958,16 @@
    <string name="sim_enter_ok">OK</string>
    <!-- SIM card lock settings screen, SIM PIN dialog button labels: -->
    <string name="sim_enter_cancel">Cancel</string>
    <!-- SIM password can't be changed as SIM LOCK is not enabled: -->
    <string name="sim_pin_change_failed_enable_sim_lock">Unable to Change SIM/RUIM PIN.\n Enable SIM/RUIM Lock.</string>
    <!-- SIM lock can't be changed - not supported -->
    <string name="sim_enable_disable_lock_not_supported">Unable to Change SIM/RUIM Lock.\n SIM/RUIM doesn\'t support it.</string>
    <!-- SIM card lock settings screen, toast displayed on wrong PIN1: -->
    <string name="sim_pin_attempts">\nAttempts Remaining :</string>
    <!-- SIM card lock settings screen, toast displayed on PIN1 enable: -->
    <string name="sim_pin_enabled">PIN1 Enabled!</string>
    <!-- SIM card lock settings screen, toast displayed on PIN1 disable: -->
    <string name="sim_pin_disabled">PIN1 Disabled!</string>

    <!-- Advanced (used for diagnostics) device info activity title -->
    <string name="device_info_settings" product="tablet">Tablet status</string>
+0 −1
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@
            android:summaryOff="@string/sim_lock_off"/>
    <com.android.settings.EditPinPreference
            android:key="sim_pin"
            android:dependency="sim_toggle"
            android:title="@string/sim_pin_change"
            android:dialogTitle="@string/sim_change_pin"
            android:dialogMessage="@string/sim_enter_old"
+50 −11
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.widget.Toast;

import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.CommandException;
import com.android.internal.telephony.TelephonyIntents;

/**
@@ -101,10 +102,10 @@ public class IccLockSettings extends PreferenceActivity
            AsyncResult ar = (AsyncResult) msg.obj;
            switch (msg.what) {
                case MSG_ENABLE_ICC_PIN_COMPLETE:
                    iccLockChanged(ar.exception == null);
                    iccLockChanged(ar);
                    break;
                case MSG_CHANGE_ICC_PIN_COMPLETE:
                    iccPinChanged(ar.exception == null);
                    iccPinChanged(ar);
                    break;
                case MSG_SIM_STATE_CHANGED:
                    updatePreferences();
@@ -351,23 +352,50 @@ public class IccLockSettings extends PreferenceActivity
        // Disable the setting till the response is received.
        mPinToggle.setEnabled(false);
    }
    /**
     * Handles exceptions encountered when performing operations like
     * PIN enable/disable, PIN change, etc.
     * Displays appropriate Toast message depending on the exception
     */
    private void handleException(Throwable exception, int requestType) {
        if (exception instanceof CommandException) {
            CommandException.Error err = ((CommandException)(exception)).getCommandError();
            if (err == CommandException.Error.REQUEST_NOT_SUPPORTED) {
                int id;
                if (requestType == MSG_ENABLE_ICC_PIN_COMPLETE) {
                    id = R.string.sim_enable_disable_lock_not_supported;
                } else {
                    id = R.string.sim_pin_change_failed_enable_sim_lock;
                }
                Toast.makeText(this, mRes.getString(id),Toast.LENGTH_SHORT).show();
            } else {
                displayRetryCounter(mRes.getString(R.string.sim_change_failed));
            }
        } else if (exception instanceof RuntimeException) {
            Toast.makeText(this, exception.getMessage(), Toast.LENGTH_SHORT).show();
        }
    }

    private void iccLockChanged(boolean success) {
        if (success) {
    private void iccLockChanged(AsyncResult ar) {
        if (ar.exception == null) {
            if (mToState) {
                Toast.makeText(this, mRes.getString(R.string.sim_pin_enabled),
                        Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(this, mRes.getString(R.string.sim_pin_disabled),
                        Toast.LENGTH_SHORT).show();
            }
            mPinToggle.setChecked(mToState);
        } else {
            Toast.makeText(this, mRes.getString(R.string.sim_lock_failed), Toast.LENGTH_SHORT)
                    .show();
            handleException(ar.exception, MSG_ENABLE_ICC_PIN_COMPLETE);
        }
        mPinToggle.setEnabled(true);
        resetDialogState();
    }

    private void iccPinChanged(boolean success) {
        if (!success) {
            Toast.makeText(this, mRes.getString(R.string.sim_change_failed),
                    Toast.LENGTH_SHORT)
                    .show();
    private void iccPinChanged(AsyncResult ar) {
        if (ar.exception != null) {
            handleException(ar.exception, MSG_CHANGE_ICC_PIN_COMPLETE);
        } else {
            Toast.makeText(this, mRes.getString(R.string.sim_change_succeeded),
                    Toast.LENGTH_SHORT)
@@ -398,4 +426,15 @@ public class IccLockSettings extends PreferenceActivity
        setDialogValues();
        mDialogState = OFF_MODE;
    }

    private void displayRetryCounter(String s) {
        int attempts = mPhone.getIccCard().getIccPin1RetryCount();
        if (attempts >= 0) {
            String displayMsg = s + mRes.getString(R.string.sim_pin_attempts) + attempts;
            Toast.makeText(this, displayMsg, Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, mRes.getString(R.string.sim_lock_failed), Toast.LENGTH_SHORT)
            .show();
        }
    }
}