1 /*
2 * Copyright (c) 2021 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 "user/multi_user_manager_service.h"
17 #include "os_account_constants.h"
18 #include "storage_daemon_communication/storage_daemon_communication.h"
19 #include "storage_service_log.h"
20 #include "storage_service_errno.h"
21
22 namespace OHOS {
23 namespace StorageManager {
MultiUserManagerService()24 MultiUserManagerService::MultiUserManagerService()
25 {
26 LOGI("DEBUG MultiUserManagerService constructer");
27 }
28
~MultiUserManagerService()29 MultiUserManagerService::~MultiUserManagerService()
30 {
31 LOGI("DEBUG ~MultiUserManagerService destructer ~");
32 }
33
CheckUserIdRange(int32_t userId)34 int32_t MultiUserManagerService::CheckUserIdRange(int32_t userId)
35 {
36 if (userId < AccountSA::Constants::START_USER_ID || userId > AccountSA::Constants::MAX_USER_ID) {
37 LOGE("MultiUserManagerService: userId:%{public}d is out of range", userId);
38 return E_USERID_RANGE;
39 }
40 return E_OK;
41 }
42
PrepareAddUser(int32_t userId,uint32_t flags)43 int32_t MultiUserManagerService::PrepareAddUser(int32_t userId, uint32_t flags)
44 {
45 LOGI("MultiUserManagerService::PrepareAddUser, userId:%{public}d", userId);
46 int32_t err = CheckUserIdRange(userId);
47 if (err != E_OK) {
48 LOGE("MultiUserManagerService::PrepareAddUser userId %{public}d out of range", userId);
49 return err;
50 }
51 std::shared_ptr<StorageDaemonCommunication> sdCommunication;
52 sdCommunication = DelayedSingleton<StorageDaemonCommunication>::GetInstance();
53 err = sdCommunication->PrepareAddUser(userId, flags);
54 return err;
55 }
56
RemoveUser(int32_t userId,uint32_t flags)57 int32_t MultiUserManagerService::RemoveUser(int32_t userId, uint32_t flags)
58 {
59 LOGI("MultiUserManagerService::RemoveUser, userId:%{public}d", userId);
60 int32_t err = CheckUserIdRange(userId);
61 if (err != E_OK) {
62 LOGE("MultiUserManagerService::RemoveUser userId %{public}d out of range", userId);
63 return err;
64 }
65 std::shared_ptr<StorageDaemonCommunication> sdCommunication;
66 sdCommunication = DelayedSingleton<StorageDaemonCommunication>::GetInstance();
67 err = sdCommunication->RemoveUser(userId, flags);
68 return err;
69 }
70
PrepareStartUser(int32_t userId)71 int32_t MultiUserManagerService::PrepareStartUser(int32_t userId)
72 {
73 LOGI("MultiUserManagerService::PrepareStartUser, userId:%{public}d", userId);
74 int32_t err = CheckUserIdRange(userId);
75 if (err != E_OK) {
76 LOGE("MultiUserManagerService::PrepareStartUser userId %{public}d out of range", userId);
77 return err;
78 }
79 std::shared_ptr<StorageDaemonCommunication> sdCommunication;
80 sdCommunication = DelayedSingleton<StorageDaemonCommunication>::GetInstance();
81 err = sdCommunication->PrepareStartUser(userId);
82 return err;
83 }
84
StopUser(int32_t userId)85 int32_t MultiUserManagerService::StopUser(int32_t userId)
86 {
87 LOGI("MultiUserManagerService::StopUser, userId:%{public}d", userId);
88 int32_t err = CheckUserIdRange(userId);
89 if (err != E_OK) {
90 LOGE("MultiUserManagerService::StopUser userId %{public}d out of range", userId);
91 return err;
92 }
93 std::shared_ptr<StorageDaemonCommunication> sdCommunication;
94 sdCommunication = DelayedSingleton<StorageDaemonCommunication>::GetInstance();
95 err = sdCommunication->StopUser(userId);
96 return err;
97 }
98 } // StorageManager
99 } // OHOS