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

Commit 11857fbe authored by Chris Ye's avatar Chris Ye
Browse files

Migrate power manager native services to AIDL.

Migrage power manager native service to AIDL. Use aidl compiler to
generate native cpp header and source files from
frameworks/base/core/java/android/os/IPowerManager.aidl, retire
manually enrolled IPowerManager header and source files.

Bug: 149479744
Test: atest PowerManagerServiceTest

Change-Id: I3123a8803c334f7e82fe6da3df0202eb56786b1c
parent e58d4ba3
Loading
Loading
Loading
Loading
+0 −78
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 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.
 */

#ifndef ANDROID_IPOWERMANAGER_H
#define ANDROID_IPOWERMANAGER_H

#include <utils/Errors.h>
#include <binder/IInterface.h>
#include <hardware/power.h>

namespace android {

// ----------------------------------------------------------------------------

class IPowerManager : public IInterface
{
public:
    // These transaction IDs must be kept in sync with the method order from
    // IPowerManager.aidl.
    enum {
        ACQUIRE_WAKE_LOCK            = IBinder::FIRST_CALL_TRANSACTION,
        ACQUIRE_WAKE_LOCK_UID        = IBinder::FIRST_CALL_TRANSACTION + 1,
        RELEASE_WAKE_LOCK            = IBinder::FIRST_CALL_TRANSACTION + 2,
        UPDATE_WAKE_LOCK_UIDS        = IBinder::FIRST_CALL_TRANSACTION + 3,
        POWER_HINT                   = IBinder::FIRST_CALL_TRANSACTION + 4,
        UPDATE_WAKE_LOCK_SOURCE      = IBinder::FIRST_CALL_TRANSACTION + 5,
        IS_WAKE_LOCK_LEVEL_SUPPORTED = IBinder::FIRST_CALL_TRANSACTION + 6,
        USER_ACTIVITY                = IBinder::FIRST_CALL_TRANSACTION + 7,
        WAKE_UP                      = IBinder::FIRST_CALL_TRANSACTION + 8,
        GO_TO_SLEEP                  = IBinder::FIRST_CALL_TRANSACTION + 9,
        NAP                          = IBinder::FIRST_CALL_TRANSACTION + 10,
        IS_INTERACTIVE               = IBinder::FIRST_CALL_TRANSACTION + 11,
        IS_POWER_SAVE_MODE           = IBinder::FIRST_CALL_TRANSACTION + 12,
        GET_POWER_SAVE_STATE         = IBinder::FIRST_CALL_TRANSACTION + 13,
        SET_POWER_SAVE_MODE_ENABLED  = IBinder::FIRST_CALL_TRANSACTION + 14,
        REBOOT                       = IBinder::FIRST_CALL_TRANSACTION + 17,
        REBOOT_SAFE_MODE             = IBinder::FIRST_CALL_TRANSACTION + 18,
        SHUTDOWN                     = IBinder::FIRST_CALL_TRANSACTION + 19,
        CRASH                        = IBinder::FIRST_CALL_TRANSACTION + 20,
    };

    DECLARE_META_INTERFACE(PowerManager)

    // The parcels created by these methods must be kept in sync with the
    // corresponding methods from IPowerManager.aidl.
    // FIXME remove the bool isOneWay parameters as they are not oneway in the .aidl
    virtual status_t acquireWakeLock(int flags, const sp<IBinder>& lock, const String16& tag,
            const String16& packageName, bool isOneWay = false) = 0;
    virtual status_t acquireWakeLockWithUid(int flags, const sp<IBinder>& lock, const String16& tag,
            const String16& packageName, int uid, bool isOneWay = false) = 0;
    virtual status_t releaseWakeLock(const sp<IBinder>& lock, int flags, bool isOneWay = false) = 0;
    virtual status_t updateWakeLockUids(const sp<IBinder>& lock, int len, const int *uids,
            bool isOneWay = false) = 0;
    virtual status_t powerHint(int hintId, int data) = 0;
    virtual status_t goToSleep(int64_t event_time_ms, int reason, int flags) = 0;
    virtual status_t reboot(bool confirm, const String16& reason, bool wait) = 0;
    virtual status_t shutdown(bool confirm, const String16& reason, bool wait) = 0;
    virtual status_t crash(const String16& message) = 0;
};

// ----------------------------------------------------------------------------

}; // namespace android

#endif // ANDROID_IPOWERMANAGER_H
+5 −3
Original line number Diff line number Diff line
@@ -2,9 +2,11 @@ cc_library_shared {
    name: "libpowermanager",

    srcs: [
        "IPowerManager.cpp",
        "Temperature.cpp",
        "BatterySaverPolicyConfig.cpp",
        "CoolingDevice.cpp",
        "PowerSaveState.cpp",
        "Temperature.cpp",
        "WorkSource.cpp",
        ":libpowermanager_aidl",
    ],

@@ -46,10 +48,10 @@ cc_test {
    ],
    shared_libs: [
        "libbase",
        "libbinder",
        "libhidlbase",
        "liblog",
        "libpowermanager",
        "libbinder",
        "libutils",
    ],
}
+112 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.
 */

