universal7885: Unify IFMSysfsSupport to IFMDevControl

Also update sepolicy svc ctx
This commit is contained in:
roynatech2544 2022-10-07 13:39:07 +09:00
commit b6537a107b
11 changed files with 89 additions and 162 deletions

View file

@ -1,22 +1,20 @@
package com.eurekateam.fmradio package com.eurekateam.fmradio
import vendor.eureka.hardware.fmradio.IFMDevControl import vendor.eureka.hardware.fmradio.IFMDevControl
import vendor.eureka.hardware.fmradio.IFMSysfsSupport
import vendor.eureka.hardware.fmradio.GetType import vendor.eureka.hardware.fmradio.GetType
import vendor.eureka.hardware.fmradio.SetType import vendor.eureka.hardware.fmradio.SetType
import vendor.eureka.hardware.fmradio.Direction
import android.os.ServiceManager import android.os.ServiceManager
class NativeFMInterface { class NativeFMInterface {
private val mDevCtl : IFMDevControl private val mDevCtl : IFMDevControl
private val mSysfsCtl : IFMSysfsSupport private val mSysfsCtl : IFMDevControl
private var mSysfs = false private val mDefaultCtl : IFMDevControl
init { init {
mDevCtl = IFMDevControl.Stub.asInterface(ServiceManager.waitForDeclaredService("vendor.eureka.hardware.fmradio.IFMDevControl/default")) mDevCtl = IFMDevControl.Stub.asInterface(ServiceManager.waitForDeclaredService("vendor.eureka.hardware.fmradio.IFMDevControl/default"))
mSysfsCtl = IFMSysfsSupport.Stub.asInterface(ServiceManager.waitForDeclaredService("vendor.eureka.hardware.fmradio.IFMSysfsSupport/default")) mSysfsCtl = IFMDevControl.Stub.asInterface(ServiceManager.waitForDeclaredService("vendor.eureka.hardware.fmradio.IFMDevControl/support"))
mSysfs = mSysfsCtl.isAvailable() mDefaultCtl = if (mSysfsCtl.getValue(GetType.GET_TYPE_FM_SYSFS_IF) == 0) mSysfsCtl else mDevCtl
} }
fun openFMDevice(): Int { fun openFMDevice(): Int {
@ -31,27 +29,13 @@ class NativeFMInterface {
fun getFmUpper(a: Int) : Int = mDevCtl.getValue(GetType.GET_TYPE_FM_UPPER_LIMIT) 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 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 getRMSSI(a: Int): Int = mDevCtl.getValue(GetType.GET_TYPE_FM_RMSSI)
fun getFMTracks(fd: Int): IntArray = if (mSysfs) { fun getFMTracks(fd: Int): IntArray = mDefaultCtl.getFreqsList()
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 setFMThread(a: Int, run: Boolean) = mDevCtl.setValue(SetType.SET_TYPE_FM_THREAD, if (run) 1 else 0) 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) { fun getNextChannel(a: Int): Int = mDefaultCtl.getValue(GetType.GET_TYPE_FM_NEXT_CHANNEL)
mSysfsCtl.adjustFreqByStep(Direction.UP) fun getBeforeChannel(a: Int): Int = mDefaultCtl.getValue(GetType.GET_TYPE_FM_BEFORE_CHANNEL)
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 stopSearching(a: Int) = mDevCtl.setValue(SetType.SET_TYPE_FM_SEARCH_CANCEL, 0) 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 setFMRSSI(a: Int, rssi: Long) = mDevCtl.setValue(SetType.SET_TYPE_FM_RMSSI, rssi.toInt())
fun closeFMDevice(fd: Int) = mDevCtl.close() 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 external fun setAudioRoute(speaker: Boolean): Int
} }

View file

@ -52,6 +52,8 @@ static int fd = -1;
case GetType::GET_TYPE_FM_NEXT_CHANNEL: case GetType::GET_TYPE_FM_NEXT_CHANNEL:
*_aidl_return = fm_radio_slsi::next_channel(fd); *_aidl_return = fm_radio_slsi::next_channel(fd);
break; break;
case GetType::GET_TYPE_FM_SYSFS_IF:
[[fallthrough]];
default: default:
break; break;
}; };

View file

@ -13,15 +13,22 @@
// limitations under the License. // limitations under the License.
#include "FMSupport.h" #include "FMSupport.h"
#include <fstream>
#include <iostream> #include <iostream>
#include <sstream>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h>
#include <FileIO.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 { namespace aidl::vendor::eureka::hardware::fmradio {
@ -30,55 +37,67 @@ constexpr const char *FM_FREQ_CTL =
constexpr const char *FM_FREQ_SEEK = constexpr const char *FM_FREQ_SEEK =
"/sys/devices/virtual/s610_radio/s610_radio/radio_freq_seek"; "/sys/devices/virtual/s610_radio/s610_radio/radio_freq_seek";
::ndk::ScopedAStatus FMSupport::setManualFreq(float freq) { ::ndk::ScopedAStatus FMSupport::open(void) { NOT_SUPPORTED; }
FileIO::writeline(FM_FREQ_CTL, freq * 1000);
return ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus FMSupport::adjustFreqByStep(Direction dir) { ::ndk::ScopedAStatus FMSupport::getValue(GetType type, int *_aidl_return) {
std::string value = ""; switch (type) {
if (dir == Direction::UP) { case GetType::GET_TYPE_FM_FREQ:
value = "1 " + std::to_string(mChannelSpacing * 10); *_aidl_return = FileIO::readline(FM_FREQ_CTL);
} 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;
break; break;
case 2: case GetType::GET_TYPE_FM_UPPER_LIMIT:
*_aidl_return = Space::CHANNEL_SPACING_20HZ; 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; break;
case 3: case GetType::GET_TYPE_FM_NEXT_CHANNEL:
*_aidl_return = Space::CHANNEL_SPACING_30HZ; FileIO::writeline(FM_FREQ_SEEK, "1 " + std::to_string(3 * 10));
break; *_aidl_return = FileIO::readline(FM_FREQ_CTL);
case 4:
*_aidl_return = Space::CHANNEL_SPACING_40HZ;
break;
case 5:
*_aidl_return = Space::CHANNEL_SPACING_50HZ;
break; break;
case GetType::GET_TYPE_FM_SYSFS_IF:
*_aidl_return = access("/sys/devices/virtual/s610_radio/s610_radio/", F_OK);
default: default:
break; break;
} };
return ndk::ScopedAStatus::ok(); 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

View file

@ -14,19 +14,18 @@
#pragma once #pragma once
#include <aidl/vendor/eureka/hardware/fmradio/BnFMSysfsSupport.h> #include <aidl/vendor/eureka/hardware/fmradio/BnFMDevControl.h>
namespace aidl::vendor::eureka::hardware::fmradio { namespace aidl::vendor::eureka::hardware::fmradio {
struct FMSupport : public BnFMSysfsSupport { struct FMSupport : public BnFMDevControl {
public: public:
FMSupport() = default; FMSupport() = default;
// Methods from aidl::vendor::eureka::hardware::fmradio::IFMRadio follow. // Methods from aidl::vendor::eureka::hardware::fmradio::IFMRadio follow.
::ndk::ScopedAStatus setManualFreq(float freq) override; ::ndk::ScopedAStatus open(void) override;
::ndk::ScopedAStatus adjustFreqByStep(Direction dir) override; ::ndk::ScopedAStatus getValue(GetType type, int *_aidl_return) override;
::ndk::ScopedAStatus isAvailable(bool *aidl_return) override; ::ndk::ScopedAStatus setValue(SetType type, int value) override;
::ndk::ScopedAStatus getFreqFromSysfs(int32_t *aidl_return) override; ::ndk::ScopedAStatus getFreqsList(std::vector<int> *_aidl_return) override;
::ndk::ScopedAStatus setChannelSpacing(Space space) override; ::ndk::ScopedAStatus close(void) override;
::ndk::ScopedAStatus getChannelSpacing(Space *_aidl_return) override;
}; };
} // namespace aidl::vendor::eureka::hardware::fmradio } // namespace aidl::vendor::eureka::hardware::fmradio

View file

@ -22,19 +22,19 @@
using ::aidl::vendor::eureka::hardware::fmradio::FMDevControl; using ::aidl::vendor::eureka::hardware::fmradio::FMDevControl;
using ::aidl::vendor::eureka::hardware::fmradio::FMSupport; using ::aidl::vendor::eureka::hardware::fmradio::FMSupport;
template <class C> static void registerAsService(std::shared_ptr<C> service) { template <class C> static void registerAsService(std::shared_ptr<C> service, const char *inst) {
const std::string instance = std::string() + C::descriptor + "/default"; const std::string instance = std::string() + C::descriptor + "/" + inst;
binder_status_t status = binder_status_t status =
AServiceManager_addService(service->asBinder().get(), instance.c_str()); AServiceManager_addService(service->asBinder().get(), instance.c_str());
CHECK(status == STATUS_OK); CHECK(status == STATUS_OK);
LOG(INFO) << "Register done for " << C::descriptor; LOG(INFO) << "Register done for instance " << inst;
} }
int main() { int main() {
ABinderProcess_setThreadPoolMaxThreadCount(0); ABinderProcess_setThreadPoolMaxThreadCount(0);
registerAsService(ndk::SharedRefBase::make<FMSupport>()); registerAsService(ndk::SharedRefBase::make<FMSupport>(), "support");
registerAsService(ndk::SharedRefBase::make<FMDevControl>()); registerAsService(ndk::SharedRefBase::make<FMDevControl>(), "default");
ABinderProcess_joinThreadPool(); ABinderProcess_joinThreadPool();
return -1; // should never get here return -1; // should never get here

View file

@ -1,7 +1,7 @@
<manifest version="1.0" type="framework"> <manifest version="1.0" type="framework">
<hal format="aidl"> <hal format="aidl">
<name>vendor.eureka.hardware.fmradio</name> <name>vendor.eureka.hardware.fmradio</name>
<fqname>IFMSysfsSupport/default</fqname> <fqname>IFMDevControl/support</fqname>
<fqname>IFMDevControl/default</fqname> <fqname>IFMDevControl/default</fqname>
</hal> </hal>
</manifest> </manifest>

View file

@ -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,
}

View file

@ -21,5 +21,6 @@ enum GetType {
GET_TYPE_FM_LOWER_LIMIT, GET_TYPE_FM_LOWER_LIMIT,
GET_TYPE_FM_RMSSI, GET_TYPE_FM_RMSSI,
GET_TYPE_FM_BEFORE_CHANNEL, GET_TYPE_FM_BEFORE_CHANNEL,
GET_TYPE_FM_NEXT_CHANNEL GET_TYPE_FM_NEXT_CHANNEL,
GET_TYPE_FM_SYSFS_IF,
} }

View file

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

View file

@ -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,
}

View file

@ -7,4 +7,3 @@ vendor.eureka.hardware.parts.ISmartCharge u:object_r:hal_parts_service:s0
# FMRadio # FMRadio
vendor.eureka.hardware.fmradio.IFMDevControl u:object_r:hal_fmradio_service:s0 vendor.eureka.hardware.fmradio.IFMDevControl u:object_r:hal_fmradio_service:s0
vendor.eureka.hardware.fmradio.IFMSysfsSupport u:object_r:hal_fmradio_service:s0