Project

General

Profile

Feature #1383 ยป 0001-make-Camera-work-on-lock-screen-secure-mode.patch

patch - Wolfgang Wiedmeyer, 10/09/2015 08:38 PM

View differences:

AndroidManifest.xml
<action android:name="android.media.action.STILL_IMAGE_CAMERA" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE_SECURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.STILL_IMAGE_CAMERA_SECURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.android.camera.VideoCamera"
android:label="@string/video_camera_label"
src/com/android/camera/ActivityBase.java
import android.app.Activity;
import android.app.KeyguardManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.hardware.Camera;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.WindowManager;
/**
* Superclass of Camera and VideoCamera activities.
......
private boolean mOnResumePending;
private Intent mResultDataForTesting;
protected Camera mCameraDevice;
// settings for lock screen camera
protected static final String INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE =
"android.media.action.STILL_IMAGE_CAMERA_SECURE";
protected static final String ACTION_IMAGE_CAPTURE_SECURE =
"android.media.action.IMAGE_CAPTURE_SECURE";
@Override
public void onCreate(Bundle icicle) {
......
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
super.onCreate(icicle);
if(isCameraSecure()){
Log.v(TAG, "Starting in secure camera mode.");
// show on lock screen
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
// Filter for screen off so that we can finish secure camera activity
// when screen is off.
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
registerReceiver(mScreenOffReceiver, filter);
}
}
@Override
......
@Override
protected void onResume() {
super.onResume();
onResumeAfterSuper();
// Don't grab the camera if in use by lockscreen. For example, face
// unlock may be using the camera. Camera may be already opened in
// onCreate. doOnResume should continue if mCameraDevice != null.
......
@Override
protected void onDestroy() {
if (isCameraSecure()) {
unregisterReceiver(mScreenOffReceiver);
}
PopupManager.removeInstance(this);
super.onDestroy();
}
private boolean isKeyguardLocked() {
protected boolean isKeyguardLocked() {
KeyguardManager kgm = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
if (LOGV) {
if (kgm != null) {
......
// isKeyguardSecure excludes the slide lock case.
return (kgm != null) && kgm.isKeyguardLocked() && kgm.isKeyguardSecure();
}
protected boolean isCameraSecure() {
// Check if this is in the secure camera mode.
String action = getIntent().getAction();
if (INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(action)
|| ACTION_IMAGE_CAPTURE_SECURE.equals(action)){
return true;
}
else{
return isKeyguardLocked();
}
}
// close activity when screen turns off
protected BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "Finishing because screen turned off.");
finish();
}
};
// implemented in class Camera, class Video needs empty one
public void onResumeAfterSuper() {};
}
src/com/android/camera/Camera.java
private static final int SHOW_TAP_TO_FOCUS_TOAST = 6;
private static final int UPDATE_THUMBNAIL = 7;
// This is the delay before we execute onResume tasks when coming
// from the lock screen, to allow time for onPause to execute.
private static final int ON_RESUME_TASKS_DELAY_MSEC = 20;
// The subset of parameters we need to update in setCameraParameters().
private static final int UPDATE_PARAM_INITIALIZE = 1;
private static final int UPDATE_PARAM_ZOOM = 2;
......
@OnClickAttr
public void onThumbnailClicked(View v) {
if (isCameraIdle() && mThumbnail != null) {
if (isCameraIdle() && mThumbnail != null && !isCameraSecure()) {
showSharePopup();
}
}
......
mAeLockSupported = mInitialParams.isAutoExposureLockSupported();
mAwbLockSupported = mInitialParams.isAutoWhiteBalanceLockSupported();
}
@Override
public void onResumeAfterSuper() {
// Add delay on resume from lock screen only, in order to to speed up
// the onResume --> onPause --> onResume cycle from lock screen.
// Don't do always because letting go of thread can cause delay.
String action = getIntent().getAction();
if (isCameraSecure()) {
Log.v(TAG, "On resume, from lock screen.");
// Note: onPauseAfterSuper() will delete this runnable, so we will
// at most have 1 copy queued up.
mHandler.postDelayed(new Runnable() {
public void run() {
doOnResume();
}
}, ON_RESUME_TASKS_DELAY_MSEC);
// show on lock screen
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
} else {
Log.v(TAG, "On resume.");
doOnResume();
}
}
}
src/com/android/camera/VideoCamera.java
@OnClickAttr
public void onThumbnailClicked(View v) {
if (!mMediaRecorderRecording && mThumbnail != null) {
if (!mMediaRecorderRecording && mThumbnail != null && !isCameraSecure()) {
showSharePopup();
}
}
    (1-1/1)