forked from aosp-mirror/platform_frameworks_base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyguardSelectorView.java
459 lines (412 loc) · 20.4 KB
/
KeyguardSelectorView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.internal.policy.impl.keyguard;
import java.io.File;
import java.net.URISyntaxException;
import java.util.ArrayList;
import android.animation.ObjectAnimator;
import android.app.SearchManager;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Slog;
import android.view.View;
import android.widget.LinearLayout;
import com.android.internal.telephony.IccCardConstants.State;
import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.multiwaveview.GlowPadView;
import com.android.internal.widget.multiwaveview.GlowPadView.OnTriggerListener;
import com.android.internal.R;
import com.android.internal.widget.multiwaveview.TargetDrawable;
public class KeyguardSelectorView extends LinearLayout implements KeyguardSecurityView {
private static final boolean DEBUG = KeyguardHostView.DEBUG;
private static final String TAG = "SecuritySelectorView";
private static final String ASSIST_ICON_METADATA_NAME =
"com.android.systemui.action_assist_icon";
private KeyguardSecurityCallback mCallback;
private GlowPadView mGlowPadView;
private ObjectAnimator mAnim;
private View mFadeView;
private boolean mIsBouncing;
private boolean mCameraDisabled;
private boolean mSearchDisabled;
private LockPatternUtils mLockPatternUtils;
private SecurityMessageDisplay mSecurityMessageDisplay;
private Drawable mBouncerFrame;
private String[] mStoredTargets;
private int mTargetOffset;
private boolean mIsScreenLarge;
private int mCreationOrientation;
OnTriggerListener mOnTriggerListener = new OnTriggerListener() {
public void onTrigger(View v, int target) {
if (mStoredTargets == null) {
final int resId = mGlowPadView.getResourceIdForTarget(target);
switch (resId) {
case com.android.internal.R.drawable.ic_action_assist_generic:
Intent assistIntent =
((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
.getAssistIntent(mContext, UserHandle.USER_CURRENT);
if (assistIntent != null) {
mActivityLauncher.launchActivity(assistIntent, false, true, null, null);
} else {
Log.w(TAG, "Failed to get intent for assist activity");
}
mCallback.userActivity(0);
break;
case com.android.internal.R.drawable.ic_lockscreen_camera:
mActivityLauncher.launchCamera(null, null);
mCallback.userActivity(0);
break;
case com.android.internal.R.drawable.ic_lockscreen_unlock_phantom:
case com.android.internal.R.drawable.ic_lockscreen_unlock:
mCallback.userActivity(0);
mCallback.dismiss(false);
break;
}
} else {
final boolean isLand = mCreationOrientation == Configuration.ORIENTATION_LANDSCAPE;
if ((target == 0 && (mIsScreenLarge || !isLand)) || (target == 2 && !mIsScreenLarge && isLand)) {
mCallback.dismiss(false);
} else {
target -= 1 + mTargetOffset;
if (target < mStoredTargets.length && mStoredTargets[target] != null) {
if (mStoredTargets[target].equals(GlowPadView.EMPTY_TARGET)) {
mCallback.dismiss(false);
} else {
try {
Intent launchIntent = Intent.parseUri(mStoredTargets[target], 0);
mActivityLauncher.launchActivity(launchIntent, false, true, null, null);
return;
} catch (URISyntaxException e) {
}
}
}
}
}
}
public void onReleased(View v, int handle) {
if (!mIsBouncing) {
doTransition(mFadeView, 1.0f);
}
}
public void onGrabbed(View v, int handle) {
mCallback.userActivity(0);
doTransition(mFadeView, 0.0f);
}
public void onGrabbedStateChange(View v, int handle) {
}
public void onFinishFinalAnimation() {
}
};
KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() {
@Override
public void onDevicePolicyManagerStateChanged() {
updateTargets();
}
@Override
public void onSimStateChanged(State simState) {
updateTargets();
}
};
private final KeyguardActivityLauncher mActivityLauncher = new KeyguardActivityLauncher() {
@Override
KeyguardSecurityCallback getCallback() {
return mCallback;
}
@Override
LockPatternUtils getLockPatternUtils() {
return mLockPatternUtils;
}
@Override
Context getContext() {
return mContext;
}};
public KeyguardSelectorView(Context context) {
this(context, null);
mCreationOrientation = Resources.getSystem().getConfiguration().orientation;
}
public KeyguardSelectorView(Context context, AttributeSet attrs) {
super(context, attrs);
mLockPatternUtils = new LockPatternUtils(getContext());
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mGlowPadView = (GlowPadView) findViewById(R.id.glow_pad_view);
mGlowPadView.setOnTriggerListener(mOnTriggerListener);
updateTargets();
mSecurityMessageDisplay = new KeyguardMessageArea.Helper(this);
View bouncerFrameView = findViewById(R.id.keyguard_selector_view_frame);
mBouncerFrame = bouncerFrameView.getBackground();
}
public void setCarrierArea(View carrierArea) {
mFadeView = carrierArea;
}
public boolean isScreenLarge() {
final int screenSize = Resources.getSystem().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK;
boolean isScreenLarge = screenSize == Configuration.SCREENLAYOUT_SIZE_LARGE ||
screenSize == Configuration.SCREENLAYOUT_SIZE_XLARGE;
return isScreenLarge;
}
private StateListDrawable getLayeredDrawable(Drawable back, Drawable front, int inset, boolean frontBlank) {
Resources res = getResources();
InsetDrawable[] inactivelayer = new InsetDrawable[2];
InsetDrawable[] activelayer = new InsetDrawable[2];
inactivelayer[0] = new InsetDrawable(res.getDrawable(com.android.internal.R.drawable.ic_lockscreen_lock_pressed), 0, 0, 0, 0);
inactivelayer[1] = new InsetDrawable(front, inset, inset, inset, inset);
activelayer[0] = new InsetDrawable(back, 0, 0, 0, 0);
activelayer[1] = new InsetDrawable(frontBlank ? res.getDrawable(android.R.color.transparent) : front, inset, inset, inset, inset);
StateListDrawable states = new StateListDrawable();
LayerDrawable inactiveLayerDrawable = new LayerDrawable(inactivelayer);
inactiveLayerDrawable.setId(0, 0);
inactiveLayerDrawable.setId(1, 1);
LayerDrawable activeLayerDrawable = new LayerDrawable(activelayer);
activeLayerDrawable.setId(0, 0);
activeLayerDrawable.setId(1, 1);
states.addState(TargetDrawable.STATE_INACTIVE, inactiveLayerDrawable);
states.addState(TargetDrawable.STATE_ACTIVE, activeLayerDrawable);
states.addState(TargetDrawable.STATE_FOCUSED, activeLayerDrawable);
return states;
}
public boolean isTargetPresent(int resId) {
return mGlowPadView.getTargetPosition(resId) != -1;
}
@Override
public void showUsabilityHint() {
mGlowPadView.ping();
}
private void updateTargets() {
int currentUserHandle = mLockPatternUtils.getCurrentUser();
DevicePolicyManager dpm = mLockPatternUtils.getDevicePolicyManager();
int disabledFeatures = dpm.getKeyguardDisabledFeatures(null, currentUserHandle);
boolean secureCameraDisabled = mLockPatternUtils.isSecure()
&& (disabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0;
boolean cameraDisabledByAdmin = dpm.getCameraDisabled(null, currentUserHandle)
|| secureCameraDisabled;
final KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(getContext());
boolean disabledBySimState = monitor.isSimLocked();
boolean cameraPresent = mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
boolean searchTargetPresent =
isTargetPresent(com.android.internal.R.drawable.ic_action_assist_generic);
if (cameraDisabledByAdmin) {
Log.v(TAG, "Camera disabled by Device Policy");
} else if (disabledBySimState) {
Log.v(TAG, "Camera disabled by Sim State");
}
boolean currentUserSetup = 0 != Settings.Secure.getIntForUser(
mContext.getContentResolver(),
Settings.Secure.USER_SETUP_COMPLETE,
0 /*default */,
currentUserHandle);
boolean searchActionAvailable =
((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
.getAssistIntent(mContext, UserHandle.USER_CURRENT) != null;
mCameraDisabled = cameraDisabledByAdmin || disabledBySimState || !cameraPresent
|| !currentUserSetup;
mSearchDisabled = disabledBySimState || !searchActionAvailable || !searchTargetPresent
|| !currentUserSetup;
updateResources();
}
public void updateResources() {
String storedVal = Settings.System.getString(mContext.getContentResolver(),
Settings.System.LOCKSCREEN_TARGETS);
if (storedVal == null) {
// Update the search icon with drawable from the search .apk
if (!mSearchDisabled) {
Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
.getAssistIntent(mContext, UserHandle.USER_CURRENT);
if (intent != null) {
// XXX Hack. We need to substitute the icon here but haven't formalized
// the public API. The "_google" metadata will be going away, so
// DON'T USE IT!
ComponentName component = intent.getComponent();
boolean replaced = mGlowPadView.replaceTargetDrawablesIfPresent(component,
ASSIST_ICON_METADATA_NAME + "_google",
com.android.internal.R.drawable.ic_action_assist_generic);
if (!replaced && !mGlowPadView.replaceTargetDrawablesIfPresent(component,
ASSIST_ICON_METADATA_NAME,
com.android.internal.R.drawable.ic_action_assist_generic)) {
Slog.w(TAG, "Couldn't grab icon from package " + component);
}
}
}
mGlowPadView.setEnableTarget(com.android.internal.R.drawable
.ic_lockscreen_camera, !mCameraDisabled);
mGlowPadView.setEnableTarget(com.android.internal.R.drawable
.ic_action_assist_generic, !mSearchDisabled);
} else {
mStoredTargets = storedVal.split("\\|");
mIsScreenLarge = isScreenLarge();
ArrayList<TargetDrawable> storedDraw = new ArrayList<TargetDrawable>();
final Resources res = getResources();
final int targetInset = res.getDimensionPixelSize(com.android.internal.R.dimen.lockscreen_target_inset);
final PackageManager packMan = mContext.getPackageManager();
final boolean isLandscape = mCreationOrientation == Configuration.ORIENTATION_LANDSCAPE;
final Drawable blankActiveDrawable = res.getDrawable(R.drawable.ic_lockscreen_target_activated);
final InsetDrawable activeBack = new InsetDrawable(blankActiveDrawable, 0, 0, 0, 0);
//Magnetic target replacement
final Drawable blankInActiveDrawable = res.getDrawable(com.android.internal.R.drawable.ic_lockscreen_lock_pressed);
final Drawable unlockActiveDrawable = res.getDrawable(com.android.internal.R.drawable.ic_lockscreen_unlock_activated);
// Shift targets for landscape lockscreen on phones
mTargetOffset = isLandscape && !mIsScreenLarge ? 2 : 0;
if (mTargetOffset == 2) {
storedDraw.add(new TargetDrawable(res, null));
storedDraw.add(new TargetDrawable(res, null));
}
// Add unlock target
storedDraw.add(new TargetDrawable(res, res.getDrawable(R.drawable.ic_lockscreen_unlock)));
for (int i = 0; i < 8 - mTargetOffset - 1; i++) {
int tmpInset = targetInset;
if (i < mStoredTargets.length) {
String uri = mStoredTargets[i];
if (!uri.equals(GlowPadView.EMPTY_TARGET)) {
try {
Intent in = Intent.parseUri(uri,0);
Drawable front = null;
Drawable back = activeBack;
boolean frontBlank = false;
if (in.hasExtra(GlowPadView.ICON_FILE)) {
String fSource = in.getStringExtra(GlowPadView.ICON_FILE);
if (fSource != null) {
File fPath = new File(fSource);
if (fPath.exists()) {
front = new BitmapDrawable(res, BitmapFactory.decodeFile(fSource));
}
}
} else if (in.hasExtra(GlowPadView.ICON_RESOURCE)) {
String rSource = in.getStringExtra(GlowPadView.ICON_RESOURCE);
String rPackage = in.getStringExtra(GlowPadView.ICON_PACKAGE);
if (rSource != null) {
if (rPackage != null) {
try {
Context rContext = mContext.createPackageContext(rPackage, 0);
int id = rContext.getResources().getIdentifier(rSource, "drawable", rPackage);
front = rContext.getResources().getDrawable(id);
id = rContext.getResources().getIdentifier(rSource.replaceAll("_normal", "_activated"),
"drawable", rPackage);
back = rContext.getResources().getDrawable(id);
tmpInset = 0;
frontBlank = true;
} catch (NameNotFoundException e) {
e.printStackTrace();
} catch (NotFoundException e) {
e.printStackTrace();
}
} else {
front = res.getDrawable(res.getIdentifier(rSource, "drawable", "android"));
back = res.getDrawable(res.getIdentifier(
rSource.replaceAll("_normal", "_activated"), "drawable", "android"));
tmpInset = 0;
frontBlank = true;
}
}
}
if (front == null || back == null) {
ActivityInfo aInfo = in.resolveActivityInfo(packMan, PackageManager.GET_ACTIVITIES);
if (aInfo != null) {
front = aInfo.loadIcon(packMan);
} else {
front = res.getDrawable(android.R.drawable.sym_def_app_icon);
}
}
TargetDrawable nDrawable = new TargetDrawable(res, getLayeredDrawable(back,front, tmpInset, frontBlank));
ComponentName compName = in.getComponent();
if (compName != null) {
String cls = compName.getClassName();
if (cls.equals("com.android.camera.CameraLauncher")) {
nDrawable.setEnabled(!mCameraDisabled);
} else if (cls.equals("SearchActivity")) {
nDrawable.setEnabled(!mSearchDisabled);
}
}
storedDraw.add(nDrawable);
} catch (Exception e) {
storedDraw.add(new TargetDrawable(res, 0));
}
} else {
storedDraw.add(new TargetDrawable(res, getLayeredDrawable(unlockActiveDrawable, blankInActiveDrawable, tmpInset, true)));
}
} else {
storedDraw.add(new TargetDrawable(res, 0));
}
}
mGlowPadView.setTargetResources(storedDraw);
}
}
void doTransition(View view, float to) {
if (mAnim != null) {
mAnim.cancel();
}
mAnim = ObjectAnimator.ofFloat(view, "alpha", to);
mAnim.start();
}
public void setKeyguardCallback(KeyguardSecurityCallback callback) {
mCallback = callback;
}
public void setLockPatternUtils(LockPatternUtils utils) {
mLockPatternUtils = utils;
}
@Override
public void reset() {
mGlowPadView.reset(false);
}
@Override
public boolean needsInput() {
return false;
}
@Override
public void onPause() {
KeyguardUpdateMonitor.getInstance(getContext()).removeCallback(mInfoCallback);
}
@Override
public void onResume(int reason) {
KeyguardUpdateMonitor.getInstance(getContext()).registerCallback(mInfoCallback);
}
@Override
public KeyguardSecurityCallback getCallback() {
return mCallback;
}
@Override
public void showBouncer(int duration) {
mIsBouncing = true;
KeyguardSecurityViewHelper.
showBouncer(mSecurityMessageDisplay, mFadeView, mBouncerFrame, duration);
}
@Override
public void hideBouncer(int duration) {
mIsBouncing = false;
KeyguardSecurityViewHelper.
hideBouncer(mSecurityMessageDisplay, mFadeView, mBouncerFrame, duration);
}
}