mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-23 12:35:33 -04:00
universal7885: parts-aidl: Just send callback through setSwapOn()
- Set callback on JNI, since Java class cant be sent through, use the ndk backend to implement callback and send to swapon()
This commit is contained in:
parent
72f2eb6800
commit
ef97fdeb77
18 changed files with 209 additions and 30 deletions
|
|
@ -1 +1 @@
|
|||
d1cebfb943ba21a23e9c502b43d6c2766f6e608d
|
||||
48bdd89bd2780de4c4254e0d52a8c4e53e416d00
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
// 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.parts;
|
||||
|
||||
@VintfStability
|
||||
interface IBoolCallback {
|
||||
void respondToBool(in boolean result);
|
||||
}
|
||||
|
|
@ -14,9 +14,10 @@
|
|||
|
||||
package vendor.eureka.hardware.parts;
|
||||
|
||||
import vendor.eureka.hardware.parts.IBoolCallback;
|
||||
|
||||
@VintfStability
|
||||
interface ISwapOnData {
|
||||
boolean getSwapOnResult();
|
||||
|
||||
boolean isMutexLocked();
|
||||
|
||||
|
|
@ -24,7 +25,7 @@ interface ISwapOnData {
|
|||
|
||||
oneway void setSwapOff();
|
||||
|
||||
oneway void setSwapOn();
|
||||
oneway void setSwapOn(in IBoolCallback cb);
|
||||
|
||||
oneway void makeSwapFile(in int size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
// 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.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
|
||||
// two cases:
|
||||
// 1). this is a frozen version file - do not edit this in any case.
|
||||
// 2). this is a 'current' file. If you make a backwards compatible change to
|
||||
// the interface (from the latest frozen version), the build system will
|
||||
// prompt you to update this file with `m <name>-update-api`.
|
||||
//
|
||||
// You must not make a backward incompatible change to any AIDL file built
|
||||
// with the aidl_interface module type with versions property set. The module
|
||||
// type is used to build AIDL files in a way that they can be used across
|
||||
// independently updatable components of the system. If a device is shipped
|
||||
// with such a backward incompatible change, it has a high risk of breaking
|
||||
// later when a module using the interface is updated, e.g., Mainline modules.
|
||||
|
||||
package vendor.eureka.hardware.parts;
|
||||
@VintfStability
|
||||
interface IBoolCallback {
|
||||
void respondToBool(in boolean result);
|
||||
}
|
||||
|
|
@ -32,10 +32,9 @@
|
|||
package vendor.eureka.hardware.parts;
|
||||
@VintfStability
|
||||
interface ISwapOnData {
|
||||
boolean getSwapOnResult();
|
||||
boolean isMutexLocked();
|
||||
oneway void removeSwapFile();
|
||||
oneway void setSwapOff();
|
||||
oneway void setSwapOn();
|
||||
oneway void setSwapOn(in vendor.eureka.hardware.parts.IBoolCallback cb);
|
||||
oneway void makeSwapFile(in int size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@ namespace aidl::vendor::eureka::hardware::parts {
|
|||
|
||||
static std::mutex thread_lock;
|
||||
|
||||
static bool swapOnRes = false;
|
||||
|
||||
static inline bool swapfile_exist(void) {
|
||||
return access(SWAP_PATH, F_OK) == 0;
|
||||
}
|
||||
|
|
@ -61,15 +59,15 @@ static void rmswap(void) {
|
|||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
static void swapon_func(void) {
|
||||
static void swapon_func(cb_t cb) {
|
||||
const std::lock_guard<std::mutex> lock(thread_lock);
|
||||
int res = swapon(SWAP_PATH, (10 << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK);
|
||||
swapOnRes = res == 0;
|
||||
if (cb != nullptr) cb->respondToBool(res == 0);
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SwapOnData::setSwapOn() {
|
||||
::ndk::ScopedAStatus SwapOnData::setSwapOn(cb_t cb) {
|
||||
if (!swapfile_exist()) return ::ndk::ScopedAStatus::ok();
|
||||
std::thread swapon_thread(swapon_func);
|
||||
std::thread swapon_thread(swapon_func, cb);
|
||||
swapon_thread.detach();
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
|
@ -86,11 +84,6 @@ static void swapoff_func(void) {
|
|||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SwapOnData::getSwapOnResult(bool *_aidl_return) {
|
||||
*_aidl_return = swapOnRes;
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SwapOnData::isMutexLocked(bool *_aidl_return) {
|
||||
if (thread_lock.try_lock()) {
|
||||
thread_lock.unlock();
|
||||
|
|
|
|||
|
|
@ -18,14 +18,15 @@
|
|||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
using cb_t = const std::shared_ptr<IBoolCallback>&;
|
||||
|
||||
struct SwapOnData : public BnSwapOnData {
|
||||
// Methods from ::aidl::vendor::eureka::hardware::parts::ISwapOnData
|
||||
// follow.
|
||||
::ndk::ScopedAStatus makeSwapFile(int32_t size);
|
||||
::ndk::ScopedAStatus setSwapOn(void);
|
||||
::ndk::ScopedAStatus setSwapOn(cb_t cb);
|
||||
::ndk::ScopedAStatus removeSwapFile(void);
|
||||
::ndk::ScopedAStatus setSwapOff(void);
|
||||
::ndk::ScopedAStatus getSwapOnResult(bool *_aidl_return);
|
||||
::ndk::ScopedAStatus isMutexLocked(bool *_aidl_return);
|
||||
};
|
||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||
|
|
|
|||
20
universal7885-common/apps/aidl-support/parts/vendor/eureka/hardware/parts/IBoolCallback.aidl
vendored
Normal file
20
universal7885-common/apps/aidl-support/parts/vendor/eureka/hardware/parts/IBoolCallback.aidl
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// 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.parts;
|
||||
|
||||
@VintfStability
|
||||
interface IBoolCallback {
|
||||
void respondToBool(in boolean result);
|
||||
}
|
||||
|
|
@ -14,9 +14,10 @@
|
|||
|
||||
package vendor.eureka.hardware.parts;
|
||||
|
||||
import vendor.eureka.hardware.parts.IBoolCallback;
|
||||
|
||||
@VintfStability
|
||||
interface ISwapOnData {
|
||||
boolean getSwapOnResult();
|
||||
|
||||
boolean isMutexLocked();
|
||||
|
||||
|
|
@ -24,7 +25,7 @@ interface ISwapOnData {
|
|||
|
||||
oneway void setSwapOff();
|
||||
|
||||
oneway void setSwapOn();
|
||||
oneway void setSwapOn(in IBoolCallback cb);
|
||||
|
||||
oneway void makeSwapFile(in int size);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue