1b0b2a9adSopenharmony_ci/*
2b0b2a9adSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3b0b2a9adSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4b0b2a9adSopenharmony_ci * you may not use this file except in compliance with the License.
5b0b2a9adSopenharmony_ci * You may obtain a copy of the License at
6b0b2a9adSopenharmony_ci *
7b0b2a9adSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8b0b2a9adSopenharmony_ci *
9b0b2a9adSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10b0b2a9adSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11b0b2a9adSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b0b2a9adSopenharmony_ci * See the License for the specific language governing permissions and
13b0b2a9adSopenharmony_ci * limitations under the License.
14b0b2a9adSopenharmony_ci */
15b0b2a9adSopenharmony_ci
16b0b2a9adSopenharmony_ciimport account_osAccount from '@ohos.account.osAccount';
17b0b2a9adSopenharmony_ciimport logger from './logger'
18b0b2a9adSopenharmony_ciimport utils from './utils'
19b0b2a9adSopenharmony_ci
20b0b2a9adSopenharmony_ciconst TAG = 'AccountManager';
21b0b2a9adSopenharmony_ci
22b0b2a9adSopenharmony_ciexport interface UserId {
23b0b2a9adSopenharmony_ci  localId: number;
24b0b2a9adSopenharmony_ci}
25b0b2a9adSopenharmony_ci
26b0b2a9adSopenharmony_ciexport class AccountManager {
27b0b2a9adSopenharmony_ci    async getAccountUserId(userId: UserId) : Promise<boolean> {
28b0b2a9adSopenharmony_ci        let accountInfo = await account_osAccount.getAccountManager().queryCurrentOsAccount();
29b0b2a9adSopenharmony_ci        if (!utils.isValid(accountInfo)) {
30b0b2a9adSopenharmony_ci            logger.warn(TAG, 'getAccountUserId queryCurrentOsAccount fail! userId is null');
31b0b2a9adSopenharmony_ci            return false;
32b0b2a9adSopenharmony_ci        }
33b0b2a9adSopenharmony_ci        userId.localId = accountInfo.localId;
34b0b2a9adSopenharmony_ci        logger.info(TAG, 'getAccountUserId accountInfo.localId=' + accountInfo.localId);
35b0b2a9adSopenharmony_ci        return true;
36b0b2a9adSopenharmony_ci    }
37b0b2a9adSopenharmony_ci}
38b0b2a9adSopenharmony_ci
39b0b2a9adSopenharmony_cilet accountManager = new AccountManager();
40b0b2a9adSopenharmony_ci
41b0b2a9adSopenharmony_ciexport default accountManager as AccountManager;