#define LOG_TAG "BatterySaverPolicyConfig"

#include <android/BatterySaverPolicyConfig.h>
#include <binder/Parcel.h>
#include <utils/Log.h>

namespace android::os {

status_t BatterySaverPolicyConfig::readDeviceSpecificSettings(const android::Parcel *parcel) {
    int32_t num = 0;
    status_t ret = parcel->readInt32(&num);
    if (ret != OK) {
        return ret;
    }
    for (int i = 0; i < num; i++) {
        String16 key, val;
        ret = parcel->readString16(&key) ?:
              parcel->readString16(&val);
        if (ret != OK) {
           return ret;
        }
        mDeviceSpecificSettings.emplace_back(key, val);
    }
    return ret;
}

status_t BatterySaverPolicyConfig::readFromParcel(const android::Parcel *parcel) {
    if (parcel == nullptr) {
        ALOGE("%s: Null parcel", __func__);
        return BAD_VALUE;
    }

    return parcel->readFloat(&mAdjustBrightnessFactor)
        ?: parcel->readBool(&mAdvertiseIsEnabled)
        ?: parcel->readBool(&mDeferFullBackup)
        ?: parcel->readBool(&mDeferKeyValueBackup)
        ?: readDeviceSpecificSettings(parcel)
        ?: parcel->readBool(&mDisableAnimation)
        ?: parcel->readBool(&mDisableAod)
        ?: parcel->readBool(&mDisableLaunchBoost)
        ?: parcel->readBool(&mDisableOptionalSensors)
        ?: parcel->readBool(&mDisableSoundTrigger)
        ?: parcel->readBool(&mDisableVibration)
        ?: parcel->readBool(&mEnableAdjustBrightness)
        ?: parcel->readBool(&mEnableDataSaver)
        ?: parcel->readBool(&mEnableFirewall)
        ?: parcel->readBool(&mEnableNightMode)
        ?: parcel->readBool(&mEnableQuickDoze)
        ?: parcel->readBool(&mForceAllAppsStandby)
        ?: parcel->readBool(&mForceBackgroundCheck)
        ?: parcel->readInt32(reinterpret_cast<int32_t *>(&mLocationMode));
}

status_t BatterySaverPolicyConfig::writeDeviceSpecificSettings(android::Parcel *parcel) const {
    status_t ret = parcel->writeInt32(mDeviceSpecificSettings.size());
    if (ret != OK) {
        return ret;
    }
    for (auto& settings : mDeviceSpecificSettings) {
        ret = parcel->writeString16(settings.first) ?:
              parcel->writeString16(settings.second);
        if (ret != OK) {
           return ret;
        }
    }
    return ret;
}

status_t BatterySaverPolicyConfig::writeToParcel(android::Parcel *parcel) const {
    if (parcel == nullptr) {
        ALOGE("%s: Null parcel", __func__);
        return BAD_VALUE;
    }

    return parcel->writeFloat(mAdjustBrightnessFactor)
        ?: parcel->writeBool(mAdvertiseIsEnabled)
        ?: parcel->writeBool(mDeferFullBackup)
        ?: parcel->writeBool(mDeferKeyValueBackup)
        ?: writeDeviceSpecificSettings(parcel)
        ?: parcel->writeBool(mDisableAnimation)
        ?: parcel->writeBool(mDisableAod)
        ?: parcel->writeBool(mDisableLaunchBoost)
        ?: parcel->writeBool(mDisableOptionalSensors)
        ?: parcel->writeBool(mDisableSoundTrigger)
        ?: parcel->writeBool(mDisableVibration)
        ?: parcel->writeBool(mEnableAdjustBrightness)
        ?: parcel->writeBool(mEnableDataSaver)
        ?: parcel->writeBool(mEnableFirewall)
        ?: parcel->writeBool(mEnableNightMode)
        ?: parcel->writeBool(mEnableQuickDoze)
        ?: parcel->writeBool(mForceAllAppsStandby)
        ?: parcel->writeBool(mForceBackgroundCheck)
        ?: parcel->writeInt32(static_cast<int32_t>(mLocationMode));
}

} // namespace android::os
+0 −142
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 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.
 */

#define LOG_TAG "IPowerManager"
//#define LOG_NDEBUG 0
#include <utils/Log.h>

#include <stdint.h>
#include <sys/types.h>

#include <binder/Parcel.h>

