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 16 #ifdef HAS_OS_ACCOUNT_PART 17 #include "os_account_manager.h" 18 #endif 19 20 #include "log.h" 21 #include "os_account_adapter.h" 22 23 #define DEFAULT_USER 100 24 GetFrontUserId(int * userId)25int GetFrontUserId(int *userId) 26 { 27 #ifdef HAS_OS_ACCOUNT_PART 28 std::vector<int> ids; 29 int errCode = OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids); 30 if (errCode != ERR_OK || ids.empty()) { 31 LOGE("QueryActiveOsAccountIds failed"); 32 return ERR_FAILED; 33 } 34 LOGI("QueryActiveOsAccountIds success"); 35 *userId = ids[0]; 36 #else 37 LOGI("no os account part, set default user"); 38 *userId = DEFAULT_USER; 39 #endif 40 return ERR_OK; 41 }