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 #include "battery_utils.h"
17 
18 #include "edm_log.h"
19 #include "edm_os_account_manager_impl.h"
20 
21 namespace OHOS {
22 namespace EDM {
23 const std::string BatteryUtils::PLUGGED_TYPE_AC = "ac";
24 const std::string BatteryUtils::PLUGGED_TYPE_DC = "dc";
25 
GetBatteryPluggedType()26 std::string BatteryUtils::GetBatteryPluggedType()
27 {
28     return PLUGGED_TYPE_DC;
29 }
30 
GetSubUserTableUri()31 std::string BatteryUtils::GetSubUserTableUri()
32 {
33     std::string userId = std::to_string(GetCurrentUserId());
34     std::string subUserTableUri =
35         "datashare:///com.ohos.settingsdata/entry/settingsdata/USER_SETTINGSDATA_SECURE_" + userId + "?Proxy=true";
36     return subUserTableUri;
37 }
38 
GetCurrentUserId()39 int32_t BatteryUtils::GetCurrentUserId()
40 {
41     std::vector<int32_t> ids;
42     ErrCode ret = std::make_shared<EdmOsAccountManagerImpl>()->QueryActiveOsAccountIds(ids);
43     if (FAILED(ret) || ids.empty()) {
44         EDMLOGE("BatteryUtils GetCurrentUserId failed");
45         return -1;
46     }
47     EDMLOGD("BatteryUtils GetCurrentUserId user id = %{public}d", ids.at(0));
48     return (ids.at(0));
49 }
50 } // namespace EDM
51 } // namespace OHOS