summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWu-cheng Li <wuchengli@google.com>2011-05-30 20:03:37 +0800
committerWu-cheng Li <wuchengli@google.com>2011-06-17 11:21:27 +0800
commitdfb6f208e3f5dd7d68bcaade644aa1d1f1f0a98f (patch)
tree27c1c0cfe663fa38f052f6da0a0ecfd48dea408d /src
parent84a4d3eb7c9a3e33e1898729a66671332fe81577 (diff)
downloadLegacyCamera-dfb6f208e3f5dd7d68bcaade644aa1d1f1f0a98f.zip
LegacyCamera-dfb6f208e3f5dd7d68bcaade644aa1d1f1f0a98f.tar.gz
LegacyCamera-dfb6f208e3f5dd7d68bcaade644aa1d1f1f0a98f.tar.bz2
Check if device policay manager has disabled camera.
Show the corresponding message if that is the case. bug:4185309 Change-Id: I0f4a5ac577f13331685f8e7343bab6317f96c3d8
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/Camera.java47
-rw-r--r--src/com/android/camera/CameraDisabledException.java24
-rw-r--r--src/com/android/camera/Util.java37
-rw-r--r--src/com/android/camera/VideoCamera.java43
4 files changed, 84 insertions, 67 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java
index 96350d9..aef5676 100644
--- a/src/com/android/camera/Camera.java
+++ b/src/com/android/camera/Camera.java
@@ -35,7 +35,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
-import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.hardware.Camera.Area;
@@ -156,6 +155,7 @@ public class Camera extends ActivityBase implements View.OnClickListener,
private GestureDetector mPopupGestureDetector;
private SwitcherSet mSwitcher;
private boolean mOpenCameraFail = false;
+ private boolean mCameraDisabled = false;
private View mPreviewFrame; // Preview frame area.
private View mPreviewBorder;
@@ -992,6 +992,7 @@ public class Camera extends ActivityBase implements View.OnClickListener,
// we need to reset exposure for the preview
resetExposureCompensation();
+
/*
* To reduce startup time, we start the preview in another thread.
* We make sure the preview is started at the end of onCreate.
@@ -999,10 +1000,13 @@ public class Camera extends ActivityBase implements View.OnClickListener,
Thread startPreviewThread = new Thread(new Runnable() {
public void run() {
try {
- openCamera();
+ mCameraDevice = Util.openCamera(Camera.this, mCameraId);
+ mInitialParams = mCameraDevice.getParameters();
startPreview();
} catch (CameraHardwareException e) {
mOpenCameraFail = true;
+ } catch (CameraDisabledException e) {
+ mCameraDisabled = true;
}
}
});
@@ -1034,7 +1038,10 @@ public class Camera extends ActivityBase implements View.OnClickListener,
try {
startPreviewThread.join();
if (mOpenCameraFail) {
- showCameraErrorAndFinish();
+ Util.showErrorAndFinish(this, R.string.cannot_connect_camera);
+ return;
+ } else if (mCameraDisabled) {
+ Util.showErrorAndFinish(this, R.string.camera_disabled);
return;
}
} catch (InterruptedException ex) {
@@ -1437,7 +1444,7 @@ public class Camera extends ActivityBase implements View.OnClickListener,
protected void onResume() {
super.onResume();
mPausing = false;
- if (mOpenCameraFail) return;
+ if (mOpenCameraFail || mCameraDisabled) return;
mJpegPictureCallbackTime = 0;
mZoomValue = 0;
@@ -1447,11 +1454,15 @@ public class Camera extends ActivityBase implements View.OnClickListener,
// Start the preview if it is not started.
if (mCameraState == PREVIEW_STOPPED) {
try {
- openCamera();
+ mCameraDevice = Util.openCamera(this, mCameraId);
+ mInitialParams = mCameraDevice.getParameters();
resetExposureCompensation();
startPreview();
} catch(CameraHardwareException e) {
- showCameraErrorAndFinish();
+ Util.showErrorAndFinish(this, R.string.cannot_connect_camera);
+ return;
+ } catch(CameraDisabledException e) {
+ Util.showErrorAndFinish(this, R.string.camera_disabled);
return;
}
}
@@ -1867,30 +1878,6 @@ public class Camera extends ActivityBase implements View.OnClickListener,
}
}
- private void openCamera() throws CameraHardwareException {
- try {
- if (mCameraDevice == null) {
- mCameraDevice = CameraHolder.instance().open(mCameraId);
- mInitialParams = mCameraDevice.getParameters();
- }
- } catch (CameraHardwareException e) {
- // In eng build, we throw the exception so that test tool
- // can detect it and report it
- if ("eng".equals(Build.TYPE)) {
- throw new RuntimeException("openCamera failed", e);
- } else {
- throw e;
- }
- }
- }
-
- private void showCameraErrorAndFinish() {
- Resources ress = getResources();
- Util.showFatalErrorAndFinish(Camera.this,
- ress.getString(R.string.camera_error_title),
- ress.getString(R.string.cannot_connect_camera));
- }
-
private void setPreviewDisplay(SurfaceHolder holder) {
try {
mCameraDevice.setPreviewDisplay(holder);
diff --git a/src/com/android/camera/CameraDisabledException.java b/src/com/android/camera/CameraDisabledException.java
new file mode 100644
index 0000000..512809b
--- /dev/null
+++ b/src/com/android/camera/CameraDisabledException.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2011 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.camera;
+
+/**
+ * This class represents the condition that device policy manager has disabled
+ * the camera.
+ */
+public class CameraDisabledException extends Exception {
+}
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java
index bf33dc9..7e5825c 100644
--- a/src/com/android/camera/Util.java
+++ b/src/com/android/camera/Util.java
@@ -18,9 +18,10 @@ package com.android.camera;
import android.app.Activity;
import android.app.AlertDialog;
+import android.app.admin.DevicePolicyManager;
import android.content.ActivityNotFoundException;
-import android.content.Context;
import android.content.ContentResolver;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
@@ -30,14 +31,13 @@ import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.Size;
import android.net.Uri;
+import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Display;
import android.view.Surface;
import android.view.View;
-import android.view.animation.Animation;
-import android.view.animation.TranslateAnimation;
import java.io.Closeable;
import java.io.IOException;
@@ -204,8 +204,29 @@ public class Util {
}
}
- public static void showFatalErrorAndFinish(
- final Activity activity, String title, String message) {
+ public static android.hardware.Camera openCamera(Activity activity, int cameraId)
+ throws CameraHardwareException, CameraDisabledException {
+ // Check if device policy has disabled the camera.
+ DevicePolicyManager dpm = (DevicePolicyManager) activity.getSystemService(
+ Context.DEVICE_POLICY_SERVICE);
+ if (dpm.getCameraDisabled(null)) {
+ throw new CameraDisabledException();
+ }
+
+ try {
+ return CameraHolder.instance().open(cameraId);
+ } catch (CameraHardwareException e) {
+ // In eng build, we throw the exception so that test tool
+ // can detect it and report it
+ if ("eng".equals(Build.TYPE)) {
+ throw new RuntimeException("openCamera failed", e);
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ public static void showErrorAndFinish(final Activity activity, int msgId) {
DialogInterface.OnClickListener buttonListener =
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
@@ -215,8 +236,8 @@ public class Util {
new AlertDialog.Builder(activity)
.setCancelable(false)
.setIconAttribute(android.R.attr.alertDialogIcon)
- .setTitle(title)
- .setMessage(message)
+ .setTitle(R.string.camera_error_title)
+ .setMessage(msgId)
.setNeutralButton(R.string.details_ok, buttonListener)
.show();
}
@@ -337,7 +358,7 @@ public class Util {
}
}
- /**
+ /**
* Returns whether the device is voice-capable (meaning, it can do MMS).
*/
public static boolean isMmsCapable(Context context) {
diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java
index d9aa4aa..b28b840 100644
--- a/src/com/android/camera/VideoCamera.java
+++ b/src/com/android/camera/VideoCamera.java
@@ -31,7 +31,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
-import android.content.res.Resources;
import android.graphics.Bitmap;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.Parameters;
@@ -166,6 +165,7 @@ public class VideoCamera extends ActivityBase
private boolean mQuickCapture;
private boolean mOpenCameraFail = false;
+ private boolean mCameraDisabled = false;
private long mStorageSpace;
@@ -310,13 +310,6 @@ public class VideoCamera extends ActivityBase
return dateFormat.format(date);
}
- private void showCameraErrorAndFinish() {
- Resources ress = getResources();
- Util.showFatalErrorAndFinish(VideoCamera.this,
- ress.getString(R.string.camera_error_title),
- ress.getString(R.string.cannot_connect_camera));
- }
-
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -356,11 +349,13 @@ public class VideoCamera extends ActivityBase
Thread startPreviewThread = new Thread(new Runnable() {
public void run() {
try {
- openCamera();
+ mCameraDevice = Util.openCamera(VideoCamera.this, mCameraId);
readVideoPreferences();
startPreview();
} catch(CameraHardwareException e) {
mOpenCameraFail = true;
+ } catch(CameraDisabledException e) {
+ mCameraDisabled = true;
}
}
});
@@ -425,7 +420,10 @@ public class VideoCamera extends ActivityBase
try {
startPreviewThread.join();
if (mOpenCameraFail) {
- showCameraErrorAndFinish();
+ Util.showErrorAndFinish(this, R.string.cannot_connect_camera);
+ return;
+ } else if (mCameraDisabled) {
+ Util.showErrorAndFinish(this, R.string.camera_disabled);
return;
}
} catch (InterruptedException ex) {
@@ -824,7 +822,7 @@ public class VideoCamera extends ActivityBase
protected void onResume() {
super.onResume();
mPausing = false;
- if (mOpenCameraFail) return;
+ if (mOpenCameraFail || mCameraDisabled) return;
mReviewImage.setVisibility(View.GONE);
@@ -833,12 +831,15 @@ public class VideoCamera extends ActivityBase
mOrientationListener.enable();
if (!mPreviewing) {
try {
- openCamera();
+ mCameraDevice = Util.openCamera(this, mCameraId);
readVideoPreferences();
resizeForPreviewAspectRatio();
startPreview();
} catch(CameraHardwareException e) {
- showCameraErrorAndFinish();
+ Util.showErrorAndFinish(this, R.string.cannot_connect_camera);
+ return;
+ } catch(CameraDisabledException e) {
+ Util.showErrorAndFinish(this, R.string.camera_disabled);
return;
}
}
@@ -884,22 +885,6 @@ public class VideoCamera extends ActivityBase
}
}
- private void openCamera() throws CameraHardwareException {
- try {
- if (mCameraDevice == null) {
- mCameraDevice = CameraHolder.instance().open(mCameraId);
- }
- } catch (CameraHardwareException e) {
- // In eng build, we throw the exception so that test tool
- // can detect it and report it
- if ("eng".equals(Build.TYPE)) {
- throw new RuntimeException("openCamera failed", e);
- } else {
- throw e;
- }
- }
- }
-
private void startPreview() {
Log.v(TAG, "startPreview");
mCameraDevice.setErrorCallback(mErrorCallback);