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

Commit 16961025 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk Committed by Android (Google) Code Review
Browse files

Merge "Convert band configuration when passing to and from HAL."

parents e287e224 31c8df0a
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -31,7 +31,10 @@ class Tuner extends ITuner.Stub {
     */
    private final long mNativeContext;

    Tuner(@NonNull ITunerCallback clientCallback) {
    private int mRegion;

    Tuner(@NonNull ITunerCallback clientCallback, int region) {
        mRegion = region;
        mNativeContext = nativeInit(clientCallback);
    }

+2 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ LOCAL_REL_DIR := core/jni
LOCAL_CFLAGS += -Wall -Werror -Wno-unused-parameter

LOCAL_SRC_FILES += \
    $(LOCAL_REL_DIR)/JavaRef.cpp \
    $(LOCAL_REL_DIR)/NativeCallbackThread.cpp \
    $(LOCAL_REL_DIR)/com_android_server_AlarmManagerService.cpp \
    $(LOCAL_REL_DIR)/com_android_server_am_BatteryStatsService.cpp \
@@ -22,6 +23,7 @@ LOCAL_SRC_FILES += \
    $(LOCAL_REL_DIR)/com_android_server_radio_RadioService.cpp \
    $(LOCAL_REL_DIR)/com_android_server_radio_Tuner.cpp \
    $(LOCAL_REL_DIR)/com_android_server_radio_Tuner_TunerCallback.cpp \
    $(LOCAL_REL_DIR)/com_android_server_radio_convert.cpp \
    $(LOCAL_REL_DIR)/com_android_server_SerialService.cpp \
    $(LOCAL_REL_DIR)/com_android_server_SyntheticPasswordManager.cpp \
    $(LOCAL_REL_DIR)/com_android_server_storage_AppFuseBridge.cpp \
+46 −0
Original line number Diff line number Diff line
/**
 * Copyright (C) 2017 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.
 */

#define LOG_TAG "JavaRef"
//#define LOG_NDEBUG 0

#include "JavaRef.h"

#include <utils/Log.h>

namespace android {

JavaRef make_javaref(JNIEnv *env, jobject ref) {
    ALOGV("wrapping %p", ref);
    ALOGE_IF(env == nullptr, "Environment is a nullptr");

    return JavaRef(ref, [env](jobject ref) {
        ALOGV("deleting %p", ref);
        if (env && ref) {
            env->DeleteLocalRef(ref);
        }
    });
}

EnvWrapper::EnvWrapper(JNIEnv *env) : mEnv(env) {
    ALOGE_IF(env == nullptr, "Environment is a nullptr");
}

JavaRef EnvWrapper::operator() (jobject ref) const {
    return make_javaref(mEnv, ref);
}

} // namespace android
+44 −0
Original line number Diff line number Diff line
/**
 * Copyright (C) 2017 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.
 */

#ifndef _ANDROID_JAVA_REF_H
#define _ANDROID_JAVA_REF_H

#include <android-base/macros.h>
#include <functional>
#include <jni.h>
#include <memory>

namespace android {

typedef std::unique_ptr<_jobject, std::function<void(jobject)>> JavaRef;

JavaRef make_javaref(JNIEnv *env, jobject ref);

class EnvWrapper {
public:
    EnvWrapper(JNIEnv *env);
    JavaRef operator() (jobject ref) const;

private:
    JNIEnv *mEnv;

    DISALLOW_COPY_AND_ASSIGN(EnvWrapper);
};

} // namespace android

#endif // _ANDROID_JAVA_REF_H
+8 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include "com_android_server_radio_RadioService.h"

#include "com_android_server_radio_Tuner.h"
#include "com_android_server_radio_convert.h"

#include <android/hardware/broadcastradio/1.1/IBroadcastRadioFactory.h>
#include <core_jni_helpers.h>
@@ -132,13 +133,15 @@ static jobject nativeOpenTuner(JNIEnv *env, jobject obj, long nativeContext, jin
        return nullptr;
    }

    jobject tuner = env->NewObject(gTunerClass, gTunerCstor, callback);
    Region region;
    BandConfig bandConfigHal = convert::BandConfigToHal(env, bandConfig, region);

    jobject tuner = env->NewObject(gTunerClass, gTunerCstor, callback, region);
    if (tuner == nullptr) {
        ALOGE("Unable to create new tuner object.");
        return nullptr;
    }

    BandConfig bandConfigHal = {};  // TODO(b/36863239): convert from bandConfig
    auto tunerCb = Tuner::getNativeCallback(env, tuner);
    Result halResult;
    sp<ITuner> halTuner = nullptr;
@@ -176,10 +179,12 @@ static const JNINativeMethod gRadioServiceMethods[] = {
void register_android_server_radio_RadioService(JNIEnv *env) {
    using namespace server::radio::RadioService;

    register_android_server_radio_convert(env);

    auto tunerClass = FindClassOrDie(env, "com/android/server/radio/Tuner");
    gTunerClass = MakeGlobalRefOrDie(env, tunerClass);
    gTunerCstor = GetMethodIDOrDie(env, tunerClass, "<init>",
            "(Landroid/hardware/radio/ITunerCallback;)V");
            "(Landroid/hardware/radio/ITunerCallback;I)V");

    auto serviceClass = FindClassOrDie(env, "com/android/server/radio/RadioService");
    gServiceClass = MakeGlobalRefOrDie(env, serviceClass);
Loading