1 /* 2 * Copyright (c) 2021 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_SYSTEM_DEVICE_ID_KITS_S 17 #define OHOS_SYSTEM_DEVICE_ID_KITS_S 18 #include <mutex> 19 #include "idevice_info.h" 20 #include "singleton.h" 21 #include "beget_ext.h" 22 23 namespace OHOS { 24 namespace device_info { 25 class INIT_LOCAL_API DeviceInfoKits final : public DelayedRefSingleton<DeviceInfoKits> { 26 DECLARE_DELAYED_REF_SINGLETON(DeviceInfoKits); 27 public: 28 DISALLOW_COPY_AND_MOVE(DeviceInfoKits); 29 30 static DeviceInfoKits &GetInstance(); 31 int32_t GetUdid(std::string& result); 32 int32_t GetSerialID(std::string& result); 33 int32_t GetDiskSN(std::string& result); 34 35 void FinishStartSASuccess(const sptr<IRemoteObject> &remoteObject); 36 void FinishStartSAFailed(); 37 void ResetService(const wptr<IRemoteObject> &remote); 38 private: 39 // For death event procession 40 class DeathRecipient final : public IRemoteObject::DeathRecipient { 41 public: 42 DeathRecipient(void) = default; 43 ~DeathRecipient(void) final = default; 44 DISALLOW_COPY_AND_MOVE(DeathRecipient); 45 void OnRemoteDied(const wptr<IRemoteObject> &remote) final; 46 }; GetDeathRecipient(void)47 sptr<IRemoteObject::DeathRecipient> GetDeathRecipient(void) 48 { 49 return deathRecipient_; 50 } 51 52 void LoadDeviceInfoSa(std::unique_lock<std::mutex> &lock); 53 sptr<IDeviceInfo> GetService(std::unique_lock<std::mutex> &lock); 54 std::mutex lock_; 55 std::condition_variable deviceInfoLoadCon_; 56 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {}; 57 sptr<IDeviceInfo> deviceInfoService_ {}; 58 }; 59 } // namespace device_info 60 } // namespace OHOS 61 #endif // OHOS_SYSTEM_DEVICE_ID_KITS_S 62