• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 "os_account_adapter.h"
17 
18 #include <vector>
19 #include "device_auth.h"
20 #include "hc_log.h"
21 #ifdef SUPPORT_OS_ACCOUNT
22 #include "os_account_manager.h"
23 #endif
24 
DevAuthGetRealOsAccountLocalId(int32_t inputId)25 int32_t DevAuthGetRealOsAccountLocalId(int32_t inputId)
26 {
27     if (inputId == ANY_OS_ACCOUNT) {
28 #ifdef SUPPORT_OS_ACCOUNT
29         std::vector<int> activatedOsAccountIds;
30         LOGI("[OsAccountManager][In]: QueryActiveOsAccountIds!");
31         OHOS::ErrCode res = OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activatedOsAccountIds);
32         LOGI("[OsAccountManager][Out]: QueryActiveOsAccountIds! res: %d", res);
33         if ((res != OHOS::ERR_OK) || (activatedOsAccountIds.size() <= 0)) {
34             LOGE("[Account]: QueryActiveOsAccountIds fail! res: %d", res);
35             return INVALID_OS_ACCOUNT;
36         }
37         int osAccountId = activatedOsAccountIds[0];
38         LOGI("[Account]: Use activated os account! [Id]: %d", osAccountId);
39         return osAccountId;
40 #else
41         return 0;
42 #endif
43     } else if (inputId >= 0) {
44         LOGI("[Account]: Use input os account! [Id]: %d", inputId);
45         return inputId;
46     } else {
47         LOGE("[Account]: The input os account is invalid! [Id]: %d", inputId);
48         return INVALID_OS_ACCOUNT;
49     }
50 }
51