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

Commit bff3b5b4 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

Initial implementation of HIDL-AIDL Telephony HAL translator

Bug: 203699028
Test: Boot and grep logcat against radiocompat
Change-Id: I182edf3b1fa39b30818e79a68fc586f12b677d19
parent ddf63247
Loading
Loading
Loading
Loading
+53 −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",
        "libbase",
        "libbinder_ndk",
        "libhidlbase",
        "libutils",
    ],
    srcs: [
        "commonStructs.cpp",
        "config/RadioConfig.cpp",
        "config/RadioConfigIndication.cpp",
        "config/RadioConfigResponse.cpp",
        "config/structs.cpp",
    ],
    export_include_dirs: ["include"],
}
+54 −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>

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;
}

}  // namespace android::hardware::radio::compat
+63 −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,
    };
}

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
+34 −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 <aidl/android/hardware/radio/RadioIndicationType.h>
#include <aidl/android/hardware/radio/RadioResponseInfo.h>
#include <android/hardware/radio/1.6/types.h>

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

V1_6::RadioResponseInfo notSupported(int32_t serial);

aidl::android::hardware::radio::RadioIndicationType toAidl(V1_0::RadioIndicationType type);
aidl::android::hardware::radio::RadioResponseType toAidl(V1_0::RadioResponseType type);
aidl::android::hardware::radio::RadioError toAidl(V1_0::RadioError type);
aidl::android::hardware::radio::RadioError toAidl(V1_6::RadioError type);

aidl::android::hardware::radio::RadioResponseInfo toAidl(const V1_0::RadioResponseInfo& info);
aidl::android::hardware::radio::RadioResponseInfo toAidl(const V1_6::RadioResponseInfo& info);

}  // namespace android::hardware::radio::compat
+103 −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/RadioConfig.h>

#include "RadioConfigIndication.h"
#include "RadioConfigResponse.h"
#include "commonStructs.h"
#include "debug.h"
#include "structs.h"

#define RADIO_MODULE "Config"

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

using ::ndk::ScopedAStatus;
namespace aidl = ::aidl::android::hardware::radio::config;
constexpr auto ok = &ScopedAStatus::ok;

RadioConfig::RadioConfig(sp<config::V1_1::IRadioConfig> hidlHal)
    : mHal1_1(hidlHal), mHal1_3(config::V1_3::IRadioConfig::castFrom(hidlHal)) {}

config::V1_3::IRadioConfigResponse& RadioConfig::respond() {
    CHECK(mRadioConfigResponse) << "setResponseFunctions was not called yet";
    return *mRadioConfigResponse;
}

ScopedAStatus RadioConfig::getHalDeviceCapabilities(int32_t serial) {
    LOG_CALL << serial;
    if (mHal1_3) {
        mHal1_3->getHalDeviceCapabilities(serial);
    } else {
        respond().getHalDeviceCapabilitiesResponse(notSupported(serial), false);
    }
    return ok();
}

ScopedAStatus RadioConfig::getNumOfLiveModems(int32_t serial) {
    LOG_CALL << serial;
    mHal1_1->getModemsConfig(serial);
    return ok();
}

ScopedAStatus RadioConfig::getPhoneCapability(int32_t serial) {
    LOG_CALL << serial;
    mHal1_1->getPhoneCapability(serial);
    return ok();
}

ScopedAStatus RadioConfig::getSimSlotsStatus(int32_t serial) {
    LOG_CALL << serial;
    mHal1_1->getSimSlotsStatus(serial);
    return ok();
}

ScopedAStatus RadioConfig::setNumOfLiveModems(int32_t serial, int8_t numOfLiveModems) {
    LOG_CALL << serial;
    mHal1_1->setModemsConfig(serial, {static_cast<uint8_t>(numOfLiveModems)});
    return ok();
}

ScopedAStatus RadioConfig::setPreferredDataModem(int32_t serial, int8_t modemId) {
    LOG_CALL << serial;
    mHal1_1->setPreferredDataModem(serial, modemId);
    return ok();
}

ScopedAStatus RadioConfig::setResponseFunctions(
        const std::shared_ptr<aidl::IRadioConfigResponse>& radioConfigResponse,
        const std::shared_ptr<aidl::IRadioConfigIndication>& radioConfigIndication) {
    LOG_CALL << radioConfigResponse << ' ' << radioConfigIndication;

    CHECK(radioConfigResponse);
    CHECK(radioConfigIndication);

    mRadioConfigResponse = sp<RadioConfigResponse>::make(radioConfigResponse);
    mRadioConfigIndication = sp<RadioConfigIndication>::make(radioConfigIndication);
    mHal1_1->setResponseFunctions(mRadioConfigResponse, mRadioConfigIndication);

    return ok();
}

ScopedAStatus RadioConfig::setSimSlotsMapping(  //
        int32_t serial, const std::vector<aidl::SlotPortMapping>& slotMap) {
    LOG_CALL << serial;
    mHal1_1->setSimSlotsMapping(serial, toHidl(slotMap));
    return ok();
}

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