Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • LMODroid/platform_hardware_lmodroid
1 result
Show changes
Commits on Source (2)
package {
// See: http://go/android-license-faq
default_applicable_licenses: ["Android-Apache-2.0"],
}
aidl_interface {
name: "lmodroid-power-ext",
vendor_available: true,
srcs: [
"lmodroid/hardware/power/extension/IPowerExt.aidl",
],
stability: "vintf",
backend: {
java: {
platform_apis: true,
},
cpp: {
enabled: true,
},
},
owner: "lmodroid",
versions_with_info: [
{
version: "1",
imports: [],
},
],
}
978ff39deab152089371091488ac46b4c21ef7f1
/*
* Copyright (C) 2023 LibreMobileOS Foundation
*
* 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 lmodroid.hardware.power.extension;
@VintfStability
interface IPowerExt {
oneway void setMode(in @utf8InCpp String mode, in boolean enabled);
boolean isModeSupported(in @utf8InCpp String mode);
oneway void setBoost(in @utf8InCpp String boost, in int durationMs);
boolean isBoostSupported(in @utf8InCpp String boost);
oneway void notifyAppState(in @utf8InCpp String packActName, in int pid, in int uid, in boolean active);
}
/*
* Copyright (C) 2023 LibreMobileOS Foundation
*
* 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 lmodroid.hardware.power.extension;
@VintfStability
interface IPowerExt {
oneway void setMode(in @utf8InCpp String mode, in boolean enabled);
boolean isModeSupported(in @utf8InCpp String mode);
oneway void setBoost(in @utf8InCpp String boost, in int durationMs);
boolean isBoostSupported(in @utf8InCpp String boost);
oneway void notifyAppState(in @utf8InCpp String packActName, in int pid, in int uid, in boolean active);
}
/*
* Copyright (C) 2023 LibreMobileOS Foundation
*
* 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 lmodroid.hardware.power.extension;
@VintfStability
interface IPowerExt {
/**
* setMode() is called to enable/disable specific hint mode, which
* may result in adjustment of power/performance parameters of the
* cpufreq governor and other controls on device side.
*
* A particular platform may choose to ignore any mode hint.
*
* @param mode which is to be enable/disable.
* @param enabled true to enable, false to disable the mode.
*/
oneway void setMode(in @utf8InCpp String mode, in boolean enabled);
/**
* isModeSupported() is called to query if the given mode hint is
* supported by vendor.
*
* @return true if the hint passed is supported on this platform.
* If false, setting the mode will have no effect.
* @param mode to be queried
*/
boolean isModeSupported(in @utf8InCpp String mode);
/**
* setBoost() indicates the device may need to boost some resources, as the
* the load is likely to increase before the kernel governors can react.
* Depending on the boost, it may be appropriate to raise the frequencies of
* CPU, GPU, memory subsystem, or stop CPU from going into deep sleep state.
* A particular platform may choose to ignore this hint.
*
* @param boost which is to be set with a timeout.
* @param durationMs The expected duration of the user's interaction, if
* known, or 0 if the expected duration is unknown.
* a negative value indicates canceling previous boost.
* A given platform can choose to boost some time based on durationMs,
* and may also pick an appropriate timeout for 0 case.
*/
oneway void setBoost(in @utf8InCpp String boost, in int durationMs);
/**
* isBoostSupported() is called to query if the given boost hint is
* supported by vendor. When returns false, set the boost will have
* no effect on the platform.
*
* @return true if the hint passed is supported on this platform.
* If false, setting the boost will have no effect.
* @param boost to be queried
*/
boolean isBoostSupported(in @utf8InCpp String boost);
/**
* notifyAppState() sends a app state notification with package name, activity name,
* pid, uid and state. This allows the implementor of this interface to take action
* on certain app packages such as known games.
*
* @param packActName package + activity name separated by a slash.
* @param pid process indentifier.
* @param uid user id.
* @param active true if application is active, false if paused or closed.
*/
oneway void notifyAppState(in @utf8InCpp String packActName, in int pid, in int uid, in boolean active);
}
cc_binary {
name: "powerext_native_test",
vendor: true,
srcs: ["test/main.cpp"],
shared_libs: [
"libpowerext",
]
}
cc_library_shared {
name: "libpowerext",
vendor_available: true,
srcs: ["PowerExt.cpp"],
shared_libs: [
"android.hardware.power-V4-ndk",
"libbinder_ndk",
"liblog",
"lmodroid-power-ext-V1-ndk",
],
export_shared_lib_headers: [
"lmodroid-power-ext-V1-ndk",
],
include_dirs: ["."],
export_include_dirs: ["."],
}
#include "PowerExt.h"
#include <android/binder_manager.h>
#include <android/log.h>
#define LOG_TAG "PowerExtClient"
#include <log/log.h>
#include <aidl/android/hardware/power/IPower.h>
namespace android {
// Construction Workers
PowerExt::PowerExt() {
init();
}
PowerExt::~PowerExt() {
ALOGE("Destroying!");
mPowerHalAidl = nullptr;
mPowerHalExtAidl = nullptr;
}
bool PowerExt::connectHAL() {
if (mPowerHalAidl && mPowerHalExtAidl) {
return true;
}
const std::string kInstance = std::string(IPower::descriptor) + "/default";
ndk::SpAIBinder pwBinder = ndk::SpAIBinder(AServiceManager_getService(kInstance.c_str()));
mPowerHalAidl = IPower::fromBinder(pwBinder);
if (!mPowerHalAidl) {
ALOGE("failed to connect power HAL");
return false;
}
ndk::SpAIBinder pwExtBinder;
AIBinder_getExtension(pwBinder.get(), pwExtBinder.getR());
mPowerHalExtAidl = IPowerExt::fromBinder(pwExtBinder);
if (!mPowerHalExtAidl) {
mPowerHalAidl = nullptr;
ALOGE("failed to connect power HAL extension");
return false;
}
ALOGE("connected power HAL successfully");
return true;
}
// Main functions
void PowerExt::setMode(const std::string& mode, bool enabled) {
if (!connectHAL()) {
ALOGE("setMode failed to connect power HAL");
return;
}
auto ret = mPowerHalExtAidl->setMode(mode, enabled);
if (!ret.isOk()) {
ALOGE("failed to set mode: %s", mode.c_str());
}
}
bool PowerExt::isModeSupported(const std::string& mode) {
if (!connectHAL()) {
ALOGE("isModeSupported failed to connect power HAL");
return false;
}
bool supported;
auto ret = mPowerHalExtAidl->isModeSupported(mode, &supported);
if (!ret.isOk()) {
ALOGE("failed to check mode: %s", mode.c_str());
return false;
}
ALOGE("isModeSupported: %s", supported ? "true" : "false");
return supported;
}
void PowerExt::setBoost(const std::string& boost, int durationMs) {
if (!connectHAL()) {
ALOGE("setBoost failed to connect power HAL");
return;
}
auto ret = mPowerHalExtAidl->setBoost(boost, durationMs);
if (!ret.isOk()) {
ALOGE("failed to set boost: %s", boost.c_str());
}
}
bool PowerExt::isBoostSupported(const std::string& boost) {
if (!connectHAL()) {
ALOGE("isBoostSupported failed to connect power HAL");
return false;
}
bool supported;
auto ret = mPowerHalExtAidl->isBoostSupported(boost, &supported);
if (!ret.isOk()) {
ALOGE("failed to check boost: %s", boost.c_str());
return false;
}
ALOGE("isBoostSupported: %s", supported ? "true" : "false");
return supported;
}
void PowerExt::notifyAppState(const std::string& packActName, int pid, int uid, bool active) {
if (!connectHAL()) {
ALOGE("notifyAppState failed to connect power HAL");
return;
}
auto ret = mPowerHalExtAidl->notifyAppState(packActName, pid, uid, active);
if (!ret.isOk()) {
ALOGE("failed to notify app state: %s", packActName.c_str());
}
}
} // namespace android
#ifndef _POWEREXT_H_
#define _POWEREXT_H_
#include <aidl/lmodroid/hardware/power/extension/IPowerExt.h>
#include <string>
using namespace aidl::lmodroid::hardware::power::extension;
namespace aidl::android::hardware::power {
class IPower;
}
using namespace aidl::android::hardware::power;
namespace android {
class PowerExt {
public:
PowerExt();
~PowerExt();
bool init() { return connectHAL(); };
void setMode(const std::string& mode, bool enabled);
bool isModeSupported(const std::string& mode);
void setBoost(const std::string& boost, int durationMs);
bool isBoostSupported(const std::string& boost);
void notifyAppState(const std::string& packActName, int pid, int uid, bool active);
protected:
bool connectHAL();
std::shared_ptr<IPower> mPowerHalAidl;
std::shared_ptr<IPowerExt> mPowerHalExtAidl;
};
}; // namespace android
#endif
#include <iostream>
#include "PowerExt.h"
using namespace std;
int main() {
android::PowerExt powerExt = android::PowerExt();
if (powerExt.connected() == false) {
cout << "Failed to connect to power HAL" << endl;
return 1;
}
int choice;
string mode;
bool enabled;
string boost;
int durationMs;
string packActName;
int pid;
int uid;
bool active;
while (true) {
cout << "Select function to test:" << endl;
cout << "1. setMode" << endl;
cout << "2. isModeSupported" << endl;
cout << "3. setBoost" << endl;
cout << "4. isBoostSupported" << endl;
cout << "5. notifyAppState" << endl;
cout << "6. Exit" << endl;
cout << "Enter choice (1-6): ";
cin >> choice;
switch (choice) {
case 1:
cout << "Enter mode and enabled (1/0): ";
cin >> mode >> enabled;
cout << "Setting mode " << mode << " to " << (enabled ? "true" : "false") << endl;
powerExt.setMode(mode, enabled);
break;
case 2:
cout << "Enter mode: ";
cin >> mode;
cout << "Mode supported: " << (powerExt.isModeSupported(mode) ? "true" : "false") << endl;
break;
case 3:
cout << "Enter boost and duration (in milliseconds): ";
cin >> boost >> durationMs;
cout << "Setting boost to " << boost << " for " << durationMs << " milliseconds" << endl;
powerExt.setBoost(boost, durationMs);
break;
case 4:
cout << "Enter boost: ";
cin >> boost;
cout << "Boost supported: " << (powerExt.isBoostSupported(boost) ? "true" : "false") << endl;
break;
case 5:
cout << "Enter packActName, pid, uid, and active (1/0): ";
cin >> packActName >> pid >> uid >> active;
powerExt.notifyAppState(packActName, pid, uid, active);
break;
case 6:
cout << "Exiting..." << endl;
return 0;
default:
cout << "Invalid choice. Please enter a number between 1 and 6." << endl;
}
}
return 0;
}