diff --git a/frameworks/cj/src/cj_sensor_impl.cpp b/frameworks/cj/src/cj_sensor_impl.cpp index b17dbbf23db1545e1963f60c8a24ab2a3e756878..5b8d50c7653edfa94c5b5bead59ba281665af172 100644 --- a/frameworks/cj/src/cj_sensor_impl.cpp +++ b/frameworks/cj/src/cj_sensor_impl.cpp @@ -360,7 +360,8 @@ int32_t CJSensorImpl::GetAllSensorList(CSensorArray &sensorList) int32_t i = 0; for (; i < count; ++i) { if ((sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_AMBIENT_LIGHT1) || - (sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_PROXIMITY1)) { + (sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_PROXIMITY1) || + (sensorInfos[i].sensorTypeId > GL_SENSOR_TYPE_PRIVATE_MIN_VALUE)) { SEN_HILOGD("This sensor is secondary ambient light"); continue; } diff --git a/frameworks/js/napi/src/sensor_js.cpp b/frameworks/js/napi/src/sensor_js.cpp index 4307fc5af4033af9f4cb99f5bf2782d7f3ef8f8e..f1d3140adf2709ec3ec7174fb9927f74812451e3 100644 --- a/frameworks/js/napi/src/sensor_js.cpp +++ b/frameworks/js/napi/src/sensor_js.cpp @@ -1020,7 +1020,8 @@ static napi_value GetSensorList(napi_env env, napi_callback_info info) } else { for (int32_t i = 0; i < count; ++i) { if ((sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_AMBIENT_LIGHT1) || - (sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_PROXIMITY1)) { + (sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_PROXIMITY1) || + (sensorInfos[i].sensorTypeId > GL_SENSOR_TYPE_PRIVATE_MIN_VALUE)) { SEN_HILOGD("This sensor is secondary ambient light"); continue; } @@ -1055,7 +1056,8 @@ static napi_value GetSensorListSync(napi_env env, napi_callback_info info) vector sensorInfoVec; for (int32_t i = 0; i < count; ++i) { if ((sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_AMBIENT_LIGHT1) || - (sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_PROXIMITY1)) { + (sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_PROXIMITY1) || + (sensorInfos[i].sensorTypeId > GL_SENSOR_TYPE_PRIVATE_MIN_VALUE)) { SEN_HILOGD("This sensor is secondary ambient light"); continue; } @@ -1106,7 +1108,8 @@ static napi_value GetSingleSensor(napi_env env, napi_callback_info info) } else { for (int32_t i = 0; i < count; ++i) { if ((sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_AMBIENT_LIGHT1) || - (sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_PROXIMITY1)) { + (sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_PROXIMITY1) || + (sensorInfos[i].sensorTypeId > GL_SENSOR_TYPE_PRIVATE_MIN_VALUE)) { SEN_HILOGD("This sensor is secondary ambient light"); continue; } @@ -1159,7 +1162,8 @@ static napi_value GetSingleSensorSync(napi_env env, napi_callback_info info) vector sensorInfoVec; for (int32_t i = 0; i < count; ++i) { if ((sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_AMBIENT_LIGHT1) || - (sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_PROXIMITY1)) { + (sensorInfos[i].sensorTypeId == SENSOR_TYPE_ID_PROXIMITY1) || + (sensorInfos[i].sensorTypeId > GL_SENSOR_TYPE_PRIVATE_MIN_VALUE)) { SEN_HILOGD("This sensor is secondary ambient light"); continue; } diff --git a/interfaces/inner_api/sensor_agent_type.h b/interfaces/inner_api/sensor_agent_type.h index 22ceecb4469153ad4c0fcd08d3e1b70cfb6b3159..c975813cfb8dbff79522c2f724cab34fb63b390c 100644 --- a/interfaces/inner_api/sensor_agent_type.h +++ b/interfaces/inner_api/sensor_agent_type.h @@ -481,13 +481,19 @@ typedef struct RPCData { * This sensor measures the angle between two screens, in degrees. The angle ranges from 0 to 180. */ typedef struct PostureData { - float gxm = 0.0; /**< The main screen acceleration on the x axis */ - float gym = 0.0; /**< The main screen acceleration on the y axis */ - float gzm = 0.0; /**< The main screen acceleration on the z axis */ - float gxs = 0.0; /**< The second screen acceleration on the x axis */ - float gys = 0.0; /**< The second screen acceleration on the y axis */ - float gzs = 0.0; /**< The second screen acceleration on the z axis */ - float angle = 0.0; /**< The angle between two screens. The angle ranges from 0 to 180 degrees. */ + float gxm = 0.0f; /**< The main screen acceleration on the x axis */ + float gym = 0.0f; /**< The main screen acceleration on the y axis */ + float gzm = 0.0f; /**< The main screen acceleration on the z axis */ + float gxs = 0.0f; /**< The second screen acceleration on the x axis */ + float gys = 0.0f; /**< The second screen acceleration on the y axis */ + float gzs = 0.0f; /**< The second screen acceleration on the z axis */ + float angle = 0.0f; /**< The angle between two screens. The angle ranges from 0 to 180 degrees. */ + float screenAndPostureStatus = 0.0f; /**< The screen and posture status. */ + float gxt = 0.0f; /**< The third screen acceleration on the x axis */ + float gyt = 0.0f; /**< The third screen acceleration on the y axis */ + float gzt = 0.0f; /**< The third screen acceleration on the z axis */ + float abAngle = 0.0f; /**< The angle between second and third screen. The angle ranges from 0 to 180 degrees. */ + float abFoldedState = 0.0f; /**< The state between second and third screen. */ } PostureData; /** diff --git a/services/src/sensor_service_stub.cpp b/services/src/sensor_service_stub.cpp index 3d08b091b91743a795fe1c39e9880b5af1325fa2..36a679fb667eb27ff5ac12f3f744882e98c6fa61 100644 --- a/services/src/sensor_service_stub.cpp +++ b/services/src/sensor_service_stub.cpp @@ -131,7 +131,8 @@ ErrCode SensorServiceStub::SensorEnableInner(MessageParcel &data, MessageParcel (void)reply; int32_t sensorId; READINT32(data, sensorId, READ_PARCEL_ERR); - if ((sensorId == SENSOR_TYPE_ID_COLOR || sensorId == SENSOR_TYPE_ID_SAR) && !IsSystemCalling()) { + if ((sensorId == SENSOR_TYPE_ID_COLOR || sensorId == SENSOR_TYPE_ID_SAR || + sensorId > GL_SENSOR_TYPE_PRIVATE_MIN_VALUE) && !IsSystemCalling()) { SEN_HILOGE("Permission check failed. A non-system application uses the system API"); return NON_SYSTEM_API; } @@ -157,7 +158,8 @@ ErrCode SensorServiceStub::SensorDisableInner(MessageParcel &data, MessageParcel (void)reply; int32_t sensorId; READINT32(data, sensorId, READ_PARCEL_ERR); - if ((sensorId == SENSOR_TYPE_ID_COLOR || sensorId == SENSOR_TYPE_ID_SAR) && !IsSystemCalling()) { + if ((sensorId == SENSOR_TYPE_ID_COLOR || sensorId == SENSOR_TYPE_ID_SAR || + sensorId > GL_SENSOR_TYPE_PRIVATE_MIN_VALUE) && !IsSystemCalling()) { SEN_HILOGE("Permission check failed. A non-system application uses the system API"); return NON_SYSTEM_API; } diff --git a/test/unittest/interfaces/inner_api/posture_test.cpp b/test/unittest/interfaces/inner_api/posture_test.cpp index e5b4d61c06282d1d5ad1e720f67ccf18fc93e188..1b9cb818b719b12d0c1216140240f96a3f0c664f 100644 --- a/test/unittest/interfaces/inner_api/posture_test.cpp +++ b/test/unittest/interfaces/inner_api/posture_test.cpp @@ -92,9 +92,12 @@ void PostureDataCallbackImpl(SensorEvent *event) return; } SEN_HILOGD("sensorId:%{public}d, version:%{public}d, dataLen:%{public}u, gxm:%{public}f, " - "gym:%{public}f, gzm:%{public}f, gxs:%{public}f, gys:%{public}f, gzs:%{public}f, angle:%{public}f", - event[0].sensorTypeId, event[0].version, event[0].dataLen, postureData->gxm, postureData->gym, - postureData->gzm, postureData->gxs, postureData->gys, postureData->gzs, postureData->angle); + "gym:%{public}f, gzm:%{public}f, gxs:%{public}f, gys:%{public}f, gzs:%{public}f, angle:%{public}f, " + "screenAndPostureStatus:%{public}f, gxt:%{public}f, gyt:%{public}f, gzt:%{public}f, " + "abAngle:%{public}f, abFoldedState:%{public}f", + event[0].sensorTypeId, event[0].version, event[0].dataLen, postureData->gxm, postureData->gym, postureData->gzm, + postureData->gxs, postureData->gys, postureData->gzs, postureData->angle, postureData->screenAndPostureStatus, + postureData->gxt, postureData->gyt, postureData->gzt, postureData->abAngle, postureData->abFoldedState); } void PostureDataCallbackImpl2(SensorEvent *event) @@ -119,9 +122,12 @@ void PostureDataCallbackImpl2(SensorEvent *event) return; } SEN_HILOGD("sensorId:%{public}d, version:%{public}d, dataLen:%{public}u, gxm:%{public}f, " - "gym:%{public}f, gzm:%{public}f, gxs:%{public}f, gys:%{public}f, gzs:%{public}f, angle:%{public}f", - event[0].sensorTypeId, event[0].version, event[0].dataLen, postureData->gxm, postureData->gym, - postureData->gzm, postureData->gxs, postureData->gys, postureData->gzs, postureData->angle); + "gym:%{public}f, gzm:%{public}f, gxs:%{public}f, gys:%{public}f, gzs:%{public}f, angle:%{public}f, " + "screenAndPostureStatus:%{public}f, gxt:%{public}f, gyt:%{public}f, gzt:%{public}f, " + "abAngle:%{public}f, abFoldedState:%{public}f", + event[0].sensorTypeId, event[0].version, event[0].dataLen, postureData->gxm, postureData->gym, postureData->gzm, + postureData->gxs, postureData->gys, postureData->gzs, postureData->angle, postureData->screenAndPostureStatus, + postureData->gxt, postureData->gyt, postureData->gzt, postureData->abAngle, postureData->abFoldedState); } HWTEST_F(PostureTest, PostureTest_001, TestSize.Level1) diff --git a/utils/common/include/sensor_errors.h b/utils/common/include/sensor_errors.h index 68e780a13933c69d9949075fa73739836c855612..7a4acd2e06da7c5ee6e68e3246cb588d9f0ffae3 100644 --- a/utils/common/include/sensor_errors.h +++ b/utils/common/include/sensor_errors.h @@ -24,6 +24,7 @@ namespace OHOS { namespace Sensors { constexpr uint32_t MAX_SENSOR_COUNT = 200; +constexpr int32_t GL_SENSOR_TYPE_PRIVATE_MIN_VALUE = 512; // Error code for user enum ErrorCode : int32_t { PERMISSION_DENIED = 201, // Use this error code when permission is denied.