Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Selim Cinek | 5f14502 | 2016-08-02 16:00:12 -0700 | [diff] [blame] | 19 | import static android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK; |
| 20 | import static android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
| 21 | |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 22 | import android.app.ActivityManager; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 23 | import android.app.ActivityManagerNative; |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 24 | import android.app.ActivityOptions; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 25 | import android.app.admin.DevicePolicyManager; |
| 26 | import android.content.BroadcastReceiver; |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 27 | import android.content.ComponentName; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 28 | import android.content.Context; |
| 29 | import android.content.Intent; |
| 30 | import android.content.IntentFilter; |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 31 | import android.content.ServiceConnection; |
| 32 | import android.content.pm.ActivityInfo; |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 33 | import android.content.pm.PackageManager; |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 34 | import android.content.pm.ResolveInfo; |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 35 | import android.content.res.Configuration; |
Yorke Lee | 583a2024 | 2014-08-12 18:47:08 -0700 | [diff] [blame] | 36 | import android.os.AsyncTask; |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 37 | import android.os.Bundle; |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 38 | import android.os.IBinder; |
| 39 | import android.os.Message; |
| 40 | import android.os.Messenger; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 41 | import android.os.RemoteException; |
| 42 | import android.os.UserHandle; |
| 43 | import android.provider.MediaStore; |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 44 | import android.service.media.CameraPrewarmService; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 45 | import android.telecom.TelecomManager; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 46 | import android.util.AttributeSet; |
| 47 | import android.util.Log; |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 48 | import android.util.TypedValue; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 49 | import android.view.View; |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 50 | import android.view.ViewGroup; |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 51 | import android.view.WindowManager; |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 52 | import android.view.accessibility.AccessibilityNodeInfo; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 53 | import android.widget.FrameLayout; |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 54 | import android.widget.TextView; |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 55 | |
| 56 | import com.android.internal.widget.LockPatternUtils; |
| 57 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 58 | import com.android.keyguard.KeyguardUpdateMonitorCallback; |
Christoph Studer | b018399 | 2014-12-22 21:02:26 +0100 | [diff] [blame] | 59 | import com.android.systemui.EventLogConstants; |
| 60 | import com.android.systemui.EventLogTags; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 61 | import com.android.systemui.Interpolators; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 62 | import com.android.systemui.R; |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 63 | import com.android.systemui.assist.AssistManager; |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 64 | import com.android.systemui.plugins.IntentButtonProvider; |
| 65 | import com.android.systemui.plugins.IntentButtonProvider.IntentButton; |
| 66 | import com.android.systemui.plugins.IntentButtonProvider.IntentButton.IconState; |
| 67 | import com.android.systemui.plugins.PluginListener; |
| 68 | import com.android.systemui.plugins.PluginManager; |
Jason Monk | 46767b7 | 2016-08-18 10:58:04 -0400 | [diff] [blame] | 69 | import com.android.systemui.plugins.qs.QSContainer.ActivityStarter; |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 70 | import com.android.systemui.statusbar.CommandQueue; |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 71 | import com.android.systemui.statusbar.KeyguardAffordanceView; |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 72 | import com.android.systemui.statusbar.KeyguardIndicationController; |
| 73 | import com.android.systemui.statusbar.policy.AccessibilityController; |
| 74 | import com.android.systemui.statusbar.policy.FlashlightController; |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 75 | import com.android.systemui.statusbar.policy.PreviewInflater; |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * Implementation for the bottom area of the Keyguard, including camera/phone affordance and status |
| 79 | * text. |
| 80 | */ |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 81 | public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickListener, |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 82 | UnlockMethodCache.OnUnlockMethodChangedListener, |
| 83 | AccessibilityController.AccessibilityStateChangedCallback, View.OnLongClickListener { |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 84 | |
| 85 | final static String TAG = "PhoneStatusBar/KeyguardBottomAreaView"; |
| 86 | |
Jorim Jaggi | 40aa881 | 2015-09-23 12:59:22 -0700 | [diff] [blame] | 87 | public static final String CAMERA_LAUNCH_SOURCE_AFFORDANCE = "lockscreen_affordance"; |
| 88 | public static final String CAMERA_LAUNCH_SOURCE_WIGGLE = "wiggle_gesture"; |
| 89 | public static final String CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP = "power_double_tap"; |
| 90 | |
| 91 | public static final String EXTRA_CAMERA_LAUNCH_SOURCE |
| 92 | = "com.android.systemui.camera_launch_source"; |
| 93 | |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 94 | private static final String LEFT_BUTTON_PLUGIN |
| 95 | = "com.android.systemui.action.PLUGIN_LOCKSCREEN_LEFT_BUTTON"; |
| 96 | private static final String RIGHT_BUTTON_PLUGIN |
| 97 | = "com.android.systemui.action.PLUGIN_LOCKSCREEN_RIGHT_BUTTON"; |
| 98 | |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 99 | private static final Intent SECURE_CAMERA_INTENT = |
| 100 | new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE) |
| 101 | .addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
Selim Cinek | 372d1bd | 2015-08-14 13:19:37 -0700 | [diff] [blame] | 102 | public static final Intent INSECURE_CAMERA_INTENT = |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 103 | new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 104 | private static final Intent PHONE_INTENT = new Intent(Intent.ACTION_DIAL); |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 105 | private static final int DOZE_ANIMATION_STAGGER_DELAY = 48; |
| 106 | private static final int DOZE_ANIMATION_ELEMENT_DURATION = 250; |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 107 | |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 108 | private KeyguardAffordanceView mRightAffordanceView; |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 109 | private KeyguardAffordanceView mLeftAffordanceView; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 110 | private LockIcon mLockIcon; |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 111 | private TextView mIndicationText; |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 112 | private ViewGroup mPreviewContainer; |
| 113 | |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 114 | private View mLeftPreview; |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 115 | private View mCameraPreview; |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 116 | |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 117 | private ActivityStarter mActivityStarter; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 118 | private UnlockMethodCache mUnlockMethodCache; |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 119 | private LockPatternUtils mLockPatternUtils; |
Adrian Roos | 1e1d6ac | 2014-07-22 17:18:55 +0200 | [diff] [blame] | 120 | private FlashlightController mFlashlightController; |
Jorim Jaggi | 781c29c | 2014-08-05 20:39:15 +0200 | [diff] [blame] | 121 | private PreviewInflater mPreviewInflater; |
Adrian Roos | 4ebcdfd | 2014-08-12 23:33:49 +0200 | [diff] [blame] | 122 | private KeyguardIndicationController mIndicationController; |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 123 | private AccessibilityController mAccessibilityController; |
| 124 | private PhoneStatusBar mPhoneStatusBar; |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 125 | |
Adrian Roos | a4eba9f | 2015-07-22 18:13:04 -0700 | [diff] [blame] | 126 | private boolean mUserSetupComplete; |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 127 | private boolean mPrewarmBound; |
| 128 | private Messenger mPrewarmMessenger; |
| 129 | private final ServiceConnection mPrewarmConnection = new ServiceConnection() { |
| 130 | |
| 131 | @Override |
| 132 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 133 | mPrewarmMessenger = new Messenger(service); |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public void onServiceDisconnected(ComponentName name) { |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 138 | mPrewarmMessenger = null; |
| 139 | } |
| 140 | }; |
| 141 | |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 142 | private boolean mLeftIsVoiceAssist; |
| 143 | private AssistManager mAssistManager; |
Adrian Roos | 72cc370 | 2014-09-18 17:25:09 +0200 | [diff] [blame] | 144 | |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 145 | private IntentButton mRightButton = new DefaultRightButton(); |
| 146 | private IntentButton mLeftButton = new DefaultLeftButton(); |
| 147 | |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 148 | public KeyguardBottomAreaView(Context context) { |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 149 | this(context, null); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | public KeyguardBottomAreaView(Context context, AttributeSet attrs) { |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 153 | this(context, attrs, 0); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | public KeyguardBottomAreaView(Context context, AttributeSet attrs, int defStyleAttr) { |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 157 | this(context, attrs, defStyleAttr, 0); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | public KeyguardBottomAreaView(Context context, AttributeSet attrs, int defStyleAttr, |
| 161 | int defStyleRes) { |
| 162 | super(context, attrs, defStyleAttr, defStyleRes); |
| 163 | } |
| 164 | |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 165 | private AccessibilityDelegate mAccessibilityDelegate = new AccessibilityDelegate() { |
| 166 | @Override |
| 167 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 168 | super.onInitializeAccessibilityNodeInfo(host, info); |
| 169 | String label = null; |
| 170 | if (host == mLockIcon) { |
| 171 | label = getResources().getString(R.string.unlock_label); |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 172 | } else if (host == mRightAffordanceView) { |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 173 | label = getResources().getString(R.string.camera_label); |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 174 | } else if (host == mLeftAffordanceView) { |
| 175 | if (mLeftIsVoiceAssist) { |
| 176 | label = getResources().getString(R.string.voice_assist_label); |
| 177 | } else { |
| 178 | label = getResources().getString(R.string.phone_label); |
| 179 | } |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 180 | } |
| 181 | info.addAction(new AccessibilityAction(ACTION_CLICK, label)); |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public boolean performAccessibilityAction(View host, int action, Bundle args) { |
| 186 | if (action == ACTION_CLICK) { |
| 187 | if (host == mLockIcon) { |
| 188 | mPhoneStatusBar.animateCollapsePanels( |
Jorim Jaggi | 4eedc1d | 2014-10-27 13:45:56 +0100 | [diff] [blame] | 189 | CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, true /* force */); |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 190 | return true; |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 191 | } else if (host == mRightAffordanceView) { |
Jorim Jaggi | 40aa881 | 2015-09-23 12:59:22 -0700 | [diff] [blame] | 192 | launchCamera(CAMERA_LAUNCH_SOURCE_AFFORDANCE); |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 193 | return true; |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 194 | } else if (host == mLeftAffordanceView) { |
| 195 | launchLeftAffordance(); |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 196 | return true; |
| 197 | } |
| 198 | } |
| 199 | return super.performAccessibilityAction(host, action, args); |
| 200 | } |
| 201 | }; |
| 202 | |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 203 | @Override |
| 204 | protected void onFinishInflate() { |
| 205 | super.onFinishInflate(); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 206 | mLockPatternUtils = new LockPatternUtils(mContext); |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 207 | mPreviewContainer = (ViewGroup) findViewById(R.id.preview_container); |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 208 | mRightAffordanceView = (KeyguardAffordanceView) findViewById(R.id.camera_button); |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 209 | mLeftAffordanceView = (KeyguardAffordanceView) findViewById(R.id.left_button); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 210 | mLockIcon = (LockIcon) findViewById(R.id.lock_icon); |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 211 | mIndicationText = (TextView) findViewById(R.id.keyguard_indication_text); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 212 | watchForCameraPolicyChanges(); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 213 | updateCameraVisibility(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 214 | mUnlockMethodCache = UnlockMethodCache.getInstance(getContext()); |
| 215 | mUnlockMethodCache.addListener(this); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 216 | mLockIcon.update(); |
Selim Cinek | baa2327 | 2014-07-08 18:01:07 +0200 | [diff] [blame] | 217 | setClipChildren(false); |
| 218 | setClipToPadding(false); |
Jorim Jaggi | 781c29c | 2014-08-05 20:39:15 +0200 | [diff] [blame] | 219 | mPreviewInflater = new PreviewInflater(mContext, new LockPatternUtils(mContext)); |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 220 | inflateCameraPreview(); |
Adrian Roos | 4ebcdfd | 2014-08-12 23:33:49 +0200 | [diff] [blame] | 221 | mLockIcon.setOnClickListener(this); |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 222 | mLockIcon.setOnLongClickListener(this); |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 223 | mRightAffordanceView.setOnClickListener(this); |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 224 | mLeftAffordanceView.setOnClickListener(this); |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 225 | initAccessibility(); |
| 226 | } |
| 227 | |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 228 | @Override |
| 229 | protected void onAttachedToWindow() { |
| 230 | super.onAttachedToWindow(); |
| 231 | PluginManager.getInstance(getContext()).addPluginListener(RIGHT_BUTTON_PLUGIN, |
| 232 | mRightListener, IntentButtonProvider.VERSION, false /* Only allow one */); |
| 233 | PluginManager.getInstance(getContext()).addPluginListener(LEFT_BUTTON_PLUGIN, |
| 234 | mLeftListener, IntentButtonProvider.VERSION, false /* Only allow one */); |
| 235 | } |
| 236 | |
| 237 | @Override |
| 238 | protected void onDetachedFromWindow() { |
| 239 | super.onDetachedFromWindow(); |
| 240 | PluginManager.getInstance(getContext()).removePluginListener(mRightListener); |
| 241 | PluginManager.getInstance(getContext()).removePluginListener(mLeftListener); |
| 242 | } |
| 243 | |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 244 | private void initAccessibility() { |
| 245 | mLockIcon.setAccessibilityDelegate(mAccessibilityDelegate); |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 246 | mLeftAffordanceView.setAccessibilityDelegate(mAccessibilityDelegate); |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 247 | mRightAffordanceView.setAccessibilityDelegate(mAccessibilityDelegate); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 248 | } |
| 249 | |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 250 | @Override |
| 251 | protected void onConfigurationChanged(Configuration newConfig) { |
| 252 | super.onConfigurationChanged(newConfig); |
| 253 | int indicationBottomMargin = getResources().getDimensionPixelSize( |
| 254 | R.dimen.keyguard_indication_margin_bottom); |
| 255 | MarginLayoutParams mlp = (MarginLayoutParams) mIndicationText.getLayoutParams(); |
| 256 | if (mlp.bottomMargin != indicationBottomMargin) { |
| 257 | mlp.bottomMargin = indicationBottomMargin; |
| 258 | mIndicationText.setLayoutParams(mlp); |
| 259 | } |
| 260 | |
| 261 | // Respect font size setting. |
| 262 | mIndicationText.setTextSize(TypedValue.COMPLEX_UNIT_PX, |
| 263 | getResources().getDimensionPixelSize( |
| 264 | com.android.internal.R.dimen.text_size_small_material)); |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 265 | |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 266 | ViewGroup.LayoutParams lp = mRightAffordanceView.getLayoutParams(); |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 267 | lp.width = getResources().getDimensionPixelSize(R.dimen.keyguard_affordance_width); |
| 268 | lp.height = getResources().getDimensionPixelSize(R.dimen.keyguard_affordance_height); |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 269 | mRightAffordanceView.setLayoutParams(lp); |
| 270 | updateRightAffordanceIcon(); |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 271 | |
| 272 | lp = mLockIcon.getLayoutParams(); |
| 273 | lp.width = getResources().getDimensionPixelSize(R.dimen.keyguard_affordance_width); |
| 274 | lp.height = getResources().getDimensionPixelSize(R.dimen.keyguard_affordance_height); |
| 275 | mLockIcon.setLayoutParams(lp); |
| 276 | mLockIcon.update(true /* force */); |
| 277 | |
| 278 | lp = mLeftAffordanceView.getLayoutParams(); |
| 279 | lp.width = getResources().getDimensionPixelSize(R.dimen.keyguard_affordance_width); |
| 280 | lp.height = getResources().getDimensionPixelSize(R.dimen.keyguard_affordance_height); |
| 281 | mLeftAffordanceView.setLayoutParams(lp); |
| 282 | updateLeftAffordanceIcon(); |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 283 | } |
| 284 | |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 285 | private void updateRightAffordanceIcon() { |
| 286 | IconState state = mRightButton.getIcon(); |
| 287 | mRightAffordanceView.setVisibility(state.isVisible ? View.VISIBLE : View.GONE); |
| 288 | mRightAffordanceView.setImageDrawable(state.drawable); |
| 289 | mRightAffordanceView.setContentDescription(state.contentDescription); |
| 290 | } |
| 291 | |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 292 | public void setActivityStarter(ActivityStarter activityStarter) { |
| 293 | mActivityStarter = activityStarter; |
| 294 | } |
| 295 | |
Adrian Roos | 1e1d6ac | 2014-07-22 17:18:55 +0200 | [diff] [blame] | 296 | public void setFlashlightController(FlashlightController flashlightController) { |
| 297 | mFlashlightController = flashlightController; |
| 298 | } |
| 299 | |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 300 | public void setAccessibilityController(AccessibilityController accessibilityController) { |
| 301 | mAccessibilityController = accessibilityController; |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 302 | mLockIcon.setAccessibilityController(accessibilityController); |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 303 | accessibilityController.addStateChangedCallback(this); |
| 304 | } |
| 305 | |
| 306 | public void setPhoneStatusBar(PhoneStatusBar phoneStatusBar) { |
| 307 | mPhoneStatusBar = phoneStatusBar; |
Dan Sandler | e163a64 | 2015-03-01 22:58:32 -0500 | [diff] [blame] | 308 | updateCameraVisibility(); // in case onFinishInflate() was called too early |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 309 | } |
| 310 | |
Adrian Roos | a4eba9f | 2015-07-22 18:13:04 -0700 | [diff] [blame] | 311 | public void setUserSetupComplete(boolean userSetupComplete) { |
| 312 | mUserSetupComplete = userSetupComplete; |
| 313 | updateCameraVisibility(); |
| 314 | updateLeftAffordanceIcon(); |
| 315 | } |
| 316 | |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 317 | private Intent getCameraIntent() { |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 318 | return mRightButton.getIntent(); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 319 | } |
| 320 | |
Zhentao Sun | 04f9740 | 2015-08-26 17:37:30 -0700 | [diff] [blame] | 321 | /** |
| 322 | * Resolves the intent to launch the camera application. |
| 323 | */ |
| 324 | public ResolveInfo resolveCameraIntent() { |
| 325 | return mContext.getPackageManager().resolveActivityAsUser(getCameraIntent(), |
| 326 | PackageManager.MATCH_DEFAULT_ONLY, |
| 327 | KeyguardUpdateMonitor.getCurrentUser()); |
| 328 | } |
| 329 | |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 330 | private void updateCameraVisibility() { |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 331 | if (mRightAffordanceView == null) { |
Dan Sandler | e163a64 | 2015-03-01 22:58:32 -0500 | [diff] [blame] | 332 | // Things are not set up yet; reply hazy, ask again later |
| 333 | return; |
| 334 | } |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 335 | mRightAffordanceView.setVisibility(mRightButton.getIcon().isVisible |
| 336 | ? View.VISIBLE : View.GONE); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 339 | private void updateLeftAffordanceIcon() { |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 340 | IconState state = mLeftButton.getIcon(); |
| 341 | mLeftAffordanceView.setVisibility(state.isVisible ? View.VISIBLE : View.GONE); |
| 342 | mLeftAffordanceView.setImageDrawable(state.drawable); |
| 343 | mLeftAffordanceView.setContentDescription(state.contentDescription); |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | public boolean isLeftVoiceAssist() { |
| 347 | return mLeftIsVoiceAssist; |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | private boolean isPhoneVisible() { |
| 351 | PackageManager pm = mContext.getPackageManager(); |
| 352 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) |
| 353 | && pm.resolveActivity(PHONE_INTENT, 0) != null; |
| 354 | } |
| 355 | |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 356 | private boolean isCameraDisabledByDpm() { |
| 357 | final DevicePolicyManager dpm = |
| 358 | (DevicePolicyManager) getContext().getSystemService(Context.DEVICE_POLICY_SERVICE); |
Dan Sandler | e163a64 | 2015-03-01 22:58:32 -0500 | [diff] [blame] | 359 | if (dpm != null && mPhoneStatusBar != null) { |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 360 | try { |
| 361 | final int userId = ActivityManagerNative.getDefault().getCurrentUser().id; |
| 362 | final int disabledFlags = dpm.getKeyguardDisabledFeatures(null, userId); |
| 363 | final boolean disabledBecauseKeyguardSecure = |
| 364 | (disabledFlags & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0 |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 365 | && mPhoneStatusBar.isKeyguardSecure(); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 366 | return dpm.getCameraDisabled(null) || disabledBecauseKeyguardSecure; |
| 367 | } catch (RemoteException e) { |
| 368 | Log.e(TAG, "Can't get userId", e); |
| 369 | } |
| 370 | } |
| 371 | return false; |
| 372 | } |
| 373 | |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 374 | private void watchForCameraPolicyChanges() { |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 375 | final IntentFilter filter = new IntentFilter(); |
| 376 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 377 | getContext().registerReceiverAsUser(mDevicePolicyReceiver, |
| 378 | UserHandle.ALL, filter, null, null); |
| 379 | KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 380 | } |
| 381 | |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 382 | @Override |
| 383 | public void onStateChanged(boolean accessibilityEnabled, boolean touchExplorationEnabled) { |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 384 | mRightAffordanceView.setClickable(touchExplorationEnabled); |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 385 | mLeftAffordanceView.setClickable(touchExplorationEnabled); |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 386 | mRightAffordanceView.setFocusable(accessibilityEnabled); |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 387 | mLeftAffordanceView.setFocusable(accessibilityEnabled); |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 388 | mLockIcon.update(); |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 389 | } |
| 390 | |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 391 | @Override |
| 392 | public void onClick(View v) { |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 393 | if (v == mRightAffordanceView) { |
Jorim Jaggi | 40aa881 | 2015-09-23 12:59:22 -0700 | [diff] [blame] | 394 | launchCamera(CAMERA_LAUNCH_SOURCE_AFFORDANCE); |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 395 | } else if (v == mLeftAffordanceView) { |
| 396 | launchLeftAffordance(); |
Adrian Roos | 4ebcdfd | 2014-08-12 23:33:49 +0200 | [diff] [blame] | 397 | } if (v == mLockIcon) { |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 398 | if (!mAccessibilityController.isAccessibilityEnabled()) { |
| 399 | handleTrustCircleClick(); |
| 400 | } else { |
| 401 | mPhoneStatusBar.animateCollapsePanels( |
| 402 | CommandQueue.FLAG_EXCLUDE_NONE, true /* force */); |
| 403 | } |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 407 | @Override |
| 408 | public boolean onLongClick(View v) { |
| 409 | handleTrustCircleClick(); |
| 410 | return true; |
| 411 | } |
| 412 | |
| 413 | private void handleTrustCircleClick() { |
Christoph Studer | b018399 | 2014-12-22 21:02:26 +0100 | [diff] [blame] | 414 | EventLogTags.writeSysuiLockscreenGesture( |
| 415 | EventLogConstants.SYSUI_LOCKSCREEN_GESTURE_TAP_LOCK, 0 /* lengthDp - N/A */, |
| 416 | 0 /* velocityDp - N/A */); |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 417 | mIndicationController.showTransientIndication( |
| 418 | R.string.keyguard_indication_trust_disabled); |
Adrian Roos | d6aa6cb | 2015-04-16 19:31:29 -0700 | [diff] [blame] | 419 | mLockPatternUtils.requireCredentialEntry(KeyguardUpdateMonitor.getCurrentUser()); |
Jorim Jaggi | b2e104f | 2014-08-15 18:12:36 +0200 | [diff] [blame] | 420 | } |
| 421 | |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 422 | public void bindCameraPrewarmService() { |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 423 | Intent intent = getCameraIntent(); |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 424 | ActivityInfo targetInfo = PreviewInflater.getTargetActivityInfo(mContext, intent, |
Selim Cinek | 5f14502 | 2016-08-02 16:00:12 -0700 | [diff] [blame] | 425 | KeyguardUpdateMonitor.getCurrentUser(), true /* onlyDirectBootAware */); |
Jorim Jaggi | 8b8fa3e | 2015-08-18 18:33:49 -0700 | [diff] [blame] | 426 | if (targetInfo != null && targetInfo.metaData != null) { |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 427 | String clazz = targetInfo.metaData.getString( |
| 428 | MediaStore.META_DATA_STILL_IMAGE_CAMERA_PREWARM_SERVICE); |
| 429 | if (clazz != null) { |
| 430 | Intent serviceIntent = new Intent(); |
| 431 | serviceIntent.setClassName(targetInfo.packageName, clazz); |
| 432 | serviceIntent.setAction(CameraPrewarmService.ACTION_PREWARM); |
| 433 | try { |
Jorim Jaggi | f610bd7 | 2015-08-17 20:17:30 -0700 | [diff] [blame] | 434 | if (getContext().bindServiceAsUser(serviceIntent, mPrewarmConnection, |
Selim Cinek | edf4748 | 2015-09-01 18:05:08 -0700 | [diff] [blame] | 435 | Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, |
| 436 | new UserHandle(UserHandle.USER_CURRENT))) { |
Jorim Jaggi | f610bd7 | 2015-08-17 20:17:30 -0700 | [diff] [blame] | 437 | mPrewarmBound = true; |
| 438 | } |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 439 | } catch (SecurityException e) { |
| 440 | Log.w(TAG, "Unable to bind to prewarm service package=" + targetInfo.packageName |
| 441 | + " class=" + clazz, e); |
| 442 | } |
| 443 | } |
Jorim Jaggi | a86790b | 2015-04-02 16:32:29 -0700 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 447 | public void unbindCameraPrewarmService(boolean launched) { |
| 448 | if (mPrewarmBound) { |
Jorim Jaggi | f610bd7 | 2015-08-17 20:17:30 -0700 | [diff] [blame] | 449 | if (mPrewarmMessenger != null && launched) { |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 450 | try { |
| 451 | mPrewarmMessenger.send(Message.obtain(null /* handler */, |
| 452 | CameraPrewarmService.MSG_CAMERA_FIRED)); |
| 453 | } catch (RemoteException e) { |
| 454 | Log.w(TAG, "Error sending camera fired message", e); |
| 455 | } |
| 456 | } |
| 457 | mContext.unbindService(mPrewarmConnection); |
| 458 | mPrewarmBound = false; |
Jorim Jaggi | a86790b | 2015-04-02 16:32:29 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
Jorim Jaggi | 40aa881 | 2015-09-23 12:59:22 -0700 | [diff] [blame] | 462 | public void launchCamera(String source) { |
Jorim Jaggi | a86790b | 2015-04-02 16:32:29 -0700 | [diff] [blame] | 463 | final Intent intent = getCameraIntent(); |
Jorim Jaggi | 40aa881 | 2015-09-23 12:59:22 -0700 | [diff] [blame] | 464 | intent.putExtra(EXTRA_CAMERA_LAUNCH_SOURCE, source); |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 465 | boolean wouldLaunchResolverActivity = PreviewInflater.wouldLaunchResolverActivity( |
Adrian Roos | d6aa6cb | 2015-04-16 19:31:29 -0700 | [diff] [blame] | 466 | mContext, intent, KeyguardUpdateMonitor.getCurrentUser()); |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 467 | if (intent == SECURE_CAMERA_INTENT && !wouldLaunchResolverActivity) { |
Jorim Jaggi | a86790b | 2015-04-02 16:32:29 -0700 | [diff] [blame] | 468 | AsyncTask.execute(new Runnable() { |
| 469 | @Override |
| 470 | public void run() { |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 471 | int result = ActivityManager.START_CANCELED; |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 472 | |
| 473 | // Normally an activity will set it's requested rotation |
| 474 | // animation on its window. However when launching an activity |
| 475 | // causes the orientation to change this is too late. In these cases |
| 476 | // the default animation is used. This doesn't look good for |
| 477 | // the camera (as it rotates the camera contents out of sync |
| 478 | // with physical reality). So, we ask the WindowManager to |
| 479 | // force the crossfade animation if an orientation change |
| 480 | // happens to occur during the launch. |
| 481 | ActivityOptions o = ActivityOptions.makeBasic(); |
| 482 | o.setRotationAnimationHint( |
Robert Carr | 57d9fbd | 2016-08-15 12:00:35 -0700 | [diff] [blame] | 483 | WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS); |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 484 | try { |
| 485 | result = ActivityManagerNative.getDefault().startActivityAsUser( |
| 486 | null, getContext().getBasePackageName(), |
| 487 | intent, |
| 488 | intent.resolveTypeIfNeeded(getContext().getContentResolver()), |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 489 | null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, o.toBundle(), |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 490 | UserHandle.CURRENT.getIdentifier()); |
| 491 | } catch (RemoteException e) { |
| 492 | Log.w(TAG, "Unable to start camera activity", e); |
| 493 | } |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 494 | mActivityStarter.preventNextAnimation(); |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 495 | final boolean launched = isSuccessfulLaunch(result); |
| 496 | post(new Runnable() { |
| 497 | @Override |
| 498 | public void run() { |
| 499 | unbindCameraPrewarmService(launched); |
| 500 | } |
| 501 | }); |
Jorim Jaggi | a86790b | 2015-04-02 16:32:29 -0700 | [diff] [blame] | 502 | } |
| 503 | }); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 504 | } else { |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 505 | |
| 506 | // We need to delay starting the activity because ResolverActivity finishes itself if |
| 507 | // launched behind lockscreen. |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 508 | mActivityStarter.startActivity(intent, false /* dismissShade */, |
| 509 | new ActivityStarter.Callback() { |
| 510 | @Override |
| 511 | public void onActivityStarted(int resultCode) { |
| 512 | unbindCameraPrewarmService(isSuccessfulLaunch(resultCode)); |
| 513 | } |
| 514 | }); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 515 | } |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 516 | } |
| 517 | |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 518 | private static boolean isSuccessfulLaunch(int result) { |
| 519 | return result == ActivityManager.START_SUCCESS |
| 520 | || result == ActivityManager.START_DELIVERED_TO_TOP |
| 521 | || result == ActivityManager.START_TASK_TO_FRONT; |
| 522 | } |
| 523 | |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 524 | public void launchLeftAffordance() { |
| 525 | if (mLeftIsVoiceAssist) { |
| 526 | launchVoiceAssist(); |
| 527 | } else { |
| 528 | launchPhone(); |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | private void launchVoiceAssist() { |
| 533 | Runnable runnable = new Runnable() { |
| 534 | @Override |
| 535 | public void run() { |
| 536 | mAssistManager.launchVoiceAssistFromKeyguard(); |
| 537 | mActivityStarter.preventNextAnimation(); |
| 538 | } |
| 539 | }; |
| 540 | if (mPhoneStatusBar.isKeyguardCurrentlySecure()) { |
| 541 | AsyncTask.execute(runnable); |
| 542 | } else { |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 543 | mPhoneStatusBar.executeRunnableDismissingKeyguard(runnable, null /* cancelAction */, |
Felipe Leme | ee5d630 | 2016-04-22 16:11:19 -0700 | [diff] [blame] | 544 | false /* dismissShade */, false /* afterKeyguardGone */, true /* deferred */); |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 545 | } |
| 546 | } |
| 547 | |
| 548 | private boolean canLaunchVoiceAssist() { |
| 549 | return mAssistManager.canVoiceAssistBeLaunchedFromKeyguard(); |
| 550 | } |
| 551 | |
| 552 | private void launchPhone() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 553 | final TelecomManager tm = TelecomManager.from(mContext); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 554 | if (tm.isInCall()) { |
Yorke Lee | 583a2024 | 2014-08-12 18:47:08 -0700 | [diff] [blame] | 555 | AsyncTask.execute(new Runnable() { |
| 556 | @Override |
| 557 | public void run() { |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 558 | tm.showInCallScreen(false /* showDialpad */); |
Yorke Lee | 583a2024 | 2014-08-12 18:47:08 -0700 | [diff] [blame] | 559 | } |
| 560 | }); |
| 561 | } else { |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 562 | mActivityStarter.startActivity(mLeftButton.getIntent(), false /* dismissShade */); |
Yorke Lee | 583a2024 | 2014-08-12 18:47:08 -0700 | [diff] [blame] | 563 | } |
Jorim Jaggi | 97b63c4 | 2014-05-02 23:03:34 +0200 | [diff] [blame] | 564 | } |
| 565 | |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 566 | |
| 567 | @Override |
| 568 | protected void onVisibilityChanged(View changedView, int visibility) { |
| 569 | super.onVisibilityChanged(changedView, visibility); |
| 570 | if (changedView == this && visibility == VISIBLE) { |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 571 | mLockIcon.update(); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 572 | updateCameraVisibility(); |
Adrian Roos | 2fe592d | 2014-05-17 03:11:59 +0200 | [diff] [blame] | 573 | } |
| 574 | } |
| 575 | |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 576 | public KeyguardAffordanceView getLeftView() { |
| 577 | return mLeftAffordanceView; |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 578 | } |
| 579 | |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 580 | public KeyguardAffordanceView getRightView() { |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 581 | return mRightAffordanceView; |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 582 | } |
| 583 | |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 584 | public View getLeftPreview() { |
| 585 | return mLeftPreview; |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 586 | } |
| 587 | |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 588 | public View getRightPreview() { |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 589 | return mCameraPreview; |
| 590 | } |
| 591 | |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 592 | public LockIcon getLockIcon() { |
Selim Cinek | 4c6969a | 2014-05-26 19:22:17 +0200 | [diff] [blame] | 593 | return mLockIcon; |
| 594 | } |
| 595 | |
Selim Cinek | f99d000 | 2014-06-13 07:36:01 +0200 | [diff] [blame] | 596 | public View getIndicationView() { |
| 597 | return mIndicationText; |
| 598 | } |
| 599 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 600 | @Override |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 601 | public boolean hasOverlappingRendering() { |
| 602 | return false; |
| 603 | } |
| 604 | |
| 605 | @Override |
Christoph Studer | 2231c6e | 2014-12-19 12:40:13 +0100 | [diff] [blame] | 606 | public void onUnlockMethodStateChanged() { |
Jorim Jaggi | 27267d6 | 2015-04-28 13:27:12 -0700 | [diff] [blame] | 607 | mLockIcon.update(); |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 608 | updateCameraVisibility(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 609 | } |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 610 | |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 611 | private void inflateCameraPreview() { |
Selim Cinek | 5f14502 | 2016-08-02 16:00:12 -0700 | [diff] [blame] | 612 | View previewBefore = mCameraPreview; |
| 613 | boolean visibleBefore = false; |
| 614 | if (previewBefore != null) { |
| 615 | mPreviewContainer.removeView(previewBefore); |
| 616 | visibleBefore = previewBefore.getVisibility() == View.VISIBLE; |
| 617 | } |
Jorim Jaggi | 781c29c | 2014-08-05 20:39:15 +0200 | [diff] [blame] | 618 | mCameraPreview = mPreviewInflater.inflatePreview(getCameraIntent()); |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 619 | if (mCameraPreview != null) { |
| 620 | mPreviewContainer.addView(mCameraPreview); |
Selim Cinek | 5f14502 | 2016-08-02 16:00:12 -0700 | [diff] [blame] | 621 | mCameraPreview.setVisibility(visibleBefore ? View.VISIBLE : View.INVISIBLE); |
Jorim Jaggi | b6cdcbc | 2014-07-25 21:58:29 +0200 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 625 | private void updateLeftPreview() { |
| 626 | View previewBefore = mLeftPreview; |
| 627 | if (previewBefore != null) { |
| 628 | mPreviewContainer.removeView(previewBefore); |
| 629 | } |
| 630 | if (mLeftIsVoiceAssist) { |
| 631 | mLeftPreview = mPreviewInflater.inflatePreviewFromService( |
| 632 | mAssistManager.getVoiceInteractorComponentName()); |
| 633 | } else { |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 634 | mLeftPreview = mPreviewInflater.inflatePreview(mLeftButton.getIntent()); |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 635 | } |
| 636 | if (mLeftPreview != null) { |
| 637 | mPreviewContainer.addView(mLeftPreview); |
| 638 | mLeftPreview.setVisibility(View.INVISIBLE); |
| 639 | } |
| 640 | } |
| 641 | |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 642 | public void startFinishDozeAnimation() { |
| 643 | long delay = 0; |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 644 | if (mLeftAffordanceView.getVisibility() == View.VISIBLE) { |
| 645 | startFinishDozeAnimationElement(mLeftAffordanceView, delay); |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 646 | delay += DOZE_ANIMATION_STAGGER_DELAY; |
| 647 | } |
| 648 | startFinishDozeAnimationElement(mLockIcon, delay); |
| 649 | delay += DOZE_ANIMATION_STAGGER_DELAY; |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 650 | if (mRightAffordanceView.getVisibility() == View.VISIBLE) { |
| 651 | startFinishDozeAnimationElement(mRightAffordanceView, delay); |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 652 | } |
| 653 | mIndicationText.setAlpha(0f); |
| 654 | mIndicationText.animate() |
| 655 | .alpha(1f) |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 656 | .setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN) |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 657 | .setDuration(NotificationPanelView.DOZE_ANIMATION_DURATION); |
| 658 | } |
| 659 | |
| 660 | private void startFinishDozeAnimationElement(View element, long delay) { |
| 661 | element.setAlpha(0f); |
| 662 | element.setTranslationY(element.getHeight() / 2); |
| 663 | element.animate() |
| 664 | .alpha(1f) |
| 665 | .translationY(0f) |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 666 | .setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN) |
Jorim Jaggi | 16423aa | 2014-10-28 11:42:58 +0100 | [diff] [blame] | 667 | .setStartDelay(delay) |
| 668 | .setDuration(DOZE_ANIMATION_ELEMENT_DURATION); |
| 669 | } |
| 670 | |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 671 | private final BroadcastReceiver mDevicePolicyReceiver = new BroadcastReceiver() { |
Jim Miller | b29814c | 2015-08-05 19:03:01 -0700 | [diff] [blame] | 672 | @Override |
Adrian Roos | a06905b | 2014-05-28 12:13:48 +0200 | [diff] [blame] | 673 | public void onReceive(Context context, Intent intent) { |
| 674 | post(new Runnable() { |
| 675 | @Override |
| 676 | public void run() { |
| 677 | updateCameraVisibility(); |
| 678 | } |
| 679 | }); |
| 680 | } |
| 681 | }; |
| 682 | |
| 683 | private final KeyguardUpdateMonitorCallback mUpdateMonitorCallback = |
| 684 | new KeyguardUpdateMonitorCallback() { |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 685 | @Override |
| 686 | public void onUserSwitchComplete(int userId) { |
| 687 | updateCameraVisibility(); |
| 688 | } |
Jorim Jaggi | e7b1252 | 2014-08-06 16:41:21 +0200 | [diff] [blame] | 689 | |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 690 | @Override |
| 691 | public void onStartedWakingUp() { |
| 692 | mLockIcon.setDeviceInteractive(true); |
| 693 | } |
Adrian Roos | 2e3ccbb | 2014-08-19 22:23:37 +0200 | [diff] [blame] | 694 | |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 695 | @Override |
| 696 | public void onFinishedGoingToSleep(int why) { |
| 697 | mLockIcon.setDeviceInteractive(false); |
| 698 | } |
Adrian Roos | b9ae090 | 2014-10-27 14:20:30 +0100 | [diff] [blame] | 699 | |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 700 | @Override |
| 701 | public void onScreenTurnedOn() { |
| 702 | mLockIcon.setScreenOn(true); |
| 703 | } |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 704 | |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 705 | @Override |
| 706 | public void onScreenTurnedOff() { |
| 707 | mLockIcon.setScreenOn(false); |
| 708 | } |
Jorim Jaggi | f1518da | 2015-07-30 11:56:36 -0700 | [diff] [blame] | 709 | |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 710 | @Override |
| 711 | public void onKeyguardVisibilityChanged(boolean showing) { |
| 712 | mLockIcon.update(); |
| 713 | } |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 714 | |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 715 | @Override |
| 716 | public void onFingerprintRunningStateChanged(boolean running) { |
| 717 | mLockIcon.update(); |
| 718 | } |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 719 | |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 720 | @Override |
| 721 | public void onStrongAuthStateChanged(int userId) { |
| 722 | mLockIcon.update(); |
| 723 | } |
| 724 | }; |
Adrian Roos | 4ebcdfd | 2014-08-12 23:33:49 +0200 | [diff] [blame] | 725 | |
| 726 | public void setKeyguardIndicationController( |
| 727 | KeyguardIndicationController keyguardIndicationController) { |
| 728 | mIndicationController = keyguardIndicationController; |
| 729 | } |
Selim Cinek | e70d653 | 2015-04-24 16:46:13 -0700 | [diff] [blame] | 730 | |
| 731 | public void setAssistManager(AssistManager assistManager) { |
| 732 | mAssistManager = assistManager; |
| 733 | updateLeftAffordance(); |
| 734 | } |
| 735 | |
| 736 | public void updateLeftAffordance() { |
| 737 | updateLeftAffordanceIcon(); |
| 738 | updateLeftPreview(); |
| 739 | } |
Selim Cinek | 5f14502 | 2016-08-02 16:00:12 -0700 | [diff] [blame] | 740 | |
| 741 | public void onKeyguardShowingChanged() { |
| 742 | updateLeftAffordance(); |
| 743 | inflateCameraPreview(); |
| 744 | } |
Jason Monk | b59f46f | 2016-09-27 12:29:18 -0400 | [diff] [blame^] | 745 | |
| 746 | private void setRightButton(IntentButton button) { |
| 747 | mRightButton = button; |
| 748 | updateRightAffordanceIcon(); |
| 749 | updateCameraVisibility(); |
| 750 | inflateCameraPreview(); |
| 751 | } |
| 752 | |
| 753 | private void setLeftButton(IntentButton button) { |
| 754 | mLeftButton = button; |
| 755 | mLeftIsVoiceAssist = false; |
| 756 | updateLeftAffordance(); |
| 757 | } |
| 758 | |
| 759 | private final PluginListener<IntentButtonProvider> mRightListener = |
| 760 | new PluginListener<IntentButtonProvider>() { |
| 761 | @Override |
| 762 | public void onPluginConnected(IntentButtonProvider plugin) { |
| 763 | setRightButton(plugin.getIntentButton()); |
| 764 | } |
| 765 | |
| 766 | @Override |
| 767 | public void onPluginDisconnected(IntentButtonProvider plugin) { |
| 768 | setRightButton(new DefaultRightButton()); |
| 769 | } |
| 770 | }; |
| 771 | |
| 772 | private final PluginListener<IntentButtonProvider> mLeftListener = |
| 773 | new PluginListener<IntentButtonProvider>() { |
| 774 | @Override |
| 775 | public void onPluginConnected(IntentButtonProvider plugin) { |
| 776 | setLeftButton(plugin.getIntentButton()); |
| 777 | } |
| 778 | |
| 779 | @Override |
| 780 | public void onPluginDisconnected(IntentButtonProvider plugin) { |
| 781 | setLeftButton(new DefaultLeftButton()); |
| 782 | } |
| 783 | }; |
| 784 | |
| 785 | private class DefaultLeftButton implements IntentButton { |
| 786 | |
| 787 | private IconState mIconState = new IconState(); |
| 788 | |
| 789 | @Override |
| 790 | public IconState getIcon() { |
| 791 | mLeftIsVoiceAssist = canLaunchVoiceAssist(); |
| 792 | if (mLeftIsVoiceAssist) { |
| 793 | mIconState.isVisible = mUserSetupComplete; |
| 794 | mIconState.drawable = mContext.getDrawable(R.drawable.ic_mic_26dp); |
| 795 | mIconState.contentDescription = mContext.getString( |
| 796 | R.string.accessibility_voice_assist_button); |
| 797 | } else { |
| 798 | mIconState.isVisible = mUserSetupComplete && isPhoneVisible(); |
| 799 | mIconState.drawable = mContext.getDrawable(R.drawable.ic_phone_24dp); |
| 800 | mIconState.contentDescription = mContext.getString( |
| 801 | R.string.accessibility_phone_button); |
| 802 | } |
| 803 | return mIconState; |
| 804 | } |
| 805 | |
| 806 | @Override |
| 807 | public Intent getIntent() { |
| 808 | return PHONE_INTENT; |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | private class DefaultRightButton implements IntentButton { |
| 813 | |
| 814 | private IconState mIconState = new IconState(); |
| 815 | |
| 816 | @Override |
| 817 | public IconState getIcon() { |
| 818 | ResolveInfo resolved = resolveCameraIntent(); |
| 819 | mIconState.isVisible = !isCameraDisabledByDpm() && resolved != null |
| 820 | && getResources().getBoolean(R.bool.config_keyguardShowCameraAffordance) |
| 821 | && mUserSetupComplete; |
| 822 | mIconState.drawable = mContext.getDrawable(R.drawable.ic_camera_alt_24dp); |
| 823 | mIconState.contentDescription = |
| 824 | mContext.getString(R.string.accessibility_camera_button); |
| 825 | return mIconState; |
| 826 | } |
| 827 | |
| 828 | @Override |
| 829 | public Intent getIntent() { |
| 830 | KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
| 831 | boolean canSkipBouncer = updateMonitor.getUserCanSkipBouncer( |
| 832 | KeyguardUpdateMonitor.getCurrentUser()); |
| 833 | boolean secure = mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser()); |
| 834 | return (secure && !canSkipBouncer) ? SECURE_CAMERA_INTENT : INSECURE_CAMERA_INTENT; |
| 835 | } |
| 836 | } |
Jorim Jaggi | a631029 | 2014-04-16 14:11:52 +0200 | [diff] [blame] | 837 | } |