From 002f04ca866911dd76c54fb2a00184f7d5ca78dd Mon Sep 17 00:00:00 2001 From: cff-gite Date: Mon, 29 Jul 2024 11:29:17 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A9=AC=E8=BE=BEsyste?= =?UTF-8?q?mUsage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite Change-Id: Ib8c69130cc5d84b8385d85c68e16343318d83c98 --- .../vibrator/include/vibrator_napi_utils.h | 1 + .../js/napi/vibrator/src/vibrator_js.cpp | 7 +-- .../napi/vibrator/src/vibrator_napi_utils.cpp | 27 +++++++++++ .../common/include/i_miscdevice_service.h | 10 ++-- .../common/include/miscdevice_service_proxy.h | 10 ++-- .../common/src/miscdevice_service_proxy.cpp | 30 ++++++++++-- .../include/vibrator_service_client.h | 11 +++-- .../vibrator/src/vibrator_service_client.cpp | 20 ++++---- frameworks/native/vibrator/vibrator_agent.cpp | 17 +++++-- .../inner_api/vibrator/vibrator_agent.h | 2 +- services/miscdevice_service/BUILD.gn | 2 + .../include/miscdevice_service.h | 10 ++-- .../include/vibration_priority_manager.h | 2 + .../src/miscdevice_service.cpp | 15 ++++-- .../src/miscdevice_service_stub.cpp | 27 ++++++++--- .../src/vibration_priority_manager.cpp | 47 ++++++++++++++----- utils/common/include/vibrator_infos.h | 1 + 17 files changed, 172 insertions(+), 67 deletions(-) diff --git a/frameworks/js/napi/vibrator/include/vibrator_napi_utils.h b/frameworks/js/napi/vibrator/include/vibrator_napi_utils.h index 6350f68..87a6191 100644 --- a/frameworks/js/napi/vibrator/include/vibrator_napi_utils.h +++ b/frameworks/js/napi/vibrator/include/vibrator_napi_utils.h @@ -70,6 +70,7 @@ bool GetInt32Value(const napi_env &env, const napi_value &value, int32_t &result bool GetDoubleValue(const napi_env &env, const napi_value &value, double &result); bool GetInt64Value(const napi_env &env, const napi_value &value, int64_t &result); bool GetStringValue(const napi_env &env, const napi_value &value, string &result); +bool GetPropertyBool(const napi_env &env, const napi_value &value, const std::string &type, bool &result); bool GetPropertyItem(const napi_env &env, const napi_value &value, const std::string &type, napi_value &item); bool GetPropertyString(const napi_env &env, const napi_value &value, const std::string &type, std::string &result); bool GetPropertyInt32(const napi_env &env, const napi_value &value, const std::string &type, int32_t &result); diff --git a/frameworks/js/napi/vibrator/src/vibrator_js.cpp b/frameworks/js/napi/vibrator/src/vibrator_js.cpp index a9e42d1..21d0ddf 100644 --- a/frameworks/js/napi/vibrator/src/vibrator_js.cpp +++ b/frameworks/js/napi/vibrator/src/vibrator_js.cpp @@ -447,22 +447,23 @@ bool ParseParameter(napi_env env, napi_value args[], size_t argc, VibrateInfo &i CHKCF(CheckVibratorPatternParameter(info.vibratorPattern), "CheckVibratorPatternParameter fail"); } CHKCF(GetPropertyString(env, args[1], "usage", info.usage), "Get vibrate usage fail"); + CHKCF(GetPropertyBool(env, args[1], "systemUsage", info.systemUsage), "Get vibrate systemUsage fail"); return true; } -bool SetUsage(const std::string &usage) +bool SetUsage(const std::string &usage, bool systemUsage) { if (auto iter = g_usageType.find(usage); iter == g_usageType.end()) { MISC_HILOGE("Wrong usage type"); return false; } - return SetUsage(g_usageType[usage]); + return SetUsage(g_usageType[usage], systemUsage); } int32_t StartVibrate(const VibrateInfo &info) { CALL_LOG_ENTER; - if (!SetUsage(info.usage)) { + if (!SetUsage(info.usage, info.systemUsage)) { MISC_HILOGE("SetUsage fail"); return PARAMETER_ERROR; } diff --git a/frameworks/js/napi/vibrator/src/vibrator_napi_utils.cpp b/frameworks/js/napi/vibrator/src/vibrator_napi_utils.cpp index 654b4ab..873802d 100644 --- a/frameworks/js/napi/vibrator/src/vibrator_napi_utils.cpp +++ b/frameworks/js/napi/vibrator/src/vibrator_napi_utils.cpp @@ -117,6 +117,16 @@ bool GetInt64Value(const napi_env &env, const napi_value &value, int64_t &result return true; } +bool GetBoolValue(const napi_env &env, const napi_value &value, bool &result) +{ + CALL_LOG_ENTER; + napi_valuetype valuetype = napi_undefined; + CHKCF(napi_typeof(env, value, &valuetype) == napi_ok, "napi_typeof failed"); + CHKCF((valuetype == napi_boolean), "Wrong argument type. bool expected"); + CHKCF(napi_get_value_bool(env, value, &result) == napi_ok, "napi_get_value_bool failed"); + return true; +} + bool GetStringValue(const napi_env &env, const napi_value &value, string &result) { CALL_LOG_ENTER; @@ -208,6 +218,23 @@ bool GetPropertyInt64(const napi_env &env, const napi_value &value, const std::s return true; } +bool GetPropertyBool(const napi_env &env, const napi_value &value, const std::string &type, bool &result) +{ + bool exist = false; + napi_status status = napi_has_named_property(env, value, type.c_str(), &exist); + if ((status != napi_ok) || (!exist)) { + MISC_HILOGD("Can not find %{public}s property", type.c_str()); + return false; + } + napi_value item = nullptr; + CHKCF((napi_get_named_property(env, value, type.c_str(), &item) == napi_ok), "napi get property fail"); + if (!GetBoolValue(env, item, result)) { + MISC_HILOGE("Get bool value fail"); + return false; + } + return true; +} + std::map g_convertFuncList = { {COMMON_CALLBACK, ConstructCommonResult}, {IS_SUPPORT_EFFECT_CALLBACK, ConstructIsSupportEffectResult}, diff --git a/frameworks/native/common/include/i_miscdevice_service.h b/frameworks/native/common/include/i_miscdevice_service.h index 2c69c91..ebb2e0c 100644 --- a/frameworks/native/common/include/i_miscdevice_service.h +++ b/frameworks/native/common/include/i_miscdevice_service.h @@ -36,12 +36,12 @@ public: IMiscdeviceService() = default; virtual ~IMiscdeviceService() = default; DECLARE_INTERFACE_DESCRIPTOR(u"IMiscdeviceService"); - virtual int32_t Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage) = 0; + virtual int32_t Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage, bool systemUsage) = 0; virtual int32_t PlayVibratorEffect(int32_t vibratorId, const std::string &effect, - int32_t loopCount, int32_t usage) = 0; + int32_t loopCount, int32_t usage, bool systemUsage) = 0; #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM virtual int32_t PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage, - const VibrateParameter ¶meter) = 0; + bool systemUsage, const VibrateParameter ¶meter) = 0; #endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM virtual int32_t StopVibrator(int32_t vibratorId) = 0; virtual int32_t StopVibrator(int32_t vibratorId, const std::string &mode) = 0; @@ -50,10 +50,10 @@ public: virtual int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) = 0; virtual int32_t TurnOff(int32_t lightId) = 0; virtual int32_t GetDelayTime(int32_t &delayTime) = 0; - virtual int32_t PlayPattern(const VibratePattern &pattern, int32_t usage, const VibrateParameter ¶meter) = 0; + virtual int32_t PlayPattern(const VibratePattern &pattern, int32_t usage, bool systemUsage, const VibrateParameter ¶meter) = 0; virtual int32_t TransferClientRemoteObject(const sptr &vibratorClient) = 0; virtual int32_t PlayPrimitiveEffect(int32_t vibratorId, const std::string &effect, int32_t intensity, - int32_t usage, int32_t count) = 0; + int32_t usage, bool systemUsage, int32_t count) = 0; virtual int32_t GetVibratorCapacity(VibratorCapacity &capacity) = 0; }; } // namespace Sensors diff --git a/frameworks/native/common/include/miscdevice_service_proxy.h b/frameworks/native/common/include/miscdevice_service_proxy.h index 370e0a9..9af91e7 100644 --- a/frameworks/native/common/include/miscdevice_service_proxy.h +++ b/frameworks/native/common/include/miscdevice_service_proxy.h @@ -27,12 +27,12 @@ class MiscdeviceServiceProxy : public IRemoteProxy { public: explicit MiscdeviceServiceProxy(const sptr &impl); ~MiscdeviceServiceProxy() = default; - virtual int32_t Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage) override; + virtual int32_t Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage, bool systemUsage) override; virtual int32_t PlayVibratorEffect(int32_t vibratorId, const std::string &effect, - int32_t loopCount, int32_t usage) override; + int32_t loopCount, int32_t usage, bool systemUsage) override; #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM virtual int32_t PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage, - const VibrateParameter ¶meter) override; + bool systemUsage, const VibrateParameter ¶meter) override; #endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM virtual int32_t StopVibrator(int32_t vibratorId) override; virtual int32_t StopVibrator(int32_t vibratorId, const std::string &mode) override; @@ -42,10 +42,10 @@ public: virtual int32_t TurnOff(int32_t lightId) override; virtual int32_t GetDelayTime(int32_t &delayTime) override; virtual int32_t PlayPattern(const VibratePattern &pattern, int32_t usage, - const VibrateParameter ¶meter) override; + bool systemUsage, const VibrateParameter ¶meter) override; virtual int32_t TransferClientRemoteObject(const sptr &vibratorClient) override; virtual int32_t PlayPrimitiveEffect(int32_t vibratorId, const std::string &effect, int32_t intensity, - int32_t usage, int32_t count) override; + int32_t usage, bool systemUsage, int32_t count) override; virtual int32_t GetVibratorCapacity(VibratorCapacity &capacity) override; private: diff --git a/frameworks/native/common/src/miscdevice_service_proxy.cpp b/frameworks/native/common/src/miscdevice_service_proxy.cpp index 7e00a34..9afc992 100644 --- a/frameworks/native/common/src/miscdevice_service_proxy.cpp +++ b/frameworks/native/common/src/miscdevice_service_proxy.cpp @@ -34,7 +34,7 @@ constexpr int32_t MAX_LIGHT_COUNT = 0XFF; MiscdeviceServiceProxy::MiscdeviceServiceProxy(const sptr &impl) : IRemoteProxy(impl) {} -int32_t MiscdeviceServiceProxy::Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage) +int32_t MiscdeviceServiceProxy::Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage, bool systemUsage) { MessageParcel data; if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { @@ -53,6 +53,10 @@ int32_t MiscdeviceServiceProxy::Vibrate(int32_t vibratorId, int32_t timeOut, int MISC_HILOGE("WriteUint32 usage failed"); return WRITE_MSG_ERR; } + if (!data.WriteBool(systemUsage)) { + MISC_HILOGE("WritBool systemUsage failed"); + return WRITE_MSG_ERR; + } sptr remote = Remote(); CHKPR(remote, ERROR); MessageParcel reply; @@ -93,7 +97,7 @@ int32_t MiscdeviceServiceProxy::StopVibrator(int32_t vibratorId) } int32_t MiscdeviceServiceProxy::PlayVibratorEffect(int32_t vibratorId, const std::string &effect, - int32_t loopCount, int32_t usage) + int32_t loopCount, int32_t usage, bool systemUsage) { MessageParcel data; if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { @@ -116,6 +120,10 @@ int32_t MiscdeviceServiceProxy::PlayVibratorEffect(int32_t vibratorId, const std MISC_HILOGE("Writeint32 usage failed"); return WRITE_MSG_ERR; } + if (!data.WriteBool(systemUsage)) { + MISC_HILOGE("Writebool systemUsage failed"); + return WRITE_MSG_ERR; + } sptr remote = Remote(); CHKPR(remote, ERROR); MessageParcel reply; @@ -191,7 +199,7 @@ int32_t MiscdeviceServiceProxy::IsSupportEffect(const std::string &effect, bool #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t MiscdeviceServiceProxy::PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage, - const VibrateParameter ¶meter) + bool systemUsage, const VibrateParameter ¶meter) { MessageParcel data; if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { @@ -206,6 +214,10 @@ int32_t MiscdeviceServiceProxy::PlayVibratorCustom(int32_t vibratorId, const Raw MISC_HILOGE("Writeint32 usage failed"); return WRITE_MSG_ERR; } + if (!data.WriteBool(systemUsage)) { + MISC_HILOGE("Writebool systemUsage failed"); + return WRITE_MSG_ERR; + } if (!parameter.Marshalling(data)) { MISC_HILOGE("Write adjust parameter failed"); return WRITE_MSG_ERR; @@ -359,7 +371,7 @@ int32_t MiscdeviceServiceProxy::GetDelayTime(int32_t &delayTime) } int32_t MiscdeviceServiceProxy::PlayPattern(const VibratePattern &pattern, int32_t usage, - const VibrateParameter ¶meter) + bool systemUsage, const VibrateParameter ¶meter) { MessageParcel data; if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { @@ -374,6 +386,10 @@ int32_t MiscdeviceServiceProxy::PlayPattern(const VibratePattern &pattern, int32 MISC_HILOGE("WriteUint32 usage failed"); return WRITE_MSG_ERR; } + if (!data.WriteBool(systemUsage)) { + MISC_HILOGE("WriteBool systemUsage failed"); + return WRITE_MSG_ERR; + } if (!parameter.Marshalling(data)) { MISC_HILOGE("Write adjust parameter failed"); return WRITE_MSG_ERR; @@ -418,7 +434,7 @@ int32_t MiscdeviceServiceProxy::TransferClientRemoteObject(const sptr { public: ~VibratorServiceClient() override; - int32_t Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage); - int32_t Vibrate(int32_t vibratorId, const std::string &effect, int32_t loopCount, int32_t usage); + int32_t Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage, bool systemUsage); + int32_t Vibrate(int32_t vibratorId, const std::string &effect, int32_t loopCount, int32_t usage, bool systemUsage); #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage, - const VibratorParameter ¶meter); + bool systemUsage, const VibratorParameter ¶meter); #endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t StopVibrator(int32_t vibratorId, const std::string &mode); int32_t StopVibrator(int32_t vibratorId); @@ -67,10 +67,11 @@ public: void ProcessDeathObserver(const wptr &object); int32_t PreProcess(const VibratorFileDescription &fd, VibratorPackage &package); int32_t GetDelayTime(int32_t &delayTime); - int32_t PlayPattern(const VibratorPattern &pattern, int32_t usage, const VibratorParameter ¶meter); + int32_t PlayPattern(const VibratorPattern &pattern, int32_t usage, bool systemUsage, + const VibratorParameter ¶meter); int32_t FreeVibratorPackage(VibratorPackage &package); int32_t PlayPrimitiveEffect(int32_t vibratorId, const std::string &effect, int32_t intensity, int32_t usage, - int32_t count); + bool systemUsage, int32_t count); bool IsSupportVibratorCustom(); private: diff --git a/frameworks/native/vibrator/src/vibrator_service_client.cpp b/frameworks/native/vibrator/src/vibrator_service_client.cpp index 93bbad2..dc0e8d7 100644 --- a/frameworks/native/vibrator/src/vibrator_service_client.cpp +++ b/frameworks/native/vibrator/src/vibrator_service_client.cpp @@ -120,7 +120,7 @@ int32_t VibratorServiceClient::TransferClientRemoteObject() return ret; } -int32_t VibratorServiceClient::Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage) +int32_t VibratorServiceClient::Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage, bool systemUsage) { MISC_HILOGD("Vibrate begin, time:%{public}d, usage:%{public}d", timeOut, usage); int32_t ret = InitServiceClient(); @@ -130,7 +130,7 @@ int32_t VibratorServiceClient::Vibrate(int32_t vibratorId, int32_t timeOut, int3 } CHKPR(miscdeviceProxy_, ERROR); StartTrace(HITRACE_TAG_SENSORS, "VibrateTime"); - ret = miscdeviceProxy_->Vibrate(vibratorId, timeOut, usage); + ret = miscdeviceProxy_->Vibrate(vibratorId, timeOut, usage, systemUsage); FinishTrace(HITRACE_TAG_SENSORS); if (ret != ERR_OK) { MISC_HILOGE("Vibrate time failed, ret:%{public}d, time:%{public}d, usage:%{public}d", ret, timeOut, usage); @@ -139,7 +139,7 @@ int32_t VibratorServiceClient::Vibrate(int32_t vibratorId, int32_t timeOut, int3 } int32_t VibratorServiceClient::Vibrate(int32_t vibratorId, const std::string &effect, - int32_t loopCount, int32_t usage) + int32_t loopCount, int32_t usage, bool systemUsage) { MISC_HILOGD("Vibrate begin, effect:%{public}s, loopCount:%{public}d, usage:%{public}d", effect.c_str(), loopCount, usage); @@ -150,7 +150,7 @@ int32_t VibratorServiceClient::Vibrate(int32_t vibratorId, const std::string &ef } CHKPR(miscdeviceProxy_, ERROR); StartTrace(HITRACE_TAG_SENSORS, "VibrateEffect"); - ret = miscdeviceProxy_->PlayVibratorEffect(vibratorId, effect, loopCount, usage); + ret = miscdeviceProxy_->PlayVibratorEffect(vibratorId, effect, loopCount, usage, systemUsage); FinishTrace(HITRACE_TAG_SENSORS); if (ret != ERR_OK) { MISC_HILOGE("Vibrate effect failed, ret:%{public}d, effect:%{public}s, loopCount:%{public}d, usage:%{public}d", @@ -161,7 +161,7 @@ int32_t VibratorServiceClient::Vibrate(int32_t vibratorId, const std::string &ef #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t VibratorServiceClient::PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage, - const VibratorParameter ¶meter) + bool systemUsage, const VibratorParameter ¶meter) { MISC_HILOGD("Vibrate begin, fd:%{public}d, offset:%{public}lld, length:%{public}lld, usage:%{public}d", rawFd.fd, static_cast(rawFd.offset), static_cast(rawFd.length), usage); @@ -176,7 +176,7 @@ int32_t VibratorServiceClient::PlayVibratorCustom(int32_t vibratorId, const RawF .intensity = parameter.intensity, .frequency = parameter.frequency }; - ret = miscdeviceProxy_->PlayVibratorCustom(vibratorId, rawFd, usage, vibateParameter); + ret = miscdeviceProxy_->PlayVibratorCustom(vibratorId, rawFd, usage, systemUsage, vibateParameter); FinishTrace(HITRACE_TAG_SENSORS); if (ret != ERR_OK) { MISC_HILOGE("PlayVibratorCustom failed, ret:%{public}d, usage:%{public}d", ret, usage); @@ -335,7 +335,7 @@ int32_t VibratorServiceClient::GetDelayTime(int32_t &delayTime) } int32_t VibratorServiceClient::PlayPattern(const VibratorPattern &pattern, int32_t usage, - const VibratorParameter ¶meter) + bool systemUsage, const VibratorParameter ¶meter) { MISC_HILOGD("Vibrate begin, usage:%{public}d", usage); int32_t ret = InitServiceClient(); @@ -377,7 +377,7 @@ int32_t VibratorServiceClient::PlayPattern(const VibratorPattern &pattern, int32 .intensity = parameter.intensity, .frequency = parameter.frequency }; - ret = miscdeviceProxy_->PlayPattern(vibratePattern, usage, vibateParameter); + ret = miscdeviceProxy_->PlayPattern(vibratePattern, usage, systemUsage, vibateParameter); FinishTrace(HITRACE_TAG_SENSORS); if (ret != ERR_OK) { MISC_HILOGE("PlayPattern failed, ret:%{public}d, usage:%{public}d", ret, usage); @@ -468,7 +468,7 @@ int32_t VibratorServiceClient::FreeVibratorPackage(VibratorPackage &package) } int32_t VibratorServiceClient::PlayPrimitiveEffect(int32_t vibratorId, const std::string &effect, int32_t intensity, - int32_t usage, int32_t count) + int32_t usage, bool systemUsage, int32_t count) { MISC_HILOGD("Vibrate begin, effect:%{public}s, intensity:%{public}d, usage:%{public}d, count:%{public}d", effect.c_str(), intensity, usage, count); @@ -479,7 +479,7 @@ int32_t VibratorServiceClient::PlayPrimitiveEffect(int32_t vibratorId, const std } CHKPR(miscdeviceProxy_, ERROR); StartTrace(HITRACE_TAG_SENSORS, "PlayPrimitiveEffect"); - ret = miscdeviceProxy_->PlayPrimitiveEffect(vibratorId, effect, intensity, usage, count); + ret = miscdeviceProxy_->PlayPrimitiveEffect(vibratorId, effect, intensity, usage, systemUsage, count); FinishTrace(HITRACE_TAG_SENSORS); if (ret != ERR_OK) { MISC_HILOGE("Play primitive effect failed, ret:%{public}d, effect:%{public}s, intensity:%{public}d," diff --git a/frameworks/native/vibrator/vibrator_agent.cpp b/frameworks/native/vibrator/vibrator_agent.cpp index 45fcf99..8eceac3 100644 --- a/frameworks/native/vibrator/vibrator_agent.cpp +++ b/frameworks/native/vibrator/vibrator_agent.cpp @@ -30,6 +30,7 @@ namespace { constexpr int32_t DEFAULT_VIBRATOR_ID = 123; int32_t g_loopCount = 1; int32_t g_usage = USAGE_UNKNOWN; +bool g_systemUsage = false; VibratorParameter g_vibratorParameter; const std::string PHONE_TYPE = "phone"; const int32_t INTENSITY_ADJUST_MIN = 0; @@ -71,9 +72,10 @@ int32_t StartVibrator(const char *effectId) MISC_HILOGD("Time delay measurement:start time"); CHKPR(effectId, PARAMETER_ERROR); auto &client = VibratorServiceClient::GetInstance(); - int32_t ret = client.Vibrate(DEFAULT_VIBRATOR_ID, effectId, g_loopCount, g_usage); + int32_t ret = client.Vibrate(DEFAULT_VIBRATOR_ID, effectId, g_loopCount, g_usage, g_systemUsage); g_loopCount = 1; g_usage = USAGE_UNKNOWN; + g_systemUsage = false; if (ret != ERR_OK) { MISC_HILOGD("Vibrate effectId failed, ret:%{public}d", ret); return NormalizeErrCode(ret); @@ -88,8 +90,9 @@ int32_t StartVibratorOnce(int32_t duration) return PARAMETER_ERROR; } auto &client = VibratorServiceClient::GetInstance(); - int32_t ret = client.Vibrate(DEFAULT_VIBRATOR_ID, duration, g_usage); + int32_t ret = client.Vibrate(DEFAULT_VIBRATOR_ID, duration, g_usage, g_systemUsage); g_usage = USAGE_UNKNOWN; + g_systemUsage = false; if (ret != ERR_OK) { MISC_HILOGD("Vibrate duration failed, ret:%{public}d", ret); return NormalizeErrCode(ret); @@ -118,8 +121,9 @@ int32_t PlayVibratorCustom(int32_t fd, int64_t offset, int64_t length) .offset = offset, .length = length }; - int32_t ret = client.PlayVibratorCustom(DEFAULT_VIBRATOR_ID, rawFd, g_usage, g_vibratorParameter); + int32_t ret = client.PlayVibratorCustom(DEFAULT_VIBRATOR_ID, rawFd, g_usage, g_systemUsage, g_vibratorParameter); g_usage = USAGE_UNKNOWN; + g_systemUsage = false; g_vibratorParameter.intensity = INTENSITY_ADJUST_MAX; g_vibratorParameter.frequency = 0; if (ret != ERR_OK) { @@ -167,6 +171,7 @@ bool SetUsage(int32_t usage) return false; } g_usage = usage; + g_systemUsage = systemUsage; return true; } @@ -213,8 +218,9 @@ int32_t GetDelayTime(int32_t &delayTime) int32_t PlayPattern(const VibratorPattern &pattern) { auto &client = VibratorServiceClient::GetInstance(); - int32_t ret = client.PlayPattern(pattern, g_usage, g_vibratorParameter); + int32_t ret = client.PlayPattern(pattern, g_usage, g_systemUsage, g_vibratorParameter); g_usage = USAGE_UNKNOWN; + g_systemUsage = false; g_vibratorParameter.intensity = INTENSITY_ADJUST_MAX; g_vibratorParameter.frequency = 0; if (ret != ERR_OK) { @@ -252,9 +258,10 @@ int32_t PlayPrimitiveEffect(const char *effectId, int32_t intensity) MISC_HILOGD("Time delay measurement:start time"); CHKPR(effectId, PARAMETER_ERROR); auto &client = VibratorServiceClient::GetInstance(); - int32_t ret = client.PlayPrimitiveEffect(DEFAULT_VIBRATOR_ID, effectId, intensity, g_usage, g_loopCount); + int32_t ret = client.PlayPrimitiveEffect(DEFAULT_VIBRATOR_ID, effectId, intensity, g_usage, g_systemUsage, g_loopCount); g_loopCount = 1; g_usage = USAGE_UNKNOWN; + g_systemUsage = false; if (ret != ERR_OK) { MISC_HILOGD("Play primitive effect failed, ret:%{public}d", ret); return NormalizeErrCode(ret); diff --git a/interfaces/inner_api/vibrator/vibrator_agent.h b/interfaces/inner_api/vibrator/vibrator_agent.h index 97a43d7..eb5b131 100644 --- a/interfaces/inner_api/vibrator/vibrator_agent.h +++ b/interfaces/inner_api/vibrator/vibrator_agent.h @@ -129,7 +129,7 @@ int32_t Cancel(); * * @since 9 */ -bool SetUsage(int32_t usage); +bool SetUsage(int32_t usage, bool systemUsage = false); /** * @brief Query whether the HdHaptic is supported. diff --git a/services/miscdevice_service/BUILD.gn b/services/miscdevice_service/BUILD.gn index dddbe33..e3ae44e 100644 --- a/services/miscdevice_service/BUILD.gn +++ b/services/miscdevice_service/BUILD.gn @@ -63,6 +63,7 @@ ohos_shared_library("libmiscdevice_service") { "ability_runtime:dataobs_manager", "access_token:libaccesstoken_sdk", "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_core", "cJSON:cjson", "c_utils:utils", @@ -153,6 +154,7 @@ ohos_static_library("libmiscdevice_service_static") { "ability_runtime:dataobs_manager", "access_token:libaccesstoken_sdk", "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_core", "cJSON:cjson", "c_utils:utils", diff --git a/services/miscdevice_service/include/miscdevice_service.h b/services/miscdevice_service/include/miscdevice_service.h index 0551a68..d30d3f9 100644 --- a/services/miscdevice_service/include/miscdevice_service.h +++ b/services/miscdevice_service/include/miscdevice_service.h @@ -63,12 +63,12 @@ public: bool IsLightAnimationValid(const LightAnimationIPC &animation); int32_t Dump(int32_t fd, const std::vector &args) override; void ProcessDeathObserver(const wptr &object); - virtual int32_t Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage) override; + virtual int32_t Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage, bool systemUsage) override; virtual int32_t PlayVibratorEffect(int32_t vibratorId, const std::string &effect, - int32_t loopCount, int32_t usage) override; + int32_t loopCount, int32_t usage, bool systemUsage) override; #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM virtual int32_t PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage, - const VibrateParameter ¶meter) override; + bool systemUsage, const VibrateParameter ¶meter) override; #endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM virtual int32_t StopVibrator(int32_t vibratorId) override; virtual int32_t StopVibrator(int32_t vibratorId, const std::string &mode) override; @@ -77,11 +77,11 @@ public: virtual int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) override; virtual int32_t TurnOff(int32_t lightId) override; virtual int32_t PlayPattern(const VibratePattern &pattern, int32_t usage, - const VibrateParameter ¶meter) override; + bool systemUsage, const VibrateParameter ¶meter) override; virtual int32_t GetDelayTime(int32_t &delayTime) override; virtual int32_t TransferClientRemoteObject(const sptr &vibratorServiceClient) override; virtual int32_t PlayPrimitiveEffect(int32_t vibratorId, const std::string &effect, int32_t intensity, - int32_t usage, int32_t count) override; + int32_t usage, bool systemUsage, int32_t count) override; virtual int32_t GetVibratorCapacity(VibratorCapacity &capacity) override; private: diff --git a/services/miscdevice_service/include/vibration_priority_manager.h b/services/miscdevice_service/include/vibration_priority_manager.h index ab08dd8..726a48a 100644 --- a/services/miscdevice_service/include/vibration_priority_manager.h +++ b/services/miscdevice_service/include/vibration_priority_manager.h @@ -81,6 +81,8 @@ private: bool ReleaseDataShareHelper(std::shared_ptr &helper); sptr CreateObserver(const MiscDeviceObserver::UpdateFunc &func); void UpdateStatus(); + bool IsSystemServiceCalling(); + bool IsSystemCalling(); sptr remoteObj_ { nullptr }; sptr observer_ { nullptr }; std::shared_ptr appMgrClientPtr_ {nullptr}; diff --git a/services/miscdevice_service/src/miscdevice_service.cpp b/services/miscdevice_service/src/miscdevice_service.cpp index a27d3ef..e1afa64 100644 --- a/services/miscdevice_service/src/miscdevice_service.cpp +++ b/services/miscdevice_service/src/miscdevice_service.cpp @@ -310,7 +310,7 @@ bool MiscdeviceService::ShouldIgnoreVibrate(const VibrateInfo &info) return (PriorityManager->ShouldIgnoreVibrate(info, vibratorThread_) != VIBRATION); } -int32_t MiscdeviceService::Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage) +int32_t MiscdeviceService::Vibrate(int32_t vibratorId, int32_t timeOut, int32_t usage, bool systemUsage) { if ((timeOut <= MIN_VIBRATOR_TIME) || (timeOut > MAX_VIBRATOR_TIME) || (usage >= USAGE_MAX) || (usage < 0)) { @@ -323,6 +323,7 @@ int32_t MiscdeviceService::Vibrate(int32_t vibratorId, int32_t timeOut, int32_t .pid = GetCallingPid(), .uid = GetCallingUid(), .usage = usage, + .systemUsage = systemUsage, .duration = timeOut }; std::lock_guard lock(vibratorThreadMutex_); @@ -366,7 +367,7 @@ int32_t MiscdeviceService::StopVibrator(int32_t vibratorId) } int32_t MiscdeviceService::PlayVibratorEffect(int32_t vibratorId, const std::string &effect, - int32_t count, int32_t usage) + int32_t count, int32_t usage, bool systemUsage) { if ((count < MIN_VIBRATOR_COUNT) || (count > MAX_VIBRATOR_COUNT) || (usage >= USAGE_MAX) || (usage < 0)) { MISC_HILOGE("Invalid parameter"); @@ -387,6 +388,7 @@ int32_t MiscdeviceService::PlayVibratorEffect(int32_t vibratorId, const std::str .pid = GetCallingPid(), .uid = GetCallingUid(), .usage = usage, + .systemUsage = systemUsage, .duration = effectInfo->duration, .effect = effect, .count = count, @@ -483,7 +485,7 @@ std::string MiscdeviceService::GetCurrentTime() #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t MiscdeviceService::PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage, - const VibrateParameter ¶meter) + bool systemUsage, const VibrateParameter ¶meter) { if (!(g_capacity.isSupportHdHaptic || g_capacity.isSupportPresetMapping || g_capacity.isSupportTimeDelay)) { MISC_HILOGE("The device does not support this operation"); @@ -510,6 +512,7 @@ int32_t MiscdeviceService::PlayVibratorCustom(int32_t vibratorId, const RawFileD .pid = GetCallingPid(), .uid = GetCallingUid(), .usage = usage, + .systemUsage = systemUsage, .package = package, }; if (g_capacity.isSupportHdHaptic) { @@ -645,7 +648,7 @@ int32_t MiscdeviceService::Dump(int32_t fd, const std::vector &a } int32_t MiscdeviceService::PlayPattern(const VibratePattern &pattern, int32_t usage, - const VibrateParameter ¶meter) + bool systemUsage, const VibrateParameter ¶meter) { if ((usage >= USAGE_MAX) || (usage < 0) || (!CheckVibratorParmeters(parameter))) { MISC_HILOGE("Invalid parameter, usage:%{public}d", usage); @@ -667,6 +670,7 @@ int32_t MiscdeviceService::PlayPattern(const VibratePattern &pattern, int32_t us .pid = GetCallingPid(), .uid = GetCallingUid(), .usage = usage, + .systemUsage = systemUsage }; if (g_capacity.isSupportHdHaptic) { std::lock_guard lock(vibratorThreadMutex_); @@ -848,7 +852,7 @@ void MiscdeviceService::DestroyClientPid(const sptr &vibratorServ } int32_t MiscdeviceService::PlayPrimitiveEffect(int32_t vibratorId, const std::string &effect, - int32_t intensity, int32_t usage, int32_t count) + int32_t intensity, int32_t usage, bool systemUsage, int32_t count) { if ((intensity <= INTENSITY_MIN) || (intensity > INTENSITY_MAX) || (usage >= USAGE_MAX) || (usage < 0)) { MISC_HILOGE("Invalid parameter"); @@ -869,6 +873,7 @@ int32_t MiscdeviceService::PlayPrimitiveEffect(int32_t vibratorId, const std::st .pid = GetCallingPid(), .uid = GetCallingUid(), .usage = usage, + .systemUsage = systemUsage, .duration = effectInfo->duration, .effect = effect, .count = count, diff --git a/services/miscdevice_service/src/miscdevice_service_stub.cpp b/services/miscdevice_service/src/miscdevice_service_stub.cpp index f08e120..a3df607 100644 --- a/services/miscdevice_service/src/miscdevice_service_stub.cpp +++ b/services/miscdevice_service/src/miscdevice_service_stub.cpp @@ -55,11 +55,13 @@ int32_t MiscdeviceServiceStub::VibrateStub(MessageParcel &data, MessageParcel &r int32_t vibratorId; int32_t duration; int32_t usage; - if ((!data.ReadInt32(vibratorId)) || (!data.ReadInt32(duration)) || (!data.ReadInt32(usage))) { + bool systemUsage; + if ((!data.ReadInt32(vibratorId)) || (!data.ReadInt32(duration)) || (!data.ReadInt32(usage))|| + (!data.ReadBool(systemUsage))) { MISC_HILOGE("Parcel read failed"); return ERROR; } - return Vibrate(vibratorId, duration, usage); + return Vibrate(vibratorId, duration, usage, systemUsage); } int32_t MiscdeviceServiceStub::StopVibratorAllStub(MessageParcel &data, MessageParcel &reply) @@ -94,12 +96,13 @@ int32_t MiscdeviceServiceStub::PlayVibratorEffectStub(MessageParcel &data, Messa std::string effect; int32_t count; int32_t usage; + bool systemUsage; if ((!data.ReadInt32(vibratorId)) || (!data.ReadString(effect)) || - (!data.ReadInt32(count)) || (!data.ReadInt32(usage))) { + (!data.ReadInt32(count)) || (!data.ReadInt32(usage)) || (!data.ReadBool(systemUsage))) { MISC_HILOGE("Parcel read failed"); return ERROR; } - return PlayVibratorEffect(vibratorId, effect, count, usage); + return PlayVibratorEffect(vibratorId, effect, count, usage, systemUsage); } int32_t MiscdeviceServiceStub::StopVibratorByModeStub(MessageParcel &data, MessageParcel &reply) @@ -167,6 +170,11 @@ int32_t MiscdeviceServiceStub::PlayVibratorCustomStub(MessageParcel &data, Messa MISC_HILOGE("Parameter Unmarshalling failed"); return ERROR; } + bool systemUsage; + if (!data.ReadBool(systemUsage)) { + MISC_HILOGE("Parcel read systemUsage failed"); + return ERROR; + } RawFileDescriptor rawFd; if (!data.ReadInt64(rawFd.offset)) { MISC_HILOGE("Parcel read offset failed"); @@ -181,7 +189,7 @@ int32_t MiscdeviceServiceStub::PlayVibratorCustomStub(MessageParcel &data, Messa MISC_HILOGE("Parcel ReadFileDescriptor failed"); return ERROR; } - ret = PlayVibratorCustom(vibratorId, rawFd, usage, parameter.value()); + ret = PlayVibratorCustom(vibratorId, rawFd, usage, systemUsage, parameter.value()); close(rawFd.fd); if (ret != ERR_OK) { MISC_HILOGD("PlayVibratorCustom failed, ret:%{public}d", ret); @@ -333,6 +341,11 @@ int32_t MiscdeviceServiceStub::PlayPatternStub(MessageParcel &data, MessageParce MISC_HILOGE("Parcel read usage failed"); return ERROR; } + bool systemUsage = false; + if (!data.ReadBool(systemUsage)) { + MISC_HILOGE("Parcel read systemUsage failed"); + return ERROR; + } VibrateParameter vibrateParameter; auto parameter = vibrateParameter.Unmarshalling(data); if (!parameter.has_value()) { @@ -382,9 +395,11 @@ int32_t MiscdeviceServiceStub::PlayPrimitiveEffectStub(MessageParcel &data, Mess std::string effect; int32_t intensity = 0; int32_t usage = 0; + bool systemUsage = false; int32_t count = 0; if ((!data.ReadInt32(vibratorId)) || (!data.ReadString(effect)) || - (!data.ReadInt32(intensity)) || (!data.ReadInt32(usage)) || (!data.ReadInt32(count))) { + (!data.ReadInt32(intensity)) || (!data.ReadInt32(usage)) || (!data.ReadBool(systemUsage)) || + (!data.ReadInt32(count))) { MISC_HILOGE("Parcel read failed"); return ERROR; } diff --git a/services/miscdevice_service/src/vibration_priority_manager.cpp b/services/miscdevice_service/src/vibration_priority_manager.cpp index 897b248..68239e0 100644 --- a/services/miscdevice_service/src/vibration_priority_manager.cpp +++ b/services/miscdevice_service/src/vibration_priority_manager.cpp @@ -15,6 +15,7 @@ #include "vibration_priority_manager.h" +#include "accesstoken_kit.h" #include "bundle_mgr_client.h" #include "ipc_skeleton.h" #include "iservice_registry.h" @@ -171,6 +172,25 @@ void VibrationPriorityManager::UpdateStatus() } } +bool VibrationPriorityManager::IsSystemServiceCalling() +{ + const auto tokenId = IPCSkeleton::GetCallingTokenID(); + const auto flag = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); + if (flag == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) { + MISC_HILOGD("system service calling, tokenId: %{public}u, flag: %{public}u", tokenId, flag); + return true; + } + return false; +} + +bool VibrationPriorityManager::IsSystemCalling() +{ + if (IsSystemServiceCalling()) { + return true; + } + return Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID()); +} + bool VibrationPriorityManager::ShouldIgnoreInputMethod(const VibrateInfo &vibrateInfo) { int32_t pid = vibrateInfo.pid; @@ -226,18 +246,21 @@ VibrateStatus VibrationPriorityManager::ShouldIgnoreVibrate(const VibrateInfo &v return VIBRATION; } UpdateStatus(); - if ((vibrateInfo.usage == USAGE_ALARM || vibrateInfo.usage == USAGE_RING || - vibrateInfo.usage == USAGE_NOTIFICATION - || vibrateInfo.usage == USAGE_COMMUNICATION) && (miscAudioRingerMode_ == RINGER_MODE_SILENT)) { - MISC_HILOGD("Vibration is ignored for ringer mode:%{public}d", static_cast(miscAudioRingerMode_)); - return IGNORE_RINGER_MODE; - } - if (((vibrateInfo.usage == USAGE_TOUCH || vibrateInfo.usage == USAGE_MEDIA || vibrateInfo.usage == USAGE_UNKNOWN - || vibrateInfo.usage == USAGE_PHYSICAL_FEEDBACK || vibrateInfo.usage == USAGE_SIMULATE_REALITY) - && (miscFeedback_ == FEEDBACK_MODE_OFF)) && !ShouldIgnoreInputMethod(vibrateInfo)) { - MISC_HILOGD("Vibration is ignored for feedback:%{public}d", static_cast(miscFeedback_)); - return IGNORE_FEEDBACK; - } + if (!IsSystemCalling() || vibrateInfo.systemUsage == false) { + MISC_HILOGE("cffSystem in"); + if ((vibrateInfo.usage == USAGE_ALARM || vibrateInfo.usage == USAGE_RING || vibrateInfo.usage == USAGE_NOTIFICATION + || vibrateInfo.usage == USAGE_COMMUNICATION) && (miscAudioRingerMode_ == RINGER_MODE_SILENT)) { + MISC_HILOGD("Vibration is ignored for ringer mode:%{public}d", static_cast(miscAudioRingerMode_)); + return IGNORE_RINGER_MODE; + } + MISC_HILOGE("cffignore in"); + if (((vibrateInfo.usage == USAGE_TOUCH || vibrateInfo.usage == USAGE_MEDIA || vibrateInfo.usage == USAGE_UNKNOWN + || vibrateInfo.usage == USAGE_PHYSICAL_FEEDBACK || vibrateInfo.usage == USAGE_SIMULATE_REALITY) + && (miscFeedback_ == FEEDBACK_MODE_OFF)) && !ShouldIgnoreInputMethod(vibrateInfo)) { + MISC_HILOGD("cffInputManager"); + MISC_HILOGD("Vibration is ignored for feedback:%{public}d", static_cast(miscFeedback_)); + return IGNORE_FEEDBACK; + } if (vibratorThread == nullptr) { MISC_HILOGD("There is no vibration, it can vibrate"); return VIBRATION; diff --git a/utils/common/include/vibrator_infos.h b/utils/common/include/vibrator_infos.h index a0e576f..47f820f 100644 --- a/utils/common/include/vibrator_infos.h +++ b/utils/common/include/vibrator_infos.h @@ -124,6 +124,7 @@ struct VibrateInfo { int32_t pid = -1; int32_t uid = -1; int32_t usage = 0; + bool systemUsage = false; int32_t duration = 0; std::string effect; int32_t count = 0; -- Gitee From e26d8ae23e015d8e5834cdb7f2a5c5b9dc2a0d7c Mon Sep 17 00:00:00 2001 From: cff-gite Date: Mon, 29 Jul 2024 14:15:56 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A9=AC=E8=BE=BEsyste?= =?UTF-8?q?mUsage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite Change-Id: Ied7e81a508e445db814e778589c62e6cac81b77c --- frameworks/js/napi/vibrator/src/vibrator_js.cpp | 1 + frameworks/native/vibrator/vibrator_agent.cpp | 2 +- .../miscdevice_service/src/vibration_priority_manager.cpp | 5 +---- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/frameworks/js/napi/vibrator/src/vibrator_js.cpp b/frameworks/js/napi/vibrator/src/vibrator_js.cpp index 21d0ddf..b6e3161 100644 --- a/frameworks/js/napi/vibrator/src/vibrator_js.cpp +++ b/frameworks/js/napi/vibrator/src/vibrator_js.cpp @@ -73,6 +73,7 @@ static std::set g_allowedTypes = {"time", "preset", "file", "patter struct VibrateInfo { std::string type; std::string usage; + bool systemUsage; int32_t duration = 0; std::string effectId; int32_t count = 0; diff --git a/frameworks/native/vibrator/vibrator_agent.cpp b/frameworks/native/vibrator/vibrator_agent.cpp index 8eceac3..ec79928 100644 --- a/frameworks/native/vibrator/vibrator_agent.cpp +++ b/frameworks/native/vibrator/vibrator_agent.cpp @@ -164,7 +164,7 @@ int32_t Cancel() return SUCCESS; } -bool SetUsage(int32_t usage) +bool SetUsage(int32_t usage, bool systemUsage) { if ((usage < 0) || (usage >= USAGE_MAX)) { MISC_HILOGE("Input invalid, usage is %{public}d", usage); diff --git a/services/miscdevice_service/src/vibration_priority_manager.cpp b/services/miscdevice_service/src/vibration_priority_manager.cpp index 68239e0..f3a8df1 100644 --- a/services/miscdevice_service/src/vibration_priority_manager.cpp +++ b/services/miscdevice_service/src/vibration_priority_manager.cpp @@ -177,7 +177,7 @@ bool VibrationPriorityManager::IsSystemServiceCalling() const auto tokenId = IPCSkeleton::GetCallingTokenID(); const auto flag = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); if (flag == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) { - MISC_HILOGD("system service calling, tokenId: %{public}u, flag: %{public}u", tokenId, flag); + MISC_HILOGD("System service calling, flag: %{public}u", flag); return true; } return false; @@ -247,17 +247,14 @@ VibrateStatus VibrationPriorityManager::ShouldIgnoreVibrate(const VibrateInfo &v } UpdateStatus(); if (!IsSystemCalling() || vibrateInfo.systemUsage == false) { - MISC_HILOGE("cffSystem in"); if ((vibrateInfo.usage == USAGE_ALARM || vibrateInfo.usage == USAGE_RING || vibrateInfo.usage == USAGE_NOTIFICATION || vibrateInfo.usage == USAGE_COMMUNICATION) && (miscAudioRingerMode_ == RINGER_MODE_SILENT)) { MISC_HILOGD("Vibration is ignored for ringer mode:%{public}d", static_cast(miscAudioRingerMode_)); return IGNORE_RINGER_MODE; } - MISC_HILOGE("cffignore in"); if (((vibrateInfo.usage == USAGE_TOUCH || vibrateInfo.usage == USAGE_MEDIA || vibrateInfo.usage == USAGE_UNKNOWN || vibrateInfo.usage == USAGE_PHYSICAL_FEEDBACK || vibrateInfo.usage == USAGE_SIMULATE_REALITY) && (miscFeedback_ == FEEDBACK_MODE_OFF)) && !ShouldIgnoreInputMethod(vibrateInfo)) { - MISC_HILOGD("cffInputManager"); MISC_HILOGD("Vibration is ignored for feedback:%{public}d", static_cast(miscFeedback_)); return IGNORE_FEEDBACK; } -- Gitee From 734bab4b1b0737bd9132939727d72f6f997f0cb9 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Mon, 29 Jul 2024 14:58:50 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A9=AC=E8=BE=BEsyste?= =?UTF-8?q?mUsage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite Change-Id: Ife3f525fe1ca8ae6a674d1c4dd1893d1f8c25adb --- services/miscdevice_service/src/miscdevice_service_stub.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/miscdevice_service/src/miscdevice_service_stub.cpp b/services/miscdevice_service/src/miscdevice_service_stub.cpp index a3df607..d5b7c97 100644 --- a/services/miscdevice_service/src/miscdevice_service_stub.cpp +++ b/services/miscdevice_service/src/miscdevice_service_stub.cpp @@ -352,7 +352,7 @@ int32_t MiscdeviceServiceStub::PlayPatternStub(MessageParcel &data, MessageParce MISC_HILOGE("Parameter Unmarshalling failed"); return ERROR; } - return PlayPattern(pattern.value(), usage, parameter.value()); + return PlayPattern(pattern.value(), usage, systemUsage, parameter.value()); } int32_t MiscdeviceServiceStub::GetDelayTimeStub(MessageParcel &data, MessageParcel &reply) @@ -403,7 +403,7 @@ int32_t MiscdeviceServiceStub::PlayPrimitiveEffectStub(MessageParcel &data, Mess MISC_HILOGE("Parcel read failed"); return ERROR; } - return PlayPrimitiveEffect(vibratorId, effect, intensity, usage, count); + return PlayPrimitiveEffect(vibratorId, effect, intensity, usage, systemUsage, count); } int32_t MiscdeviceServiceStub::GetVibratorCapacityStub(MessageParcel &data, MessageParcel &reply) -- Gitee From aa058959f45ad44ac247f94c421a6171c837fdeb Mon Sep 17 00:00:00 2001 From: cff-gite Date: Mon, 29 Jul 2024 15:29:35 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A9=AC=E8=BE=BEsyste?= =?UTF-8?q?mUsage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite Change-Id: I518826c4bc30d0359970197573df7a67cdde20d3 --- frameworks/native/common/include/i_miscdevice_service.h | 3 ++- frameworks/native/vibrator/vibrator_agent.cpp | 3 ++- .../miscdevice_service/src/vibration_priority_manager.cpp | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/frameworks/native/common/include/i_miscdevice_service.h b/frameworks/native/common/include/i_miscdevice_service.h index ebb2e0c..f555c7a 100644 --- a/frameworks/native/common/include/i_miscdevice_service.h +++ b/frameworks/native/common/include/i_miscdevice_service.h @@ -50,7 +50,8 @@ public: virtual int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) = 0; virtual int32_t TurnOff(int32_t lightId) = 0; virtual int32_t GetDelayTime(int32_t &delayTime) = 0; - virtual int32_t PlayPattern(const VibratePattern &pattern, int32_t usage, bool systemUsage, const VibrateParameter ¶meter) = 0; + virtual int32_t PlayPattern(const VibratePattern &pattern, int32_t usage, bool systemUsage, + const VibrateParameter ¶meter) = 0; virtual int32_t TransferClientRemoteObject(const sptr &vibratorClient) = 0; virtual int32_t PlayPrimitiveEffect(int32_t vibratorId, const std::string &effect, int32_t intensity, int32_t usage, bool systemUsage, int32_t count) = 0; diff --git a/frameworks/native/vibrator/vibrator_agent.cpp b/frameworks/native/vibrator/vibrator_agent.cpp index ec79928..8f0f17f 100644 --- a/frameworks/native/vibrator/vibrator_agent.cpp +++ b/frameworks/native/vibrator/vibrator_agent.cpp @@ -258,7 +258,8 @@ int32_t PlayPrimitiveEffect(const char *effectId, int32_t intensity) MISC_HILOGD("Time delay measurement:start time"); CHKPR(effectId, PARAMETER_ERROR); auto &client = VibratorServiceClient::GetInstance(); - int32_t ret = client.PlayPrimitiveEffect(DEFAULT_VIBRATOR_ID, effectId, intensity, g_usage, g_systemUsage, g_loopCount); + int32_t ret = client.PlayPrimitiveEffect(DEFAULT_VIBRATOR_ID, effectId, intensity, + g_usage, g_systemUsage, g_loopCount); g_loopCount = 1; g_usage = USAGE_UNKNOWN; g_systemUsage = false; diff --git a/services/miscdevice_service/src/vibration_priority_manager.cpp b/services/miscdevice_service/src/vibration_priority_manager.cpp index f3a8df1..dcaa5fd 100644 --- a/services/miscdevice_service/src/vibration_priority_manager.cpp +++ b/services/miscdevice_service/src/vibration_priority_manager.cpp @@ -247,8 +247,9 @@ VibrateStatus VibrationPriorityManager::ShouldIgnoreVibrate(const VibrateInfo &v } UpdateStatus(); if (!IsSystemCalling() || vibrateInfo.systemUsage == false) { - if ((vibrateInfo.usage == USAGE_ALARM || vibrateInfo.usage == USAGE_RING || vibrateInfo.usage == USAGE_NOTIFICATION - || vibrateInfo.usage == USAGE_COMMUNICATION) && (miscAudioRingerMode_ == RINGER_MODE_SILENT)) { + if ((vibrateInfo.usage == USAGE_ALARM || vibrateInfo.usage == USAGE_RING + || vibrateInfo.usage == USAGE_NOTIFICATION || vibrateInfo.usage == USAGE_COMMUNICATION) + && (miscAudioRingerMode_ == RINGER_MODE_SILENT)) { MISC_HILOGD("Vibration is ignored for ringer mode:%{public}d", static_cast(miscAudioRingerMode_)); return IGNORE_RINGER_MODE; } -- Gitee From 36c92c989a4fe75dd6b8238aa8d563fe8d944c4e Mon Sep 17 00:00:00 2001 From: cff-gite Date: Mon, 29 Jul 2024 15:49:56 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A9=AC=E8=BE=BEsyste?= =?UTF-8?q?mUsage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite Change-Id: I4da2503d1d9ef785bc8faf3b9a041632c3f1b87a --- services/miscdevice_service/src/vibration_priority_manager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/miscdevice_service/src/vibration_priority_manager.cpp b/services/miscdevice_service/src/vibration_priority_manager.cpp index dcaa5fd..29c4945 100644 --- a/services/miscdevice_service/src/vibration_priority_manager.cpp +++ b/services/miscdevice_service/src/vibration_priority_manager.cpp @@ -15,6 +15,8 @@ #include "vibration_priority_manager.h" +#include + #include "accesstoken_kit.h" #include "bundle_mgr_client.h" #include "ipc_skeleton.h" @@ -259,6 +261,7 @@ VibrateStatus VibrationPriorityManager::ShouldIgnoreVibrate(const VibrateInfo &v MISC_HILOGD("Vibration is ignored for feedback:%{public}d", static_cast(miscFeedback_)); return IGNORE_FEEDBACK; } + } if (vibratorThread == nullptr) { MISC_HILOGD("There is no vibration, it can vibrate"); return VIBRATION; -- Gitee From 09e61cf12c42c8fb5f3084642ec8133481240cf6 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Mon, 29 Jul 2024 17:22:46 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A9=AC=E8=BE=BEsyste?= =?UTF-8?q?mUsage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite Change-Id: I426ad639240cc1d8477106b2bfe1d99aa1487e72 --- .../miscdevice_service/src/miscdevice_service_stub.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services/miscdevice_service/src/miscdevice_service_stub.cpp b/services/miscdevice_service/src/miscdevice_service_stub.cpp index d5b7c97..964294c 100644 --- a/services/miscdevice_service/src/miscdevice_service_stub.cpp +++ b/services/miscdevice_service/src/miscdevice_service_stub.cpp @@ -164,17 +164,17 @@ int32_t MiscdeviceServiceStub::PlayVibratorCustomStub(MessageParcel &data, Messa MISC_HILOGE("Parcel read usage failed"); return ERROR; } + bool systemUsage; + if (!data.ReadBool(systemUsage)) { + MISC_HILOGE("Parcel read systemUsage failed"); + return ERROR; + } VibrateParameter vibrateParameter; auto parameter = vibrateParameter.Unmarshalling(data); if (!parameter.has_value()) { MISC_HILOGE("Parameter Unmarshalling failed"); return ERROR; } - bool systemUsage; - if (!data.ReadBool(systemUsage)) { - MISC_HILOGE("Parcel read systemUsage failed"); - return ERROR; - } RawFileDescriptor rawFd; if (!data.ReadInt64(rawFd.offset)) { MISC_HILOGE("Parcel read offset failed"); -- Gitee From f70dce07d83d7ff09ab0a2660c42f396b60cd6f4 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Mon, 29 Jul 2024 18:28:37 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A9=AC=E8=BE=BEsyste?= =?UTF-8?q?mUsage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite Change-Id: Ie98555eb034a93197b6ba77c9ba543a9c9f37698 --- .../miscdevice_service/src/miscdevice_service_stub.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/services/miscdevice_service/src/miscdevice_service_stub.cpp b/services/miscdevice_service/src/miscdevice_service_stub.cpp index 964294c..606630b 100644 --- a/services/miscdevice_service/src/miscdevice_service_stub.cpp +++ b/services/miscdevice_service/src/miscdevice_service_stub.cpp @@ -160,13 +160,9 @@ int32_t MiscdeviceServiceStub::PlayVibratorCustomStub(MessageParcel &data, Messa return ERROR; } int32_t usage; - if (!data.ReadInt32(usage)) { - MISC_HILOGE("Parcel read usage failed"); - return ERROR; - } bool systemUsage; - if (!data.ReadBool(systemUsage)) { - MISC_HILOGE("Parcel read systemUsage failed"); + if (!data.ReadInt32(usage) || !data.ReadBool(systemUsage)) { + MISC_HILOGE("Parcel read failed"); return ERROR; } VibrateParameter vibrateParameter; -- Gitee From aad2d52cfc23c7b81f5e3a3f222e44abbba5b6a0 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 30 Jul 2024 11:00:48 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A9=AC=E8=BE=BEsyste?= =?UTF-8?q?mUsage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite Change-Id: Ibb9a5f032f5dad4b98e5863f158fb7f295ae38ad --- frameworks/js/napi/vibrator/src/vibrator_js.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frameworks/js/napi/vibrator/src/vibrator_js.cpp b/frameworks/js/napi/vibrator/src/vibrator_js.cpp index b6e3161..1eb03af 100644 --- a/frameworks/js/napi/vibrator/src/vibrator_js.cpp +++ b/frameworks/js/napi/vibrator/src/vibrator_js.cpp @@ -448,7 +448,9 @@ bool ParseParameter(napi_env env, napi_value args[], size_t argc, VibrateInfo &i CHKCF(CheckVibratorPatternParameter(info.vibratorPattern), "CheckVibratorPatternParameter fail"); } CHKCF(GetPropertyString(env, args[1], "usage", info.usage), "Get vibrate usage fail"); - CHKCF(GetPropertyBool(env, args[1], "systemUsage", info.systemUsage), "Get vibrate systemUsage fail"); + if (!GetPropertyBool(env, args[1], "systemUsage", info.systemUsage)) { + info.systemUsage = false; + } return true; } -- Gitee From d674ace233de8a6da2ad7cb7853213f590f079e9 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 30 Jul 2024 11:22:12 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A9=AC=E8=BE=BEsyste?= =?UTF-8?q?mUsage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite Change-Id: I4eb12d1000a3ac2bf7f952f89df825e3011ca921 --- frameworks/js/napi/vibrator/src/vibrator_js.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/js/napi/vibrator/src/vibrator_js.cpp b/frameworks/js/napi/vibrator/src/vibrator_js.cpp index 1eb03af..05c7a3f 100644 --- a/frameworks/js/napi/vibrator/src/vibrator_js.cpp +++ b/frameworks/js/napi/vibrator/src/vibrator_js.cpp @@ -449,6 +449,7 @@ bool ParseParameter(napi_env env, napi_value args[], size_t argc, VibrateInfo &i } CHKCF(GetPropertyString(env, args[1], "usage", info.usage), "Get vibrate usage fail"); if (!GetPropertyBool(env, args[1], "systemUsage", info.systemUsage)) { + MISC_HILOGE("Get vibrate bool fail"); info.systemUsage = false; } return true; -- Gitee From c79ac4a0653f0819ef22d38818bdde07d9fc2b87 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 30 Jul 2024 11:29:51 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A9=AC=E8=BE=BEsyste?= =?UTF-8?q?mUsage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite Change-Id: Ifd3f22dacac0b060647ca505bb515b3d2fc9817b --- frameworks/js/napi/vibrator/src/vibrator_js.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/frameworks/js/napi/vibrator/src/vibrator_js.cpp b/frameworks/js/napi/vibrator/src/vibrator_js.cpp index 05c7a3f..1eb03af 100644 --- a/frameworks/js/napi/vibrator/src/vibrator_js.cpp +++ b/frameworks/js/napi/vibrator/src/vibrator_js.cpp @@ -449,7 +449,6 @@ bool ParseParameter(napi_env env, napi_value args[], size_t argc, VibrateInfo &i } CHKCF(GetPropertyString(env, args[1], "usage", info.usage), "Get vibrate usage fail"); if (!GetPropertyBool(env, args[1], "systemUsage", info.systemUsage)) { - MISC_HILOGE("Get vibrate bool fail"); info.systemUsage = false; } return true; -- Gitee