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

Commit a15bdb94 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I670f78af,Ie2dce95b,Ic44227c9,I5770ee41,I82d27049, ...

* changes:
  Implement RadioModem for AIDL-HIDL Telephony HAL translator
  Implement RadioVoice for AIDL-HIDL Telephony HAL translator
  Implement RadioNetwork for AIDL-HIDL Telephony HAL translator
  Implement RadioData for AIDL-HIDL Telephony HAL translator
  Implement RadioSim for AIDL-HIDL Telephony HAL translator
  Implement RadioMessaging for AIDL-HIDL Telephony HAL translator
  Initial implementation of HIDL-AIDL Telephony HAL translator
parents 4c12800d dcbae487
Loading
Loading
Loading
Loading
+93 −0
Original line number Diff line number Diff line
// Copyright (C) 2021 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.

package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "hardware_interfaces_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["hardware_interfaces_license"],
}

cc_library {
    name: "android.hardware.radio-library.compat",
    relative_install_path: "hw",
    vendor: true,
    cflags: [
        "-Wall",
        "-Wextra",
        //"-Wold-style-cast",  // TODO(b/203699028) enable after aosp/1900880 gets merged
        "-DANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION",
    ],
    shared_libs: [
        "android.hardware.radio.config-V1-ndk",
        "android.hardware.radio.config@1.0",
        "android.hardware.radio.config@1.1",
        "android.hardware.radio.config@1.2",
        "android.hardware.radio.config@1.3",
        "android.hardware.radio.data-V1-ndk",
        "android.hardware.radio.messaging-V1-ndk",
        "android.hardware.radio.modem-V1-ndk",
        "android.hardware.radio.network-V1-ndk",
        "android.hardware.radio.sim-V1-ndk",
        "android.hardware.radio.voice-V1-ndk",
        "android.hardware.radio@1.0",
        "android.hardware.radio@1.1",
        "android.hardware.radio@1.2",
        "android.hardware.radio@1.3",
        "android.hardware.radio@1.4",
        "android.hardware.radio@1.5",
        "android.hardware.radio@1.6",
        "libbase",
        "libbinder_ndk",
        "libhidlbase",
        "libutils",
    ],
    srcs: [
        "RadioCompatBase.cpp",
        "RadioResponse.cpp",
        "commonStructs.cpp",
        "config/RadioConfig.cpp",
        "config/RadioConfigIndication.cpp",
        "config/RadioConfigResponse.cpp",
        "config/structs.cpp",
        "data/RadioIndication-data.cpp",
        "data/RadioResponse-data.cpp",
        "data/RadioData.cpp",
        "data/structs.cpp",
        "messaging/RadioIndication-messaging.cpp",
        "messaging/RadioMessaging.cpp",
        "messaging/RadioResponse-messaging.cpp",
        "messaging/structs.cpp",
        "modem/RadioIndication-modem.cpp",
        "modem/RadioResponse-modem.cpp",
        "modem/RadioModem.cpp",
        "modem/structs.cpp",
        "network/RadioIndication-network.cpp",
        "network/RadioNetwork.cpp",
        "network/RadioResponse-network.cpp",
        "network/structs.cpp",
        "network/utils.cpp",
        "sim/RadioIndication-sim.cpp",
        "sim/RadioResponse-sim.cpp",
        "sim/RadioSim.cpp",
        "sim/structs.cpp",
        "voice/RadioIndication-voice.cpp",
        "voice/RadioResponse-voice.cpp",
        "voice/RadioVoice.cpp",
        "voice/structs.cpp",
    ],
    export_include_dirs: ["include"],
}
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.
 */

#include <libradiocompat/RadioCompatBase.h>

#include <android-base/logging.h>

namespace android::hardware::radio::compat {

RadioCompatBase::RadioCompatBase(sp<V1_5::IRadio> hidlHal, sp<RadioResponse> radioResponse,
                                 sp<RadioIndication> radioIndication)
    : mHal1_5(hidlHal),
      mHal1_6(V1_6::IRadio::castFrom(hidlHal)),
      mRadioResponse(radioResponse),
      mRadioIndication(radioIndication) {}

V1_6::IRadioResponse& RadioCompatBase::respond() {
    CHECK(mRadioResponse) << "This shouldn't happen (response functions are passed in constructor)";
    return *mRadioResponse;
}

}  // namespace android::hardware::radio::compat
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.
 */

#include <libradiocompat/RadioResponse.h>

#include "debug.h"

#define RADIO_MODULE "Common"

namespace android::hardware::radio::compat {

Return<void> RadioResponse::acknowledgeRequest(int32_t serial) {
    LOG_CALL << serial;
    // TODO(b/203699028): send to correct requestor or confirm if spam is not a problem
    if (mDataCb) mDataCb->acknowledgeRequest(serial);
    if (mMessagingCb) mMessagingCb->acknowledgeRequest(serial);
    if (mModemCb) mModemCb->acknowledgeRequest(serial);
    if (mNetworkCb) mNetworkCb->acknowledgeRequest(serial);
    if (mSimCb) mSimCb->acknowledgeRequest(serial);
    if (mVoiceCb) mVoiceCb->acknowledgeRequest(serial);
    return {};
}

}  // namespace android::hardware::radio::compat
+122 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.
 */