#include <powermanager/IPowerManager.h>

namespace android {

class BpPowerManager : public BpInterface<IPowerManager>
{
public:
    explicit BpPowerManager(const sp<IBinder>& impl)
        : BpInterface<IPowerManager>(impl)
    {
    }

    virtual status_t acquireWakeLock(int flags, const sp<IBinder>& lock, const String16& tag,
            const String16& packageName, bool isOneWay)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());

        data.writeStrongBinder(lock);
        data.writeInt32(flags);
        data.writeString16(tag);
        data.writeString16(packageName);
        data.writeInt32(0); // no WorkSource
        data.writeString16(NULL, 0); // no history tag
        return remote()->transact(ACQUIRE_WAKE_LOCK, data, &reply,
                isOneWay ? IBinder::FLAG_ONEWAY : 0);
    }

    virtual status_t acquireWakeLockWithUid(int flags, const sp<IBinder>& lock, const String16& tag,
            const String16& packageName, int uid, bool isOneWay)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());

        data.writeStrongBinder(lock);
        data.writeInt32(flags);
        data.writeString16(tag);
        data.writeString16(packageName);
        data.writeInt32(uid); // uid to blame for the work
        return remote()->transact(ACQUIRE_WAKE_LOCK_UID, data, &reply,
                isOneWay ? IBinder::FLAG_ONEWAY : 0);
    }

    virtual status_t releaseWakeLock(const sp<IBinder>& lock, int flags, bool isOneWay)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
        data.writeStrongBinder(lock);
        data.writeInt32(flags);
        return remote()->transact(RELEASE_WAKE_LOCK, data, &reply,
                isOneWay ? IBinder::FLAG_ONEWAY : 0);
    }

    virtual status_t updateWakeLockUids(const sp<IBinder>& lock, int len, const int *uids,
            bool isOneWay) {
        Parcel data, reply;
        data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
        data.writeStrongBinder(lock);
        data.writeInt32Array(len, uids);
        return remote()->transact(UPDATE_WAKE_LOCK_UIDS, data, &reply,
                isOneWay ? IBinder::FLAG_ONEWAY : 0);
    }

    virtual status_t powerHint(int hintId, int param)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
        data.writeInt32(hintId);
        data.writeInt32(param);
        // This FLAG_ONEWAY is in the .aidl, so there is no way to disable it
        return remote()->transact(POWER_HINT, data, &reply, IBinder::FLAG_ONEWAY);
    }

    virtual status_t goToSleep(int64_t event_time_ms, int reason, int flags)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
        data.writeInt64(event_time_ms);
        data.writeInt32(reason);
        data.writeInt32(flags);
        return remote()->transact(GO_TO_SLEEP, data, &reply, 0);
    }

    virtual status_t reboot(bool confirm, const String16& reason, bool wait)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
        data.writeInt32(confirm);
        data.writeString16(reason);
        data.writeInt32(wait);
        return remote()->transact(REBOOT, data, &reply, 0);
    }

    virtual status_t shutdown(bool confirm, const String16& reason, bool wait)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
        data.writeInt32(confirm);
        data.writeString16(reason);
        data.writeInt32(wait);
        return remote()->transact(SHUTDOWN, data, &reply, 0);
    }

    virtual status_t crash(const String16& message)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
        data.writeString16(message);
        return remote()->transact(CRASH, data, &reply, 0);
    }
};

IMPLEMENT_META_INTERFACE(PowerManager, "android.os.IPowerManager");

// ----------------------------------------------------------------------------

}; // namespace android
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.
 */

#define LOG_TAG "PowerSaveState"

#include <android/PowerSaveState.h>
#include <binder/Parcel.h>
#include <utils/Log.h>

namespace android::os {

status_t PowerSaveState::readFromParcel(const android::Parcel *parcel) {
    if (parcel == nullptr) {
        ALOGE("%s: Null parcel", __func__);
        return BAD_VALUE;
    }

    return parcel->readBool(&mBatterySaverEnabled)
        ?: parcel->readBool(&mGlobalBatterySaverEnabled)
        ?: parcel->readInt32(reinterpret_cast<int32_t *>(&mLocationMode))
        ?: parcel->readFloat(&mBrightnessFactor);
}

status_t PowerSaveState::writeToParcel(android::Parcel *parcel) const {
    if (parcel == nullptr) {
        ALOGE("%s: Null parcel", __func__);
        return BAD_VALUE;
    }

    return parcel->writeBool(mBatterySaverEnabled)
        ?: parcel->writeBool(mGlobalBatterySaverEnabled)
        ?: parcel->writeInt32(static_cast<int32_t>(mLocationMode))
        ?: parcel->writeFloat(mBrightnessFactor);
}

} // namespace android::os
Loading