Merge "Manual frameworks/base merge from lockhotness (camera)." into jb-mr1-lockscreen-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2e8a98e269
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 MiB |
@@ -3935,14 +3935,6 @@
|
||||
you will be asked to unlock your phone using an email account.\n\n
|
||||
Try again in <xliff:g id="number">%d</xliff:g> seconds.
|
||||
</string>
|
||||
<!-- Placeholder text shown if the camera widget layout is missing or invalid -->
|
||||
<string name="kg_camera_widget_not_found">Camera widget not found</string>
|
||||
<!-- DO NOT TRANSLATE. Context package to use when locating the camera widget -->
|
||||
<string name="kg_camera_widget_context_package">com.google.android.gallery3d</string>
|
||||
<!-- DO NOT TRANSLATE. Layout package to use when locating the camera widget -->
|
||||
<string name="kg_camera_widget_layout_package">com.android.gallery3d</string>
|
||||
<!-- DO NOT TRANSLATE. Layout name to use when locating the camera widget -->
|
||||
<string name="kg_camera_widget_layout_name">keyguard_widget</string>
|
||||
|
||||
<!-- Message shown in dialog when user is attempting to set the music volume above the
|
||||
recommended maximum level for headphones -->
|
||||
|
||||
@@ -1383,10 +1383,6 @@
|
||||
<java-symbol type="string" name="keyguard_password_enter_pin_code" />
|
||||
<java-symbol type="string" name="keyguard_password_enter_puk_code" />
|
||||
<java-symbol type="string" name="keyguard_password_wrong_pin_code" />
|
||||
<java-symbol type="string" name="kg_camera_widget_context_package" />
|
||||
<java-symbol type="string" name="kg_camera_widget_layout_name" />
|
||||
<java-symbol type="string" name="kg_camera_widget_layout_package" />
|
||||
<java-symbol type="string" name="kg_camera_widget_not_found" />
|
||||
<java-symbol type="string" name="lockscreen_carrier_default" />
|
||||
<java-symbol type="string" name="lockscreen_charged" />
|
||||
<java-symbol type="string" name="lockscreen_failed_attempts_almost_at_wipe" />
|
||||
|
||||
@@ -16,34 +16,27 @@
|
||||
|
||||
package com.android.internal.policy.impl.keyguard;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.os.Handler;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ImageView.ScaleType;
|
||||
|
||||
import com.android.internal.policy.impl.keyguard.KeyguardActivityLauncher.CameraWidgetInfo;
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
|
||||
public class CameraWidgetFrame extends KeyguardWidgetFrame {
|
||||
private static final String TAG = CameraWidgetFrame.class.getSimpleName();
|
||||
private static final boolean DEBUG = KeyguardHostView.DEBUG;
|
||||
private static final int WIDGET_ANIMATION_DURATION = 250;
|
||||
|
||||
interface Callbacks {
|
||||
void onLaunchingCamera();
|
||||
@@ -51,45 +44,65 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame {
|
||||
}
|
||||
|
||||
private final Handler mHandler = new Handler();
|
||||
private final LockPatternUtils mLockPatternUtils;
|
||||
private final KeyguardActivityLauncher mActivityLauncher;
|
||||
private final Callbacks mCallbacks;
|
||||
|
||||
private boolean mCameraWidgetFound;
|
||||
private View mWidgetView;
|
||||
private long mLaunchCameraStart;
|
||||
|
||||
private final Runnable mLaunchCameraRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
launchCamera();
|
||||
mActivityLauncher.launchCamera();
|
||||
}};
|
||||
|
||||
public CameraWidgetFrame(Context context, Callbacks callbacks) {
|
||||
private final Runnable mRenderRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
render();
|
||||
}};
|
||||
|
||||
private CameraWidgetFrame(Context context, Callbacks callbacks,
|
||||
KeyguardActivityLauncher activityLauncher) {
|
||||
super(context);
|
||||
|
||||
mLockPatternUtils = new LockPatternUtils(context);
|
||||
mCallbacks = callbacks;
|
||||
|
||||
View cameraView = createCameraView();
|
||||
addView(cameraView);
|
||||
mActivityLauncher = activityLauncher;
|
||||
}
|
||||
|
||||
private View createCameraView() {
|
||||
View cameraView = null;
|
||||
public static CameraWidgetFrame create(Context context, Callbacks callbacks,
|
||||
KeyguardActivityLauncher launcher) {
|
||||
if (context == null || callbacks == null || launcher == null)
|
||||
return null;
|
||||
|
||||
CameraWidgetInfo widgetInfo = launcher.getCameraWidgetInfo();
|
||||
if (widgetInfo == null)
|
||||
return null;
|
||||
View widgetView = widgetInfo.layoutId > 0 ?
|
||||
inflateWidgetView(context, widgetInfo) :
|
||||
inflateGenericWidgetView(context);
|
||||
if (widgetView == null)
|
||||
return null;
|
||||
|
||||
ImageView preview = new ImageView(context);
|
||||
preview.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
|
||||
preview.setScaleType(ScaleType.FIT_CENTER);
|
||||
CameraWidgetFrame cameraWidgetFrame = new CameraWidgetFrame(context, callbacks, launcher);
|
||||
cameraWidgetFrame.addView(preview);
|
||||
cameraWidgetFrame.mWidgetView = widgetView;
|
||||
return cameraWidgetFrame;
|
||||
}
|
||||
|
||||
private static View inflateWidgetView(Context context, CameraWidgetInfo widgetInfo) {
|
||||
View widgetView = null;
|
||||
Exception exception = null;
|
||||
try {
|
||||
String contextPackage = mContext.getString(R.string.kg_camera_widget_context_package);
|
||||
String layoutPackage = mContext.getString(R.string.kg_camera_widget_layout_package);
|
||||
String layoutName = mContext.getString(R.string.kg_camera_widget_layout_name);
|
||||
|
||||
Context cameraContext = mContext.createPackageContext(
|
||||
contextPackage, Context.CONTEXT_RESTRICTED);
|
||||
Context cameraContext = context.createPackageContext(
|
||||
widgetInfo.contextPackage, Context.CONTEXT_RESTRICTED);
|
||||
LayoutInflater cameraInflater = (LayoutInflater)
|
||||
cameraContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
cameraInflater = cameraInflater.cloneInContext(cameraContext);
|
||||
|
||||
int layoutId = cameraContext.getResources()
|
||||
.getIdentifier(layoutName, "layout", layoutPackage);
|
||||
cameraView = cameraInflater.inflate(layoutId, null, false);
|
||||
widgetView = cameraInflater.inflate(widgetInfo.layoutId, null, false);
|
||||
} catch (NameNotFoundException e) {
|
||||
exception = e;
|
||||
} catch (RuntimeException e) {
|
||||
@@ -98,27 +111,44 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame {
|
||||
if (exception != null) {
|
||||
Log.w(TAG, "Error creating camera widget view", exception);
|
||||
}
|
||||
if (cameraView == null) {
|
||||
cameraView = createCameraErrorView();
|
||||
} else {
|
||||
mCameraWidgetFound = true;
|
||||
}
|
||||
return cameraView;
|
||||
return widgetView;
|
||||
}
|
||||
|
||||
private View createCameraErrorView() {
|
||||
TextView errorView = new TextView(mContext);
|
||||
errorView.setGravity(Gravity.CENTER);
|
||||
errorView.setText(R.string.kg_camera_widget_not_found);
|
||||
errorView.setBackgroundColor(Color.argb(127, 0, 0, 0));
|
||||
return errorView;
|
||||
private static View inflateGenericWidgetView(Context context) {
|
||||
ImageView iv = new ImageView(context);
|
||||
iv.setImageResource(com.android.internal.R.drawable.ic_lockscreen_camera);
|
||||
iv.setScaleType(ScaleType.CENTER);
|
||||
iv.setBackgroundColor(Color.argb(127, 0, 0, 0));
|
||||
return iv;
|
||||
}
|
||||
|
||||
public void render() {
|
||||
int width = getRootView().getWidth();
|
||||
int height = getRootView().getHeight();
|
||||
if (DEBUG) Log.d(TAG, String.format("render [%sx%s]", width, height));
|
||||
Bitmap offscreen = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Canvas c = new Canvas(offscreen);
|
||||
mWidgetView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
|
||||
mWidgetView.layout(0, 0, width, height);
|
||||
mWidgetView.draw(c);
|
||||
((ImageView)getChildAt(0)).setImageBitmap(offscreen);
|
||||
}
|
||||
|
||||
private void transitionToCamera() {
|
||||
int startWidth = getChildAt(0).getWidth();
|
||||
int startHeight = getChildAt(0).getHeight();
|
||||
|
||||
int finishWidth = getRootView().getWidth();
|
||||
int finishHeight = getRootView().getHeight();
|
||||
|
||||
float scaleX = (float) finishWidth / startWidth;
|
||||
float scaleY = (float) finishHeight / startHeight;
|
||||
|
||||
float scale = Math.max(scaleX, scaleY);
|
||||
animate()
|
||||
.scaleX(1.22f) // TODO compute this at runtime
|
||||
.scaleY(1.22f)
|
||||
.setDuration(250)
|
||||
.scaleX(scale)
|
||||
.scaleY(scale)
|
||||
.setDuration(WIDGET_ANIMATION_DURATION)
|
||||
.withEndAction(mLaunchCameraRunnable)
|
||||
.start();
|
||||
mCallbacks.onLaunchingCamera();
|
||||
@@ -127,7 +157,6 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame {
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasWindowFocus) {
|
||||
super.onWindowFocusChanged(hasWindowFocus);
|
||||
if (!mCameraWidgetFound) return;
|
||||
|
||||
if (!hasWindowFocus) {
|
||||
if (mLaunchCameraStart > 0) {
|
||||
@@ -141,8 +170,6 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame {
|
||||
|
||||
@Override
|
||||
public void onActive(boolean isActive) {
|
||||
if (!mCameraWidgetFound) return;
|
||||
|
||||
if (isActive) {
|
||||
mHandler.post(new Runnable(){
|
||||
@Override
|
||||
@@ -165,85 +192,9 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame {
|
||||
setScaleY(1);
|
||||
}
|
||||
|
||||
// =========== from KeyguardSelectorView ===========
|
||||
protected void launchCamera() {
|
||||
mLaunchCameraStart = SystemClock.uptimeMillis();
|
||||
boolean isSecure = mLockPatternUtils.isSecure();
|
||||
if (DEBUG) Log.d(TAG, "launchCamera " + (isSecure?"(secure)":"(insecure)"));
|
||||
if (isSecure) {
|
||||
// Launch the secure version of the camera
|
||||
final Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
|
||||
|
||||
if (wouldLaunchResolverActivity(intent)) {
|
||||
// TODO: Show disambiguation dialog instead.
|
||||
// For now, we'll treat this like launching any other app from secure keyguard.
|
||||
// When they do, user sees the system's ResolverActivity which lets them choose
|
||||
// which secure camera to use.
|
||||
launchActivity(intent, false);
|
||||
} else {
|
||||
launchActivity(intent, true);
|
||||
}
|
||||
} else {
|
||||
// Launch the normal camera
|
||||
launchActivity(new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA), false);
|
||||
}
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
mHandler.post(mRenderRunnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches the said intent for the current foreground user.
|
||||
* @param intent
|
||||
* @param showsWhileLocked true if the activity can be run on top of keyguard.
|
||||
* See {@link WindowManager#FLAG_SHOW_WHEN_LOCKED}
|
||||
*/
|
||||
private void launchActivity(final Intent intent, boolean showsWhileLocked) {
|
||||
intent.addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
boolean isSecure = mLockPatternUtils.isSecure();
|
||||
if (!isSecure || showsWhileLocked) {
|
||||
if (!isSecure) try {
|
||||
ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
|
||||
} catch (RemoteException e) {
|
||||
Log.w(TAG, "can't dismiss keyguard on launch");
|
||||
}
|
||||
try {
|
||||
mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.w(TAG, "Activity not found for intent + " + intent.getAction());
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "TODO: handle this case");
|
||||
onCameraLaunched();
|
||||
// // Create a runnable to start the activity and ask the user to enter their
|
||||
// // credentials.
|
||||
// mCallback.setOnDismissRunnable(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
|
||||
// }
|
||||
// });
|
||||
// mCallback.dismiss(false);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean wouldLaunchResolverActivity(Intent intent) {
|
||||
PackageManager packageManager = mContext.getPackageManager();
|
||||
ResolveInfo resolved = packageManager.resolveActivityAsUser(intent,
|
||||
PackageManager.MATCH_DEFAULT_ONLY, mLockPatternUtils.getCurrentUser());
|
||||
final List<ResolveInfo> appList = packageManager.queryIntentActivitiesAsUser(
|
||||
intent, PackageManager.MATCH_DEFAULT_ONLY, mLockPatternUtils.getCurrentUser());
|
||||
// If the list contains the above resolved activity, then it can't be
|
||||
// ResolverActivity itself.
|
||||
for (int i = 0; i < appList.size(); i++) {
|
||||
ResolveInfo tmp = appList.get(i);
|
||||
if (tmp.activityInfo.name.equals(resolved.activityInfo.name)
|
||||
&& tmp.activityInfo.packageName.equals(resolved.activityInfo.packageName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* 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 android.app.ActivityManagerNative;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class KeyguardActivityLauncher {
|
||||
private static final String TAG = KeyguardActivityLauncher.class.getSimpleName();
|
||||
private static final boolean DEBUG = KeyguardHostView.DEBUG;
|
||||
private static final String META_DATA_KEYGUARD_LAYOUT = "com.android.keyguard.layout";
|
||||
private static final Intent SECURE_CAMERA_INTENT =
|
||||
new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
|
||||
private static final Intent INSECURE_CAMERA_INTENT =
|
||||
new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
|
||||
|
||||
abstract Context getContext();
|
||||
|
||||
abstract KeyguardSecurityCallback getCallback();
|
||||
|
||||
abstract LockPatternUtils getLockPatternUtils();
|
||||
|
||||
public static class CameraWidgetInfo {
|
||||
public String contextPackage;
|
||||
public int layoutId;
|
||||
}
|
||||
|
||||
public CameraWidgetInfo getCameraWidgetInfo() {
|
||||
CameraWidgetInfo info = new CameraWidgetInfo();
|
||||
Intent intent = getCameraIntent();
|
||||
PackageManager packageManager = getContext().getPackageManager();
|
||||
final List<ResolveInfo> appList = packageManager.queryIntentActivitiesAsUser(
|
||||
intent, PackageManager.MATCH_DEFAULT_ONLY, getLockPatternUtils().getCurrentUser());
|
||||
if (appList.size() == 0) {
|
||||
if (DEBUG) Log.d(TAG, "getCameraWidgetInfo(): Nothing found");
|
||||
return null;
|
||||
}
|
||||
ResolveInfo resolved = packageManager.resolveActivityAsUser(intent,
|
||||
PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
|
||||
getLockPatternUtils().getCurrentUser());
|
||||
if (DEBUG) Log.d(TAG, "getCameraWidgetInfo(): resolved: " + resolved);
|
||||
if (wouldLaunchResolverActivity(resolved, appList)) {
|
||||
if (DEBUG) Log.d(TAG, "getCameraWidgetInfo(): Would launch resolver");
|
||||
return info;
|
||||
}
|
||||
if (resolved == null || resolved.activityInfo == null) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.activityInfo.metaData == null || resolved.activityInfo.metaData.isEmpty()) {
|
||||
if (DEBUG) Log.d(TAG, "getCameraWidgetInfo(): no metadata found");
|
||||
return info;
|
||||
}
|
||||
int layoutId = resolved.activityInfo.metaData.getInt(META_DATA_KEYGUARD_LAYOUT);
|
||||
if (layoutId == 0) {
|
||||
if (DEBUG) Log.d(TAG, "getCameraWidgetInfo(): no layout specified");
|
||||
return info;
|
||||
}
|
||||
info.contextPackage = resolved.activityInfo.packageName;
|
||||
info.layoutId = layoutId;
|
||||
return info;
|
||||
}
|
||||
|
||||
public void launchCamera() {
|
||||
LockPatternUtils lockPatternUtils = getLockPatternUtils();
|
||||
if (lockPatternUtils.isSecure()) {
|
||||
// Launch the secure version of the camera
|
||||
if (wouldLaunchResolverActivity(SECURE_CAMERA_INTENT)) {
|
||||
// TODO: Show disambiguation dialog instead.
|
||||
// For now, we'll treat this like launching any other app from secure keyguard.
|
||||
// When they do, user sees the system's ResolverActivity which lets them choose
|
||||
// which secure camera to use.
|
||||
launchActivity(SECURE_CAMERA_INTENT, false);
|
||||
} else {
|
||||
launchActivity(SECURE_CAMERA_INTENT, true);
|
||||
}
|
||||
} else {
|
||||
// wouldLaunchResolverActivity(new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA));
|
||||
// Launch the normal camera
|
||||
launchActivity(INSECURE_CAMERA_INTENT, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches the said intent for the current foreground user.
|
||||
* @param intent
|
||||
* @param showsWhileLocked true if the activity can be run on top of keyguard.
|
||||
* See {@link WindowManager#FLAG_SHOW_WHEN_LOCKED}
|
||||
*/
|
||||
public void launchActivity(final Intent intent, boolean showsWhileLocked) {
|
||||
final Context context = getContext();
|
||||
LockPatternUtils lockPatternUtils = getLockPatternUtils();
|
||||
intent.addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
boolean isSecure = lockPatternUtils.isSecure();
|
||||
if (!isSecure || showsWhileLocked) {
|
||||
if (!isSecure) try {
|
||||
ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
|
||||
} catch (RemoteException e) {
|
||||
Log.w(TAG, "can't dismiss keyguard on launch");
|
||||
}
|
||||
try {
|
||||
context.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.w(TAG, "Activity not found for intent + " + intent.getAction());
|
||||
}
|
||||
} else {
|
||||
// Create a runnable to start the activity and ask the user to enter their
|
||||
// credentials.
|
||||
KeyguardSecurityCallback callback = getCallback();
|
||||
callback.setOnDismissRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
context.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
|
||||
}
|
||||
});
|
||||
callback.dismiss(false);
|
||||
}
|
||||
}
|
||||
|
||||
private Intent getCameraIntent() {
|
||||
return getLockPatternUtils().isSecure() ? SECURE_CAMERA_INTENT : INSECURE_CAMERA_INTENT;
|
||||
}
|
||||
|
||||
private boolean wouldLaunchResolverActivity(Intent intent) {
|
||||
PackageManager packageManager = getContext().getPackageManager();
|
||||
ResolveInfo resolved = packageManager.resolveActivityAsUser(intent,
|
||||
PackageManager.MATCH_DEFAULT_ONLY, getLockPatternUtils().getCurrentUser());
|
||||
List<ResolveInfo> appList = packageManager.queryIntentActivitiesAsUser(
|
||||
intent, PackageManager.MATCH_DEFAULT_ONLY, getLockPatternUtils().getCurrentUser());
|
||||
return wouldLaunchResolverActivity(resolved, appList);
|
||||
}
|
||||
|
||||
private boolean wouldLaunchResolverActivity(ResolveInfo resolved, List<ResolveInfo> appList) {
|
||||
// If the list contains the above resolved activity, then it can't be
|
||||
// ResolverActivity itself.
|
||||
for (int i = 0; i < appList.size(); i++) {
|
||||
ResolveInfo tmp = appList.get(i);
|
||||
if (tmp.activityInfo.name.equals(resolved.activityInfo.name)
|
||||
&& tmp.activityInfo.packageName.equals(resolved.activityInfo.packageName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,6 @@ import android.view.WindowManager;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.RemoteViews.OnClickHandler;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ViewFlipper;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.policy.impl.keyguard.KeyguardSecurityModel.SecurityMode;
|
||||
@@ -831,6 +830,46 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
}
|
||||
}
|
||||
|
||||
private final CameraWidgetFrame.Callbacks mCameraWidgetCallbacks =
|
||||
new CameraWidgetFrame.Callbacks() {
|
||||
@Override
|
||||
public void onLaunchingCamera() {
|
||||
SlidingChallengeLayout slider = locateSlider();
|
||||
if (slider != null) {
|
||||
slider.showHandle(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraLaunched() {
|
||||
SlidingChallengeLayout slider = locateSlider();
|
||||
if (slider != null) {
|
||||
slider.showHandle(true);
|
||||
}
|
||||
mAppWidgetContainer.scrollLeft();
|
||||
}
|
||||
|
||||
private SlidingChallengeLayout locateSlider() {
|
||||
return (SlidingChallengeLayout) findViewById(R.id.sliding_layout);
|
||||
}
|
||||
};
|
||||
|
||||
private final KeyguardActivityLauncher mActivityLauncher = new KeyguardActivityLauncher() {
|
||||
@Override
|
||||
Context getContext() {
|
||||
return mContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
KeyguardSecurityCallback getCallback() {
|
||||
return mCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
LockPatternUtils getLockPatternUtils() {
|
||||
return mLockPatternUtils;
|
||||
}};
|
||||
|
||||
private void addDefaultWidgets() {
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
inflater.inflate(R.layout.keyguard_transport_control_view, this, true);
|
||||
@@ -840,30 +879,11 @@ public class KeyguardHostView extends KeyguardViewBase {
|
||||
View statusWidget = inflater.inflate(R.layout.keyguard_status_view, null, true);
|
||||
mAppWidgetContainer.addWidget(statusWidget);
|
||||
if (mContext.getResources().getBoolean(R.bool.kg_enable_camera_default_widget)) {
|
||||
View cameraWidget = new CameraWidgetFrame(mContext, new CameraWidgetFrame.Callbacks() {
|
||||
|
||||
private SlidingChallengeLayout locateSlider() {
|
||||
return (SlidingChallengeLayout) findViewById(R.id.sliding_layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLaunchingCamera() {
|
||||
SlidingChallengeLayout slider = locateSlider();
|
||||
if (slider != null) {
|
||||
slider.showHandle(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraLaunched() {
|
||||
SlidingChallengeLayout slider = locateSlider();
|
||||
if (slider != null) {
|
||||
slider.showHandle(true);
|
||||
}
|
||||
mAppWidgetContainer.scrollLeft();
|
||||
}
|
||||
});
|
||||
mAppWidgetContainer.addWidget(cameraWidget);
|
||||
View cameraWidget =
|
||||
CameraWidgetFrame.create(mContext, mCameraWidgetCallbacks, mActivityLauncher);
|
||||
if (cameraWidget != null) {
|
||||
mAppWidgetContainer.addWidget(cameraWidget);
|
||||
}
|
||||
}
|
||||
|
||||
View addWidgetButton = addWidget.findViewById(R.id.keyguard_add_widget_view);
|
||||
|
||||
@@ -16,18 +16,12 @@
|
||||
package com.android.internal.policy.impl.keyguard;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.SearchManager;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.Settings;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
@@ -41,8 +35,6 @@ import com.android.internal.widget.multiwaveview.GlowPadView;
|
||||
import com.android.internal.widget.multiwaveview.GlowPadView.OnTriggerListener;
|
||||
import com.android.internal.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class KeyguardSelectorView extends LinearLayout implements KeyguardSecurityView {
|
||||
private static final boolean DEBUG = KeyguardHostView.DEBUG;
|
||||
private static final String TAG = "SecuritySelectorView";
|
||||
@@ -67,7 +59,7 @@ public class KeyguardSelectorView extends LinearLayout implements KeyguardSecuri
|
||||
((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
|
||||
.getAssistIntent(mContext, UserHandle.USER_CURRENT);
|
||||
if (assistIntent != null) {
|
||||
launchActivity(assistIntent, false);
|
||||
mActivityLauncher.launchActivity(assistIntent, false);
|
||||
} else {
|
||||
Log.w(TAG, "Failed to get intent for assist activity");
|
||||
}
|
||||
@@ -75,7 +67,7 @@ public class KeyguardSelectorView extends LinearLayout implements KeyguardSecuri
|
||||
break;
|
||||
|
||||
case com.android.internal.R.drawable.ic_lockscreen_camera:
|
||||
launchCamera();
|
||||
mActivityLauncher.launchCamera();
|
||||
mCallback.userActivity(0);
|
||||
break;
|
||||
|
||||
@@ -119,49 +111,27 @@ public class KeyguardSelectorView extends LinearLayout implements KeyguardSecuri
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private boolean wouldLaunchResolverActivity(Intent intent) {
|
||||
PackageManager packageManager = mContext.getPackageManager();
|
||||
ResolveInfo resolved = packageManager.resolveActivityAsUser(intent,
|
||||
PackageManager.MATCH_DEFAULT_ONLY, mLockPatternUtils.getCurrentUser());
|
||||
final List<ResolveInfo> appList = packageManager.queryIntentActivitiesAsUser(
|
||||
intent, PackageManager.MATCH_DEFAULT_ONLY, mLockPatternUtils.getCurrentUser());
|
||||
// If the list contains the above resolved activity, then it can't be
|
||||
// ResolverActivity itself.
|
||||
for (int i = 0; i < appList.size(); i++) {
|
||||
ResolveInfo tmp = appList.get(i);
|
||||
if (tmp.activityInfo.name.equals(resolved.activityInfo.name)
|
||||
&& tmp.activityInfo.packageName.equals(resolved.activityInfo.packageName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void launchCamera() {
|
||||
if (mLockPatternUtils.isSecure()) {
|
||||
// Launch the secure version of the camera
|
||||
final Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
|
||||
|
||||
if (wouldLaunchResolverActivity(intent)) {
|
||||
// TODO: Show disambiguation dialog instead.
|
||||
// For now, we'll treat this like launching any other app from secure keyguard.
|
||||
// When they do, user sees the system's ResolverActivity which lets them choose
|
||||
// which secure camera to use.
|
||||
launchActivity(intent, false);
|
||||
} else {
|
||||
launchActivity(intent, true);
|
||||
}
|
||||
} else {
|
||||
// Launch the normal camera
|
||||
launchActivity(new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA), false);
|
||||
}
|
||||
}
|
||||
|
||||
public KeyguardSelectorView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mLockPatternUtils = new LockPatternUtils(getContext());
|
||||
@@ -267,42 +237,6 @@ public class KeyguardSelectorView extends LinearLayout implements KeyguardSecuri
|
||||
mLockPatternUtils = utils;
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches the said intent for the current foreground user.
|
||||
* @param intent
|
||||
* @param showsWhileLocked true if the activity can be run on top of keyguard.
|
||||
* See {@link WindowManager#FLAG_SHOW_WHEN_LOCKED}
|
||||
*/
|
||||
private void launchActivity(final Intent intent, boolean showsWhileLocked) {
|
||||
intent.addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
boolean isSecure = mLockPatternUtils.isSecure();
|
||||
if (!isSecure || showsWhileLocked) {
|
||||
if (!isSecure) try {
|
||||
ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
|
||||
} catch (RemoteException e) {
|
||||
Log.w(TAG, "can't dismiss keyguard on launch");
|
||||
}
|
||||
try {
|
||||
mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.w(TAG, "Activity not found for intent + " + intent.getAction());
|
||||
}
|
||||
} else {
|
||||
// Create a runnable to start the activity and ask the user to enter their
|
||||
// credentials.
|
||||
mCallback.setOnDismissRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
|
||||
}
|
||||
});
|
||||
mCallback.dismiss(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
mGlowPadView.reset(false);
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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 android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
public class SecureCamera extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(new FrameLayout(this));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user