1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "running_lock_mgr.h"
17
18 #include <cinttypes>
19
20 #include <datetime_ex.h>
21 #include <hisysevent.h>
22 #include <ipc_skeleton.h>
23 #include <securec.h>
24
25 #include "hitrace_meter.h"
26 #include "power_log.h"
27 #include "power_mgr_factory.h"
28 #include "power_mgr_service.h"
29
30 using namespace std;
31
32 namespace OHOS {
33 namespace PowerMgr {
34 namespace {
35 const string TASK_RUNNINGLOCK_FORCEUNLOCK = "RunningLock_ForceUnLock";
36 }
37
~RunningLockMgr()38 RunningLockMgr::~RunningLockMgr() {}
39
Init()40 bool RunningLockMgr::Init()
41 {
42 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Init start");
43 std::lock_guard<std::mutex> lock(mutex_);
44 if (runningLockDeathRecipient_ == nullptr) {
45 runningLockDeathRecipient_ = new RunningLockDeathRecipient();
46 }
47 if (runningLockAction_ == nullptr) {
48 runningLockAction_ = PowerMgrFactory::GetRunningLockAction();
49 if (!runningLockAction_) {
50 POWER_HILOGE(FEATURE_RUNNING_LOCK, "Get running lock action fail");
51 return false;
52 }
53 }
54 auto pmsptr = pms_.promote();
55 if (pmsptr == nullptr) {
56 POWER_HILOGE(FEATURE_RUNNING_LOCK, "Power manager service is null");
57 return false;
58 }
59 handler_ = pmsptr->GetHandler();
60
61 systemLocks_.emplace(SystemLockType::SYSTEM_LOCK_APP,
62 std::make_shared<SystemLock>(runningLockAction_, LOCK_TAG_APP));
63 systemLocks_.emplace(SystemLockType::SYSTEM_LOCK_DISPLAY,
64 std::make_shared<SystemLock>(runningLockAction_, LOCK_TAG_DISPLAY));
65
66 bool ret = InitLocks();
67
68 POWER_HILOGI(FEATURE_RUNNING_LOCK, "Init success");
69 return ret;
70 }
71
InitLocks()72 bool RunningLockMgr::InitLocks()
73 {
74 InitLocksTypeScreen();
75 InitLocksTypeBackground();
76 InitLocksTypeProximity();
77 return true;
78 }
79
InitLocksTypeScreen()80 void RunningLockMgr::InitLocksTypeScreen()
81 {
82 lockCounters_.emplace(RunningLockType::RUNNINGLOCK_SCREEN,
83 std::make_shared<LockCounter>(
84 RunningLockType::RUNNINGLOCK_SCREEN, [this](bool active) {
85 POWER_HILOGD(FEATURE_RUNNING_LOCK, "RUNNINGLOCK_SCREEN action start");
86 auto pms = DelayedSpSingleton<PowerMgrService>::GetInstance();
87 if (pms == nullptr) {
88 return;
89 }
90 auto stateMachine = pms->GetPowerStateMachine();
91 if (stateMachine == nullptr) {
92 return;
93 }
94 if (active) {
95 POWER_HILOGI(FEATURE_RUNNING_LOCK, "RUNNINGLOCK_SCREEN active");
96 stateMachine->SetState(PowerState::AWAKE,
97 StateChangeReason::STATE_CHANGE_REASON_RUNNING_LOCK);
98 stateMachine->CancelDelayTimer(
99 PowermsEventHandler::CHECK_USER_ACTIVITY_TIMEOUT_MSG);
100 stateMachine->CancelDelayTimer(
101 PowermsEventHandler::CHECK_USER_ACTIVITY_OFF_TIMEOUT_MSG);
102 } else {
103 POWER_HILOGI(FEATURE_RUNNING_LOCK, "RUNNINGLOCK_SCREEN inactive");
104 if (stateMachine->GetState() == PowerState::AWAKE) {
105 stateMachine->ResetInactiveTimer();
106 } else {
107 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Screen unlock in state: %{public}d",
108 stateMachine->GetState());
109 }
110 }
111 })
112 );
113 }
114
InitLocksTypeBackground()115 void RunningLockMgr::InitLocksTypeBackground()
116 {
117 lockCounters_.emplace(RunningLockType::RUNNINGLOCK_BACKGROUND,
118 std::make_shared<LockCounter>(
119 RunningLockType::RUNNINGLOCK_BACKGROUND, [this](bool active) {
120 POWER_HILOGD(FEATURE_RUNNING_LOCK, "RUNNINGLOCK_BACKGROUND action start");
121 auto pms = DelayedSpSingleton<PowerMgrService>::GetInstance();
122 if (pms == nullptr) {
123 return;
124 }
125 auto stateMachine = pms->GetPowerStateMachine();
126 if (stateMachine == nullptr) {
127 return;
128 }
129 auto iterator = systemLocks_.find(SystemLockType::SYSTEM_LOCK_APP);
130 if (iterator == systemLocks_.end()) {
131 return;
132 }
133 std::shared_ptr<SystemLock> pSysLock = iterator->second;
134 if (active) {
135 POWER_HILOGI(FEATURE_RUNNING_LOCK, "RUNNINGLOCK_BACKGROUND active");
136 stateMachine->CancelDelayTimer(
137 PowermsEventHandler::CHECK_USER_ACTIVITY_SLEEP_TIMEOUT_MSG);
138 pSysLock->Lock();
139 } else {
140 POWER_HILOGI(FEATURE_RUNNING_LOCK, "RUNNINGLOCK_BACKGROUND inactive");
141 if (stateMachine->GetState() == PowerState::INACTIVE) {
142 stateMachine->ResetSleepTimer();
143 } else {
144 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Background unlock in state: %{public}d",
145 stateMachine->GetState());
146 }
147 pSysLock->Unlock();
148 }
149 })
150 );
151 }
152
InitLocksTypeProximity()153 void RunningLockMgr::InitLocksTypeProximity()
154 {
155 lockCounters_.emplace(RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL,
156 std::make_shared<LockCounter>(
157 RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL, [this](bool active) {
158 POWER_HILOGD(FEATURE_RUNNING_LOCK, "RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL action start");
159 auto pms = DelayedSpSingleton<PowerMgrService>::GetInstance();
160 if (pms == nullptr) {
161 return;
162 }
163 auto stateMachine = pms->GetPowerStateMachine();
164 if (stateMachine == nullptr) {
165 return;
166 }
167 auto iterator = systemLocks_.find(SystemLockType::SYSTEM_LOCK_APP);
168 if (iterator == systemLocks_.end()) {
169 return;
170 }
171 std::shared_ptr<SystemLock> pSysLock = iterator->second;
172 if (active) {
173 POWER_HILOGI(FEATURE_RUNNING_LOCK, "RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL active");
174 proximityController_.Enable();
175 if (proximityController_.IsClose()) {
176 POWER_HILOGI(FEATURE_RUNNING_LOCK, "INACTIVE when proximity is closed");
177 stateMachine->SetState(PowerState::INACTIVE,
178 StateChangeReason::STATE_CHANGE_REASON_RUNNING_LOCK, true);
179 } else {
180 POWER_HILOGI(FEATURE_RUNNING_LOCK, "AWAKE when proximity is away");
181 stateMachine->SetState(PowerState::AWAKE,
182 StateChangeReason::STATE_CHANGE_REASON_RUNNING_LOCK, true);
183 }
184 stateMachine->CancelDelayTimer(
185 PowermsEventHandler::CHECK_USER_ACTIVITY_TIMEOUT_MSG);
186 stateMachine->CancelDelayTimer(
187 PowermsEventHandler::CHECK_USER_ACTIVITY_OFF_TIMEOUT_MSG);
188 pSysLock->Lock();
189 } else {
190 POWER_HILOGI(FEATURE_RUNNING_LOCK, "RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL inactive");
191 stateMachine->SetState(PowerState::AWAKE,
192 StateChangeReason::STATE_CHANGE_REASON_RUNNING_LOCK);
193 stateMachine->ResetInactiveTimer();
194 pSysLock->Unlock();
195 proximityController_.Disable();
196 }
197 })
198 );
199 }
200
GetRunningLockInner(const sptr<IRemoteObject> & remoteObj)201 std::shared_ptr<RunningLockInner> RunningLockMgr::GetRunningLockInner(
202 const sptr<IRemoteObject>& remoteObj)
203 {
204 std::lock_guard<std::mutex> lock(mutex_);
205 auto iterator = runningLocks_.find(remoteObj);
206 if (iterator != runningLocks_.end()) {
207 return iterator->second;
208 }
209 return nullptr;
210 }
211
CreateRunningLock(const sptr<IRemoteObject> & remoteObj,const RunningLockInfo & runningLockInfo,const UserIPCInfo & userIPCinfo)212 std::shared_ptr<RunningLockInner> RunningLockMgr::CreateRunningLock(
213 const sptr<IRemoteObject>& remoteObj,
214 const RunningLockInfo& runningLockInfo,
215 const UserIPCInfo& userIPCinfo)
216 {
217 auto lockInner = RunningLockInner::CreateRunningLockInner(runningLockInfo, userIPCinfo);
218 if (lockInner == nullptr) {
219 return nullptr;
220 }
221 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Create lock success, name=%{public}s, type=%{public}d",
222 runningLockInfo.name.c_str(), runningLockInfo.type);
223
224 mutex_.lock();
225 runningLocks_.emplace(remoteObj, lockInner);
226 mutex_.unlock();
227 remoteObj->AddDeathRecipient(runningLockDeathRecipient_);
228 return lockInner;
229 }
230
ReleaseLock(const sptr<IRemoteObject> remoteObj)231 bool RunningLockMgr::ReleaseLock(const sptr<IRemoteObject> remoteObj)
232 {
233 bool result = false;
234 auto lockInner = GetRunningLockInner(remoteObj);
235 if (lockInner == nullptr) {
236 return result;
237 }
238 if (!lockInner->GetDisabled()) {
239 UnLock(remoteObj);
240 }
241 mutex_.lock();
242 runningLocks_.erase(remoteObj);
243 mutex_.unlock();
244 result = remoteObj->RemoveDeathRecipient(runningLockDeathRecipient_);
245 return result;
246 }
247
RemoveAndPostUnlockTask(const sptr<IRemoteObject> & remoteObj,uint32_t timeOutMS)248 void RunningLockMgr::RemoveAndPostUnlockTask(
249 const sptr<IRemoteObject>& remoteObj, uint32_t timeOutMS)
250 {
251 auto handler = handler_.lock();
252 if (handler == nullptr) {
253 POWER_HILOGI(FEATURE_RUNNING_LOCK, "Handler is nullptr");
254 return;
255 }
256 const string& remoteObjStr = to_string(reinterpret_cast<uintptr_t>(remoteObj.GetRefPtr()));
257 POWER_HILOGD(FEATURE_RUNNING_LOCK, "remoteObjStr=%{public}s, timeOutMS=%{public}d",
258 remoteObjStr.c_str(), timeOutMS);
259 handler->RemoveTask(remoteObjStr);
260 if (timeOutMS != 0) {
261 std::function<void()> unLockFunc = std::bind(&RunningLockMgr::UnLock, this, remoteObj);
262 handler->PostTask(unLockFunc, remoteObjStr, timeOutMS);
263 }
264 }
265
Lock(const sptr<IRemoteObject> & remoteObj,const RunningLockInfo & runningLockInfo,const UserIPCInfo & userIPCinfo,uint32_t timeOutMS)266 void RunningLockMgr::Lock(const sptr<IRemoteObject>& remoteObj,
267 const RunningLockInfo& runningLockInfo,
268 const UserIPCInfo& userIPCinfo, uint32_t timeOutMS)
269 {
270 StartTrace(HITRACE_TAG_POWER, "RunningLock_Lock");
271 POWER_HILOGD(FEATURE_RUNNING_LOCK, "name=%{public}s, type=%{public}d",
272 runningLockInfo.name.c_str(), runningLockInfo.type);
273
274 auto lockInner = GetRunningLockInner(remoteObj);
275 if (lockInner == nullptr) {
276 POWER_HILOGE(FEATURE_RUNNING_LOCK, "LockInner is nullptr");
277 return;
278 }
279 if (!lockInner->GetDisabled()) {
280 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Lock is already enabled");
281 return;
282 }
283
284 auto iterator = lockCounters_.find(lockInner->GetRunningLockType());
285 if (iterator == lockCounters_.end()) {
286 POWER_HILOGE(FEATURE_RUNNING_LOCK, "Lock failed unsupported type, type=%{public}d",
287 lockInner->GetRunningLockType());
288 return;
289 }
290 std::shared_ptr<LockCounter> counter = iterator->second;
291 counter->Increase(remoteObj, lockInner);
292 lockInner->SetDisabled(false);
293 POWER_HILOGD(FEATURE_RUNNING_LOCK, "LockCounter type=%{public}d, count=%{public}d", lockInner->GetRunningLockType(),
294 counter->GetCount());
295 if (timeOutMS > 0) {
296 RemoveAndPostUnlockTask(remoteObj, timeOutMS);
297 }
298 FinishTrace(HITRACE_TAG_POWER);
299 }
300
UnLock(const sptr<IRemoteObject> remoteObj)301 void RunningLockMgr::UnLock(const sptr<IRemoteObject> remoteObj)
302 {
303 StartTrace(HITRACE_TAG_POWER, "RunningLock_Unlock");
304
305 auto lockInner = GetRunningLockInner(remoteObj);
306 if (lockInner == nullptr) {
307 return;
308 }
309 POWER_HILOGI(FEATURE_RUNNING_LOCK, "LockInner name=%{public}s, type=%{public}d",
310 lockInner->GetRunningLockName().c_str(), lockInner->GetRunningLockType());
311 if (lockInner->GetDisabled()) {
312 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Lock is already disabled name=%{public}s",
313 lockInner->GetRunningLockName().c_str());
314 return;
315 }
316 RemoveAndPostUnlockTask(remoteObj);
317
318 auto iterator = lockCounters_.find(lockInner->GetRunningLockType());
319 if (iterator == lockCounters_.end()) {
320 POWER_HILOGE(FEATURE_RUNNING_LOCK, "Unlock failed unsupported type, type=%{public}d",
321 lockInner->GetRunningLockType());
322 return;
323 }
324 std::shared_ptr<LockCounter> counter = iterator->second;
325 counter->Decrease(remoteObj, lockInner);
326 lockInner->SetDisabled(true);
327 POWER_HILOGD(FEATURE_RUNNING_LOCK, "LockCounter type=%{public}d, count=%{public}d", lockInner->GetRunningLockType(),
328 counter->GetCount());
329 FinishTrace(HITRACE_TAG_POWER);
330 }
331
IsUsed(const sptr<IRemoteObject> & remoteObj)332 bool RunningLockMgr::IsUsed(const sptr<IRemoteObject>& remoteObj)
333 {
334 auto lockInner = GetRunningLockInner(remoteObj);
335 if (lockInner == nullptr || lockInner->GetDisabled()) {
336 return false;
337 }
338 return true;
339 }
340
GetRunningLockNum(RunningLockType type)341 uint32_t RunningLockMgr::GetRunningLockNum(RunningLockType type)
342 {
343 std::lock_guard<std::mutex> lock(mutex_);
344 if (type == RunningLockType::RUNNINGLOCK_BUTT) {
345 return runningLocks_.size();
346 }
347 return std::count_if(runningLocks_.begin(), runningLocks_.end(),
348 [&type](const auto& pair) {
349 return pair.second->GetRunningLockType() == type;
350 });
351 }
352
GetValidRunningLockNum(RunningLockType type)353 uint32_t RunningLockMgr::GetValidRunningLockNum(RunningLockType type)
354 {
355 auto iterator = lockCounters_.find(type);
356 if (iterator == lockCounters_.end()) {
357 POWER_HILOGD(FEATURE_RUNNING_LOCK, "No specific lock, type=%{public}d", type);
358 return 0;
359 }
360 std::shared_ptr<LockCounter> counter = iterator->second;
361
362 return counter->GetCount();
363 }
364
ExistValidRunningLock()365 bool RunningLockMgr::ExistValidRunningLock()
366 {
367 std::lock_guard<std::mutex> lock(mutex_);
368 for (auto it = runningLocks_.begin(); it != runningLocks_.end(); it++) {
369 auto& lockinner = it->second;
370 if (lockinner->GetDisabled() == false) {
371 return true;
372 }
373 }
374 return false;
375 }
376
SetWorkTriggerList(const sptr<IRemoteObject> & remoteObj,const WorkTriggerList & workTriggerList)377 void RunningLockMgr::SetWorkTriggerList(const sptr<IRemoteObject>& remoteObj,
378 const WorkTriggerList& workTriggerList)
379 {
380 auto lockInner = GetRunningLockInner(remoteObj);
381 if (lockInner == nullptr) {
382 return;
383 }
384 lockInner->SetWorkTriggerList(workTriggerList);
385 NotifyRunningLockChanged(remoteObj, lockInner, NOTIFY_RUNNINGLOCK_WORKTRIGGER_CHANGED);
386 // After update triggerlist, maybe need disabled the lock or enable the lock.
387 SetRunningLockDisableFlag(lockInner);
388 // If enabled, we really lock here.
389 LockReally(remoteObj, lockInner);
390 // If disabled, we really unlock here.
391 UnLockReally(remoteObj, lockInner);
392 }
393
NotifyHiViewRunningLockInfo(const string & remoteObjStr,const RunningLockInner & lockInner,RunningLockChangedType changeType) const394 void RunningLockMgr::NotifyHiViewRunningLockInfo(const string& remoteObjStr,
395 const RunningLockInner& lockInner,
396 RunningLockChangedType changeType) const
397 {
398 string msg = "token=" + remoteObjStr;
399 NotifyHiView(changeType, msg, lockInner);
400 }
401
CheckOverTime()402 void RunningLockMgr::CheckOverTime()
403 {
404 auto handler = handler_.lock();
405 if (handler == nullptr) {
406 return;
407 }
408 handler->RemoveEvent(PowermsEventHandler::CHECK_RUNNINGLOCK_OVERTIME_MSG);
409 if (runningLocks_.empty()) {
410 return;
411 }
412 int64_t curTime = GetTickCount();
413 int64_t detectTime = curTime - CHECK_TIMEOUT_INTERVAL_MS;
414 POWER_HILOGI(FEATURE_RUNNING_LOCK, "curTime=%{public}" PRId64 " detectTime=%{public}" PRId64 "", curTime,
415 detectTime);
416 if (detectTime < 0) {
417 return;
418 }
419 int64_t nextDetectTime = INT_MAX;
420 for (auto& it : runningLocks_) {
421 auto lockInner = it.second;
422 if (!lockInner->GetDisabled() && (!lockInner->GetOverTimeFlag())) {
423 if (lockInner->GetLockTimeMs() < detectTime) {
424 lockInner->SetOverTimeFlag(true);
425 NotifyRunningLockChanged(it.first, lockInner, NOTIFY_RUNNINGLOCK_OVERTIME);
426 } else {
427 if (lockInner->GetLockTimeMs() < nextDetectTime) {
428 nextDetectTime = lockInner->GetLockTimeMs();
429 }
430 }
431 }
432 }
433 if (nextDetectTime != INT_MAX) {
434 detectTime = nextDetectTime - curTime + CHECK_TIMEOUT_INTERVAL_MS;
435 SendCheckOverTimeMsg(detectTime);
436 }
437 }
438
SendCheckOverTimeMsg(int64_t delayTime)439 void RunningLockMgr::SendCheckOverTimeMsg(int64_t delayTime)
440 {
441 auto handler = handler_.lock();
442 if (handler == nullptr) {
443 return;
444 }
445 POWER_HILOGD(FEATURE_RUNNING_LOCK, "delayTime=%{public}" PRId64 "", delayTime);
446 handler->SendEvent(PowermsEventHandler::CHECK_RUNNINGLOCK_OVERTIME_MSG, 0, delayTime);
447 }
448
NotifyRunningLockChanged(const sptr<IRemoteObject> & remoteObj,std::shared_ptr<RunningLockInner> & lockInner,RunningLockChangedType changeType)449 void RunningLockMgr::NotifyRunningLockChanged(const sptr<IRemoteObject>& remoteObj,
450 std::shared_ptr<RunningLockInner>& lockInner, RunningLockChangedType changeType)
451 {
452 if (changeType >= RUNNINGLOCK_CHANGED_BUTT) {
453 return;
454 }
455 const string& remoteObjStr = to_string(reinterpret_cast<uintptr_t>(remoteObj.GetRefPtr()));
456 switch (changeType) {
457 case NOTIFY_RUNNINGLOCK_ADD: {
458 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Add remoteObjStr=%{public}s", remoteObjStr.c_str());
459 NotifyHiViewRunningLockInfo(remoteObjStr, *lockInner, changeType);
460 SendCheckOverTimeMsg(CHECK_TIMEOUT_INTERVAL_MS);
461 break;
462 }
463 case NOTIFY_RUNNINGLOCK_REMOVE: {
464 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Remove remoteObjStr=%{public}s", remoteObjStr.c_str());
465 string str = "token=" + remoteObjStr;
466 NotifyHiView(changeType, str, *lockInner);
467 break;
468 }
469 case NOTIFY_RUNNINGLOCK_WORKTRIGGER_CHANGED: {
470 POWER_HILOGD(FEATURE_RUNNING_LOCK, "WorkTriggerChanged remoteObjStr=%{public}s", remoteObjStr.c_str());
471 NotifyHiViewRunningLockInfo(remoteObjStr, *lockInner, changeType);
472 break;
473 }
474 case NOTIFY_RUNNINGLOCK_OVERTIME: {
475 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Overtime remoteObjStr=%{public}s", remoteObjStr.c_str());
476 break;
477 }
478 default: {
479 break;
480 }
481 }
482 }
MatchProxyMap(const UserIPCInfo & userIPCinfo)483 bool RunningLockMgr::MatchProxyMap(const UserIPCInfo& userIPCinfo)
484 {
485 if (proxyMap_.empty()) {
486 POWER_HILOGW(FEATURE_RUNNING_LOCK, "ProxyMap_ is empty, uid = %{public}d, pid = %{public}d",
487 userIPCinfo.uid, userIPCinfo.pid);
488 return false;
489 }
490 auto it = proxyMap_.find(userIPCinfo.uid);
491 // 1. Find pidset by uid.
492 if (it == proxyMap_.end()) {
493 POWER_HILOGW(FEATURE_RUNNING_LOCK, "Pid set not match, uid = %{public}d, pid = %{public}d",
494 userIPCinfo.uid, userIPCinfo.pid);
495 return false;
496 }
497 auto& pidset = it->second;
498 // 2. Count by owner pid.
499 if (pidset.count(userIPCinfo.pid) > 0) {
500 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Pid set match and count > 0, uid = %{public}d, pid = %{public}d",
501 userIPCinfo.uid, userIPCinfo.pid);
502 return true;
503 }
504 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Pid set match and count(-1) = %{public}d, uid = %{public}d, pid = %{public}d",
505 static_cast<unsigned int>(pidset.count(INVALID_PID)), userIPCinfo.uid, userIPCinfo.pid);
506 // 3. Count by INVALID_PID, return true when proxy (uid, -1).
507 return (pidset.count(INVALID_PID) > 0);
508 }
509
SetRunningLockDisableFlag(std::shared_ptr<RunningLockInner> & lockInner,bool forceRefresh)510 void RunningLockMgr::SetRunningLockDisableFlag(
511 std::shared_ptr<RunningLockInner>& lockInner,
512 bool forceRefresh)
513 {
514 if (proxyMap_.empty() && (!forceRefresh)) {
515 /**
516 * Generally when proxymap empty keep the default value false.
517 * When PGManager cancel proxy uid and pid,
518 * because we update the proxy map before, so we should refresh
519 * all of the runninglock disable flag always.
520 */
521 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Set lock enable, proxyMap_ is empty and forceRefresh is false");
522 lockInner->SetDisabled(false);
523 return;
524 }
525 const UserIPCInfo& userIPCinfo = lockInner->GetUserIPCInfo();
526 bool matched = MatchProxyMap(userIPCinfo);
527 if (matched) {
528 // Matched the lock owner useripcinfo, set disabled directly.
529 lockInner->SetDisabled(true);
530 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Lock and ipc matched, uid = %{public}d, pid = %{public}d",
531 userIPCinfo.uid, userIPCinfo.pid);
532 return;
533 }
534 const RunningLockInfo& runningLockInfo = lockInner->GetRunningLockInfo();
535 const WorkTriggerList& list = runningLockInfo.workTriggerlist;
536 if (list.empty()) {
537 // Not matched, and no trigger list.
538 lockInner->SetDisabled(false);
539 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Work trigger list is empty");
540 return;
541 }
542 bool triggerMatched = true;
543 // Have trigger list, need to judge whether or not all of the list matched,
544 // otherwise we should hold the lock.
545 for (auto& workTrigger : list) {
546 UserIPCInfo triggerIPCInfo {workTrigger->GetUid(), workTrigger->GetPid()};
547 if (!MatchProxyMap(triggerIPCInfo)) {
548 triggerMatched = false;
549 POWER_HILOGD(FEATURE_RUNNING_LOCK, "WorkTrigger not matched uid = %{public}d, pid = %{public}d",
550 triggerIPCInfo.uid, triggerIPCInfo.pid);
551 break;
552 }
553 }
554 POWER_HILOGD(FEATURE_RUNNING_LOCK, "TriggerMatched = %{public}d, uid = %{public}d, pid = %{public}d",
555 userIPCinfo.uid, userIPCinfo.pid, triggerMatched);
556 lockInner->SetDisabled(triggerMatched);
557 }
558
LockReally(const sptr<IRemoteObject> & remoteObj,std::shared_ptr<RunningLockInner> & lockInner)559 void RunningLockMgr::LockReally(const sptr<IRemoteObject>& remoteObj,
560 std::shared_ptr<RunningLockInner>& lockInner)
561 {
562 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Start");
563 if (lockInner->GetReallyLocked()) {
564 POWER_HILOGD(FEATURE_RUNNING_LOCK, "lockInner->GetReallyLocked() is true, return");
565 return;
566 }
567 if (lockInner->GetDisabled()) {
568 POWER_HILOGD(FEATURE_RUNNING_LOCK, "lockInner->GetDisabled() is true, return");
569 return;
570 }
571 runningLockAction_->Acquire(lockInner->GetRunningLockType());
572 lockInner->SetReallyLocked(true);
573 NotifyRunningLockChanged(remoteObj, lockInner, NOTIFY_RUNNINGLOCK_ADD);
574 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Finish");
575 }
UnLockReally(const sptr<IRemoteObject> & remoteObj,std::shared_ptr<RunningLockInner> & lockInner)576 void RunningLockMgr::UnLockReally(const sptr<IRemoteObject>& remoteObj,
577 std::shared_ptr<RunningLockInner>& lockInner)
578 {
579 /**
580 * Case 1: Firstly PGManager ProxyRunningLock by uid and pid,
581 * secondly application lock by the same uid and
582 * pid, when call Lock() we matched the proxymap, and no really locked to kernel.
583 * So we don't need to unlocked to kernel.
584 * Case 2: Firstly application create the runninglock and call Lock(),
585 * and then PGManager Proxyed it,
586 * At this time, lock should be unlocked to kernel because we have locked to kernel for it.
587 */
588 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Start");
589 if (!lockInner->GetReallyLocked()) {
590 POWER_HILOGD(FEATURE_RUNNING_LOCK, "lockInner->GetReallyLocked() is false, return");
591 return;
592 }
593 // If disabled, unlock to the kernel.
594 if (!lockInner->GetDisabled()) {
595 POWER_HILOGD(FEATURE_RUNNING_LOCK, "lockInner->GetDisabled() is false, return");
596 return;
597 }
598 runningLockAction_->Release(lockInner->GetRunningLockType());
599 lockInner->SetReallyLocked(false);
600 NotifyRunningLockChanged(remoteObj, lockInner, NOTIFY_RUNNINGLOCK_REMOVE);
601 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Finish");
602 }
603
ProxyRunningLockInner(bool proxyLock)604 void RunningLockMgr::ProxyRunningLockInner(bool proxyLock)
605 {
606 if (proxyLock) {
607 for (auto& it : runningLocks_) {
608 SetRunningLockDisableFlag(it.second);
609 UnLockReally(it.first, it.second);
610 }
611 } else {
612 for (auto& it : runningLocks_) {
613 SetRunningLockDisableFlag(it.second, true);
614 LockReally(it.first, it.second);
615 }
616 }
617 }
618
ProxyRunningLock(bool proxyLock,pid_t uid,pid_t pid)619 void RunningLockMgr::ProxyRunningLock(bool proxyLock, pid_t uid, pid_t pid)
620 {
621 POWER_HILOGD(FEATURE_RUNNING_LOCK, "proxyLock = %{public}d, uid = %{public}d, pid = %{public}d",
622 proxyLock, uid, pid);
623 auto it = proxyMap_.find(uid);
624 if (proxyLock) {
625 // PGManager insert proxy info.
626 if (it == proxyMap_.end()) {
627 unordered_set<pid_t> pidset({pid});
628 proxyMap_.emplace(uid, pidset);
629 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Emplace first proxyMap_ {uid = %{public}d, pid = %{public}d}",
630 uid, pid);
631 } else {
632 if (pid == INVALID_PID) {
633 // Insert uid, pid = -1,remove other pid
634 proxyMap_.erase(uid);
635 unordered_set<pid_t> pidset({pid});
636 proxyMap_.emplace(uid, pidset);
637 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Re-emplace proxyMap_ {uid = %{public}d, pid = %{public}d}",
638 uid, pid);
639 } else {
640 auto& pidset = it->second;
641 pidset.insert(pid);
642 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Insert proxyMap_ {uid = %{public}d, pid = %{public}d}", uid, pid);
643 }
644 }
645 // 1. Set the matched runninglock inner disabled flag.
646 } else {
647 if (it == proxyMap_.end()) {
648 // No insert proxy info, nothing to erase.
649 POWER_HILOGD(FEATURE_RUNNING_LOCK, "No uid in proxyMap_, uid = %{public}d", uid);
650 return;
651 }
652 // 1. Clear the runninglock inner disabled flag 2.removed from proxyMap_
653 if (pid == INVALID_PID) {
654 proxyMap_.erase(uid);
655 POWER_HILOGD(FEATURE_RUNNING_LOCK, "pid = -1, erase from proxyMap_, uid = %{public}d", uid);
656 } else {
657 auto& pidset = it->second;
658 pidset.erase(pid);
659 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Erase from proxyMap_, uid = %{public}d, pid = %{public}d", uid, pid);
660 if (pidset.size() == 0) {
661 proxyMap_.erase(uid);
662 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Pidset is empty erase uid from proxyMap_, uid = %{public}d", uid);
663 }
664 }
665 }
666 ProxyRunningLockInner(proxyLock);
667 }
668
NotifyHiView(RunningLockChangedType changeType,const std::string & msg,const RunningLockInner & lockInner) const669 void RunningLockMgr::NotifyHiView(RunningLockChangedType changeType,
670 const std::string& msg, const RunningLockInner& lockInner) const
671 {
672 const UserIPCInfo& ipcInfo = lockInner.GetUserIPCInfo();
673 int32_t pid = ipcInfo.pid;
674 int32_t uid = ipcInfo.uid;
675 bool state = lockInner.GetDisabled();
676 int32_t type = static_cast <int32_t>(lockInner.GetRunningLockType());
677 string name = lockInner.GetRunningLockName();
678 const int logLevel = 2;
679 const string &tag = runninglockNotifyStr_.at(changeType);
680 HiviewDFX::HiSysEvent::Write("POWER", "POWER_RUNNINGLOCK",
681 HiviewDFX::HiSysEvent::EventType::STATISTIC,
682 "PID", pid, "UID", uid, "STATE", state, "TYPE", type, "NAME", name,
683 "LOG_LEVEL", logLevel, "TAG", tag, "MESSAGE", msg);
684 POWER_HILOGD(FEATURE_RUNNING_LOCK, "pid = %{public}d, uid= %{public}d, tag=%{public}s, msg=%{public}s",
685 pid, uid, tag.c_str(), msg.c_str());
686 }
687
EnableMock(IRunningLockAction * mockAction)688 void RunningLockMgr::EnableMock(IRunningLockAction* mockAction)
689 {
690 // reset lock list
691 runningLocks_.clear();
692 for (auto it = lockCounters_.begin(); it != lockCounters_.end(); it++) {
693 it->second->Clear();
694 }
695 proximityController_.Clear();
696
697 std::shared_ptr<IRunningLockAction> mock(mockAction);
698 for (auto it = systemLocks_.begin(); it != systemLocks_.end(); it++) {
699 it->second->EnableMock(mock);
700 }
701 runningLockAction_ = mock;
702 }
703
GetRunningLockTypeString(RunningLockType type)704 static const std::string GetRunningLockTypeString(RunningLockType type)
705 {
706 switch (type) {
707 case RunningLockType::RUNNINGLOCK_SCREEN:
708 return "SCREEN";
709 case RunningLockType::RUNNINGLOCK_BACKGROUND:
710 return "BACKGROUND";
711 case RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL:
712 return "PROXIMITY_SCREEN_CONTROL";
713 case RunningLockType::RUNNINGLOCK_BUTT:
714 return "BUTT";
715 default:
716 break;
717 }
718
719 return "UNKNOWN";
720 }
721
DumpInfo(std::string & result)722 void RunningLockMgr::DumpInfo(std::string& result)
723 {
724 auto validSize = GetValidRunningLockNum();
725 std::lock_guard<std::mutex> lock(mutex_);
726
727 result.append("RUNNING LOCK DUMP:\n");
728 result.append(" totalSize=").append(ToString(runningLocks_.size()))
729 .append(" validSize=").append(ToString(validSize)).append("\n");
730 result.append("Summary By Type: \n");
731 for (auto it = lockCounters_.begin(); it != lockCounters_.end(); it++) {
732 result.append(" ")
733 .append(GetRunningLockTypeString(it->first))
734 .append(": ")
735 .append(ToString(it->second->GetCount()))
736 .append("\n");
737 }
738
739 if (runningLocks_.empty()) {
740 result.append("Lock List is Empty. \n");
741 return;
742 }
743
744 result.append("Dump Lock List: \n");
745 auto curTick = GetTickCount();
746 int index = 0;
747 for (auto& it : runningLocks_) {
748 index++;
749 auto lockInner = it.second;
750 if (lockInner == nullptr) {
751 return;
752 }
753 auto& lockinfo = lockInner->GetRunningLockInfo();
754 auto& ipcinfo = lockInner->GetUserIPCInfo();
755 result.append(" index=").append(ToString(index))
756 .append(" time=").append(ToString(curTick - lockInner->GetLockTimeMs()))
757 .append(" type=").append(GetRunningLockTypeString(lockinfo.type))
758 .append(" name=").append(lockinfo.name)
759 .append(" uid=").append(ToString(ipcinfo.uid))
760 .append(" pid=").append(ToString(ipcinfo.pid))
761 .append(" disable=").append(ToString(lockInner->GetDisabled()))
762 .append("\n");
763 }
764
765 result.append("Peripherals Info: \n")
766 .append(" Proximity: ")
767 .append("Enabled=")
768 .append(ToString(proximityController_.IsEnabled()))
769 .append(" Status=")
770 .append(ToString(proximityController_.GetStatus()))
771 .append("\n");
772 }
773
OnRemoteDied(const wptr<IRemoteObject> & remote)774 void RunningLockMgr::RunningLockDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
775 {
776 if (remote.promote() == nullptr) {
777 POWER_HILOGW(FEATURE_RUNNING_LOCK, "Remote is nullptr");
778 return;
779 }
780 auto pms = DelayedSpSingleton<PowerMgrService>::GetInstance();
781 if (pms == nullptr) {
782 POWER_HILOGW(FEATURE_RUNNING_LOCK, "Power service is nullptr");
783 return;
784 }
785 auto handler = pms->GetHandler();
786 if (handler == nullptr) {
787 POWER_HILOGW(FEATURE_RUNNING_LOCK, "Handler is nullptr");
788 return;
789 }
790 std::function<void()> forceUnLockFunc = std::bind(&PowerMgrService::ForceUnLock, pms,
791 remote.promote());
792 handler->PostTask(forceUnLockFunc, TASK_RUNNINGLOCK_FORCEUNLOCK);
793 }
794
Lock()795 void RunningLockMgr::SystemLock::Lock()
796 {
797 if (!locking_) {
798 action_->Lock(RunningLockType::RUNNINGLOCK_BUTT, tag_.c_str());
799 locking_ = true;
800 }
801 }
802
Unlock()803 void RunningLockMgr::SystemLock::Unlock()
804 {
805 if (locking_) {
806 action_->Unlock(RunningLockType::RUNNINGLOCK_BUTT, tag_.c_str());
807 locking_ = false;
808 }
809 }
810
Increase(const sptr<IRemoteObject> & remoteObj,std::shared_ptr<RunningLockInner> & lockInner)811 uint32_t RunningLockMgr::LockCounter::Increase(const sptr<IRemoteObject>& remoteObj,
812 std::shared_ptr<RunningLockInner>& lockInner)
813 {
814 ++counter_;
815 if (counter_ == 1) {
816 activate_(true);
817 }
818 auto pms = DelayedSpSingleton<PowerMgrService>::GetInstance();
819 if (pms == nullptr) {
820 POWER_HILOGW(FEATURE_RUNNING_LOCK, "No power service instance");
821 return counter_;
822 }
823 pms->GetRunningLockMgr()->NotifyRunningLockChanged(remoteObj, lockInner, NOTIFY_RUNNINGLOCK_ADD);
824 return counter_;
825 }
826
Decrease(const sptr<IRemoteObject> remoteObj,std::shared_ptr<RunningLockInner> & lockInner)827 uint32_t RunningLockMgr::LockCounter::Decrease(const sptr<IRemoteObject> remoteObj,
828 std::shared_ptr<RunningLockInner>& lockInner)
829 {
830 --counter_;
831 if (counter_ == 0) {
832 activate_(false);
833 }
834 auto pms = DelayedSpSingleton<PowerMgrService>::GetInstance();
835 if (pms == nullptr) {
836 POWER_HILOGW(FEATURE_RUNNING_LOCK, "No power service instance");
837 return counter_;
838 }
839 pms->GetRunningLockMgr()->NotifyRunningLockChanged(remoteObj, lockInner, NOTIFY_RUNNINGLOCK_REMOVE);
840 return counter_;
841 }
842
Clear()843 void RunningLockMgr::LockCounter::Clear()
844 {
845 counter_ = 0;
846 }
847
RecordSensorCallback(SensorEvent * event)848 void RunningLockMgr::ProximityController::RecordSensorCallback(SensorEvent *event)
849 {
850 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Sensor Callback come in");
851 if (event == nullptr) {
852 POWER_HILOGW(FEATURE_RUNNING_LOCK, "Sensor event is nullptr");
853 return;
854 }
855 if (event->sensorTypeId != SENSOR_TYPE_ID_PROXIMITY) {
856 POWER_HILOGW(FEATURE_RUNNING_LOCK, "Sensor type is not PROXIMITY");
857 return;
858 }
859 auto pms = DelayedSpSingleton<PowerMgrService>::GetInstance();
860 if (pms == nullptr) {
861 POWER_HILOGE(FEATURE_RUNNING_LOCK, "Power service is nullptr");
862 return;
863 }
864 auto runningLock = pms->GetRunningLockMgr();
865 ProximityData* data = (ProximityData*)event->data;
866 int32_t distance = static_cast<int32_t>(data->distance);
867
868 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Sensor Callback data->distance=%{public}d", distance);
869 if (distance == PROXIMITY_CLOSE_SCALAR) {
870 runningLock->SetProximity(PROXIMITY_CLOSE);
871 } else if (distance == PROXIMITY_AWAY_SCALAR) {
872 runningLock->SetProximity(PROXIMITY_AWAY);
873 }
874 }
875
ProximityController()876 RunningLockMgr::ProximityController::ProximityController()
877 {
878 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Instance enter");
879 SensorInfo* sensorInfo = nullptr;
880 int32_t count;
881 int ret = GetAllSensors(&sensorInfo, &count);
882 if (ret != 0 || sensorInfo == nullptr) {
883 POWER_HILOGE(FEATURE_RUNNING_LOCK, "Get sensors fail, ret=%{public}d", ret);
884 return;
885 }
886 for (int32_t i = 0; i < count; i++) {
887 if (sensorInfo[i].sensorTypeId == SENSOR_TYPE_ID_PROXIMITY) {
888 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Support PROXIMITY sensor");
889 support_ = true;
890 break;
891 }
892 }
893 if (!support_) {
894 POWER_HILOGE(FEATURE_RUNNING_LOCK, "PROXIMITY sensor not support");
895 return;
896 }
897 if (strcpy_s(user_.name, sizeof(user_.name), "RunningLock") != EOK) {
898 POWER_HILOGE(FEATURE_RUNNING_LOCK, "strcpy_s error");
899 return;
900 }
901 user_.userData = nullptr;
902 user_.callback = &RecordSensorCallback;
903 }
904
~ProximityController()905 RunningLockMgr::ProximityController::~ProximityController()
906 {
907 if (support_) {
908 UnsubscribeSensor(SENSOR_TYPE_ID_PROXIMITY, &user_);
909 }
910 }
911
Enable()912 void RunningLockMgr::ProximityController::Enable()
913 {
914 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Enter");
915 enabled_ = true;
916 if (!support_) {
917 POWER_HILOGE(FEATURE_RUNNING_LOCK, "PROXIMITY sensor not support");
918 return;
919 }
920
921 int32_t errorCode = SubscribeSensor(SENSOR_TYPE_ID_PROXIMITY, &user_);
922 if (errorCode != ERR_OK) {
923 POWER_HILOGW(FEATURE_RUNNING_LOCK, "SubscribeSensor PROXIMITY failed, errorCode=%{public}d", errorCode);
924 return;
925 }
926 SetBatch(SENSOR_TYPE_ID_PROXIMITY, &user_, SAMPLING_RATE, SAMPLING_RATE);
927 errorCode = ActivateSensor(SENSOR_TYPE_ID_PROXIMITY, &user_);
928 if (errorCode != ERR_OK) {
929 POWER_HILOGW(FEATURE_RUNNING_LOCK, "ActivateSensor PROXIMITY failed, errorCode=%{public}d", errorCode);
930 return;
931 }
932 SetMode(SENSOR_TYPE_ID_PROXIMITY, &user_, SENSOR_ON_CHANGE);
933 }
934
Disable()935 void RunningLockMgr::ProximityController::Disable()
936 {
937 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Enter");
938 enabled_ = false;
939 if (!support_) {
940 POWER_HILOGE(FEATURE_RUNNING_LOCK, "PROXIMITY sensor not support");
941 return;
942 }
943
944 DeactivateSensor(SENSOR_TYPE_ID_PROXIMITY, &user_);
945 int32_t errorCode = UnsubscribeSensor(SENSOR_TYPE_ID_PROXIMITY, &user_);
946 if (errorCode != ERR_OK) {
947 POWER_HILOGW(FEATURE_RUNNING_LOCK, "UnsubscribeSensor PROXIMITY failed, errorCode=%{public}d", errorCode);
948 }
949 }
950
IsClose()951 bool RunningLockMgr::ProximityController::IsClose()
952 {
953 POWER_HILOGD(FEATURE_RUNNING_LOCK, "PROXIMITY IsClose: %{public}d", isClose);
954 return isClose;
955 }
956
OnClose()957 void RunningLockMgr::ProximityController::OnClose()
958 {
959 if (!enabled_ || IsClose()) {
960 POWER_HILOGD(FEATURE_RUNNING_LOCK, "PROXIMITY is disabled or closed already");
961 return;
962 }
963 auto pms = DelayedSpSingleton<PowerMgrService>::GetInstance();
964 if (pms == nullptr) {
965 POWER_HILOGE(FEATURE_RUNNING_LOCK, "Power service is nullptr");
966 return;
967 }
968 auto stateMachine = pms->GetPowerStateMachine();
969 if (stateMachine == nullptr) {
970 POWER_HILOGE(FEATURE_RUNNING_LOCK, "state machine is nullptr");
971 return;
972 }
973 isClose = true;
974 POWER_HILOGD(FEATURE_RUNNING_LOCK, "PROXIMITY is closed");
975 auto runningLock = pms->GetRunningLockMgr();
976 if (runningLock->GetValidRunningLockNum(
977 RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL) > 0) {
978 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Change state to INACITVE when holding PROXIMITY LOCK");
979 stateMachine->SetState(PowerState::INACTIVE,
980 StateChangeReason::STATE_CHANGE_REASON_SENSOR,
981 true);
982 }
983 }
984
OnAway()985 void RunningLockMgr::ProximityController::OnAway()
986 {
987 if (!enabled_ || !IsClose()) {
988 POWER_HILOGD(FEATURE_RUNNING_LOCK, "PROXIMITY is disabled or away already");
989 return;
990 }
991 auto pms = DelayedSpSingleton<PowerMgrService>::GetInstance();
992 if (pms == nullptr) {
993 POWER_HILOGE(FEATURE_RUNNING_LOCK, "Power service is nullptr");
994 return;
995 }
996 auto stateMachine = pms->GetPowerStateMachine();
997 if (stateMachine == nullptr) {
998 POWER_HILOGE(FEATURE_RUNNING_LOCK, "state machine is nullptr");
999 return;
1000 }
1001 isClose = false;
1002 POWER_HILOGD(FEATURE_RUNNING_LOCK, "PROXIMITY is away");
1003 auto runningLock = pms->GetRunningLockMgr();
1004 if (runningLock->GetValidRunningLockNum(
1005 RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL) > 0) {
1006 POWER_HILOGD(FEATURE_RUNNING_LOCK, "Change state to AWAKE when holding PROXIMITY LOCK");
1007 stateMachine->SetState(PowerState::AWAKE,
1008 StateChangeReason::STATE_CHANGE_REASON_SENSOR,
1009 true);
1010 }
1011 }
1012
Clear()1013 void RunningLockMgr::ProximityController::Clear()
1014 {
1015 isClose = false;
1016 }
1017
SetProximity(uint32_t status)1018 void RunningLockMgr::SetProximity(uint32_t status)
1019 {
1020 switch (status) {
1021 case PROXIMITY_CLOSE:
1022 proximityController_.OnClose();
1023 break;
1024 case PROXIMITY_AWAY:
1025 proximityController_.OnAway();
1026 break;
1027 default:
1028 break;
1029 }
1030 }
1031 } // namespace PowerMgr
1032 } // namespace OHOS
1033