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