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