Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 16 | package com.android.keyguard; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 17 | |
| 18 | import android.animation.ObjectAnimator; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 19 | import android.app.SearchManager; |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 20 | import android.app.admin.DevicePolicyManager; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 21 | import android.content.ComponentName; |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
Chris Wren | efbfa68 | 2012-11-07 19:18:46 -0500 | [diff] [blame] | 24 | import android.graphics.drawable.Drawable; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 25 | import android.os.UserHandle; |
John Spurlock | fafdb6f | 2012-10-09 18:30:11 -0400 | [diff] [blame] | 26 | import android.provider.Settings; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 27 | import android.util.AttributeSet; |
| 28 | import android.util.Log; |
| 29 | import android.util.Slog; |
| 30 | import android.view.View; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 31 | import android.widget.LinearLayout; |
| 32 | |
Jim Miller | 47df44a | 2012-09-06 17:51:12 -0700 | [diff] [blame] | 33 | import com.android.internal.telephony.IccCardConstants.State; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 34 | import com.android.internal.widget.LockPatternUtils; |
| 35 | import com.android.internal.widget.multiwaveview.GlowPadView; |
| 36 | import com.android.internal.widget.multiwaveview.GlowPadView.OnTriggerListener; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 37 | |
| 38 | public class KeyguardSelectorView extends LinearLayout implements KeyguardSecurityView { |
| 39 | private static final boolean DEBUG = KeyguardHostView.DEBUG; |
| 40 | private static final String TAG = "SecuritySelectorView"; |
| 41 | private static final String ASSIST_ICON_METADATA_NAME = |
| 42 | "com.android.systemui.action_assist_icon"; |
Jim Miller | d542810 | 2013-08-29 18:58:21 -0700 | [diff] [blame] | 43 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 44 | private KeyguardSecurityCallback mCallback; |
| 45 | private GlowPadView mGlowPadView; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 46 | private ObjectAnimator mAnim; |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 47 | private View mFadeView; |
Chris Wren | efbfa68 | 2012-11-07 19:18:46 -0500 | [diff] [blame] | 48 | private boolean mIsBouncing; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 49 | private boolean mCameraDisabled; |
| 50 | private boolean mSearchDisabled; |
| 51 | private LockPatternUtils mLockPatternUtils; |
Chris Wren | efbfa68 | 2012-11-07 19:18:46 -0500 | [diff] [blame] | 52 | private SecurityMessageDisplay mSecurityMessageDisplay; |
| 53 | private Drawable mBouncerFrame; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 54 | |
| 55 | OnTriggerListener mOnTriggerListener = new OnTriggerListener() { |
| 56 | |
| 57 | public void onTrigger(View v, int target) { |
| 58 | final int resId = mGlowPadView.getResourceIdForTarget(target); |
Sandeep Siddhartha | 42c3e02 | 2013-08-26 20:58:53 -0700 | [diff] [blame] | 59 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 60 | switch (resId) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 61 | case R.drawable.ic_lockscreen_unlock_phantom: |
| 62 | case R.drawable.ic_lockscreen_unlock: |
Jeff Brown | 3dc524b | 2012-09-30 19:49:11 -0700 | [diff] [blame] | 63 | mCallback.userActivity(0); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 64 | mCallback.dismiss(false); |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | public void onReleased(View v, int handle) { |
Chris Wren | efbfa68 | 2012-11-07 19:18:46 -0500 | [diff] [blame] | 70 | if (!mIsBouncing) { |
| 71 | doTransition(mFadeView, 1.0f); |
| 72 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | public void onGrabbed(View v, int handle) { |
Jeff Brown | 3dc524b | 2012-09-30 19:49:11 -0700 | [diff] [blame] | 76 | mCallback.userActivity(0); |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 77 | doTransition(mFadeView, 0.0f); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | public void onGrabbedStateChange(View v, int handle) { |
| 81 | |
| 82 | } |
| 83 | |
| 84 | public void onFinishFinalAnimation() { |
| 85 | |
| 86 | } |
| 87 | |
| 88 | }; |
| 89 | |
Sandeep Siddhartha | f4d922b | 2013-08-15 16:08:42 -0700 | [diff] [blame] | 90 | KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 91 | |
| 92 | @Override |
| 93 | public void onDevicePolicyManagerStateChanged() { |
| 94 | updateTargets(); |
| 95 | } |
| 96 | |
| 97 | @Override |
Jim Miller | 47df44a | 2012-09-06 17:51:12 -0700 | [diff] [blame] | 98 | public void onSimStateChanged(State simState) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 99 | updateTargets(); |
| 100 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | public KeyguardSelectorView(Context context) { |
| 104 | this(context, null); |
| 105 | } |
| 106 | |
| 107 | public KeyguardSelectorView(Context context, AttributeSet attrs) { |
| 108 | super(context, attrs); |
| 109 | mLockPatternUtils = new LockPatternUtils(getContext()); |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | protected void onFinishInflate() { |
| 114 | super.onFinishInflate(); |
| 115 | mGlowPadView = (GlowPadView) findViewById(R.id.glow_pad_view); |
| 116 | mGlowPadView.setOnTriggerListener(mOnTriggerListener); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 117 | updateTargets(); |
Chris Wren | efbfa68 | 2012-11-07 19:18:46 -0500 | [diff] [blame] | 118 | |
| 119 | mSecurityMessageDisplay = new KeyguardMessageArea.Helper(this); |
| 120 | View bouncerFrameView = findViewById(R.id.keyguard_selector_view_frame); |
| 121 | mBouncerFrame = bouncerFrameView.getBackground(); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Jim Miller | 0ff7f01 | 2012-10-11 20:40:01 -0700 | [diff] [blame] | 124 | public void setCarrierArea(View carrierArea) { |
| 125 | mFadeView = carrierArea; |
| 126 | } |
| 127 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 128 | public boolean isTargetPresent(int resId) { |
| 129 | return mGlowPadView.getTargetPosition(resId) != -1; |
| 130 | } |
| 131 | |
Adam Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 132 | @Override |
| 133 | public void showUsabilityHint() { |
Adam Cohen | 0a8d326 | 2012-10-03 13:50:55 -0700 | [diff] [blame] | 134 | mGlowPadView.ping(); |
| 135 | } |
| 136 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 137 | private void updateTargets() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 138 | int currentUserHandle = mLockPatternUtils.getCurrentUser(); |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 139 | DevicePolicyManager dpm = mLockPatternUtils.getDevicePolicyManager(); |
| 140 | int disabledFeatures = dpm.getKeyguardDisabledFeatures(null, currentUserHandle); |
| 141 | boolean secureCameraDisabled = mLockPatternUtils.isSecure() |
| 142 | && (disabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0; |
| 143 | boolean cameraDisabledByAdmin = dpm.getCameraDisabled(null, currentUserHandle) |
| 144 | || secureCameraDisabled; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 145 | final KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(getContext()); |
| 146 | boolean disabledBySimState = monitor.isSimLocked(); |
| 147 | boolean cameraTargetPresent = |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 148 | isTargetPresent(R.drawable.ic_lockscreen_camera); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 149 | boolean searchTargetPresent = |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 150 | isTargetPresent(R.drawable.ic_action_assist_generic); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 151 | |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 152 | if (cameraDisabledByAdmin) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 153 | Log.v(TAG, "Camera disabled by Device Policy"); |
| 154 | } else if (disabledBySimState) { |
| 155 | Log.v(TAG, "Camera disabled by Sim State"); |
| 156 | } |
John Spurlock | fafdb6f | 2012-10-09 18:30:11 -0400 | [diff] [blame] | 157 | boolean currentUserSetup = 0 != Settings.Secure.getIntForUser( |
| 158 | mContext.getContentResolver(), |
| 159 | Settings.Secure.USER_SETUP_COMPLETE, |
| 160 | 0 /*default */, |
| 161 | currentUserHandle); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 162 | boolean searchActionAvailable = |
| 163 | ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 164 | .getAssistIntent(mContext, false, UserHandle.USER_CURRENT) != null; |
John Spurlock | fafdb6f | 2012-10-09 18:30:11 -0400 | [diff] [blame] | 165 | mCameraDisabled = cameraDisabledByAdmin || disabledBySimState || !cameraTargetPresent |
| 166 | || !currentUserSetup; |
| 167 | mSearchDisabled = disabledBySimState || !searchActionAvailable || !searchTargetPresent |
| 168 | || !currentUserSetup; |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 169 | updateResources(); |
| 170 | } |
| 171 | |
| 172 | public void updateResources() { |
| 173 | // Update the search icon with drawable from the search .apk |
| 174 | if (!mSearchDisabled) { |
| 175 | Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 176 | .getAssistIntent(mContext, false, UserHandle.USER_CURRENT); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 177 | if (intent != null) { |
| 178 | // XXX Hack. We need to substitute the icon here but haven't formalized |
| 179 | // the public API. The "_google" metadata will be going away, so |
| 180 | // DON'T USE IT! |
| 181 | ComponentName component = intent.getComponent(); |
| 182 | boolean replaced = mGlowPadView.replaceTargetDrawablesIfPresent(component, |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 183 | ASSIST_ICON_METADATA_NAME + "_google", R.drawable.ic_action_assist_generic); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 184 | |
| 185 | if (!replaced && !mGlowPadView.replaceTargetDrawablesIfPresent(component, |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 186 | ASSIST_ICON_METADATA_NAME, R.drawable.ic_action_assist_generic)) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 187 | Slog.w(TAG, "Couldn't grab icon from package " + component); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 192 | mGlowPadView.setEnableTarget(R.drawable.ic_lockscreen_camera, !mCameraDisabled); |
| 193 | mGlowPadView.setEnableTarget(R.drawable.ic_action_assist_generic, !mSearchDisabled); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 196 | void doTransition(View view, float to) { |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 197 | if (mAnim != null) { |
| 198 | mAnim.cancel(); |
| 199 | } |
Jim Miller | 109f1fd | 2012-09-19 20:44:16 -0700 | [diff] [blame] | 200 | mAnim = ObjectAnimator.ofFloat(view, "alpha", to); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 201 | mAnim.start(); |
| 202 | } |
| 203 | |
| 204 | public void setKeyguardCallback(KeyguardSecurityCallback callback) { |
| 205 | mCallback = callback; |
| 206 | } |
| 207 | |
| 208 | public void setLockPatternUtils(LockPatternUtils utils) { |
| 209 | mLockPatternUtils = utils; |
| 210 | } |
| 211 | |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 212 | @Override |
| 213 | public void reset() { |
| 214 | mGlowPadView.reset(false); |
| 215 | } |
| 216 | |
| 217 | @Override |
| 218 | public boolean needsInput() { |
| 219 | return false; |
| 220 | } |
| 221 | |
| 222 | @Override |
| 223 | public void onPause() { |
Sandeep Siddhartha | f4d922b | 2013-08-15 16:08:42 -0700 | [diff] [blame] | 224 | KeyguardUpdateMonitor.getInstance(getContext()).removeCallback(mUpdateCallback); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | @Override |
Chris Wren | a042ac9 | 2012-11-07 11:37:06 -0500 | [diff] [blame] | 228 | public void onResume(int reason) { |
Sandeep Siddhartha | f4d922b | 2013-08-15 16:08:42 -0700 | [diff] [blame] | 229 | KeyguardUpdateMonitor.getInstance(getContext()).registerCallback(mUpdateCallback); |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public KeyguardSecurityCallback getCallback() { |
| 234 | return mCallback; |
| 235 | } |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 236 | |
| 237 | @Override |
| 238 | public void showBouncer(int duration) { |
Chris Wren | efbfa68 | 2012-11-07 19:18:46 -0500 | [diff] [blame] | 239 | mIsBouncing = true; |
| 240 | KeyguardSecurityViewHelper. |
| 241 | showBouncer(mSecurityMessageDisplay, mFadeView, mBouncerFrame, duration); |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | @Override |
| 245 | public void hideBouncer(int duration) { |
Chris Wren | efbfa68 | 2012-11-07 19:18:46 -0500 | [diff] [blame] | 246 | mIsBouncing = false; |
| 247 | KeyguardSecurityViewHelper. |
| 248 | hideBouncer(mSecurityMessageDisplay, mFadeView, mBouncerFrame, duration); |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 249 | } |
Jim Miller | dcb3d84 | 2012-08-23 19:18:12 -0700 | [diff] [blame] | 250 | } |