1 /* 2 * Copyright (c) 2021-2023 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_native_test.h" 17 18 #include <ipc_skeleton.h> 19 20 #include "actions/irunning_lock_action.h" 21 22 using namespace testing::ext; 23 using namespace OHOS::PowerMgr; 24 using namespace OHOS; 25 using namespace std; 26 27 namespace { 28 constexpr int64_t CALLTIMEMS = 1; 29 constexpr pid_t PID = 1; 30 constexpr pid_t PID_A = 2; 31 constexpr pid_t UNPID = -1; 32 constexpr pid_t UID = 1; 33 constexpr pid_t UID_A = 2; 34 constexpr pid_t UNUID = -1; 35 constexpr uint32_t LOCKNUM_A = 0; 36 constexpr uint32_t LOCKNUM_B = 1; 37 constexpr int32_t TIMEOUTMS = 7; 38 constexpr uint32_t MAXTYPE = 77; 39 constexpr int32_t UNTYPE = -1; 40 } //namespace 41 42 namespace { 43 /** 44 * @tc.name: RunningLockNative001 45 * @tc.desc: test init in runningLockMgr 46 * @tc.type: FUNC 47 */ 48 HWTEST_F (RunningLockNativeTest, RunningLockNative001, TestSize.Level0) 49 { 50 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 51 pmsTest->OnStart(); 52 auto stateMachine = std::make_shared<PowerStateMachine>(pmsTest); 53 EXPECT_TRUE(stateMachine->Init()); 54 UserActivityType userActivityType = UserActivityType::USER_ACTIVITY_TYPE_ACCESSIBILITY; 55 stateMachine->RefreshActivityInner(PID, CALLTIMEMS, userActivityType, true); 56 57 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 58 EXPECT_TRUE(runningLockMgr->Init()); 59 sptr<IRemoteObject> remoteObject = new RunningLockTokenStub(); 60 EXPECT_TRUE(runningLockMgr->GetRunningLockInner(remoteObject) == nullptr); 61 sptr<IRemoteObject> remoteObj = new RunningLockTokenStub(); 62 int32_t pid = IPCSkeleton::GetCallingPid(); 63 int32_t uid = IPCSkeleton::GetCallingUid(); 64 RunningLockParam runningLockParam { 65 "runninglockNativeTest1", RunningLockType::RUNNINGLOCK_SCREEN, TIMEOUTMS, pid, uid}; 66 EXPECT_TRUE(runningLockMgr->CreateRunningLock(remoteObj, runningLockParam) != nullptr); 67 EXPECT_FALSE(runningLockMgr->IsUsed(remoteObj)); 68 runningLockMgr->Lock(remoteObj, TIMEOUTMS); 69 EXPECT_TRUE(runningLockMgr->GetRunningLockNum(RunningLockType::RUNNINGLOCK_SCREEN) == LOCKNUM_B); 70 EXPECT_TRUE(runningLockMgr->GetRunningLockNum(RunningLockType::RUNNINGLOCK_BUTT) == LOCKNUM_B); 71 EXPECT_TRUE(runningLockMgr->GetValidRunningLockNum(RunningLockType::RUNNINGLOCK_SCREEN) == LOCKNUM_B); 72 EXPECT_TRUE(runningLockMgr->GetValidRunningLockNum(static_cast<RunningLockType>(MAXTYPE)) == LOCKNUM_A); 73 EXPECT_TRUE(runningLockMgr->IsUsed(remoteObj)); 74 sptr<IRemoteObject> token = new RunningLockTokenStub(); 75 EXPECT_FALSE(runningLockMgr->IsUsed(token)); 76 runningLockMgr->Lock(token, TIMEOUTMS); 77 runningLockMgr->UnLock(remoteObj); 78 runningLockMgr->UnLock(token); 79 80 EXPECT_FALSE(runningLockMgr->ReleaseLock(remoteObj)); 81 EXPECT_FALSE(runningLockMgr->ReleaseLock(token)); 82 83 POWER_HILOGI(LABEL_TEST, "RunningLockNative001 end"); 84 } 85 86 /** 87 * @tc.name: RunningLockNative002 88 * @tc.desc: test proxyRunningLock in runningLockMgr 89 * @tc.type: FUNC 90 */ 91 HWTEST_F (RunningLockNativeTest, RunningLockNative002, TestSize.Level0) 92 { 93 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 94 pmsTest->OnStart(); 95 auto stateMachine = std::make_shared<PowerStateMachine>(pmsTest); 96 EXPECT_TRUE(stateMachine->Init()); 97 UserActivityType userActivityType = UserActivityType::USER_ACTIVITY_TYPE_ACCESSIBILITY; 98 stateMachine->RefreshActivityInner(UID, PID, userActivityType, true); 99 100 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 101 EXPECT_TRUE(runningLockMgr->Init()); 102 EXPECT_FALSE(runningLockMgr->ExistValidRunningLock()); 103 runningLockMgr->CheckOverTime(); 104 sptr<IRemoteObject> remoteObj = new RunningLockTokenStub(); 105 int32_t pid = IPCSkeleton::GetCallingPid(); 106 int32_t uid = IPCSkeleton::GetCallingUid(); 107 RunningLockParam runningLockParam { 108 "runninglockNativeTest1", RunningLockType::RUNNINGLOCK_SCREEN, TIMEOUTMS, pid, uid}; 109 EXPECT_TRUE(runningLockMgr->CreateRunningLock(remoteObj, runningLockParam) != nullptr); 110 EXPECT_FALSE(runningLockMgr->ExistValidRunningLock()); 111 runningLockMgr->Lock(remoteObj, TIMEOUTMS); 112 EXPECT_TRUE(runningLockMgr->ExistValidRunningLock() == true); 113 runningLockMgr->CheckOverTime(); 114 runningLockMgr->CheckOverTime(); 115 116 runningLockMgr->ProxyRunningLock(false, pid, uid); 117 runningLockMgr->ProxyRunningLock(true, pid, uid); 118 runningLockMgr->ProxyRunningLock(true, pid, uid); 119 runningLockMgr->ProxyRunningLock(true, UNPID, UID); 120 runningLockMgr->ProxyRunningLock(true, UNPID, UID); 121 runningLockMgr->ProxyRunningLock(false, pid, uid); 122 runningLockMgr->ProxyRunningLock(false, UNPID, UID); 123 124 runningLockMgr->ProxyRunningLockInner(false, pid, uid); 125 runningLockMgr->ProxyRunningLockInner(true, pid, uid); 126 runningLockMgr->ProxyRunningLockInner(true, pid, uid); 127 runningLockMgr->ProxyRunningLockInner(true, UNPID, UID); 128 runningLockMgr->ProxyRunningLockInner(true, UNPID, UID); 129 runningLockMgr->ProxyRunningLockInner(false, pid, uid); 130 runningLockMgr->ProxyRunningLockInner(false, UNPID, UID); 131 runningLockMgr->UnLock(remoteObj); 132 EXPECT_FALSE(runningLockMgr->ReleaseLock(remoteObj)); 133 POWER_HILOGI(LABEL_TEST, "RunningLockNative002 end"); 134 } 135 136 /** 137 * @tc.name: RunningLockNative003 138 * @tc.desc: test enableMock and dumpInfo in runningLockMgr 139 * @tc.type: FUNC 140 */ 141 HWTEST_F (RunningLockNativeTest, RunningLockNative003, TestSize.Level0) 142 { 143 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 144 pmsTest->OnStart(); 145 auto stateMachine = std::make_shared<PowerStateMachine>(pmsTest); 146 EXPECT_TRUE(stateMachine->Init()); 147 UserActivityType userActivityType = UserActivityType::USER_ACTIVITY_TYPE_ACCESSIBILITY; 148 stateMachine->RefreshActivityInner(UID, PID, userActivityType, true); 149 150 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 151 EXPECT_TRUE(runningLockMgr->Init()); 152 IRunningLockAction *runLockAction = new RunningLockAction(); 153 runningLockMgr->EnableMock(runLockAction); 154 std::string result; 155 runningLockMgr->DumpInfo(result); 156 157 RunningLockParam runningLockParam { 158 "runninglockNativeTest2", RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL, TIMEOUTMS, PID, UID}; 159 sptr<IRemoteObject> token = new RunningLockTokenStub(); 160 EXPECT_TRUE(runningLockMgr->CreateRunningLock(token, runningLockParam) != nullptr); 161 runningLockMgr->DumpInfo(result); 162 runningLockMgr->Lock(token, TIMEOUTMS); 163 runningLockMgr->UnLock(token); 164 165 EXPECT_FALSE(runningLockMgr->ReleaseLock(token)); 166 POWER_HILOGI(LABEL_TEST, "RunningLockNative003 end"); 167 } 168 169 /** 170 * @tc.name: RunningLockNative004 171 * @tc.desc: test setProximity in runningLockMgr 172 * @tc.type: FUNC 173 */ 174 HWTEST_F (RunningLockNativeTest, RunningLockNative004, TestSize.Level0) 175 { 176 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 177 pmsTest->OnStart(); 178 auto stateMachine = std::make_shared<PowerStateMachine>(pmsTest); 179 EXPECT_TRUE(stateMachine->Init()); 180 UserActivityType userActivityType = UserActivityType::USER_ACTIVITY_TYPE_ACCESSIBILITY; 181 stateMachine->RefreshActivityInner(PID, CALLTIMEMS, userActivityType, true); 182 183 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 184 EXPECT_TRUE(runningLockMgr->Init()); 185 runningLockMgr->SetProximity(RunningLockMgr::PROXIMITY_AWAY); 186 runningLockMgr->SetProximity(RunningLockMgr::PROXIMITY_CLOSE); 187 runningLockMgr->SetProximity(MAXTYPE); 188 189 RunningLockParam runningLockParam { 190 "runninglockNativeTest", RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL, TIMEOUTMS, PID, UID}; 191 sptr<IRemoteObject> token = new RunningLockTokenStub(); 192 EXPECT_TRUE(runningLockMgr->CreateRunningLock(token, runningLockParam) != nullptr); 193 runningLockMgr->Lock(token, TIMEOUTMS); 194 runningLockMgr->SetProximity(RunningLockMgr::PROXIMITY_AWAY); 195 runningLockMgr->SetProximity(RunningLockMgr::PROXIMITY_CLOSE); 196 runningLockMgr->SetProximity(RunningLockMgr::PROXIMITY_CLOSE); 197 runningLockMgr->SetProximity(RunningLockMgr::PROXIMITY_AWAY); 198 runningLockMgr->UnLock(token); 199 200 RunningLockParam runningLockParam2 { 201 "runninglockNativeTest2", static_cast<RunningLockType>(7U), TIMEOUTMS, PID_A, UID_A}; 202 sptr<IRemoteObject> remoteObj = new RunningLockTokenStub(); 203 EXPECT_TRUE(runningLockMgr->CreateRunningLock(remoteObj, runningLockParam2) != nullptr); 204 runningLockMgr->Lock(remoteObj, TIMEOUTMS); 205 runningLockMgr->UnLock(remoteObj); 206 POWER_HILOGI(LABEL_TEST, "RunningLockNative004 end"); 207 } 208 209 /** 210 * @tc.name: RunningLockNative005 211 * @tc.desc: test lock and unlock in runningLockMgr 212 * @tc.type: FUNC 213 */ 214 HWTEST_F (RunningLockNativeTest, RunningLockNative005, TestSize.Level0) 215 { 216 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 217 pmsTest->OnStart(); 218 auto stateMachine = std::make_shared<PowerStateMachine>(pmsTest); 219 EXPECT_TRUE(stateMachine->Init()); 220 UserActivityType userActivityType = UserActivityType::USER_ACTIVITY_TYPE_ACCESSIBILITY; 221 stateMachine->RefreshActivityInner(UID, PID, userActivityType, true); 222 223 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 224 EXPECT_TRUE(runningLockMgr->Init()); 225 sptr<IRemoteObject> remoteObj = new RunningLockTokenStub(); 226 RunningLockParam runningLockParam { 227 "runninglockNativeTest1", RunningLockType::RUNNINGLOCK_SCREEN, TIMEOUTMS, UNPID, UNUID}; 228 EXPECT_TRUE(runningLockMgr->CreateRunningLock(remoteObj, runningLockParam) != nullptr); 229 runningLockMgr->Lock(remoteObj, TIMEOUTMS); 230 runningLockMgr->Lock(remoteObj, TIMEOUTMS); 231 RunningLockParam runningLockParam1 { 232 "runninglockNativeTest2", static_cast<RunningLockType>(MAXTYPE), TIMEOUTMS, UNPID, UNUID}; 233 sptr<IRemoteObject> token = new RunningLockTokenStub(); 234 EXPECT_TRUE(runningLockMgr->CreateRunningLock(token, runningLockParam1) != nullptr); 235 runningLockMgr->Lock(token, TIMEOUTMS); 236 runningLockMgr->UnLock(token); 237 238 EXPECT_FALSE(runningLockMgr->ReleaseLock(remoteObj)); 239 EXPECT_FALSE(runningLockMgr->ReleaseLock(token)); 240 POWER_HILOGI(LABEL_TEST, "RunningLockNative005 end"); 241 } 242 243 /** 244 * @tc.name: RunningLockNative006 245 * @tc.desc: test callback in runningLockMgr 246 * @tc.type: FUNC 247 */ 248 HWTEST_F (RunningLockNativeTest, RunningLockNative006, TestSize.Level0) 249 { 250 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 251 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 252 EXPECT_TRUE(runningLockMgr->Init()); 253 RunningLockParam runningLockParam { 254 "runninglockNativeTest1", RunningLockType::RUNNINGLOCK_SCREEN, TIMEOUTMS, UNPID, UNUID}; 255 sptr<IRemoteObject> remoteObj = new RunningLockTokenStub(); 256 EXPECT_TRUE(runningLockMgr->CreateRunningLock(remoteObj, runningLockParam) != nullptr); 257 runningLockMgr->Lock(remoteObj, TIMEOUTMS); 258 259 RunningLockMgr::RunningLockChangedType type = RunningLockMgr::RunningLockChangedType::NOTIFY_RUNNINGLOCK_OVERTIME; 260 auto lockInner = RunningLockInner::CreateRunningLockInner(runningLockParam); 261 runningLockMgr->NotifyRunningLockChanged(remoteObj, lockInner, type); 262 type = RunningLockMgr::RunningLockChangedType::RUNNINGLOCK_CHANGED_BUTT; 263 runningLockMgr->NotifyRunningLockChanged(remoteObj, lockInner, type); 264 type = static_cast<RunningLockMgr::RunningLockChangedType>(UNTYPE); 265 runningLockMgr->NotifyRunningLockChanged(remoteObj, lockInner, type); 266 267 auto runningLockMgrController = std::make_shared<RunningLockMgr::ProximityController>(); 268 SensorEvent sensorEvent; 269 ProximityData data; 270 data.distance = RunningLockMgr::ProximityController::PROXIMITY_CLOSE_SCALAR; 271 sensorEvent.sensorTypeId = SENSOR_TYPE_ID_PROXIMITY; 272 sensorEvent.data = reinterpret_cast<uint8_t*>(&data); 273 runningLockMgrController->RecordSensorCallback(&sensorEvent); 274 data.distance = RunningLockMgr::ProximityController::PROXIMITY_AWAY_SCALAR; 275 runningLockMgrController->RecordSensorCallback(&sensorEvent); 276 data.distance = RunningLockMgr::ProximityController::SAMPLING_RATE; 277 runningLockMgrController->RecordSensorCallback(&sensorEvent); 278 sensorEvent.sensorTypeId = TIMEOUTMS; 279 runningLockMgrController->RecordSensorCallback(&sensorEvent); 280 runningLockMgrController->RecordSensorCallback(nullptr); 281 runningLockMgrController->support_ = true; 282 runningLockMgrController->Enable(); 283 runningLockMgrController->Disable(); 284 285 EXPECT_FALSE(runningLockMgr->ReleaseLock(remoteObj)); 286 POWER_HILOGI(LABEL_TEST, "RunningLockNative006 end"); 287 } 288 289 /** 290 * @tc.name: RunningLockNative007 291 * @tc.desc: test CheckOverTime in runningLockMgr 292 * @tc.type: FUNC 293 */ 294 HWTEST_F (RunningLockNativeTest, RunningLockNative007, TestSize.Level0) 295 { 296 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 297 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 298 EXPECT_TRUE(runningLockMgr->Init()); 299 sptr<IRemoteObject> remoteObj = new RunningLockTokenStub(); 300 runningLockMgr->CheckOverTime(); 301 runningLockMgr->RemoveAndPostUnlockTask(remoteObj); 302 runningLockMgr->SendCheckOverTimeMsg(CALLTIMEMS); 303 POWER_HILOGI(LABEL_TEST, "RunningLockNative007 end"); 304 } 305 306 /** 307 * @tc.name: RunningLockNative008 308 * @tc.desc: test activate in lockCounters 309 * @tc.type: FUNC 310 * @tc.require: issueI7MNRN 311 */ 312 HWTEST_F(RunningLockNativeTest, RunningLockNative008, TestSize.Level0) 313 { 314 auto pmsTest_ = DelayedSpSingleton<PowerMgrService>::GetInstance(); 315 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest_); 316 EXPECT_TRUE(runningLockMgr->Init()); 317 std::shared_ptr<RunningLockMgr::LockCounter> ptr1 = 318 runningLockMgr->lockCounters_[RunningLockType::RUNNINGLOCK_SCREEN]; 319 ptr1->activate_(true); 320 ptr1->activate_(false); 321 EXPECT_TRUE(runningLockMgr->lockCounters_.size() != 0); 322 323 pmsTest_->powerStateMachine_->SetState(PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_TIMEOUT); 324 std::shared_ptr<RunningLockMgr::LockCounter> ptr2 = 325 runningLockMgr->lockCounters_[RunningLockType::RUNNINGLOCK_BACKGROUND]; 326 ptr2->activate_(true); 327 ptr2->activate_(false); 328 EXPECT_TRUE(runningLockMgr->lockCounters_.size() != 0); 329 330 pmsTest_->powerStateMachine_->SetState(PowerState::FREEZE, StateChangeReason::STATE_CHANGE_REASON_TIMEOUT); 331 ptr2->activate_(true); 332 ptr2->activate_(false); 333 EXPECT_TRUE(runningLockMgr->lockCounters_.size() != 0); 334 335 std::shared_ptr<RunningLockMgr::LockCounter> ptr3 = 336 runningLockMgr->lockCounters_[RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL]; 337 ptr3->activate_(true); 338 ptr3->activate_(false); 339 EXPECT_TRUE(runningLockMgr->lockCounters_.size() != 0); 340 341 auto stateMachine = pmsTest_->GetPowerStateMachine(); 342 pmsTest_->powerStateMachine_ = nullptr; 343 ptr3->activate_(true); 344 pmsTest_->powerStateMachine_ = stateMachine; 345 EXPECT_TRUE(pmsTest_->powerStateMachine_ != nullptr); 346 347 POWER_HILOGI(LABEL_TEST, "RunningLockNative008 end"); 348 } 349 350 /** 351 * @tc.name: RunningLockNative009 352 * @tc.desc: test RemoveAndPostUnlockTask in runningLockMgr 353 * @tc.type: FUNC 354 * @tc.require: issueI7MNRN 355 */ 356 HWTEST_F(RunningLockNativeTest, RunningLockNative009, TestSize.Level0) 357 { 358 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 359 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 360 EXPECT_TRUE(runningLockMgr->Init()); 361 sptr<IRemoteObject> remoteObject = new RunningLockTokenStub(); 362 runningLockMgr->RemoveAndPostUnlockTask(remoteObject, 1); 363 EXPECT_TRUE(runningLockMgr != nullptr); 364 POWER_HILOGI(LABEL_TEST, "RunningLockNative009 end"); 365 } 366 367 /** 368 * @tc.name: RunningLockNative010 369 * @tc.desc: test Lock 370 * @tc.type: FUNC 371 * @tc.require: issueI7MNRN 372 */ 373 HWTEST_F(RunningLockNativeTest, RunningLockNative010, TestSize.Level0) 374 { 375 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 376 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 377 EXPECT_TRUE(runningLockMgr->Init()); 378 sptr<IRemoteObject> remoteObject = new RunningLockTokenStub(); 379 runningLockMgr->Lock(remoteObject, 0); 380 runningLockMgr->Lock(remoteObject, 1); 381 EXPECT_TRUE(runningLockMgr != nullptr); 382 POWER_HILOGI(LABEL_TEST, "RunningLockNative010 end"); 383 } 384 385 /** 386 * @tc.name: RunningLockNative011 387 * @tc.desc: test Lock 388 * @tc.type: FUNC 389 * @tc.require: issueI7MNRN 390 */ 391 HWTEST_F(RunningLockNativeTest, RunningLockNative011, TestSize.Level0) 392 { 393 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 394 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 395 EXPECT_TRUE(runningLockMgr->Init()); 396 sptr<IRemoteObject> remoteObject = new RunningLockTokenStub(); 397 runningLockMgr->UnLock(remoteObject); 398 EXPECT_TRUE(runningLockMgr != nullptr); 399 runningLockMgr->lockCounters_.clear(); 400 runningLockMgr->UnLock(remoteObject); 401 EXPECT_TRUE(runningLockMgr != nullptr); 402 POWER_HILOGI(LABEL_TEST, "RunningLockNative011 end"); 403 } 404 405 /** 406 * @tc.name: RunningLockNative012 407 * @tc.desc: test IsUsed 408 * @tc.type: FUNC 409 * @tc.require: issueI7MNRN 410 */ 411 HWTEST_F(RunningLockNativeTest, RunningLockNative012, TestSize.Level0) 412 { 413 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 414 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 415 EXPECT_TRUE(runningLockMgr->Init()); 416 sptr<IRemoteObject> remoteObject = new RunningLockTokenStub(); 417 runningLockMgr->IsUsed(remoteObject); 418 EXPECT_TRUE(runningLockMgr != nullptr); 419 POWER_HILOGI(LABEL_TEST, "RunningLockNative012 end"); 420 } 421 422 /** 423 * @tc.name: RunningLockNative013 424 * @tc.desc: test GetRunningLockNum 425 * @tc.type: FUNC 426 * @tc.require: issueI7MNRN 427 */ 428 HWTEST_F(RunningLockNativeTest, RunningLockNative013, TestSize.Level0) 429 { 430 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 431 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 432 EXPECT_TRUE(runningLockMgr->Init()); 433 runningLockMgr->GetRunningLockNum(RunningLockType::RUNNINGLOCK_BUTT); 434 EXPECT_TRUE(runningLockMgr != nullptr); 435 POWER_HILOGI(LABEL_TEST, "RunningLockNative013 end"); 436 } 437 438 /** 439 * @tc.name: RunningLockNative014 440 * @tc.desc: test GetValidRunningLockNum 441 * @tc.type: FUNC 442 * @tc.require: issueI7MNRN 443 */ 444 HWTEST_F(RunningLockNativeTest, RunningLockNative014, TestSize.Level0) 445 { 446 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 447 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 448 EXPECT_TRUE(runningLockMgr->Init()); 449 runningLockMgr->GetValidRunningLockNum(static_cast<RunningLockType>(-1)); 450 EXPECT_TRUE(runningLockMgr != nullptr); 451 POWER_HILOGI(LABEL_TEST, "RunningLockNative014 end"); 452 } 453 454 /** 455 * @tc.name: RunningLockNative015 456 * @tc.desc: test CheckOverTime 457 * @tc.type: FUNC 458 * @tc.require: issueI7MNRN 459 */ 460 HWTEST_F(RunningLockNativeTest, RunningLockNative015, TestSize.Level0) 461 { 462 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 463 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 464 EXPECT_TRUE(runningLockMgr->Init()); 465 runningLockMgr->runningLocks_.clear(); 466 runningLockMgr->CheckOverTime(); 467 EXPECT_TRUE(runningLockMgr != nullptr); 468 POWER_HILOGI(LABEL_TEST, "RunningLockNative015 end"); 469 } 470 471 /** 472 * @tc.name: RunningLockNative016 473 * @tc.desc: test NotifyRunningLockChanged 474 * @tc.type: FUNC 475 * @tc.require: issueI7MNRN 476 */ 477 HWTEST_F(RunningLockNativeTest, RunningLockNative016, TestSize.Level0) 478 { 479 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 480 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 481 EXPECT_TRUE(runningLockMgr->Init()); 482 sptr<IRemoteObject> remoteObj = new RunningLockTokenStub(); 483 RunningLockParam runningLockParam { 484 "runninglockNativeTest1", RunningLockType::RUNNINGLOCK_SCREEN, TIMEOUTMS, UNPID, UNUID}; 485 RunningLockMgr::RunningLockChangedType type = RunningLockMgr::RunningLockChangedType::RUNNINGLOCK_CHANGED_BUTT; 486 auto lockInner = RunningLockInner::CreateRunningLockInner(runningLockParam); 487 runningLockMgr->NotifyRunningLockChanged(remoteObj, lockInner, type); 488 type = RunningLockMgr::RunningLockChangedType::NOTIFY_RUNNINGLOCK_ADD; 489 runningLockMgr->NotifyRunningLockChanged(remoteObj, lockInner, type); 490 type = RunningLockMgr::RunningLockChangedType::NOTIFY_RUNNINGLOCK_OVERTIME; 491 runningLockMgr->NotifyRunningLockChanged(remoteObj, lockInner, type); 492 type = static_cast<RunningLockMgr::RunningLockChangedType>(UNTYPE); 493 runningLockMgr->NotifyRunningLockChanged(remoteObj, lockInner, type); 494 EXPECT_TRUE(runningLockMgr != nullptr); 495 POWER_HILOGI(LABEL_TEST, "RunningLockNative016 end"); 496 } 497 498 /** 499 * @tc.name: RunningLockNative017 500 * @tc.desc: test ProxyRunningLock 501 * @tc.type: FUNC 502 * @tc.require: issueI7MNRN 503 */ 504 HWTEST_F(RunningLockNativeTest, RunningLockNative017, TestSize.Level0) 505 { 506 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 507 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 508 EXPECT_TRUE(runningLockMgr->Init()); 509 510 pid_t pid = 1; 511 pid_t uid = 0; 512 EXPECT_TRUE(runningLockMgr->ProxyRunningLock(true, pid, uid) == true); 513 EXPECT_TRUE(runningLockMgr->ProxyRunningLock(false, pid, uid) == true); 514 EXPECT_TRUE(runningLockMgr->ProxyRunningLock(true, 0, uid) == false); 515 POWER_HILOGI(LABEL_TEST, "RunningLockNative017 end"); 516 } 517 518 /** 519 * @tc.name: RunningLockNative018 520 * @tc.desc: test ProxyRunningLockInner 521 * @tc.type: FUNC 522 * @tc.require: issueI7MNRN 523 */ 524 HWTEST_F(RunningLockNativeTest, RunningLockNative018, TestSize.Level0) 525 { 526 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 527 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 528 EXPECT_TRUE(runningLockMgr->Init()); 529 530 pid_t pid = 0; 531 pid_t uid = 0; 532 runningLockMgr->ProxyRunningLockInner(true, pid, uid); 533 EXPECT_TRUE(runningLockMgr != nullptr); 534 535 RunningLockParam runningLockParam { 536 "runninglockNativeTest1", RunningLockType::RUNNINGLOCK_SCREEN, TIMEOUTMS, UNPID, UNUID}; 537 sptr<IRemoteObject> remoteObj = new RunningLockTokenStub(); 538 EXPECT_TRUE(runningLockMgr->CreateRunningLock(remoteObj, runningLockParam) != nullptr); 539 runningLockMgr->ProxyRunningLockInner(false, pid, uid); 540 EXPECT_TRUE(runningLockMgr != nullptr); 541 runningLockMgr->ProxyRunningLockInner(true, pid, uid); 542 EXPECT_TRUE(runningLockMgr != nullptr); 543 runningLockMgr->runninglockProxy_->AddRunningLock(pid, uid, nullptr); 544 runningLockMgr->ProxyRunningLockInner(true, pid, uid); 545 EXPECT_TRUE(runningLockMgr != nullptr); 546 POWER_HILOGI(LABEL_TEST, "RunningLockNative018 end"); 547 } 548 549 /** 550 * @tc.name: RunningLockNative020 551 * @tc.desc: test DumpInfo 552 * @tc.type: FUNC 553 * @tc.require: issueI7MNRN 554 */ 555 HWTEST_F(RunningLockNativeTest, RunningLockNative020, TestSize.Level0) 556 { 557 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 558 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 559 EXPECT_TRUE(runningLockMgr->Init()); 560 std::string result; 561 RunningLockParam runningLockParam { 562 "runninglockNativeTest1", RunningLockType::RUNNINGLOCK_SCREEN, TIMEOUTMS, UNPID, UNUID}; 563 sptr<IRemoteObject> remoteObj = new RunningLockTokenStub(); 564 EXPECT_TRUE(runningLockMgr->CreateRunningLock(remoteObj, runningLockParam) != nullptr); 565 runningLockMgr->DumpInfo(result); 566 EXPECT_TRUE(runningLockMgr != nullptr); 567 runningLockMgr->runningLocks_.clear(); 568 runningLockMgr->DumpInfo(result); 569 EXPECT_TRUE(runningLockMgr != nullptr); 570 571 POWER_HILOGI(LABEL_TEST, "RunningLockNative020 end"); 572 } 573 574 /** 575 * @tc.name: RunningLockNative021 576 * @tc.desc: test Lock 577 * @tc.type: FUNC 578 * @tc.require: issueI7MNRN 579 */ 580 HWTEST_F(RunningLockNativeTest, RunningLockNative021, TestSize.Level0) 581 { 582 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 583 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 584 EXPECT_TRUE(runningLockMgr->Init()); 585 runningLockMgr->backgroundLock_->locking_ = false; 586 runningLockMgr->backgroundLock_->Lock(); 587 EXPECT_TRUE(runningLockMgr != nullptr); 588 POWER_HILOGI(LABEL_TEST, "RunningLockNative021 end"); 589 } 590 591 /** 592 * @tc.name: RunningLockNative022 593 * @tc.desc: test Unlock 594 * @tc.type: FUNC 595 * @tc.require: issueI7MNRN 596 */ 597 HWTEST_F(RunningLockNativeTest, RunningLockNative022, TestSize.Level0) 598 { 599 auto pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance(); 600 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest); 601 EXPECT_TRUE(runningLockMgr->Init()); 602 runningLockMgr->backgroundLock_->locking_ = true; 603 runningLockMgr->backgroundLock_->Unlock(); 604 EXPECT_TRUE(runningLockMgr != nullptr); 605 POWER_HILOGI(LABEL_TEST, "RunningLockNative022 end"); 606 } 607 608 /** 609 * @tc.name: RunningLockNative023 610 * @tc.desc: test activate in lockCounters 611 * @tc.type: FUNC 612 * @tc.require: issueI7MNRN 613 */ 614 HWTEST_F(RunningLockNativeTest, RunningLockNative023, TestSize.Level0) 615 { 616 auto pmsTest_ = DelayedSpSingleton<PowerMgrService>::GetInstance(); 617 auto runningLockMgr = std::make_shared<RunningLockMgr>(pmsTest_); 618 EXPECT_TRUE(runningLockMgr->Init()); 619 RunningLockParam runningLockParam { 620 "runninglockNativeTest1", RunningLockType::RUNNINGLOCK_SCREEN, TIMEOUTMS, UNPID, UNUID}; 621 sptr<IRemoteObject> remoteObj = new RunningLockTokenStub(); 622 auto lockInner = RunningLockInner::CreateRunningLockInner(runningLockParam); 623 runningLockMgr->lockCounters_[RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL]->Increase( 624 remoteObj, lockInner); 625 EXPECT_TRUE(runningLockMgr != nullptr); 626 runningLockMgr->lockCounters_[RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL]->Decrease( 627 remoteObj, lockInner); 628 EXPECT_TRUE(runningLockMgr != nullptr); 629 POWER_HILOGI(LABEL_TEST, "RunningLockNative023 end"); 630 } 631 } // namespace 632