Loading src/com/android/settings/IccLockSettings.java +63 −32 Original line number Diff line number Diff line Loading @@ -16,7 +16,10 @@ package com.android.settings; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Resources; import android.os.AsyncResult; import android.os.Bundle; Loading @@ -30,6 +33,7 @@ import android.widget.Toast; import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneFactory; import com.android.internal.telephony.TelephonyIntents; /** * Implements the preference screen to enable/disable ICC lock and Loading Loading @@ -87,26 +91,39 @@ public class IccLockSettings extends PreferenceActivity private Resources mRes; // For async handler to identify request type private static final int ENABLE_ICC_PIN_COMPLETE = 100; private static final int CHANGE_ICC_PIN_COMPLETE = 101; private static final int MSG_ENABLE_ICC_PIN_COMPLETE = 100; private static final int MSG_CHANGE_ICC_PIN_COMPLETE = 101; private static final int MSG_SIM_STATE_CHANGED = 102; // For replies from IccCard interface private Handler mHandler = new Handler() { public void handleMessage(Message msg) { AsyncResult ar = (AsyncResult) msg.obj; switch (msg.what) { case ENABLE_ICC_PIN_COMPLETE: case MSG_ENABLE_ICC_PIN_COMPLETE: iccLockChanged(ar.exception == null); break; case CHANGE_ICC_PIN_COMPLETE: case MSG_CHANGE_ICC_PIN_COMPLETE: iccPinChanged(ar.exception == null); break; case MSG_SIM_STATE_CHANGED: updatePreferences(); break; } return; } }; private final BroadcastReceiver mSimStateReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) { mHandler.sendMessage(mHandler.obtainMessage(MSG_SIM_STATE_CHANGED)); } } }; // For top-level settings screen to query static boolean isIccLockEnabled() { return PhoneFactory.getDefaultPhone().getIccCard().getIccLockEnabled(); Loading Loading @@ -164,13 +181,21 @@ public class IccLockSettings extends PreferenceActivity mPhone = PhoneFactory.getDefaultPhone(); mRes = getResources(); updatePreferences(); } private void updatePreferences() { mPinToggle.setChecked(mPhone.getIccCard().getIccLockEnabled()); } @Override protected void onResume() { super.onResume(); mPinToggle.setChecked(mPhone.getIccCard().getIccLockEnabled()); // ACTION_SIM_STATE_CHANGED is sticky, so we'll receive current state after this call, // which will call updatePreferences(). final IntentFilter filter = new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED); registerReceiver(mSimStateReceiver, filter); if (mDialogState != OFF_MODE) { showPinDialog(); Loading @@ -180,6 +205,12 @@ public class IccLockSettings extends PreferenceActivity } } @Override protected void onPause() { super.onPause(); unregisterReceiver(mSimStateReceiver); } @Override protected void onSaveInstanceState(Bundle out) { // Need to store this state for slider open/close Loading Loading @@ -315,7 +346,7 @@ public class IccLockSettings extends PreferenceActivity private void tryChangeIccLockState() { // Try to change icc lock. If it succeeds, toggle the lock state and // reset dialog state. Else inject error message and show dialog again. Message callback = Message.obtain(mHandler, ENABLE_ICC_PIN_COMPLETE); Message callback = Message.obtain(mHandler, MSG_ENABLE_ICC_PIN_COMPLETE); mPhone.getIccCard().setIccLockEnabled(mToState, mPin, callback); } Loading Loading @@ -345,7 +376,7 @@ public class IccLockSettings extends PreferenceActivity } private void tryChangePin() { Message callback = Message.obtain(mHandler, CHANGE_ICC_PIN_COMPLETE); Message callback = Message.obtain(mHandler, MSG_CHANGE_ICC_PIN_COMPLETE); mPhone.getIccCard().changeIccLockPassword(mOldPin, mNewPin, callback); } Loading Loading
src/com/android/settings/IccLockSettings.java +63 −32 Original line number Diff line number Diff line Loading @@ -16,7 +16,10 @@ package com.android.settings; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Resources; import android.os.AsyncResult; import android.os.Bundle; Loading @@ -30,6 +33,7 @@ import android.widget.Toast; import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneFactory; import com.android.internal.telephony.TelephonyIntents; /** * Implements the preference screen to enable/disable ICC lock and Loading Loading @@ -87,26 +91,39 @@ public class IccLockSettings extends PreferenceActivity private Resources mRes; // For async handler to identify request type private static final int ENABLE_ICC_PIN_COMPLETE = 100; private static final int CHANGE_ICC_PIN_COMPLETE = 101; private static final int MSG_ENABLE_ICC_PIN_COMPLETE = 100; private static final int MSG_CHANGE_ICC_PIN_COMPLETE = 101; private static final int MSG_SIM_STATE_CHANGED = 102; // For replies from IccCard interface private Handler mHandler = new Handler() { public void handleMessage(Message msg) { AsyncResult ar = (AsyncResult) msg.obj; switch (msg.what) { case ENABLE_ICC_PIN_COMPLETE: case MSG_ENABLE_ICC_PIN_COMPLETE: iccLockChanged(ar.exception == null); break; case CHANGE_ICC_PIN_COMPLETE: case MSG_CHANGE_ICC_PIN_COMPLETE: iccPinChanged(ar.exception == null); break; case MSG_SIM_STATE_CHANGED: updatePreferences(); break; } return; } }; private final BroadcastReceiver mSimStateReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) { mHandler.sendMessage(mHandler.obtainMessage(MSG_SIM_STATE_CHANGED)); } } }; // For top-level settings screen to query static boolean isIccLockEnabled() { return PhoneFactory.getDefaultPhone().getIccCard().getIccLockEnabled(); Loading Loading @@ -164,13 +181,21 @@ public class IccLockSettings extends PreferenceActivity mPhone = PhoneFactory.getDefaultPhone(); mRes = getResources(); updatePreferences(); } private void updatePreferences() { mPinToggle.setChecked(mPhone.getIccCard().getIccLockEnabled()); } @Override protected void onResume() { super.onResume(); mPinToggle.setChecked(mPhone.getIccCard().getIccLockEnabled()); // ACTION_SIM_STATE_CHANGED is sticky, so we'll receive current state after this call, // which will call updatePreferences(). final IntentFilter filter = new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED); registerReceiver(mSimStateReceiver, filter); if (mDialogState != OFF_MODE) { showPinDialog(); Loading @@ -180,6 +205,12 @@ public class IccLockSettings extends PreferenceActivity } } @Override protected void onPause() { super.onPause(); unregisterReceiver(mSimStateReceiver); } @Override protected void onSaveInstanceState(Bundle out) { // Need to store this state for slider open/close Loading Loading @@ -315,7 +346,7 @@ public class IccLockSettings extends PreferenceActivity private void tryChangeIccLockState() { // Try to change icc lock. If it succeeds, toggle the lock state and // reset dialog state. Else inject error message and show dialog again. Message callback = Message.obtain(mHandler, ENABLE_ICC_PIN_COMPLETE); Message callback = Message.obtain(mHandler, MSG_ENABLE_ICC_PIN_COMPLETE); mPhone.getIccCard().setIccLockEnabled(mToState, mPin, callback); } Loading Loading @@ -345,7 +376,7 @@ public class IccLockSettings extends PreferenceActivity } private void tryChangePin() { Message callback = Message.obtain(mHandler, CHANGE_ICC_PIN_COMPLETE); Message callback = Message.obtain(mHandler, MSG_CHANGE_ICC_PIN_COMPLETE); mPhone.getIccCard().changeIccLockPassword(mOldPin, mNewPin, callback); } Loading