mirror of
https://gitee.com/openharmony/sensors_sensor
synced 2025-01-31 11:01:57 +00:00
fix call func
Signed-off-by: lixiangpeng5 <lixiangpeng5@huawei.com> Change-Id: Id351aa4c79e3a01ffbb782d0056ff3f2b14844d2
This commit is contained in:
parent
f6a7e7bb3c
commit
7fc969445f
@ -19,7 +19,6 @@
|
||||
],
|
||||
"deps": {
|
||||
"components": [
|
||||
"ability_runtime",
|
||||
"bundle_framework",
|
||||
"c_utils",
|
||||
"hilog",
|
||||
@ -33,8 +32,7 @@
|
||||
"memmgr",
|
||||
"safwk",
|
||||
"samgr",
|
||||
"eventhandler",
|
||||
"os_account"
|
||||
"eventhandler"
|
||||
],
|
||||
"third_party": []
|
||||
},
|
||||
|
@ -39,12 +39,14 @@ ohos_shared_library("libsensor") {
|
||||
}
|
||||
deps = [ "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native" ]
|
||||
external_deps = [
|
||||
"ability_runtime:app_manager",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_single",
|
||||
"napi:ace_napi",
|
||||
"os_account:os_account_innerkits"
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
relative_install_dir = "module"
|
||||
part_name = "sensor"
|
||||
|
@ -59,7 +59,7 @@ bool CreateFailMessage(CallbackDataType type, int32_t code, string message,
|
||||
bool ConvertToBodyData(const napi_env &env, sptr<AsyncCallbackInfo> asyncCallbackInfo, napi_value result[2]);
|
||||
bool ConvertToCompass(const napi_env &env, sptr<AsyncCallbackInfo> asyncCallbackInfo, napi_value result[2]);
|
||||
void ReleaseCallback(sptr<AsyncCallbackInfo> asyncCallbackInfo);
|
||||
int32_t GetTargetSDKVersion(int32_t pid);
|
||||
bool GetSelfTargetVersion(uint32_t &targetVersion);
|
||||
|
||||
|
||||
#define CHKNCF(env, cond, message) \
|
||||
|
@ -41,6 +41,7 @@ constexpr int32_t SENSOR_SUBSCRIBE_FAILURE = 1001;
|
||||
constexpr int32_t INPUT_ERROR = 202;
|
||||
constexpr float BODY_STATE_EXCEPT = 1.0f;
|
||||
constexpr float THRESHOLD = 0.000001f;
|
||||
constexpr uint32_t COMPATIBILITY_CHANGE_VERSION_API12 = 12;
|
||||
} // namespace
|
||||
static std::map<std::string, int64_t> g_samplingPeriod = {
|
||||
{"normal", 200000000},
|
||||
@ -1036,8 +1037,12 @@ static napi_value GetSensorListSync(napi_env env, napi_callback_info info)
|
||||
static napi_value GetSingleSensor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
CALL_LOG_ENTER;
|
||||
int32_t targetSdkVersion = GetTargetSDKVersion(getpid());
|
||||
SEN_HILOGE("targetSdkVersion = %{public}d", targetSdkVersion);
|
||||
uint32_t targetVersion = 0;
|
||||
if (GetSelfTargetVersion(targetVersion)) {
|
||||
SEN_HILOGI("targetVersion: %{public}d", targetVersion);
|
||||
} else {
|
||||
SEN_HILOGE("Get self target version fail");
|
||||
}
|
||||
size_t argc = 2;
|
||||
napi_value args[2] = { 0 };
|
||||
napi_value thisVar = nullptr;
|
||||
@ -1074,6 +1079,10 @@ static napi_value GetSingleSensor(napi_env env, napi_callback_info info)
|
||||
}
|
||||
}
|
||||
if (asyncCallbackInfo->sensorInfos.empty()) {
|
||||
if (GetSelfTargetVersion(targetVersion) && (targetVersion < COMPATIBILITY_CHANGE_VERSION_API12)) {
|
||||
ThrowErr(env, PARAMETER_ERROR, "The sensor is not supported by the device");
|
||||
return nullptr;
|
||||
}
|
||||
ThrowErr(env, SENSOR_NO_SUPPORT, "The sensor is not supported by the device");
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -19,9 +19,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "app_mgr_client.h"
|
||||
#include "bundle_mgr_client.h"
|
||||
#include "os_account_manager.h"
|
||||
#include "bundle_mgr_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "sensor_napi_error.h"
|
||||
|
||||
@ -29,7 +30,6 @@ namespace OHOS {
|
||||
namespace Sensors {
|
||||
namespace {
|
||||
constexpr int32_t STRING_LENGTH_MAX = 64;
|
||||
constexpr int32_t INVALID_TARGET_VERSION = -1;
|
||||
} // namespace
|
||||
bool IsSameValue(const napi_env &env, const napi_value &lhs, const napi_value &rhs)
|
||||
{
|
||||
@ -613,38 +613,32 @@ void EmitPromiseWork(sptr<AsyncCallbackInfo> asyncCallbackInfo)
|
||||
}
|
||||
}
|
||||
|
||||
int32_t GetTargetSDKVersion(int32_t pid)
|
||||
bool GetSelfTargetVersion(uint32_t &targetVersion)
|
||||
{
|
||||
AppExecFwk::RunningProcessInfo processinfo;
|
||||
AppExecFwk::AppMgrClient appMgrClient;
|
||||
int32_t ret = appMgrClient.AppExecFwk::AppMgrClient::GetRunningProcessInfoByPid(pid, processinfo);
|
||||
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (samgr == nullptr) {
|
||||
SEN_HILOGE("Samgr error");
|
||||
return false;
|
||||
}
|
||||
auto bundleObj = samgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
|
||||
if (bundleObj == nullptr) {
|
||||
SEN_HILOGE("BundleObj error");
|
||||
return false;
|
||||
}
|
||||
auto bundleMgrProxy = iface_cast<AppExecFwk::IBundleMgr>(bundleObj);
|
||||
if (bundleMgrProxy == nullptr) {
|
||||
SEN_HILOGE("BundleMgrProxy error");
|
||||
return false;
|
||||
}
|
||||
AppExecFwk::BundleInfo bundleInfo;
|
||||
ErrCode ret = bundleMgrProxy->GetBundleInfoForSelf(OHOS::AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo);
|
||||
if (ret != ERR_OK) {
|
||||
SEN_HILOGE("Getrunningprocessinfobypid failed");
|
||||
return INVALID_TARGET_VERSION;
|
||||
SEN_HILOGE("GetBundleInfoForSelf error");
|
||||
return false;
|
||||
}
|
||||
std::vector<int32_t> activeUserIds;
|
||||
int32_t retId = AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeUserIds);
|
||||
if (retId != 0) {
|
||||
SEN_HILOGE("QueryActiveOsAccountIds failed %{public}d", retId);
|
||||
return INVALID_TARGET_VERSION;
|
||||
}
|
||||
if (activeUserIds.empty()) {
|
||||
SEN_HILOGE("activeUserId empty");
|
||||
return INVALID_TARGET_VERSION;
|
||||
}
|
||||
for (const auto &bundleName : processinfo.bundleNames) {
|
||||
SEN_HILOGD("bundleName = %{public}s", bundleName.c_str());
|
||||
AppExecFwk::BundleMgrClient bundleMgrClient;
|
||||
AppExecFwk::BundleInfo bundleInfo;
|
||||
auto res = bundleMgrClient.AppExecFwk::BundleMgrClient::GetBundleInfo(bundleName,
|
||||
AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, activeUserIds[0]);
|
||||
if (!res) {
|
||||
SEN_HILOGE("Getbundleinfo fail");
|
||||
return INVALID_TARGET_VERSION;
|
||||
}
|
||||
return bundleInfo.targetVersion;
|
||||
}
|
||||
return INVALID_TARGET_VERSION;
|
||||
SEN_HILOGI("Bundle targetVersion is %{public}d", bundleInfo.targetVersion);
|
||||
targetVersion = bundleInfo.targetVersion;
|
||||
return true;
|
||||
}
|
||||
} // namespace Sensors
|
||||
} // namespace OHOS
|
Loading…
x
Reference in New Issue
Block a user