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

Commit 67383ec2 authored by Yu-Han Yang's avatar Yu-Han Yang
Browse files

Refactor GNSS JNI: GnssMeasurement

Bug: 171245018
Test: atest GnssPseudorangeVerificationTest
Change-Id: Ic89f63716f3c10765aab0e2dd042467512650a2f
parent 6eef6227
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@ cc_library_static {
        "BroadcastRadio/convert.cpp",
        "BroadcastRadio/regions.cpp",
        "gnss/GnssConfiguration.cpp",
        "gnss/GnssMeasurement.cpp",
        "gnss/GnssMeasurementCallback.cpp",
        "gnss/Utils.cpp",
        "stats/PowerStatsPuller.cpp",
        "stats/SubsystemSleepStatePuller.cpp",
        "com_android_server_adb_AdbDebuggingManager.cpp",
+25 −632

File changed.

Preview size limit exceeded, changes collapsed.

+1 −23
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#define LOG_TAG "GnssConfigurationJni"

#include "GnssConfiguration.h"
#include "Utils.h"

using android::hardware::gnss::GnssConstellationType;
using GnssConstellationType_V1_0 = android::hardware::gnss::V1_0::GnssConstellationType;
@@ -42,29 +43,6 @@ namespace {
jclass class_gnssConfiguration_halInterfaceVersion;
jmethodID method_halInterfaceVersionCtor;

jboolean checkAidlStatus(const Status& status, const char* errorMessage) {
    if (!status.isOk()) {
        ALOGE("%s AIDL transport error: %s", errorMessage, status.toString8().c_str());
        return JNI_FALSE;
    }
    return JNI_TRUE;
}

template <class T>
inline void logHidlError(Return<T>& result, const char* errorMessage) {
    ALOGE("%s HIDL transport error: %s", errorMessage, result.description().c_str());
}

template <class T>
jboolean checkHidlReturn(Return<T>& result, const char* errorMessage) {
    if (!result.isOk()) {
        logHidlError(result, errorMessage);
        return JNI_FALSE;
    } else {
        return JNI_TRUE;
    }
}

jobject createHalInterfaceVersionJavaObject(JNIEnv* env, jint major, jint minor) {
    return env->NewObject(class_gnssConfiguration_halInterfaceVersion,
                          method_halInterfaceVersionCtor, major, minor);
+114 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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 before <log/log.h> to overwrite the default value.
#define LOG_TAG "GnssMeasurementJni"

#include "GnssMeasurement.h"
#include "Utils.h"

using android::hardware::hidl_vec;
using android::hardware::Return;

using IGnssMeasurement_V1_0 = android::hardware::gnss::V1_0::IGnssMeasurement;
using IGnssMeasurement_V1_1 = android::hardware::gnss::V1_1::IGnssMeasurement;
using IGnssMeasurement_V2_0 = android::hardware::gnss::V2_0::IGnssMeasurement;
using IGnssMeasurement_V2_1 = android::hardware::gnss::V2_1::IGnssMeasurement;

namespace {
jboolean checkGnssMeasurementStatus(const IGnssMeasurement_V1_0::GnssMeasurementStatus& status) {
    if (status != IGnssMeasurement_V1_0::GnssMeasurementStatus::SUCCESS) {
        ALOGE("An error has been found on GnssMeasurementInterface::init, status=%d",
              static_cast<int32_t>(status));
        return JNI_FALSE;
    } else {
        ALOGD("gnss measurement infc has been enabled");
        return JNI_TRUE;
    }
}
} // anonymous namespace

namespace android::gnss {

// Implementation of GnssMeasurement_V1_0

GnssMeasurement_V1_0::GnssMeasurement_V1_0(const sp<IGnssMeasurement_V1_0>& iGnssMeasurement)
      : mIGnssMeasurement_V1_0(iGnssMeasurement) {}

jboolean GnssMeasurement_V1_0::setCallback(const sp<GnssMeasurementCallback>& callback,
                                           bool enableFullTracking) {
    if (enableFullTracking == true) {
        ALOGW("Full tracking is mode not supported in 1.0 GNSS HAL.");
    }
    auto status = mIGnssMeasurement_V1_0->setCallback(callback);
    if (!checkHidlReturn(status, "IGnssMeasurement setCallback() failed.")) {
        return JNI_FALSE;
    }

    return checkGnssMeasurementStatus(status);
}

jboolean GnssMeasurement_V1_0::close() {
    auto result = mIGnssMeasurement_V1_0->close();
    return checkHidlReturn(result, "IGnssMeasurement close() failed.");
}

// Implementation of GnssMeasurement_V1_1

GnssMeasurement_V1_1::GnssMeasurement_V1_1(const sp<IGnssMeasurement_V1_1>& iGnssMeasurement)
      : GnssMeasurement_V1_0{iGnssMeasurement}, mIGnssMeasurement_V1_1(iGnssMeasurement) {}

jboolean GnssMeasurement_V1_1::setCallback(const sp<GnssMeasurementCallback>& callback,
                                           bool enableFullTracking) {
    auto status = mIGnssMeasurement_V1_1->setCallback_1_1(callback, enableFullTracking);
    if (!checkHidlReturn(status, "IGnssMeasurement setCallback_V1_1() failed.")) {
        return JNI_FALSE;
    }

    return checkGnssMeasurementStatus(status);
}

// Implementation of GnssMeasurement_V2_0

GnssMeasurement_V2_0::GnssMeasurement_V2_0(const sp<IGnssMeasurement_V2_0>& iGnssMeasurement)
      : GnssMeasurement_V1_1{iGnssMeasurement}, mIGnssMeasurement_V2_0(iGnssMeasurement) {}

jboolean GnssMeasurement_V2_0::setCallback(const sp<GnssMeasurementCallback>& callback,
                                           bool enableFullTracking) {
    auto status = mIGnssMeasurement_V2_0->setCallback_2_0(callback, enableFullTracking);
    if (!checkHidlReturn(status, "IGnssMeasurement setCallback_2_0() failed.")) {
        return JNI_FALSE;
    }

    return checkGnssMeasurementStatus(status);
}

// Implementation of GnssMeasurement_V2_1

GnssMeasurement_V2_1::GnssMeasurement_V2_1(const sp<IGnssMeasurement_V2_1>& iGnssMeasurement)
      : GnssMeasurement_V2_0{iGnssMeasurement}, mIGnssMeasurement_V2_1(iGnssMeasurement) {}

jboolean GnssMeasurement_V2_1::setCallback(const sp<GnssMeasurementCallback>& callback,
                                           bool enableFullTracking) {
    auto status = mIGnssMeasurement_V2_1->setCallback_2_1(callback, enableFullTracking);
    if (!checkHidlReturn(status, "IGnssMeasurement setCallback_2_1() failed.")) {
        return JNI_FALSE;
    }

    return checkGnssMeasurementStatus(status);
}

} // namespace android::gnss
 No newline at end of file
+91 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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_SERVER_GNSS_GNSSMEASUREMENT_H
#define _ANDROID_SERVER_GNSS_GNSSMEASUREMENT_H

#pragma once

#ifndef LOG_TAG
#error LOG_TAG must be defined before including this file.
#endif

#include <android/hardware/gnss/1.0/IGnssMeasurement.h>
#include <android/hardware/gnss/1.1/IGnssMeasurement.h>
#include <android/hardware/gnss/2.0/IGnssMeasurement.h>
#include <android/hardware/gnss/2.1/IGnssMeasurement.h>
#include <log/log.h>
#include "GnssMeasurementCallback.h"
#include "jni.h"

namespace android::gnss {

class GnssMeasurementInterface {
public:
    virtual ~GnssMeasurementInterface() {}
    virtual jboolean setCallback(const sp<GnssMeasurementCallback>& callback,
                                 bool enableFullTracking) = 0;
    virtual jboolean close() = 0;
};

class GnssMeasurement_V1_0 : public GnssMeasurementInterface {
public:
    GnssMeasurement_V1_0(
            const sp<android::hardware::gnss::V1_0::IGnssMeasurement>& iGnssMeasurement);
    jboolean setCallback(const sp<GnssMeasurementCallback>& callback,
                         bool enableFullTracking) override;
    jboolean close() override;

private:
    const sp<android::hardware::gnss::V1_0::IGnssMeasurement> mIGnssMeasurement_V1_0;
};

class GnssMeasurement_V1_1 : public GnssMeasurement_V1_0 {
public:
    GnssMeasurement_V1_1(
            const sp<android::hardware::gnss::V1_1::IGnssMeasurement>& iGnssMeasurement);
    jboolean setCallback(const sp<GnssMeasurementCallback>& callback,
                         bool enableFullTracking) override;

private:
    const sp<android::hardware::gnss::V1_1::IGnssMeasurement> mIGnssMeasurement_V1_1;
};

class GnssMeasurement_V2_0 : public GnssMeasurement_V1_1 {
public:
    GnssMeasurement_V2_0(
            const sp<android::hardware::gnss::V2_0::IGnssMeasurement>& iGnssMeasurement);
    jboolean setCallback(const sp<GnssMeasurementCallback>& callback,
                         bool enableFullTracking) override;

private:
    const sp<android::hardware::gnss::V2_0::IGnssMeasurement> mIGnssMeasurement_V2_0;
};

class GnssMeasurement_V2_1 : public GnssMeasurement_V2_0 {
public:
    GnssMeasurement_V2_1(
            const sp<android::hardware::gnss::V2_1::IGnssMeasurement>& iGnssMeasurement);
    jboolean setCallback(const sp<GnssMeasurementCallback>& callback,
                         bool enableFullTracking) override;

private:
    const sp<android::hardware::gnss::V2_1::IGnssMeasurement> mIGnssMeasurement_V2_1;
};

} // namespace android::gnss

#endif // _ANDROID_SERVER_GNSS_GNSSMEASUREMENT_H
 No newline at end of file
Loading