• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef OHOS_DEVICE_NAME_MANAGER_H
17 #define OHOS_DEVICE_NAME_MANAGER_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 
23 #include "datashare_helper.h"
24 #include "device_name_change_monitor.h"
25 #include "single_instance.h"
26 
27 namespace OHOS {
28 namespace DistributedHardware {
29 class DeviceNameManager {
30     DECLARE_SINGLE_INSTANCE_BASE(DeviceNameManager);
31 public:
32     int32_t UnInit();
33 
34     void DataShareReady();
35     void AccountSysReady(int32_t userId);
36     int32_t InitDeviceNameWhenSoftBusReady();
37 
38     int32_t GetLocalDisplayDeviceName(int32_t maxNamelength, std::string &displayName);
39     int32_t InitDeviceNameWhenUserSwitch(int32_t curUserId, int32_t preUserId);
40     int32_t InitDeviceNameWhenLogout();
41     int32_t InitDeviceNameWhenLogin();
42     int32_t InitDeviceNameWhenNickChange();
43     int32_t InitDeviceNameWhenNameChange(int32_t userId);
44     int32_t ModifyUserDefinedName(const std::string &deviceName);
45     int32_t RestoreLocalDeviceName();
46     int32_t InitDeviceNameWhenLanguageOrRegionChanged();
47     std::string GetUserDefinedDeviceName();
48     std::string GetLocalMarketName();
49 
50 private:
51     DeviceNameManager() = default;
52     ~DeviceNameManager() = default;
53     bool DependsIsReady();
54     void RegisterDeviceNameChangeMonitor(int32_t curUserId, int32_t preUserId);
55     void UnRegisterDeviceNameChangeMonitor(int32_t userId);
56     void InitDeviceName(int32_t userId);
57     void InitDeviceNameToSoftBus(const std::string &prefixName, const std::string &subffixName);
58     std::string GetLocalDisplayDeviceName(const std::string &prefixName, const std::string &subffixName,
59         int32_t maxNamelength);
60     std::string SubstrByBytes(const std::string &str, int32_t maxNumBytes);
61 
62     std::string GetSystemLanguage();
63     std::string GetSystemRegion();
64 
65     int32_t InitDisplayDeviceNameToSettingsData(const std::string &nickName, const std::string &deviceName,
66         int32_t userId);
67     int32_t GetUserDefinedDeviceName(int32_t userId, std::string &deviceName);
68     int32_t SetUserDefinedDeviceName(const std::string &deviceName, int32_t userId);
69     int32_t GetDisplayDeviceName(int32_t userId, std::string &deviceName);
70     int32_t SetDisplayDeviceName(const std::string &deviceName, int32_t userId);
71     int32_t SetDisplayDeviceNameState(const std::string &state, int32_t userId);
72     int32_t GetDeviceName(std::string &deviceName);
73     int32_t SetDeviceName(const std::string &deviceName);
74     int32_t GetValue(const std::string &tableName, int32_t userId, const std::string &key, std::string &value);
75     int32_t SetValue(const std::string &tableName, int32_t userId, const std::string &key, const std::string &value);
76     std::string GetProxyUriStr(const std::string &tableName, int32_t userId);
77     std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper(const std::string &proxyUri);
78     Uri MakeUri(const std::string &proxyUri, const std::string &key);
79     bool ReleaseDataShareHelper(std::shared_ptr<DataShare::DataShareHelper> helper);
80 
81     sptr<IRemoteObject> GetRemoteObj();
82 private:
83     std::mutex remoteObjMtx_;
84     sptr<IRemoteObject> remoteObj_ = nullptr;
85     std::mutex localMarketNameMtx_;
86     std::string localMarketName_ = "";
87     std::mutex monitorMapMtx_;
88     std::map<int32_t, sptr<DeviceNameChangeMonitor>> monitorMap_;
89     std::atomic<bool> isDataShareReady_ = false;
90     std::atomic<bool> isAccountSysReady_ = false;
91 };
92 } // DistributedHardware
93 } // OHOS
94 #endif // OHOS_DEVICE_NAME_MANAGER_H