#pragma once

#include <hidl/HidlSupport.h>

#include <type_traits>
#include <variant>

namespace android::hardware::radio::compat {

/**
 * Converts hidl_vec<T> HIDL list to std::vector<T> AIDL list.
 *
 * To convert values, the template uses toAidl functions for a given type T, assuming it's defined.
 *
 * \param inp vector to convert
 */
template <typename T>
auto toAidl(const hidl_vec<T>& inp) {
    std::vector<decltype(toAidl(T{}))> out(inp.size());
    for (size_t i = 0; i < inp.size(); i++) {
        out[i] = toAidl(inp[i]);
    }
    return out;
}

/**
 * Converts std::vector<T> AIDL list to hidl_vec<T> HIDL list.
 *
 * To convert values, the template uses toHidl functions for a given type T, assuming it's defined.
 *
 * \param inp vector to convert
 */
template <typename T>
auto toHidl(const std::vector<T>& inp) {
    hidl_vec<decltype(toHidl(T{}))> out(inp.size());
    for (size_t i = 0; i < inp.size(); i++) {
        out[i] = toHidl(inp[i]);
    }
    return out;
}

/**
 * Converts hidl_array<T> HIDL list to std::vector<T> AIDL list.
 *
 * To convert values, the template uses toAidl functions for a given type T, assuming it's defined.
 *
 * \param inp array to convert
 */
template <typename T, size_t N>
auto toAidl(const hidl_array<T, N>& inp) {
    std::vector<decltype(toAidl(T{}))> out(N);
    for (size_t i = 0; i < N; i++) {
        out[i] = toAidl(inp[i]);
    }
    return out;
}

/**
 * Converts T=OptionalX HIDL value to std::optional<X> AIDL value.
 *
 * To convert values, the template uses toAidl functions for a given type T.value.
 */
template <typename T>
std::optional<decltype(toAidl(T{}.value()))> toAidl(const T& opt) {
    if (opt.getDiscriminator() == T::hidl_discriminator::noinit) return std::nullopt;
    return toAidl(opt.value());
}

/**
 * Converts T=OptionalX HIDL value to std::variant<bool, X> AIDL value.
 *
 * For some reason, not every OptionalX gets generated into a std::optional<X>.
 */
template <typename T>
std::variant<bool, decltype(toAidl(T{}.value()))> toAidlVariant(const T& opt) {
    if (opt.getDiscriminator() == T::hidl_discriminator::noinit) return false;
    return toAidl(opt.value());
}

/**
 * Converts std::optional<X> AIDL value to T=OptionalX HIDL value.
 *
 * X is inferred from toAidl(T.value) declaration. Please note that toAidl(T.value) doesn't have to
 * be implemented if it's not needed for anything else than giving this hint to type system.
 *
 * To convert values, the template uses toHidl functions for a given type T, assuming it's defined.
 *
 * \param opt value to convert
 */
template <typename T>
T toHidl(const std::optional<decltype(toAidl(T{}.value()))>& opt) {
    T hidl;
    if (opt.has_value()) hidl.value(toHidl(*opt));
    return hidl;
}

/**
 * Converts U AIDL bitfield value to HIDL T bitfield value.
 *
 * \param val value to convert
 */
template <typename T, typename U>
hidl_bitfield<T> toHidlBitfield(U val) {
    return static_cast<int>(val);
}

}  // namespace android::hardware::radio::compat
+83 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.
 */

#include "commonStructs.h"

namespace android::hardware::radio::compat {

namespace aidl = ::aidl::android::hardware::radio;

V1_6::RadioResponseInfo notSupported(int32_t serial) {
    return {
            .type = V1_0::RadioResponseType::SOLICITED,
            .serial = serial,
            .error = V1_6::RadioError::REQUEST_NOT_SUPPORTED,
    };
}

std::string toAidl(const hidl_string& str) {
    return str;
}

hidl_string toHidl(const std::string& str) {
    return str;
}

uint8_t toAidl(int8_t v) {
    return v;
}

int8_t toAidl(uint8_t v) {
    return v;
}

int32_t toAidl(uint32_t v) {
    return v;
}

aidl::RadioIndicationType toAidl(V1_0::RadioIndicationType type) {
    return aidl::RadioIndicationType(type);
}

aidl::RadioResponseType toAidl(V1_0::RadioResponseType type) {
    return aidl::RadioResponseType(type);
}

aidl::RadioError toAidl(V1_0::RadioError err) {
    return aidl::RadioError(err);
}

aidl::RadioError toAidl(V1_6::RadioError err) {
    return aidl::RadioError(err);
}

aidl::RadioResponseInfo toAidl(const V1_0::RadioResponseInfo& info) {
    return {
            .type = toAidl(info.type),
            .serial = info.serial,
            .error = toAidl(info.error),
    };
}

aidl::RadioResponseInfo toAidl(const V1_6::RadioResponseInfo& info) {
    return {
            .type = toAidl(info.type),
            .serial = info.serial,
            .error = toAidl(info.error),
    };
}

}  // namespace android::hardware::radio::compat
Loading