Merge "Camera and MediaRecorder: Support AppOps" into jb-mr2-dev

This commit is contained in:
Eino-Ville Talvala
2013-02-26 01:36:04 +00:00
committed by Android (Google) Code Review
5 changed files with 36 additions and 9 deletions

View File

@@ -16,6 +16,7 @@
package android.hardware;
import android.app.ActivityThread;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.content.Context;
@@ -337,7 +338,9 @@ public class Camera {
mEventHandler = null;
}
native_setup(new WeakReference<Camera>(this), cameraId);
String packageName = ActivityThread.currentPackageName();
native_setup(new WeakReference<Camera>(this), cameraId, packageName);
}
/**
@@ -350,7 +353,9 @@ public class Camera {
release();
}
private native final void native_setup(Object camera_this, int cameraId);
private native final void native_setup(Object camera_this, int cameraId,
String packageName);
private native final void native_release();

View File

@@ -465,9 +465,16 @@ static void android_hardware_Camera_getCameraInfo(JNIEnv *env, jobject thiz,
// connect to camera service
static void android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz,
jobject weak_this, jint cameraId)
jobject weak_this, jint cameraId, jstring clientPackageName)
{
sp<Camera> camera = Camera::connect(cameraId);
// Convert jstring to String16
const char16_t *rawClientName = env->GetStringChars(clientPackageName, NULL);
jsize rawClientNameLen = env->GetStringLength(clientPackageName);
String16 clientName(rawClientName, rawClientNameLen);
env->ReleaseStringChars(clientPackageName, rawClientName);
sp<Camera> camera = Camera::connect(cameraId, clientName,
Camera::USE_CALLING_UID);
if (camera == NULL) {
jniThrowRuntimeException(env, "Fail to connect to camera service");
@@ -859,7 +866,7 @@ static JNINativeMethod camMethods[] = {
"(ILandroid/hardware/Camera$CameraInfo;)V",
(void*)android_hardware_Camera_getCameraInfo },
{ "native_setup",
"(Ljava/lang/Object;I)V",
"(Ljava/lang/Object;ILjava/lang/String;)V",
(void*)android_hardware_Camera_native_setup },
{ "native_release",
"()V",

View File

@@ -126,6 +126,7 @@
<assign-permission name="android.permission.ACCESS_DRM" uid="media" />
<assign-permission name="android.permission.ACCESS_SURFACE_FLINGER" uid="media" />
<assign-permission name="android.permission.WAKE_LOCK" uid="media" />
<assign-permission name="android.permission.UPDATE_APP_OPS_STATS" uid="media" />
<assign-permission name="android.permission.ACCESS_SURFACE_FLINGER" uid="graphics" />

View File

@@ -16,6 +16,7 @@
package android.media;
import android.app.ActivityThread;
import android.hardware.Camera;
import android.os.Handler;
import android.os.Looper;
@@ -105,10 +106,11 @@ public class MediaRecorder
mEventHandler = null;
}
String packageName = ActivityThread.currentPackageName();
/* Native setup requires a weak reference to our object.
* It's easier to create it here than in C++.
*/
native_setup(new WeakReference<MediaRecorder>(this));
native_setup(new WeakReference<MediaRecorder>(this), packageName);
}
/**
@@ -977,7 +979,8 @@ public class MediaRecorder
private static native final void native_init();
private native final void native_setup(Object mediarecorder_this) throws IllegalStateException;
private native final void native_setup(Object mediarecorder_this,
String clientName) throws IllegalStateException;
private native final void native_finalize();

View File

@@ -416,9 +416,11 @@ android_media_MediaRecorder_native_init(JNIEnv *env)
static void
android_media_MediaRecorder_native_setup(JNIEnv *env, jobject thiz, jobject weak_this)
android_media_MediaRecorder_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
jstring packageName)
{
ALOGV("setup");
sp<MediaRecorder> mr = new MediaRecorder();
if (mr == NULL) {
jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
@@ -433,6 +435,15 @@ android_media_MediaRecorder_native_setup(JNIEnv *env, jobject thiz, jobject weak
sp<JNIMediaRecorderListener> listener = new JNIMediaRecorderListener(env, thiz, weak_this);
mr->setListener(listener);
// Convert client name jstring to String16
const char16_t *rawClientName = env->GetStringChars(packageName, NULL);
jsize rawClientNameLen = env->GetStringLength(packageName);
String16 clientName(rawClientName, rawClientNameLen);
env->ReleaseStringChars(packageName, rawClientName);
// pass client package name for permissions tracking
mr->setClientName(clientName);
setMediaRecorder(env, thiz, mr);
}
@@ -465,7 +476,7 @@ static JNINativeMethod gMethods[] = {
{"native_reset", "()V", (void *)android_media_MediaRecorder_native_reset},
{"release", "()V", (void *)android_media_MediaRecorder_release},
{"native_init", "()V", (void *)android_media_MediaRecorder_native_init},
{"native_setup", "(Ljava/lang/Object;)V", (void *)android_media_MediaRecorder_native_setup},
{"native_setup", "(Ljava/lang/Object;Ljava/lang/String;)V", (void *)android_media_MediaRecorder_native_setup},
{"native_finalize", "()V", (void *)android_media_MediaRecorder_native_finalize},
};