summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Roos <roosa@google.com>2015-01-15 23:20:20 +0100
committerAdrian Roos <roosa@google.com>2015-02-03 19:12:23 +0100
commitc2e01683b34029729262e2fb346ceea4bfe4b4b6 (patch)
tree0c12607980e306a1b78e11d5c23dd2d2e90df910
parent5656036dd779fd81d89b755b871e85fa6d959c4f (diff)
downloadframeworks_base-c2e01683b34029729262e2fb346ceea4bfe4b4b6.zip
frameworks_base-c2e01683b34029729262e2fb346ceea4bfe4b4b6.tar.gz
frameworks_base-c2e01683b34029729262e2fb346ceea4bfe4b4b6.tar.bz2
Remove UI code from LockPatternUtils
Bug: 18931518 Change-Id: I951166f675731ec7a2bc51585e0a51e0cd92611d
-rw-r--r--core/java/com/android/internal/widget/LockPatternUtils.java76
-rw-r--r--packages/Keyguard/src/com/android/keyguard/CarrierText.java8
-rw-r--r--packages/Keyguard/src/com/android/keyguard/EmergencyButton.java70
-rw-r--r--packages/Keyguard/src/com/android/keyguard/KeyguardSecurityModel.java68
4 files changed, 94 insertions, 128 deletions
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java
index ec01703..bf0a3a0 100644
--- a/core/java/com/android/internal/widget/LockPatternUtils.java
+++ b/core/java/com/android/internal/widget/LockPatternUtils.java
@@ -18,7 +18,6 @@ package com.android.internal.widget;
import android.Manifest;
import android.app.ActivityManagerNative;
-import android.app.AlarmManager;
import android.app.admin.DevicePolicyManager;
import android.app.trust.TrustManager;
import android.content.ComponentName;
@@ -37,18 +36,12 @@ import android.os.UserManager;
import android.os.storage.IMountService;
import android.os.storage.StorageManager;
import android.provider.Settings;
-import android.telecom.TelecomManager;
import android.text.TextUtils;
import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-import com.android.internal.R;
import com.google.android.collect.Lists;
import java.nio.charset.StandardCharsets;
-import libcore.util.HexEncoding;
-
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
@@ -56,6 +49,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import libcore.util.HexEncoding;
+
/**
* Utilities for the lock pattern and its settings.
*/
@@ -1070,21 +1065,6 @@ public class LockPatternUtils {
return deadline;
}
- public boolean isEmergencyCallCapable() {
- return mContext.getResources().getBoolean(
- com.android.internal.R.bool.config_voice_capable);
- }
-
- public boolean isPukUnlockScreenEnable() {
- return mContext.getResources().getBoolean(
- com.android.internal.R.bool.config_enable_puk_unlock_screen);
- }
-
- public boolean isEmergencyCallEnabledWhileSimLocked() {
- return mContext.getResources().getBoolean(
- com.android.internal.R.bool.config_enable_emergency_call_while_sim_locked);
- }
-
private boolean getBoolean(String secureSettingKey, boolean defaultValue, int userId) {
try {
return getLockSettings().getBoolean(secureSettingKey, defaultValue, userId);
@@ -1136,58 +1116,6 @@ public class LockPatternUtils {
}
}
- /**
- * Sets the emergency button visibility based on isEmergencyCallCapable().
- *
- * If the emergency button is visible, sets the text on the emergency button
- * to indicate what action will be taken.
- *
- * If there's currently a call in progress, the button will take them to the call
- * @param button The button to update
- * @param shown Indicates whether the given screen wants the emergency button to show at all
- * @param showIcon Indicates whether to show a phone icon for the button.
- */
- public void updateEmergencyCallButtonState(Button button, boolean shown, boolean showIcon) {
- if (isEmergencyCallCapable() && shown) {
- button.setVisibility(View.VISIBLE);
- } else {
- button.setVisibility(View.GONE);
- return;
- }
-
- int textId;
- if (isInCall()) {
- // show "return to call" text and show phone icon
- textId = R.string.lockscreen_return_to_call;
- int phoneCallIcon = showIcon ? R.drawable.stat_sys_phone_call : 0;
- button.setCompoundDrawablesWithIntrinsicBounds(phoneCallIcon, 0, 0, 0);
- } else {
- textId = R.string.lockscreen_emergency_call;
- int emergencyIcon = showIcon ? R.drawable.ic_emergency : 0;
- button.setCompoundDrawablesWithIntrinsicBounds(emergencyIcon, 0, 0, 0);
- }
- button.setText(textId);
- }
-
- /**
- * Resumes a call in progress. Typically launched from the EmergencyCall button
- * on various lockscreens.
- */
- public void resumeCall() {
- getTelecommManager().showInCallScreen(false);
- }
-
- /**
- * @return {@code true} if there is a call currently in progress, {@code false} otherwise.
- */
- public boolean isInCall() {
- return getTelecommManager().isInCall();
- }
-
- private TelecomManager getTelecommManager() {
- return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
- }
-
public void setPowerButtonInstantlyLocks(boolean enabled) {
setBoolean(LOCKSCREEN_POWER_BUTTON_INSTANTLY_LOCKS, enabled, getCurrentOrCallingUserId());
}
diff --git a/packages/Keyguard/src/com/android/keyguard/CarrierText.java b/packages/Keyguard/src/com/android/keyguard/CarrierText.java
index d8b0c71..c023dc6 100644
--- a/packages/Keyguard/src/com/android/keyguard/CarrierText.java
+++ b/packages/Keyguard/src/com/android/keyguard/CarrierText.java
@@ -41,7 +41,8 @@ public class CarrierText extends TextView {
private static CharSequence mSeparator;
- private LockPatternUtils mLockPatternUtils;
+ private final boolean mIsEmergencyCallCapable;
+
private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback() {
@@ -78,7 +79,8 @@ public class CarrierText extends TextView {
public CarrierText(Context context, AttributeSet attrs) {
super(context, attrs);
- mLockPatternUtils = new LockPatternUtils(mContext);
+ mIsEmergencyCallCapable = context.getResources().getBoolean(
+ com.android.internal.R.bool.config_voice_capable);
boolean useAllCaps;
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs, R.styleable.CarrierText, 0, 0);
@@ -222,7 +224,7 @@ public class CarrierText extends TextView {
*/
private CharSequence makeCarrierStringOnEmergencyCapable(
CharSequence simMessage, CharSequence emergencyCallMessage) {
- if (mLockPatternUtils.isEmergencyCallCapable()) {
+ if (mIsEmergencyCallCapable) {
return concatenate(simMessage, emergencyCallMessage);
}
return simMessage;
diff --git a/packages/Keyguard/src/com/android/keyguard/EmergencyButton.java b/packages/Keyguard/src/com/android/keyguard/EmergencyButton.java
index 4a9440c..3627e3e 100644
--- a/packages/Keyguard/src/com/android/keyguard/EmergencyButton.java
+++ b/packages/Keyguard/src/com/android/keyguard/EmergencyButton.java
@@ -21,7 +21,7 @@ import android.content.Intent;
import android.os.PowerManager;
import android.os.SystemClock;
import android.os.UserHandle;
-import android.telephony.TelephonyManager;
+import android.telecom.TelecomManager;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
@@ -59,12 +59,19 @@ public class EmergencyButton extends Button {
private PowerManager mPowerManager;
private EmergencyButtonCallback mEmergencyButtonCallback;
+ private final boolean mIsVoiceCapable;
+ private final boolean mEnableEmergencyCallWhileSimLocked;
+
public EmergencyButton(Context context) {
this(context, null);
}
public EmergencyButton(Context context, AttributeSet attrs) {
super(context, attrs);
+ mIsVoiceCapable = context.getResources().getBoolean(
+ com.android.internal.R.bool.config_voice_capable);
+ mEnableEmergencyCallWhileSimLocked = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_enable_emergency_call_while_sim_locked);
}
@Override
@@ -99,8 +106,8 @@ public class EmergencyButton extends Button {
// TODO: implement a shorter timeout once new PowerManager API is ready.
// should be the equivalent to the old userActivity(EMERGENCY_CALL_TIMEOUT)
mPowerManager.userActivity(SystemClock.uptimeMillis(), true);
- if (mLockPatternUtils.isInCall()) {
- mLockPatternUtils.resumeCall();
+ if (isInCall()) {
+ resumeCall();
if (mEmergencyButtonCallback != null) {
mEmergencyButtonCallback.onEmergencyButtonClickedWhenInCall();
}
@@ -116,24 +123,57 @@ public class EmergencyButton extends Button {
}
private void updateEmergencyCallButton() {
- boolean enabled = false;
- if (mLockPatternUtils.isInCall()) {
- enabled = true; // always show "return to call" if phone is off-hook
- } else if (mLockPatternUtils.isEmergencyCallCapable()) {
- final boolean simLocked = KeyguardUpdateMonitor.getInstance(mContext).isSimPinVoiceSecure();
- if (simLocked) {
- // Some countries can't handle emergency calls while SIM is locked.
- enabled = mLockPatternUtils.isEmergencyCallEnabledWhileSimLocked();
+ boolean visible = false;
+ if (mIsVoiceCapable) {
+ // Emergency calling requires voice capability.
+ if (isInCall()) {
+ visible = true; // always show "return to call" if phone is off-hook
+ } else {
+ final boolean simLocked = KeyguardUpdateMonitor.getInstance(mContext)
+ .isSimPinVoiceSecure();
+ if (simLocked) {
+ // Some countries can't handle emergency calls while SIM is locked.
+ visible = mEnableEmergencyCallWhileSimLocked;
+ } else {
+ // Only show if there is a secure screen (pin/pattern/SIM pin/SIM puk);
+ visible = mLockPatternUtils.isSecure();
+ }
+ }
+ }
+ if (visible) {
+ setVisibility(View.VISIBLE);
+
+ int textId;
+ if (isInCall()) {
+ textId = com.android.internal.R.string.lockscreen_return_to_call;
} else {
- // True if we need to show a secure screen (pin/pattern/SIM pin/SIM puk);
- // hides emergency button on "Slide" screen if device is not secure.
- enabled = mLockPatternUtils.isSecure();
+ textId = com.android.internal.R.string.lockscreen_emergency_call;
}
+ setText(textId);
+ } else {
+ setVisibility(View.GONE);
}
- mLockPatternUtils.updateEmergencyCallButtonState(this, enabled, false);
}
public void setCallback(EmergencyButtonCallback callback) {
mEmergencyButtonCallback = callback;
}
+
+ /**
+ * Resumes a call in progress.
+ */
+ private void resumeCall() {
+ getTelecommManager().showInCallScreen(false);
+ }
+
+ /**
+ * @return {@code true} if there is a call currently in progress.
+ */
+ private boolean isInCall() {
+ return getTelecommManager().isInCall();
+ }
+
+ private TelecomManager getTelecommManager() {
+ return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
+ }
}
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityModel.java b/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityModel.java
index 107f417..3eb31ad 100644
--- a/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityModel.java
+++ b/packages/Keyguard/src/com/android/keyguard/KeyguardSecurityModel.java
@@ -17,20 +17,16 @@ package com.android.keyguard;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
-import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
import com.android.internal.telephony.IccCardConstants;
import com.android.internal.widget.LockPatternUtils;
-import java.util.List;
-
public class KeyguardSecurityModel {
/**
- * The different types of security available for {@link Mode#UnlockScreen}.
- * @see com.android.internal.policy.impl.LockPatternKeyguardView#getUnlockMode()
+ * The different types of security available.
+ * @see KeyguardSecurityContainer#showSecurityScreen
*/
public enum SecurityMode {
Invalid, // NULL state
@@ -42,12 +38,16 @@ public class KeyguardSecurityModel {
SimPuk // Unlock by entering a sim puk
}
- private Context mContext;
+ private final Context mContext;
+ private final boolean mIsPukScreenAvailable;
+
private LockPatternUtils mLockPatternUtils;
KeyguardSecurityModel(Context context) {
mContext = context;
mLockPatternUtils = new LockPatternUtils(context);
+ mIsPukScreenAvailable = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_enable_puk_unlock_screen);
}
void setLockPatternUtils(LockPatternUtils utils) {
@@ -56,39 +56,35 @@ public class KeyguardSecurityModel {
SecurityMode getSecurityMode() {
KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
- SecurityMode mode = SecurityMode.None;
+
if (SubscriptionManager.isValidSubscriptionId(
monitor.getNextSubIdForState(IccCardConstants.State.PIN_REQUIRED))) {
- mode = SecurityMode.SimPin;
- } else if (SubscriptionManager.isValidSubscriptionId(
- monitor.getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED))
- && mLockPatternUtils.isPukUnlockScreenEnable()) {
- mode = SecurityMode.SimPuk;
- } else {
- final int security = mLockPatternUtils.getKeyguardStoredPasswordQuality();
- switch (security) {
- case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
- case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
- mode = mLockPatternUtils.isLockPasswordEnabled() ?
- SecurityMode.PIN : SecurityMode.None;
- break;
- case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
- case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
- case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
- mode = mLockPatternUtils.isLockPasswordEnabled() ?
- SecurityMode.Password : SecurityMode.None;
- break;
+ return SecurityMode.SimPin;
+ }
+
+ if (mIsPukScreenAvailable && SubscriptionManager.isValidSubscriptionId(
+ monitor.getNextSubIdForState(IccCardConstants.State.PUK_REQUIRED))) {
+ return SecurityMode.SimPuk;
+ }
+
+ final int security = mLockPatternUtils.getActivePasswordQuality();
+ switch (security) {
+ case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
+ case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
+ return SecurityMode.PIN;
+
+ case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
+ case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
+ case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
+ return SecurityMode.Password;
- case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
- case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED:
- mode = mLockPatternUtils.isLockPatternEnabled() ?
- SecurityMode.Pattern : SecurityMode.None;
- break;
+ case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
+ return SecurityMode.Pattern;
+ case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED:
+ return SecurityMode.None;
- default:
- throw new IllegalStateException("Unknown security quality:" + security);
- }
+ default:
+ throw new IllegalStateException("Unknown security quality:" + security);
}
- return mode;
}
}