Loading core/java/com/android/internal/widget/LockPatternUtils.java +2 −74 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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. */ Loading Loading @@ -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); Loading Loading @@ -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()); } Loading packages/Keyguard/src/com/android/keyguard/CarrierText.java +5 −3 Original line number Diff line number Diff line Loading @@ -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() { Loading Loading @@ -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); Loading Loading @@ -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; Loading packages/Keyguard/src/com/android/keyguard/EmergencyButton.java +55 −15 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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(); } Loading @@ -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(); 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. enabled = mLockPatternUtils.isEmergencyCallEnabledWhileSimLocked(); visible = mEnableEmergencyCallWhileSimLocked; } 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(); // Only show if there is a secure screen (pin/pattern/SIM pin/SIM puk); visible = mLockPatternUtils.isSecure(); } } mLockPatternUtils.updateEmergencyCallButtonState(this, enabled, false); } if (visible) { setVisibility(View.VISIBLE); int textId; if (isInCall()) { textId = com.android.internal.R.string.lockscreen_return_to_call; } else { textId = com.android.internal.R.string.lockscreen_emergency_call; } setText(textId); } else { setVisibility(View.GONE); } } 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); } } packages/Keyguard/src/com/android/keyguard/KeyguardSecurityModel.java +32 −36 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) { Loading @@ -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(); 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: mode = mLockPatternUtils.isLockPasswordEnabled() ? SecurityMode.PIN : SecurityMode.None; break; return SecurityMode.PIN; 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.Password; case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: return SecurityMode.Pattern; case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED: mode = mLockPatternUtils.isLockPatternEnabled() ? SecurityMode.Pattern : SecurityMode.None; break; return SecurityMode.None; default: throw new IllegalStateException("Unknown security quality:" + security); } } return mode; } } Loading
core/java/com/android/internal/widget/LockPatternUtils.java +2 −74 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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. */ Loading Loading @@ -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); Loading Loading @@ -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()); } Loading
packages/Keyguard/src/com/android/keyguard/CarrierText.java +5 −3 Original line number Diff line number Diff line Loading @@ -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() { Loading Loading @@ -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); Loading Loading @@ -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; Loading
packages/Keyguard/src/com/android/keyguard/EmergencyButton.java +55 −15 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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(); } Loading @@ -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(); 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. enabled = mLockPatternUtils.isEmergencyCallEnabledWhileSimLocked(); visible = mEnableEmergencyCallWhileSimLocked; } 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(); // Only show if there is a secure screen (pin/pattern/SIM pin/SIM puk); visible = mLockPatternUtils.isSecure(); } } mLockPatternUtils.updateEmergencyCallButtonState(this, enabled, false); } if (visible) { setVisibility(View.VISIBLE); int textId; if (isInCall()) { textId = com.android.internal.R.string.lockscreen_return_to_call; } else { textId = com.android.internal.R.string.lockscreen_emergency_call; } setText(textId); } else { setVisibility(View.GONE); } } 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); } }
packages/Keyguard/src/com/android/keyguard/KeyguardSecurityModel.java +32 −36 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) { Loading @@ -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(); 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: mode = mLockPatternUtils.isLockPasswordEnabled() ? SecurityMode.PIN : SecurityMode.None; break; return SecurityMode.PIN; 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.Password; case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: return SecurityMode.Pattern; case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED: mode = mLockPatternUtils.isLockPatternEnabled() ? SecurityMode.Pattern : SecurityMode.None; break; return SecurityMode.None; default: throw new IllegalStateException("Unknown security quality:" + security); } } return mode; } }