Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c54940f2 authored by Dichen Zhang's avatar Dichen Zhang Committed by Android (Google) Code Review
Browse files

Merge "jWakeLock"

parents 150c46ef 8022ba12
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1334,11 +1334,11 @@ public class MediaPlayer2 implements AutoCloseable
        return addTask(new Task(CALL_COMPLETED_SET_WAKE_LOCK, false) {
            @Override
            void process() {
                boolean washeld = false;
                boolean wasHeld = false;

                if (mWakeLock != null) {
                    if (mWakeLock.isHeld()) {
                        washeld = true;
                        wasHeld = true;
                        mWakeLock.release();
                    }
                }
@@ -1346,7 +1346,7 @@ public class MediaPlayer2 implements AutoCloseable
                mWakeLock = wakeLock;
                if (mWakeLock != null) {
                    mWakeLock.setReferenceCounted(false);
                    if (washeld) {
                    if (wasHeld) {
                        mWakeLock.acquire();
                    }
                }
+0 −1
Original line number Diff line number Diff line
@@ -102,7 +102,6 @@ cc_library_shared {
        "libhidlbase",
        "libhidlmemory",

        "libpowermanager",  // Used by JWakeLock. Will be replace with public SDK API.
        "libmediametrics",  // Used by MediaMetrics. Will be replaced with stable C API.
        "libbinder",  // Used by JWakeLock and MediaMetrics.

+13 −6
Original line number Diff line number Diff line
@@ -86,7 +86,8 @@ using media::VolumeShaper;
// ----------------------------------------------------------------------------

struct fields_t {
    jfieldID    context;
    jfieldID    context;               // passed from Java to native, used for creating JWakeLock
    jfieldID    nativeContext;         // mNativeContext in MediaPlayer2.java
    jfieldID    surface_texture;

    jmethodID   post_event;
@@ -225,21 +226,21 @@ void JNIMediaPlayer2Listener::notify(int64_t srcId, int msg, int ext1, int ext2,
static sp<MediaPlayer2> getMediaPlayer(JNIEnv* env, jobject thiz)
{
    Mutex::Autolock l(sLock);
    MediaPlayer2* const p = (MediaPlayer2*)env->GetLongField(thiz, fields.context);
    MediaPlayer2* const p = (MediaPlayer2*)env->GetLongField(thiz, fields.nativeContext);
    return sp<MediaPlayer2>(p);
}

static sp<MediaPlayer2> setMediaPlayer(JNIEnv* env, jobject thiz, const sp<MediaPlayer2>& player)
{
    Mutex::Autolock l(sLock);
    sp<MediaPlayer2> old = (MediaPlayer2*)env->GetLongField(thiz, fields.context);
    sp<MediaPlayer2> old = (MediaPlayer2*)env->GetLongField(thiz, fields.nativeContext);
    if (player.get()) {
        player->incStrong((void*)setMediaPlayer);
    }
    if (old != 0) {
        old->decStrong((void*)setMediaPlayer);
    }
    env->SetLongField(thiz, fields.context, (jlong)player.get());
    env->SetLongField(thiz, fields.nativeContext, (jlong)player.get());
    return old;
}

@@ -955,11 +956,16 @@ android_media_MediaPlayer2_native_init(JNIEnv *env)
        return;
    }

    fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
    fields.context = env->GetFieldID(clazz, "mContext", "Landroid/content/Context;");
    if (fields.context == NULL) {
        return;
    }

    fields.nativeContext = env->GetFieldID(clazz, "mNativeContext", "J");
    if (fields.nativeContext == NULL) {
        return;
    }

    fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative",
                                               "(Ljava/lang/Object;JIII[B)V");
    if (fields.post_event == NULL) {
@@ -1013,7 +1019,8 @@ android_media_MediaPlayer2_native_setup(JNIEnv *env, jobject thiz,
        jint sessionId, jobject weak_this)
{
    ALOGV("native_setup");
    sp<MediaPlayer2> mp = MediaPlayer2::Create(sessionId);
    jobject context = env->GetObjectField(thiz, fields.context);
    sp<MediaPlayer2> mp = MediaPlayer2::Create(sessionId, context);
    if (mp == NULL) {
        jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
        return;