From 2cf329915fc01ca394151c61e70d5a7bf9361151 Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Fri, 25 Feb 2022 16:47:08 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E6=94=AF=E6=8C=81js=20GetUdid?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AE=89=E5=85=A8=E6=A0=A1=E9=AA=8C=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81js=20GetUdid=E6=8E=A5=E5=8F=A3=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E6=A0=A1=E9=AA=8C=20=E6=94=AF=E6=8C=81js=20GetSerial?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AE=89=E5=85=A8=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xionglei6 --- bundle.json | 7 +- device_info/BUILD.gn | 66 ++++++++++++ device_info/device_info_kits.cpp | 142 ++++++++++++++++++++++++++ device_info/device_info_kits.h | 55 ++++++++++ device_info/device_info_proxy.cpp | 50 +++++++++ device_info/device_info_proxy.h | 36 +++++++ device_info/device_info_stub.cpp | 119 +++++++++++++++++++++ device_info/device_info_stub.h | 50 +++++++++ device_info/etc/3902.xml | 24 +++++ device_info/etc/deviceinfoservice.cfg | 25 +++++ device_info/idevice_info.h | 56 ++++++++++ interfaces/innerkits/BUILD.gn | 25 +++-- services/begetctl/BUILD.gn | 4 +- test/plugintest/plugin_param_cmd.c | 12 +++ 14 files changed, 658 insertions(+), 13 deletions(-) create mode 100755 device_info/BUILD.gn create mode 100755 device_info/device_info_kits.cpp create mode 100755 device_info/device_info_kits.h create mode 100755 device_info/device_info_proxy.cpp create mode 100755 device_info/device_info_proxy.h create mode 100755 device_info/device_info_stub.cpp create mode 100755 device_info/device_info_stub.h create mode 100755 device_info/etc/3902.xml create mode 100755 device_info/etc/deviceinfoservice.cfg create mode 100755 device_info/idevice_info.h diff --git a/bundle.json b/bundle.json index 07ff7d49..e813a843 100644 --- a/bundle.json +++ b/bundle.json @@ -43,11 +43,12 @@ "//base/startup/init_lite/services/begetctl:paramshell", "//base/startup/init_lite/services/plugin:plugin", "//base/startup/init_lite/interfaces/innerkits:libbegetutil", - "//base/startup/init_lite/interfaces/innerkits:libservice_watcher", + "//base/startup/init_lite/interfaces/innerkits:libbeget_proxy", "//base/startup/init_lite/interfaces/innerkits/file:libfile", "//base/startup/init_lite/interfaces/innerkits/socket:libsocket", "//base/startup/init_lite/services/loopevent:loopevent", - "//base/startup/init_lite/interfaces/innerkits/plugin:libplugin" + "//base/startup/init_lite/interfaces/innerkits/plugin:libplugin", + "//base/startup/init_lite/device_info:device_info_group" ], "inner_kits": [ { @@ -72,7 +73,7 @@ "service_watcher.h" ] }, - "name": "//base/startup/init_lite/interfaces/innerkits:libservice_watcher" + "name": "//base/startup/init_lite/interfaces/innerkits:libbeget_proxy" } ], "test": [ diff --git a/device_info/BUILD.gn b/device_info/BUILD.gn new file mode 100755 index 00000000..02009f3c --- /dev/null +++ b/device_info/BUILD.gn @@ -0,0 +1,66 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//build/ohos.gni") +import("//build/ohos/sa_profile/sa_profile.gni") + +ohos_sa_profile("device_info_profile") { + sources = [ "etc/3902.xml" ] + part_name = "init" +} + +ohos_prebuilt_etc("device_info.cfg") { + source = "etc/deviceinfoservice.cfg" + relative_install_dir = "init" + part_name = "init" +} + +ohos_shared_library("deviceinfoservice") { + sources = [ "device_info_stub.cpp" ] + + defines = [ + "INIT_AGENT", + "DINFO_LABEL=\"DeviceInfoService\"", + ] + include_dirs = [ + ".", + "//base/startup/init_lite/interfaces/innerkits/include", + "//base/startup/syspara_lite/hals/parameter/include", + "//utils/native/base/include", + "//utils/system/safwk/native/include", + ] + + deps = [ + "//base/startup/init_lite/services/log:agent_log", + "//base/startup/syspara_lite/hals/parameter:sysparam_hal", + "//third_party/bounds_checking_function:libsec_shared", + "//utils/native/base:utils", + ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] + install_images = [ "system" ] + part_name = "init" +} + +group("device_info_group") { + deps = [ + ":device_info.cfg", + ":device_info_profile", + ":deviceinfoservice", + ] +} diff --git a/device_info/device_info_kits.cpp b/device_info/device_info_kits.cpp new file mode 100755 index 00000000..f5cc59f9 --- /dev/null +++ b/device_info/device_info_kits.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "device_info_kits.h" + +#include "beget_ext.h" +#include "device_info_proxy.h" +#include "idevice_info.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" +#include "securec.h" + +namespace { +static constexpr int UDID_LEN = 65; +static constexpr int MAX_SERIAL_LEN = 65; +} // namespace name + +namespace OHOS { +namespace device_info { +DeviceInfoKits::DeviceInfoKits() {} + +DeviceInfoKits::~DeviceInfoKits() {} + +DeviceInfoKits &DeviceInfoKits::GetInstance() +{ + return DelayedRefSingleton::GetInstance(); +} + +void DeviceInfoKits::ResetService(const wptr &remote) +{ + std::lock_guard lock(lock_); + if (deviceInfoService_ != nullptr) { + sptr object = deviceInfoService_->AsObject(); + if ((object != nullptr) && (remote == object)) { + object->RemoveDeathRecipient(deathRecipient_); + deviceInfoService_ = nullptr; + } + } +} + +sptr DeviceInfoKits::GetService() +{ + std::lock_guard lock(lock_); + if (deviceInfoService_ != nullptr) { + return deviceInfoService_; + } + + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + DINFO_CHECK(samgr != nullptr, return nullptr, "Get samgr failed"); + sptr object = samgr->GetSystemAbility(SYSPARAM_DEVICE_SERVICE_ID); + DINFO_CHECK(object != nullptr, return nullptr, "Get device service object from samgr failed"); + if (deathRecipient_ == nullptr) { + deathRecipient_ = new DeathRecipient(); + } + + if ((object->IsProxyObject()) && (!object->AddDeathRecipient(deathRecipient_))) { + DINFO_LOGE("Failed to add death recipient"); + } + deviceInfoService_ = iface_cast(object); + if (deviceInfoService_ == nullptr) { + DINFO_LOGE("device service iface_cast failed"); + } + return deviceInfoService_; +} + +void DeviceInfoKits::DeathRecipient::OnRemoteDied(const wptr &remote) +{ + DelayedRefSingleton::GetInstance().ResetService(remote); +} + +int32_t DeviceInfoKits::GetUdid(std::string& result) +{ + printf("DeviceInfoKits::GetUdid \n"); + auto deviceService = GetService(); + DINFO_CHECK(deviceService != nullptr, return -1, "Failed to get watcher manager"); + return deviceService->GetUdid(result); +} + +int32_t DeviceInfoKits::GetSerialID(std::string& result) +{ + auto deviceService = GetService(); + DINFO_CHECK(deviceService != nullptr, return -1, "Failed to get watcher manager"); + return deviceService->GetSerialID(result); +} +} // namespace device_info +} // namespace OHOS + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +int AclGetDevUdid(char *udid, int size) +{ + if (udid == nullptr || size < UDID_LEN) { + return -1; + } + printf("AclGetDevUdid \n"); + DINFO_LOGI("AclGetDevUdid"); + std::string result = {}; + OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance(); + int ret = instance.GetUdid(result); + if (ret == 0) { + ret = strcpy_s(udid, size, result.c_str()); + } + printf("GetDevUdid %s \n", udid); + DINFO_LOGI("GetDevUdid %s", udid); + return ret; +} + +const char *AclGetSerial(void) +{ + DINFO_LOGI("AclGetSerial"); + static char serialNumber[MAX_SERIAL_LEN] = {"1234567890"}; + std::string result = {}; + OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance(); + int ret = instance.GetSerialID(result); + if (ret == 0) { + (void)strcpy_s(serialNumber, sizeof(serialNumber), result.c_str()); + } + DINFO_LOGI("GetSerial %s", serialNumber); + return serialNumber; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ \ No newline at end of file diff --git a/device_info/device_info_kits.h b/device_info/device_info_kits.h new file mode 100755 index 00000000..e9aace73 --- /dev/null +++ b/device_info/device_info_kits.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_SYSTEM_DEVICE_ID_KITS_S +#define OHOS_SYSTEM_DEVICE_ID_KITS_S +#include +#include "idevice_info.h" +#include "singleton.h" + +namespace OHOS { +namespace device_info { +class DeviceInfoKits final : public DelayedRefSingleton { + DECLARE_DELAYED_REF_SINGLETON(DeviceInfoKits); +public: + DISALLOW_COPY_AND_MOVE(DeviceInfoKits); + + static DeviceInfoKits &GetInstance(); + int32_t GetUdid(std::string& result); + int32_t GetSerialID(std::string& result); + void ResetService(const wptr &remote); + + // For death event procession + class DeathRecipient final : public IRemoteObject::DeathRecipient { + public: + DeathRecipient() = default; + ~DeathRecipient() final = default; + DISALLOW_COPY_AND_MOVE(DeathRecipient); + void OnRemoteDied(const wptr &remote) final; + }; + sptr GetDeathRecipient() + { + return deathRecipient_; + } + +private: + sptr GetService(); + std::mutex lock_; + sptr deviceInfoService_ {}; + sptr deathRecipient_ {}; +}; +} // namespace device_info +} // namespace OHOS +#endif // OHOS_SYSTEM_DEVICE_ID_KITS_S diff --git a/device_info/device_info_proxy.cpp b/device_info/device_info_proxy.cpp new file mode 100755 index 00000000..ec35e42b --- /dev/null +++ b/device_info/device_info_proxy.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "device_info_proxy.h" + +#include "beget_ext.h" +#include "idevice_info.h" +#include "parcel.h" +#include "string_ex.h" + +namespace OHOS { +namespace device_info { +int32_t DeviceInfoProxy::GetUdid(std::string& result) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option { MessageOption::TF_SYNC }; + printf("DeviceInfoProxy::GetUdid \n"); + data.WriteInterfaceToken(DeviceInfoProxy::GetDescriptor()); + int32_t ret = Remote()->SendRequest(COMMAND_GET_UDID, data, reply, option); + DINFO_CHECK(ret == ERR_NONE, return ret, "getUdid failed, error code is %d", ret); + result = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +int32_t DeviceInfoProxy::GetSerialID(std::string& result) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option { MessageOption::TF_SYNC }; + + data.WriteInterfaceToken(DeviceInfoProxy::GetDescriptor()); + int32_t ret = Remote()->SendRequest(COMMAND_GET_SERIAL_ID, data, reply, option); + DINFO_CHECK(ret == ERR_NONE, return ret, "GetSerial failed, error code is %d", ret); + result = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} +} // namespace device_info +} // namespace OHOS diff --git a/device_info/device_info_proxy.h b/device_info/device_info_proxy.h new file mode 100755 index 00000000..208bde0e --- /dev/null +++ b/device_info/device_info_proxy.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_SYSTEM_DEVICEIDPROXY_H +#define OHOS_SYSTEM_DEVICEIDPROXY_H + +#include "iremote_proxy.h" +#include "idevice_info.h" + +namespace OHOS { +namespace device_info { +class DeviceInfoProxy : public IRemoteProxy { +public: + explicit DeviceInfoProxy(const sptr &impl) : IRemoteProxy(impl) {} + virtual ~DeviceInfoProxy() {} + + virtual int32_t GetUdid(std::string& result) override; + virtual int32_t GetSerialID(std::string& result) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace system +} // namespace OHOS +#endif // OHOS_SYSTEM_DEVICEIDPROXY_H \ No newline at end of file diff --git a/device_info/device_info_stub.cpp b/device_info/device_info_stub.cpp new file mode 100755 index 00000000..b7e191cf --- /dev/null +++ b/device_info/device_info_stub.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device_info_stub.h" + +#include "beget_ext.h" +#include "idevice_info.h" +#include "ipc_skeleton.h" +#include "accesstoken_kit.h" +#include "parameter_hal.h" +#include "parcel.h" +#include "string_ex.h" +#include "system_ability_definition.h" + +using std::u16string; +namespace { +static constexpr int UDID_LEN = 65; +} // namespace name + +namespace OHOS { +using namespace Security; +using namespace Security::AccessToken; + +namespace device_info { +REGISTER_SYSTEM_ABILITY_BY_ID(DeviceInfoService, SYSPARAM_DEVICE_SERVICE_ID, true) + +int32_t DeviceInfoStub::OnRemoteRequest(uint32_t code, + MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + std::u16string myDescripter = IDeviceInfo::GetDescriptor(); + std::u16string remoteDescripter = data.ReadInterfaceToken(); + DINFO_CHECK(myDescripter == remoteDescripter, return ERR_INVALD_DESC, "Invalid remoteDescripter"); + + int ret = ERR_FAIL; + switch (code) { + case COMMAND_GET_UDID: { + if (!CheckPermission(data, PERMISSION_UDID)) { + return ERR_FAIL; + } + char localDeviceInfo[UDID_LEN] = {0}; + ret = HalGetDevUdid(localDeviceInfo, UDID_LEN); + DINFO_CHECK(ret == 0, break, "Failed to get dev udid"); + reply.WriteString16(Str8ToStr16(localDeviceInfo)); + break; + } + case COMMAND_GET_SERIAL_ID: { + if (!CheckPermission(data, PERMISSION_UDID)) { + return ERR_FAIL; + } + const char *serialNumber = HalGetSerial(); + DINFO_CHECK(serialNumber != nullptr, break, "Failed to get serialNumber"); + reply.WriteString16(Str8ToStr16(serialNumber)); + break; + } + default: { + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + } + return ret; +} + +bool DeviceInfoStub::CheckPermission(MessageParcel &data, const std::string &permission) +{ + AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); + int32_t result = TypePermissionState::PERMISSION_GRANTED; + int32_t tokenType = AccessTokenKit::GetTokenTypeFlag(callerToken); + if (tokenType == TOKEN_NATIVE) { +#ifdef SUPPORT_NATIVE + result = AccessTokenKit::VerifyNativeToken(callerToken, permission); +#endif + } else if (tokenType == TOKEN_HAP) { + result = AccessTokenKit::VerifyAccessToken(callerToken, permission); + } else { + DINFO_LOGE("AccessToken type:%d, permission:%d denied!", tokenType, callerToken); + return false; + } + if (result == TypePermissionState::PERMISSION_DENIED) { + DINFO_LOGE("AccessTokenID:%d, permission:%s denied!", callerToken, permission.c_str()); + return false; + } + DINFO_LOGI("dAccessTokenID:%d, permission:%s matched!", callerToken, permission.c_str()); + return true; +} + +int32_t DeviceInfoService::GetUdid(std::string& result) +{ + return 0; +} +int32_t DeviceInfoService::GetSerialID(std::string& result) +{ + return 0; +} + +void DeviceInfoService::OnStart(void) +{ + DINFO_LOGI("WatcherManager OnStart"); + bool res = Publish(this); + if (!res) { + DINFO_LOGE("WatcherManager Publish failed"); + } + return; +} +void DeviceInfoService::OnStop() +{ +} +} // namespace device_info +} // namespace OHOS diff --git a/device_info/device_info_stub.h b/device_info/device_info_stub.h new file mode 100755 index 00000000..8e1e74ee --- /dev/null +++ b/device_info/device_info_stub.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_SYSTEM_DEVICEIDSTUB_H +#define OHOS_SYSTEM_DEVICEIDSTUB_H + +#include "iremote_stub.h" +#include "idevice_info.h" +#include "system_ability.h" + +namespace OHOS { +namespace device_info { +class DeviceInfoStub : public IRemoteStub { +public: + int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, + MessageOption &option) override; +private: + bool CheckPermission(MessageParcel &data, const std::string &permission); +}; + +class DeviceInfoService : public SystemAbility, public DeviceInfoStub { +public: + DECLARE_SYSTEM_ABILITY(DeviceInfoService); + DISALLOW_COPY_AND_MOVE(DeviceInfoService); + explicit DeviceInfoService(int32_t systemAbilityId, bool runOnCreate = true) + : SystemAbility(systemAbilityId, runOnCreate) + { + } + ~DeviceInfoService() override {} + virtual int32_t GetUdid(std::string& result) override; + virtual int32_t GetSerialID(std::string& result) override; +protected: + void OnStart() override; + void OnStop() override; +}; +} // namespace device_info +} // namespace OHOS +#endif // OHOS_SYSTEM_DEVICEIDSTUB_H \ No newline at end of file diff --git a/device_info/etc/3902.xml b/device_info/etc/3902.xml new file mode 100755 index 00000000..3f442337 --- /dev/null +++ b/device_info/etc/3902.xml @@ -0,0 +1,24 @@ + + + + deviceinfoservice + + 3902 + libdeviceinfoservice.z.so + true + false + 1 + + \ No newline at end of file diff --git a/device_info/etc/deviceinfoservice.cfg b/device_info/etc/deviceinfoservice.cfg new file mode 100755 index 00000000..5e6db395 --- /dev/null +++ b/device_info/etc/deviceinfoservice.cfg @@ -0,0 +1,25 @@ +{ + "jobs" : [ { + "name" : "services:deviceinfoservice", + "cmds" : [ + "chown shell system /data/init_agent", + "chmod 0771 /data/init_agent", + "chown shell system /data/init_agent/begetctrl.log", + "chown shell system /data/init_agent/device_infokits.log", + "chmod 0666 /data/init_agent/begetctrl.log", + "chmod 0666 /data/init_agent/param.log", + "chmod 0666 /data/init_agent/device_infokits.log" + ] + } + ], + "services" : [{ + "name" : "deviceinfoservice", + "path" : ["/system/bin/sa_main", "/system/profile/deviceinfoservice.xml"], + "uid" : "system", + "gid" : ["system", "shell"], + "jobs" : { + "on-start" : "services:deviceinfoservice" + } + } + ] +} \ No newline at end of file diff --git a/device_info/idevice_info.h b/device_info/idevice_info.h new file mode 100755 index 00000000..320d0e23 --- /dev/null +++ b/device_info/idevice_info.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_SYSTEM_IDEVICEID_H +#define OHOS_SYSTEM_IDEVICEID_H + +#include +#include "beget_ext.h" +#include "iremote_broker.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace device_info { +class IDeviceInfo : public OHOS::IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.system.IDeviceInfo"); + + virtual int32_t GetUdid(std::string& result) = 0; + virtual int32_t GetSerialID(std::string& result) = 0; + + static constexpr int COMMAND_GET_UDID = MIN_TRANSACTION_ID + 0; + static constexpr int COMMAND_GET_SERIAL_ID = MIN_TRANSACTION_ID + 1; + static constexpr int ERR_FAIL = -1; + static constexpr int ERR_INVALD_DESC = -1; + const std::string PERMISSION_UDID = "ohos.permission.sec.ACCESS_UDID"; +}; +} // namespace device_info +} // namespace OHOS + +#define DINFO_LOGI(fmt, ...) STARTUP_LOGI("begetctrl.log", "DeviceInfoKits", fmt, ##__VA_ARGS__) +#define DINFO_LOGE(fmt, ...) STARTUP_LOGE("begetctrl.log", "DeviceInfoKits", fmt, ##__VA_ARGS__) +#define DINFO_LOGV(fmt, ...) STARTUP_LOGV("begetctrl.log", "DeviceInfoKits", fmt, ##__VA_ARGS__) + +#define DINFO_CHECK(ret, exper, ...) \ + if (!(ret)) { \ + DINFO_LOGE(__VA_ARGS__); \ + exper; \ + } +#define DINFO_ONLY_CHECK(ret, exper, ...) \ + if (!(ret)) { \ + exper; \ + } + +#endif // OHOS_SYSTEM_IDEVICEID_H \ No newline at end of file diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index fa15eb8b..21bd0053 100755 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -63,29 +63,38 @@ ohos_shared_library("libbegetutil") { } # watcher lib must separate compilation avoid interdependence. -ohos_shared_library("libservice_watcher") { - sources = [ "service_watcher/service_watcher.c" ] +ohos_shared_library("libbeget_proxy") { + sources = [ + "//base/startup/init_lite/device_info/device_info_kits.cpp", + "//base/startup/init_lite/device_info/device_info_proxy.cpp", + "service_watcher/service_watcher.c", + ] include_dirs = [ "./include", + "//base/startup/init_lite/device_info", + "//utils/native/base/include", + "//base/startup/init_lite/interfaces/innerkits/include", "//base/startup/init_lite/services/include", "//base/startup/init_lite/services/include/param", "//third_party/bounds_checking_function/include", ] deps = [ + "//base/startup/init_lite/services/log:agent_log", "//base/startup/init_lite/services/param/watcher:param_watcheragent", "//base/startup/init_lite/services/utils:libinit_utils", "//third_party/bounds_checking_function:libsec_shared", + "//utils/native/base:utils", ] - deps += [ "//base/startup/init_lite/services/log:init_log" ] - - part_name = "init" - install_images = [ - "system", - "updater", + external_deps = [ + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", ] + part_name = "init" + install_images = [ "system" ] } # For init only diff --git a/services/begetctl/BUILD.gn b/services/begetctl/BUILD.gn index e7016d4b..d9c10628 100755 --- a/services/begetctl/BUILD.gn +++ b/services/begetctl/BUILD.gn @@ -52,7 +52,7 @@ ohos_executable("begetctl") { if (param_test) { sources += [ "//base/startup/init_lite/test/plugintest/plugin_param_cmd.c" ] deps += [ - "//base/startup/init_lite/interfaces/innerkits:libservice_watcher", + "//base/startup/init_lite/interfaces/innerkits:libbeget_proxy", "//base/startup/init_lite/services/loopevent:loopevent", "//base/startup/init_lite/services/param/watcher:param_watcheragent", ] @@ -110,7 +110,7 @@ ohos_executable("paramshell") { if (param_test) { sources += [ "//base/startup/init_lite/test/plugintest/plugin_param_cmd.c" ] deps += [ - "//base/startup/init_lite/interfaces/innerkits:libservice_watcher", + "//base/startup/init_lite/interfaces/innerkits:libbeget_proxy", "//base/startup/init_lite/services/loopevent:loopevent", "//base/startup/init_lite/services/param/watcher:param_watcheragent", ] diff --git a/test/plugintest/plugin_param_cmd.c b/test/plugintest/plugin_param_cmd.c index eefcbf4c..00ac6e07 100755 --- a/test/plugintest/plugin_param_cmd.c +++ b/test/plugintest/plugin_param_cmd.c @@ -25,6 +25,7 @@ #include "service_watcher.h" #include "shell_utils.h" #include "sys_param.h" +#include "parameter.h" #define READ_DURATION 100000 static char *GetLocalBuffer(uint32_t *buffSize) @@ -148,6 +149,16 @@ static int32_t BShellParamCmdGroupTest(BShellHandle shell, int32_t argc, char *a return 0; } +static int32_t BShellParamCmdUdidGet(BShellHandle shell, int32_t argc, char *argv[]) +{ + PLUGIN_CHECK(argc >= 1, return -1, "Invalid parameter"); + PLUGIN_LOGI("BShellParamCmdUdidGet "); + char localDeviceId[65] = {0}; // 65 udid len + AclGetDevUdid(localDeviceId, 65); // 65 udid len + BShellEnvOutput(shell, " udid: %s\r\n", localDeviceId); + return 0; +} + int32_t BShellCmdRegister(BShellHandle shell, int execMode) { if (execMode == 0) { @@ -165,6 +176,7 @@ int32_t BShellCmdRegister(BShellHandle shell, int execMode) {"install", BShellParamCmdInstall, "install plugin", "install [name]", ""}, {"uninstall", BShellParamCmdInstall, "uninstall plugin", "uninstall [name]", ""}, {"group", BShellParamCmdGroupTest, "group test", "group test [stage]", "group test"}, + {"display", BShellParamCmdUdidGet, "display udid", "display udid", "display udid"}, }; for (size_t i = 0; i < sizeof(infos) / sizeof(infos[0]); i++) { BShellEnvRegitsterCmd(GetShellHandle(), &infos[i]); -- GitLab