• 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 
48 private:
49     DeviceNameManager() = default;
50     ~DeviceNameManager() = default;
51     bool DependsIsReady();
52     void RegisterDeviceNameChangeMonitor(int32_t curUserId, int32_t preUserId);
53     void UnRegisterDeviceNameChangeMonitor(int32_t userId);
54     void InitDeviceName(int32_t userId);
55     void InitDeviceNameToSoftBus(const std::string &prefixName, const std::string &subffixName);
56     std::string GetLocalDisplayDeviceName(const std::string &prefixName, const std::string &subffixName,
57         int32_t maxNamelength);
58     std::string SubstrByBytes(const std::string &str, int32_t maxNumBytes);
59 
60     std::string GetSystemLanguage();
61     std::string GetSystemRegion();
62     std::string GetLocalMarketName();
63 
64     int32_t InitDisplayDeviceNameToSettingsData(const std::string &nickName, const std::string &deviceName,
65         int32_t userId);
66     int32_t GetUserDefinedDeviceName(int32_t userId, std::string &deviceName);
67     int32_t SetUserDefinedDeviceName(const std::string &deviceName, int32_t userId);
68     int32_t GetDisplayDeviceName(int32_t userId, std::string &deviceName);
69     int32_t SetDisplayDeviceName(const std::string &deviceName, int32_t userId);
70     int32_t SetDisplayDeviceNameState(const std::string &state, int32_t userId);
71     int32_t GetDeviceName(std::string &deviceName);
72     int32_t SetDeviceName(const std::string &deviceName);
73     int32_t GetValue(const std::string &tableName, int32_t userId, const std::string &key, std::string &value);
74     int32_t SetValue(const std::string &tableName, int32_t userId, const std::string &key, const std::string &value);
75     std::string GetProxyUriStr(const std::string &tableName, int32_t userId);
76     std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper(const std::string &proxyUri);
77     Uri MakeUri(const std::string &proxyUri, const std::string &key);
78     bool ReleaseDataShareHelper(std::shared_ptr<DataShare::DataShareHelper> helper);
79 
80     sptr<IRemoteObject> GetRemoteObj();
81 private:
82     std::mutex remoteObjMtx_;
83     sptr<IRemoteObject> remoteObj_ = nullptr;
84     std::mutex localMarketNameMtx_;
85     std::string localMarketName_ = "";
86     std::mutex monitorMapMtx_;
87     std::map<int32_t, sptr<DeviceNameChangeMonitor>> monitorMap_;
88     std::atomic<bool> isDataShareReady_ = false;
89     std::atomic<bool> isAccountSysReady_ = false;
90 };
91 } // DistributedHardware
92 } // OHOS
93 #endif // OHOS_DEVICE_NAME_MANAGER_H