mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-22 04:05:31 -04:00
universal7885: Unify IFMSysfsSupport to IFMDevControl
Also update sepolicy svc ctx
This commit is contained in:
parent
d3adcd6380
commit
b6537a107b
11 changed files with 89 additions and 162 deletions
|
|
@ -1,22 +1,20 @@
|
|||
package com.eurekateam.fmradio
|
||||
|
||||
import vendor.eureka.hardware.fmradio.IFMDevControl
|
||||
import vendor.eureka.hardware.fmradio.IFMSysfsSupport
|
||||
import vendor.eureka.hardware.fmradio.GetType
|
||||
import vendor.eureka.hardware.fmradio.SetType
|
||||
import vendor.eureka.hardware.fmradio.Direction
|
||||
|
||||
import android.os.ServiceManager
|
||||
|
||||
class NativeFMInterface {
|
||||
private val mDevCtl : IFMDevControl
|
||||
private val mSysfsCtl : IFMSysfsSupport
|
||||
private var mSysfs = false
|
||||
private val mSysfsCtl : IFMDevControl
|
||||
private val mDefaultCtl : IFMDevControl
|
||||
|
||||
init {
|
||||
mDevCtl = IFMDevControl.Stub.asInterface(ServiceManager.waitForDeclaredService("vendor.eureka.hardware.fmradio.IFMDevControl/default"))
|
||||
mSysfsCtl = IFMSysfsSupport.Stub.asInterface(ServiceManager.waitForDeclaredService("vendor.eureka.hardware.fmradio.IFMSysfsSupport/default"))
|
||||
mSysfs = mSysfsCtl.isAvailable()
|
||||
mSysfsCtl = IFMDevControl.Stub.asInterface(ServiceManager.waitForDeclaredService("vendor.eureka.hardware.fmradio.IFMDevControl/support"))
|
||||
mDefaultCtl = if (mSysfsCtl.getValue(GetType.GET_TYPE_FM_SYSFS_IF) == 0) mSysfsCtl else mDevCtl
|
||||
}
|
||||
|
||||
fun openFMDevice(): Int {
|
||||
|
|
@ -31,27 +29,13 @@ class NativeFMInterface {
|
|||
fun getFmUpper(a: Int) : Int = mDevCtl.getValue(GetType.GET_TYPE_FM_UPPER_LIMIT)
|
||||
fun getFMLower(a: Int): Int = mDevCtl.getValue(GetType.GET_TYPE_FM_LOWER_LIMIT)
|
||||
fun getRMSSI(a: Int): Int = mDevCtl.getValue(GetType.GET_TYPE_FM_RMSSI)
|
||||
fun getFMTracks(fd: Int): IntArray = if (mSysfs) {
|
||||
var mRes = intArrayOf()
|
||||
for (a in 1..30) {
|
||||
mSysfsCtl.adjustFreqByStep(Direction.UP)
|
||||
var freq = mSysfsCtl.getFreqFromSysfs()
|
||||
if (mRes.contains(freq)) continue else mRes += freq
|
||||
}
|
||||
mRes
|
||||
} else mDevCtl.getFreqsList()
|
||||
fun getFMTracks(fd: Int): IntArray = mDefaultCtl.getFreqsList()
|
||||
fun setFMThread(a: Int, run: Boolean) = mDevCtl.setValue(SetType.SET_TYPE_FM_THREAD, if (run) 1 else 0)
|
||||
fun getNextChannel(a: Int): Int = if (mSysfs) {
|
||||
mSysfsCtl.adjustFreqByStep(Direction.UP)
|
||||
mSysfsCtl.getFreqFromSysfs()
|
||||
} else mDevCtl.getValue(GetType.GET_TYPE_FM_NEXT_CHANNEL)
|
||||
fun getBeforeChannel(a: Int): Int = if (mSysfs) {
|
||||
mSysfsCtl.adjustFreqByStep(Direction.DOWN)
|
||||
mSysfsCtl.getFreqFromSysfs()
|
||||
} else mDevCtl.getValue(GetType.GET_TYPE_FM_BEFORE_CHANNEL)
|
||||
fun getNextChannel(a: Int): Int = mDefaultCtl.getValue(GetType.GET_TYPE_FM_NEXT_CHANNEL)
|
||||
fun getBeforeChannel(a: Int): Int = mDefaultCtl.getValue(GetType.GET_TYPE_FM_BEFORE_CHANNEL)
|
||||
fun stopSearching(a: Int) = mDevCtl.setValue(SetType.SET_TYPE_FM_SEARCH_CANCEL, 0)
|
||||
fun setFMRSSI(a: Int, rssi: Long) = mDevCtl.setValue(SetType.SET_TYPE_FM_RMSSI, rssi.toInt())
|
||||
fun closeFMDevice(fd: Int) = mDevCtl.close()
|
||||
fun getSysfsSupport(): Boolean = mSysfs
|
||||
fun getSysfsSupport(): Boolean = mSysfsCtl.getValue(GetType.GET_TYPE_FM_SYSFS_IF) == 0
|
||||
external fun setAudioRoute(speaker: Boolean): Int
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ static int fd = -1;
|
|||
case GetType::GET_TYPE_FM_NEXT_CHANNEL:
|
||||
*_aidl_return = fm_radio_slsi::next_channel(fd);
|
||||
break;
|
||||
case GetType::GET_TYPE_FM_SYSFS_IF:
|
||||
[[fallthrough]];
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,15 +13,22 @@
|
|||
// limitations under the License.
|
||||
|
||||
#include "FMSupport.h"
|
||||
#include <fstream>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <FileIO.h>
|
||||
|
||||
static int mChannelSpacing = 3;
|
||||
#include <android-base/logging.h>
|
||||
|
||||
#define NOT_SUPPORTED \
|
||||
({ \
|
||||
LOG(ERROR) << __func__ << ": Attempted to invoke unsupported operation"; \
|
||||
return ::ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); \
|
||||
})
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::fmradio {
|
||||
|
||||
|
|
@ -30,55 +37,67 @@ constexpr const char *FM_FREQ_CTL =
|
|||
constexpr const char *FM_FREQ_SEEK =
|
||||
"/sys/devices/virtual/s610_radio/s610_radio/radio_freq_seek";
|
||||
|
||||
::ndk::ScopedAStatus FMSupport::setManualFreq(float freq) {
|
||||
FileIO::writeline(FM_FREQ_CTL, freq * 1000);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
::ndk::ScopedAStatus FMSupport::open(void) { NOT_SUPPORTED; }
|
||||
|
||||
::ndk::ScopedAStatus FMSupport::adjustFreqByStep(Direction dir) {
|
||||
std::string value = "";
|
||||
if (dir == Direction::UP) {
|
||||
value = "1 " + std::to_string(mChannelSpacing * 10);
|
||||
} else if (dir == Direction::DOWN) {
|
||||
value = "0 " + std::to_string(mChannelSpacing * 10);
|
||||
}
|
||||
FileIO::writeline(FM_FREQ_SEEK, value);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
::ndk::ScopedAStatus FMSupport::isAvailable(bool *_aidl_return) {
|
||||
struct stat info;
|
||||
*_aidl_return =
|
||||
stat("/sys/devices/virtual/s610_radio/s610_radio/", &info) != 0;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
::ndk::ScopedAStatus FMSupport::setChannelSpacing(Space space) {
|
||||
mChannelSpacing = static_cast<int>(space);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
::ndk::ScopedAStatus FMSupport::getFreqFromSysfs(int32_t *_aidl_return) {
|
||||
*_aidl_return = FileIO::readline(FM_FREQ_CTL);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
::ndk::ScopedAStatus FMSupport::getChannelSpacing(Space *_aidl_return) {
|
||||
switch (mChannelSpacing) {
|
||||
case 1:
|
||||
*_aidl_return = Space::CHANNEL_SPACING_10HZ;
|
||||
::ndk::ScopedAStatus FMSupport::getValue(GetType type, int *_aidl_return) {
|
||||
switch (type) {
|
||||
case GetType::GET_TYPE_FM_FREQ:
|
||||
*_aidl_return = FileIO::readline(FM_FREQ_CTL);
|
||||
break;
|
||||
case 2:
|
||||
*_aidl_return = Space::CHANNEL_SPACING_20HZ;
|
||||
case GetType::GET_TYPE_FM_UPPER_LIMIT:
|
||||
case GetType::GET_TYPE_FM_LOWER_LIMIT:
|
||||
case GetType::GET_TYPE_FM_RMSSI:
|
||||
NOT_SUPPORTED;
|
||||
case GetType::GET_TYPE_FM_BEFORE_CHANNEL:
|
||||
FileIO::writeline(FM_FREQ_SEEK, "0 " + std::to_string(3 * 10));
|
||||
*_aidl_return = FileIO::readline(FM_FREQ_CTL);
|
||||
break;
|
||||
case 3:
|
||||
*_aidl_return = Space::CHANNEL_SPACING_30HZ;
|
||||
break;
|
||||
case 4:
|
||||
*_aidl_return = Space::CHANNEL_SPACING_40HZ;
|
||||
break;
|
||||
case 5:
|
||||
*_aidl_return = Space::CHANNEL_SPACING_50HZ;
|
||||
case GetType::GET_TYPE_FM_NEXT_CHANNEL:
|
||||
FileIO::writeline(FM_FREQ_SEEK, "1 " + std::to_string(3 * 10));
|
||||
*_aidl_return = FileIO::readline(FM_FREQ_CTL);
|
||||
break;
|
||||
case GetType::GET_TYPE_FM_SYSFS_IF:
|
||||
*_aidl_return = access("/sys/devices/virtual/s610_radio/s610_radio/", F_OK);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
} // namespace vendor::eureka::hardware::fmradio::V1_2
|
||||
:ndk::ScopedAStatus FMSupport::setValue(SetType type, int value) {
|
||||
switch (type) {
|
||||
case SetType::SET_TYPE_FM_FREQ:
|
||||
FileIO::writeline(FM_FREQ_CTL, freq * 1000);
|
||||
break;
|
||||
case SetType::SET_TYPE_FM_MUTE:
|
||||
case SetType::SET_TYPE_FM_VOLUME:
|
||||
case SetType::SET_TYPE_FM_THREAD:
|
||||
case SetType::SET_TYPE_FM_RMSSI:
|
||||
case SetType::SET_TYPE_FM_SEARCH_CANCEL:
|
||||
NOT_SUPPORTED;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
static inline bool vector_contains(const std::vector<int> vec,
|
||||
const int search) {
|
||||
for (auto i : vec) {
|
||||
if (i == search)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus FMSupport::getFreqsList(std::vector<int> *_aidl_return) {
|
||||
for (int i = 0; i < TRACK_SIZE; i++) {
|
||||
FileIO::writeline(FM_FREQ_SEEK, "1 " + std::to_string(3 * 10));
|
||||
int freq = FileIO::readline(FM_FREQ_CTL);
|
||||
if (vector_contains(*_aidl_return, freq))
|
||||
continue;
|
||||
_aidl_return->push_back(freq);
|
||||
}
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
::ndk::ScopedAStatus FMSupport::close() { NOT_SUPPORTED; }
|
||||
} // namespace aidl::vendor::eureka::hardware::fmradio
|
||||
|
|
|
|||
|
|
@ -14,19 +14,18 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <aidl/vendor/eureka/hardware/fmradio/BnFMSysfsSupport.h>
|
||||
#include <aidl/vendor/eureka/hardware/fmradio/BnFMDevControl.h>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::fmradio {
|
||||
|
||||
struct FMSupport : public BnFMSysfsSupport {
|
||||
struct FMSupport : public BnFMDevControl {
|
||||
public:
|
||||
FMSupport() = default;
|
||||
// Methods from aidl::vendor::eureka::hardware::fmradio::IFMRadio follow.
|
||||
::ndk::ScopedAStatus setManualFreq(float freq) override;
|
||||
::ndk::ScopedAStatus adjustFreqByStep(Direction dir) override;
|
||||
::ndk::ScopedAStatus isAvailable(bool *aidl_return) override;
|
||||
::ndk::ScopedAStatus getFreqFromSysfs(int32_t *aidl_return) override;
|
||||
::ndk::ScopedAStatus setChannelSpacing(Space space) override;
|
||||
::ndk::ScopedAStatus getChannelSpacing(Space *_aidl_return) override;
|
||||
::ndk::ScopedAStatus open(void) override;
|
||||
::ndk::ScopedAStatus getValue(GetType type, int *_aidl_return) override;
|
||||
::ndk::ScopedAStatus setValue(SetType type, int value) override;
|
||||
::ndk::ScopedAStatus getFreqsList(std::vector<int> *_aidl_return) override;
|
||||
::ndk::ScopedAStatus close(void) override;
|
||||
};
|
||||
} // namespace aidl::vendor::eureka::hardware::fmradio
|
||||
|
|
|
|||
|
|
@ -22,19 +22,19 @@
|
|||
using ::aidl::vendor::eureka::hardware::fmradio::FMDevControl;
|
||||
using ::aidl::vendor::eureka::hardware::fmradio::FMSupport;
|
||||
|
||||
template <class C> static void registerAsService(std::shared_ptr<C> service) {
|
||||
const std::string instance = std::string() + C::descriptor + "/default";
|
||||
template <class C> static void registerAsService(std::shared_ptr<C> service, const char *inst) {
|
||||
const std::string instance = std::string() + C::descriptor + "/" + inst;
|
||||
binder_status_t status =
|
||||
AServiceManager_addService(service->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
LOG(INFO) << "Register done for " << C::descriptor;
|
||||
LOG(INFO) << "Register done for instance " << inst;
|
||||
}
|
||||
|
||||
int main() {
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
|
||||
registerAsService(ndk::SharedRefBase::make<FMSupport>());
|
||||
registerAsService(ndk::SharedRefBase::make<FMDevControl>());
|
||||
registerAsService(ndk::SharedRefBase::make<FMSupport>(), "support");
|
||||
registerAsService(ndk::SharedRefBase::make<FMDevControl>(), "default");
|
||||
|
||||
ABinderProcess_joinThreadPool();
|
||||
return -1; // should never get here
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<manifest version="1.0" type="framework">
|
||||
<hal format="aidl">
|
||||
<name>vendor.eureka.hardware.fmradio</name>
|
||||
<fqname>IFMSysfsSupport/default</fqname>
|
||||
<fqname>IFMDevControl/support</fqname>
|
||||
<fqname>IFMDevControl/default</fqname>
|
||||
</hal>
|
||||
</manifest>
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
// Copyright (C) 2022 Eureka Team
|
||||
//
|
||||
// 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 vendor.eureka.hardware.fmradio;
|
||||
|
||||
@Backing(type="int")
|
||||
enum Direction {
|
||||
UP,
|
||||
DOWN,
|
||||
}
|
||||
|
|
@ -21,5 +21,6 @@ enum GetType {
|
|||
GET_TYPE_FM_LOWER_LIMIT,
|
||||
GET_TYPE_FM_RMSSI,
|
||||
GET_TYPE_FM_BEFORE_CHANNEL,
|
||||
GET_TYPE_FM_NEXT_CHANNEL
|
||||
GET_TYPE_FM_NEXT_CHANNEL,
|
||||
GET_TYPE_FM_SYSFS_IF,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
// Copyright (C) 2022 Eureka Team
|
||||
//
|
||||
// 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 vendor.eureka.hardware.fmradio;
|
||||
|
||||
import vendor.eureka.hardware.fmradio.Direction;
|
||||
import vendor.eureka.hardware.fmradio.Space;
|
||||
|
||||
interface IFMSysfsSupport {
|
||||
void adjustFreqByStep(in Direction dir);
|
||||
|
||||
Space getChannelSpacing();
|
||||
|
||||
int getFreqFromSysfs();
|
||||
|
||||
boolean isAvailable();
|
||||
|
||||
void setChannelSpacing(in Space space);
|
||||
|
||||
void setManualFreq(in float freq);
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright (C) 2022 Eureka Team
|
||||
//
|
||||
// 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 vendor.eureka.hardware.fmradio;
|
||||
|
||||
@Backing(type="int")
|
||||
enum Space {
|
||||
CHANNEL_SPACING_10HZ = 1,
|
||||
CHANNEL_SPACING_20HZ,
|
||||
CHANNEL_SPACING_30HZ,
|
||||
CHANNEL_SPACING_40HZ,
|
||||
CHANNEL_SPACING_50HZ = 5,
|
||||
}
|
||||
|
|
@ -7,4 +7,3 @@ vendor.eureka.hardware.parts.ISmartCharge u:object_r:hal_parts_service:s0
|
|||
|
||||
# FMRadio
|
||||
vendor.eureka.hardware.fmradio.IFMDevControl u:object_r:hal_fmradio_service:s0
|
||||
vendor.eureka.hardware.fmradio.IFMSysfsSupport u:object_r:hal_fmradio_service:s0
|
||||
|
|
|
|||
Loading…
Reference in a new issue