android STR suspend/resume framework
android STR suspend/resume framework
console:/sys/power # cat wake_lock PowerManager.SuspendLockout PowerManagerService.Display
console:/sys/power # cat wake_unlock KeyEvents PowerManagerService.WakeLocks
上述wake_lock、wake_unlock里的内容分别是如下incSuspendCounter()、decSuspendCounter()写进去的,mUseSuspendCounter的值是0:
system\hardware\interfaces\suspend\1.0\default\SystemSuspend.cpp
void SystemSuspend::incSuspendCounter(const string& name) { auto l = std::lock_guard(mCounterLock); if (mUseSuspendCounter) { mSuspendCounter++; } else { if (!WriteStringToFd(name, mWakeLockFd)) { PLOG(ERROR) << "error writing " << name << " to " << kSysPowerWakeLock; } } }
void SystemSuspend::decSuspendCounter(const string& name) { auto l = std::lock_guard(mCounterLock); if (mUseSuspendCounter) { if (--mSuspendCounter == 0) { mCounterCondVar.notify_one(); } } else { if (!WriteStringToFd(name, mWakeUnlockFd)) { PLOG(ERROR) << "error writing " << name << " to " << kSysPowerWakeUnlock; } } }
上面wake_lock写入路径
PowerManagerService.Display(hwbinder server端):
12-31 19:00:11.805 2746 2746 D listed wake lock: #00 pc 000000000000b868 /system/bin/hw/android.system.suspend@1.0-service (android::system::suspend::V1_0::SystemSuspend::incSuspendCounter(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)+136) 12-31 19:00:11.805 2746 2746 D listed wake lock: #01 pc 000000000000c4dc /system/bin/hw/android.system.suspend@1.0-service (android::system::suspend::V1_0::SystemSuspend::acquireWakeLock(android::system::suspend::V1_0::WakeLockType, android::hardware::hidl_string const&)+332) 12-31 19:00:11.805 2746 2746 D listed wake lock: #02 pc 000000000000fc64 /system/lib64/android.system.suspend@1.0.so (android::system::suspend::V1_0::BnHwSystemSuspend::_hidl_acquireWakeLock(android::hidl::base::V1_0::BnHwBase*, android::hardware::Parcel const&, android::hardware::Parcel*, std::__1::function<void (android::hardware::Parcel&)>)+252) 12-31 19:00:11.805 2746 2746 D listed wake lock: #03 pc 0000000000010194 /system/lib64/android.system.suspend@1.0.so (android::system::suspend::V1_0::BnHwSystemSuspend::onTransact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+316) 12-31 19:00:11.805 2746 2746 D listed wake lock: #04 pc 0000000000096604 /system/lib64/libhidlbase.so (android::hardware::BHwBinder::transact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+68) 12-31 19:00:11.805 2746 2746 D listed wake lock: #05 pc 0000000000099fcc /system/lib64/libhidlbase.so (android::hardware::IPCThreadState::getAndExecuteCommand()+1036) 12-31 19:00:11.805 2746 2746 D listed wake lock: #06 pc 000000000009b1e0 /system/lib64/libhidlbase.so (android::hardware::IPCThreadState::joinThreadPool(bool)+96) 12-31 19:00:11.805 2746 2746 D listed wake lock: #07 pc 000000000000a608 /system/bin/hw/android.system.suspend@1.0-service (main+1464) 12-31 19:00:11.805 2746 2746 D listed wake lock: #08 pc 000000000007d844 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+108) 12-31 19:00:11.805 2746 2746 E /system/bin/hw/android.system.suspend@1.0-service: inc suspend cnt, name:PowerManagerService.DisplaymUseSuspendCounter: 0: Success
上面wake_unlock写入路径:
PowerManagerService.WakeLocks(hwbinder serser端):
09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #00 pc 000000000000cbb4 /system/bin/hw/android.system.suspend@1.0-service (android::system::suspend::V1_0::SystemSuspend::decSuspendCounter(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)+116) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #01 pc 000000000000d1a4 /system/bin/hw/android.system.suspend@1.0-service (_ZNSt3__117__call_once_proxyINS_5tupleIJOZN7android6system7suspend4V1_08WakeLock11releaseOnceEvEUlvE_EEEEEvPv+52) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #02 pc 00000000000b0f74 /system/lib64/libc++.so (std::__1::__call_once(unsigned long volatile&, void*, void (*)(void*))+156) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #03 pc 000000000000bcc8 /system/bin/hw/android.system.suspend@1.0-service (android::system::suspend::V1_0::WakeLock::release()+80) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #04 pc 0000000000016f5c /system/lib64/android.system.suspend@1.0.so (android::system::suspend::V1_0::BnHwWakeLock::_hidl_release(android::hidl::base::V1_0::BnHwBase*, android::hardware::Parcel const&, android::hardware::Parcel*, std::__1::function<void (android::hardware::Parcel&)>)+164) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #05 pc 000000000001734c /system/lib64/android.system.suspend@1.0.so (android::system::suspend::V1_0::BnHwWakeLock::onTransact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+308) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #06 pc 0000000000096604 /system/lib64/libhidlbase.so (android::hardware::BHwBinder::transact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+68) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #07 pc 0000000000099fcc /system/lib64/libhidlbase.so (android::hardware::IPCThreadState::getAndExecuteCommand()+1036) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #08 pc 000000000009b1e0 /system/lib64/libhidlbase.so (android::hardware::IPCThreadState::joinThreadPool(bool)+96) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #09 pc 000000000000a608 /system/bin/hw/android.system.suspend@1.0-service (main+1464) 09-19 09:31:00.023 2748 2748 D listed wake unlock(a on): #10 pc 000000000007d844 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+108) 09-19 09:31:00.023 2748 2748 E /system/bin/hw/android.system.suspend@1.0-service: dec suspend cnt, name:PowerManagerService.WakeLocksmUseSuspendCounter: 0: Success
STR待机过程中,会先将wake_lock里的lock release,在STR resume时再acquire lock:
STR待机过程中release lock(PowerManagerService.Display):
09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #00 pc 000000000000cc28 /system/bin/hw/android.system.suspend@1.0-service (android::system::suspend::V1_0::SystemSuspend::decSuspendCounter(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)+232) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #01 pc 000000000000d1a4 /system/bin/hw/android.system.suspend@1.0-service (_ZNSt3__117__call_once_proxyINS_5tupleIJOZN7android6system7suspend4V1_08WakeLock11releaseOnceEvEUlvE_EEEEEvPv+52) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #02 pc 00000000000b0f74 /system/lib64/libc++.so (std::__1::__call_once(unsigned long volatile&, void*, void (*)(void*))+156) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #03 pc 000000000000bcc8 /system/bin/hw/android.system.suspend@1.0-service (android::system::suspend::V1_0::WakeLock::release()+80) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #04 pc 0000000000016f5c /system/lib64/android.system.suspend@1.0.so (android::system::suspend::V1_0::BnHwWakeLock::_hidl_release(android::hidl::base::V1_0::BnHwBase*, android::hardware::Parcel const&, android::hardware::Parcel*, std::__1::function<void (android::hardware::Parcel&)>)+164) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #05 pc 000000000001734c /system/lib64/android.system.suspend@1.0.so (android::system::suspend::V1_0::BnHwWakeLock::onTransact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+308) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #06 pc 0000000000096604 /system/lib64/libhidlbase.so (android::hardware::BHwBinder::transact(unsigned int, android::hardware::Parcel const&, android::hardware::Parcel*, unsigned int, std::__1::function<void (android::hardware::Parcel&)>)+68) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #07 pc 0000000000099fcc /system/lib64/libhidlbase.so (android::hardware::IPCThreadState::getAndExecuteCommand()+1036) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #08 pc 000000000009b1e0 /system/lib64/libhidlbase.so (android::hardware::IPCThreadState::joinThreadPool(bool)+96) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #09 pc 000000000000a608 /system/bin/hw/android.system.suspend@1.0-service (main+1464) 09-19 09:36:24.666 2748 2748 D listed wake unlock(suspend): #10 pc 000000000007d844 /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+108) 09-19 09:36:24.666 2748 2748 E /system/bin/hw/android.system.suspend@1.0-service: dec suspend cnt, name:PowerManagerService.DisplaymUseSuspendCounter: 0: Success
wakeup count file
system\hardware\interfaces\suspend\1.0\default\main.cpp
static constexpr char kSysPowerWakeupCount[] = "/sys/power/wakeup_count"; int main() { unique_fd wakeupCountFd{TEMP_FAILURE_RETRY(open(kSysPowerWakeupCount, O_CLOEXEC | O_RDWR))}; sp<SystemSuspend> suspend = new SystemSuspend(std::move(wakeupCountFd), std::move(stateFd), 100 /* maxStatsEntries */, 100ms /* baseSleepTime */, suspendControl, false /* mUseSuspendCounter*/); status_t status = suspend->registerAsService();
SystemSuspend::SystemSuspend(unique_fd wakeupCountFd, unique_fd stateFd, size_t maxStatsEntries, std::chrono::milliseconds baseSleepTime, const sp<SuspendControlService>& controlService, bool useSuspendCounter) : mSuspendCounter(0), mWakeupCountFd(std::move(wakeupCountFd)),
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
2020-10-14 link hub(other)
2018-10-14 双重顶(M顶)& 双重底(W底)