diff options
Diffstat (limited to 'src/com/android/camera/ActivityBase.java')
-rw-r--r-- | src/com/android/camera/ActivityBase.java | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/com/android/camera/ActivityBase.java b/src/com/android/camera/ActivityBase.java index e399421..4a29469 100644 --- a/src/com/android/camera/ActivityBase.java +++ b/src/com/android/camera/ActivityBase.java @@ -20,13 +20,16 @@ import com.android.camera.ui.PopupManager; 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. @@ -38,6 +41,11 @@ abstract public class ActivityBase extends Activity { 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) { @@ -47,6 +55,18 @@ abstract public class ActivityBase extends Activity { 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 @@ -62,6 +82,7 @@ abstract public class ActivityBase extends Activity { @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. @@ -127,11 +148,14 @@ abstract public class ActivityBase extends Activity { @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) { @@ -142,4 +166,28 @@ abstract public class ActivityBase extends Activity { // 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() {}; } |