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