mirror of
https://gitee.com/openharmony/sensors_sensor
synced 2024-12-04 12:53:20 +00:00
!608 【泛Sensor】【sensor】错误码增加版本隔离
Merge pull request !608 from lixiangpeng5/lxp
This commit is contained in:
commit
35b0d9551d
@ -19,6 +19,7 @@
|
||||
],
|
||||
"deps": {
|
||||
"components": [
|
||||
"bundle_framework",
|
||||
"c_utils",
|
||||
"hilog",
|
||||
"build_framework",
|
||||
|
@ -39,9 +39,14 @@ ohos_shared_library("libsensor") {
|
||||
}
|
||||
deps = [ "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native" ]
|
||||
external_deps = [
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_single",
|
||||
"napi:ace_napi",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
relative_install_dir = "module"
|
||||
part_name = "sensor"
|
||||
|
@ -59,6 +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);
|
||||
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},
|
||||
@ -1049,8 +1050,7 @@ static napi_value GetSingleSensor(napi_env env, napi_callback_info info)
|
||||
ThrowErr(env, PARAMETER_ERROR, "Wrong argument type, get number fail");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<AsyncCallbackInfo> asyncCallbackInfo =
|
||||
new (std::nothrow) AsyncCallbackInfo(env, GET_SINGLE_SENSOR);
|
||||
sptr<AsyncCallbackInfo> asyncCallbackInfo = new (std::nothrow) AsyncCallbackInfo(env, GET_SINGLE_SENSOR);
|
||||
CHKPP(asyncCallbackInfo);
|
||||
SensorInfo *sensorInfos = nullptr;
|
||||
int32_t count = 0;
|
||||
@ -1072,6 +1072,11 @@ static napi_value GetSingleSensor(napi_env env, napi_callback_info info)
|
||||
}
|
||||
}
|
||||
if (asyncCallbackInfo->sensorInfos.empty()) {
|
||||
uint32_t targetVersion = 0;
|
||||
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,12 +19,17 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "bundle_mgr_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "sensor_napi_error.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Sensors {
|
||||
namespace {
|
||||
constexpr int32_t STRING_LENGTH_MAX = 64;
|
||||
constexpr int32_t STRING_LENGTH_MAX = 64;
|
||||
} // namespace
|
||||
bool IsSameValue(const napi_env &env, const napi_value &lhs, const napi_value &rhs)
|
||||
{
|
||||
@ -607,5 +612,32 @@ void EmitPromiseWork(sptr<AsyncCallbackInfo> asyncCallbackInfo)
|
||||
asyncCallbackInfo->DecStrongRef(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
bool GetSelfTargetVersion(uint32_t &targetVersion)
|
||||
{
|
||||
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("GetBundleInfoForSelf error");
|
||||
return false;
|
||||
}
|
||||
targetVersion = bundleInfo.targetVersion;
|
||||
return true;
|
||||
}
|
||||
} // namespace Sensors
|
||||
} // namespace OHOS
|
@ -7,8 +7,8 @@
|
||||
"name": "1.0"
|
||||
},
|
||||
"apiVersion": {
|
||||
"compatible": 4,
|
||||
"target": 5
|
||||
"compatible": 12,
|
||||
"target": 12
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
|
Loading…
Reference in New Issue
Block a user