diff options
author | Wu-cheng Li <wuchengli@google.com> | 2011-05-30 20:03:37 +0800 |
---|---|---|
committer | Wu-cheng Li <wuchengli@google.com> | 2011-06-17 11:21:27 +0800 |
commit | dfb6f208e3f5dd7d68bcaade644aa1d1f1f0a98f (patch) | |
tree | 27c1c0cfe663fa38f052f6da0a0ecfd48dea408d /src/com/android/camera/Util.java | |
parent | 84a4d3eb7c9a3e33e1898729a66671332fe81577 (diff) | |
download | LegacyCamera-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/com/android/camera/Util.java')
-rw-r--r-- | src/com/android/camera/Util.java | 37 |
1 files changed, 29 insertions, 8 deletions
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) { |