1 /*
2  * Copyright (c) 2024 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 #include "user_record_manager.h"
16 
17 #include <mutex>
18 #include "hilog_tag_wrapper.h"
19 
20 namespace OHOS {
21 namespace AppExecFwk {
22 namespace {
23 constexpr int32_t U0_USER_ID = 0;
24 }
~UserRecordManager()25 UserRecordManager::~UserRecordManager() {}
26 
UserRecordManager()27 UserRecordManager::UserRecordManager() {}
28 
GetInstance()29 UserRecordManager &UserRecordManager::GetInstance()
30 {
31     static UserRecordManager instance;
32     return instance;
33 }
34 
IsLogoutUser(int32_t userId)35 bool UserRecordManager::IsLogoutUser(int32_t userId)
36 {
37     if (userId == U0_USER_ID) {
38         return false;
39     }
40     std::lock_guard lock(logoutUserIdLock_);
41     return logoutUserIdSet_.find(userId) != logoutUserIdSet_.end();
42 }
43 
SetEnableStartProcessFlagByUserId(int32_t userId,bool enableStartProcess)44 void UserRecordManager::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess)
45 {
46     TAG_LOGI(AAFwkTag::APPMGR, "userId:%{public}d, enableStartProcess:%{public}d", userId, enableStartProcess);
47     if (enableStartProcess) {
48         std::lock_guard lock(logoutUserIdLock_);
49         logoutUserIdSet_.erase(userId);
50     } else {
51         std::lock_guard lock(logoutUserIdLock_);
52         logoutUserIdSet_.insert(userId);
53     }
54 }
55 }  // namespace AppExecFwk
56 }  // namespace OHOS
57