diff --git a/interfaces/kits/changes.diff b/interfaces/kits/changes.diff new file mode 100644 index 0000000000000000000000000000000000000000..f7e1343df7f73c587edaba528b07b063f5b0f7f9 --- /dev/null +++ b/interfaces/kits/changes.diff @@ -0,0 +1,228 @@ +diff --git a/interfaces/kits/napi/webviewcontroller/native_media_player_impl.cpp b/interfaces/kits/napi/webviewcontroller/native_media_player_impl.cpp +index a23f9415..4c1715a7 100644 +--- a/interfaces/kits/napi/webviewcontroller/native_media_player_impl.cpp ++++ b/interfaces/kits/napi/webviewcontroller/native_media_player_impl.cpp +@@ -167,144 +167,6 @@ void NWebNativeMediaPlayerBridgeImpl::SuspendMediaPlayer(SuspendType type) + NAPI_CALL_RETURN_VOID(env_, napi_call_function(env_, value_, callback, INTEGER_ONE, argv, nullptr)); + } + +-NapiNativeMediaPlayerHandlerImpl::NapiNativeMediaPlayerHandlerImpl( +- int32_t nwebId, std::shared_ptr handler) +- : nwebId_(nwebId), handler_(handler) +-{} +- +-void NapiNativeMediaPlayerHandlerImpl::HandleStatusChanged(PlaybackStatus status) +-{ +- WVLOG_D("begin to handle status changed,nweb id is %{public}d", nwebId_); +- +- if (handler_) { +- handler_->HandleStatusChanged(status); +- } +-} +- +-void NapiNativeMediaPlayerHandlerImpl::HandleVolumeChanged(double volume) +-{ +- WVLOG_D("begin to handle volume changed,nweb id is %{public}d", nwebId_); +- +- if (handler_) { +- handler_->HandleVolumeChanged(volume); +- } +-} +- +-void NapiNativeMediaPlayerHandlerImpl::HandleMutedChanged(bool isMuted) +-{ +- WVLOG_D("begin to handle muted changed,nweb id is %{public}d", nwebId_); +- +- if (handler_) { +- handler_->HandleMutedChanged(isMuted); +- } +-} +- +-void NapiNativeMediaPlayerHandlerImpl::HandlePlaybackRateChanged(double playbackRate) +-{ +- WVLOG_D("begin to handle playback rate changed,nweb id is %{public}d", nwebId_); +- +- if (handler_) { +- handler_->HandlePlaybackRateChanged(playbackRate); +- } +-} +- +-void NapiNativeMediaPlayerHandlerImpl::HandleDurationChanged(double duration) +-{ +- WVLOG_D("begin to handle duration changed,nweb id is %{public}d", nwebId_); +- +- if (handler_) { +- handler_->HandleDurationChanged(duration); +- } +-} +- +-void NapiNativeMediaPlayerHandlerImpl::HandleTimeUpdate(double playTime) +-{ +- if (handler_) { +- handler_->HandleTimeUpdate(playTime); +- } +-} +- +-void NapiNativeMediaPlayerHandlerImpl::HandleBufferedEndTimeChanged(double bufferedEndTime) +-{ +- WVLOG_D("begin to handle buffered end time changed,nweb id is %{public}d", nwebId_); +- +- if (handler_) { +- handler_->HandleBufferedEndTimeChanged(bufferedEndTime); +- } +-} +- +-void NapiNativeMediaPlayerHandlerImpl::HandleEnded() +-{ +- WVLOG_D("begin to handle end,nweb id is %{public}d", nwebId_); +- +- if (handler_) { +- handler_->HandleEnded(); +- } +-} +- +-void NapiNativeMediaPlayerHandlerImpl::HandleNetworkStateChanged(NetworkState state) +-{ +- WVLOG_D("begin to handle network state changed,nweb id is %{public}d", nwebId_); +- +- if (handler_) { +- handler_->HandleNetworkStateChanged(state); +- } +-} +- +-void NapiNativeMediaPlayerHandlerImpl::HandleReadyStateChanged(ReadyState state) +-{ +- WVLOG_D("begin to handle ready state changed,nweb id is %{public}d", nwebId_); +- +- if (handler_) { +- handler_->HandleReadyStateChanged(state); +- } +-} +- +-void NapiNativeMediaPlayerHandlerImpl::HandleFullScreenChanged(bool isFullScreen) +-{ +- WVLOG_D("begin to handle full screen changed,nweb id is %{public}d", nwebId_); +- +- if (handler_) { +- handler_->HandleFullScreenChanged(isFullScreen); +- } +-} +- +-void NapiNativeMediaPlayerHandlerImpl::HandleSeeking() +-{ +- WVLOG_D("begin to handle seeking,nweb id is %{public}d", nwebId_); +- +- if (handler_) { +- handler_->HandleSeeking(); +- } +-} +- +-void NapiNativeMediaPlayerHandlerImpl::HandleSeekFinished() +-{ +- WVLOG_D("begin to handle seek finished,nweb id is %{public}d", nwebId_); +- +- if (handler_) { +- handler_->HandleSeekFinished(); +- } +-} +- +-void NapiNativeMediaPlayerHandlerImpl::HandleError(MediaError error, const std::string& message) +-{ +- WVLOG_D("begin to handle error,nweb id is %{public}d", nwebId_); +- +- if (handler_) { +- handler_->HandleError(error, message); +- } +-} +- +-void NapiNativeMediaPlayerHandlerImpl::HandleVideoSizeChanged(double width, double height) +-{ +- WVLOG_D("begin to handle video size changed,nweb id is %{public}d", nwebId_); +- +- if (handler_) { +- handler_->HandleVideoSizeChanged(width, height); +- } +-} +- + NWebCreateNativeMediaPlayerCallbackImpl::NWebCreateNativeMediaPlayerCallbackImpl( + int32_t nwebId, napi_env env, napi_ref callback) + : nwebId_(nwebId), env_(env), callback_(callback) +diff --git a/interfaces/kits/napi/webviewcontroller/native_media_player_impl.h b/interfaces/kits/napi/webviewcontroller/native_media_player_impl.h +index fcca2c53..2c968ffb 100644 +--- a/interfaces/kits/napi/webviewcontroller/native_media_player_impl.h ++++ b/interfaces/kits/napi/webviewcontroller/native_media_player_impl.h +@@ -18,6 +18,7 @@ + + #include "napi/native_api.h" + #include "nweb_native_media_player.h" ++#include "napi_native_mediaplayer_handler_impl.h" + + namespace OHOS::NWeb { + +@@ -56,46 +57,6 @@ private: + napi_value value_ = nullptr; + }; + +-class NapiNativeMediaPlayerHandlerImpl { +-public: +- NapiNativeMediaPlayerHandlerImpl(int32_t nwebId, std::shared_ptr handler); +- ~NapiNativeMediaPlayerHandlerImpl() = default; +- +- void HandleStatusChanged(PlaybackStatus status); +- +- void HandleVolumeChanged(double volume); +- +- void HandleMutedChanged(bool isMuted); +- +- void HandlePlaybackRateChanged(double playbackRate); +- +- void HandleDurationChanged(double duration); +- +- void HandleTimeUpdate(double playTime); +- +- void HandleBufferedEndTimeChanged(double bufferedEndTime); +- +- void HandleEnded(); +- +- void HandleNetworkStateChanged(NetworkState state); +- +- void HandleReadyStateChanged(ReadyState state); +- +- void HandleFullScreenChanged(bool isFullScreen); +- +- void HandleSeeking(); +- +- void HandleSeekFinished(); +- +- void HandleError(MediaError error, const std::string& message); +- +- void HandleVideoSizeChanged(double width, double height); +- +-private: +- int32_t nwebId_ = -1; +- std::shared_ptr handler_ = nullptr; +-}; +- + class NWebCreateNativeMediaPlayerCallbackImpl : public NWebCreateNativeMediaPlayerCallback { + public: + explicit NWebCreateNativeMediaPlayerCallbackImpl(int32_t nwebId, napi_env env, napi_ref callback); +diff --git a/interfaces/kits/nativecommon/BUILD.gn b/interfaces/kits/nativecommon/BUILD.gn +index 52ac2484..2cda0edd 100644 +--- a/interfaces/kits/nativecommon/BUILD.gn ++++ b/interfaces/kits/nativecommon/BUILD.gn +@@ -30,6 +30,8 @@ ohos_shared_library("webview_common") { + "web_message_port.h", + "web_errors.cpp", + "transfer_referenced_count.h", ++ "napi_native_mediaplayer_handler_impl.cpp", ++ "napi_native_mediaplayer_handler_impl.h", + ] + + deps = [ +@@ -58,4 +60,4 @@ ohos_shared_library("webview_common") { + + part_name = "webview" + subsystem_name = "web" +-} +\ No newline at end of file ++} diff --git a/interfaces/kits/napi/webviewcontroller/native_media_player_impl.cpp b/interfaces/kits/napi/webviewcontroller/native_media_player_impl.cpp index a23f9415200eddd5ddf18bff6812d9c9b8ecb2f2..4c1715a7cbad1df33da27016047005f00efb16a7 100644 --- a/interfaces/kits/napi/webviewcontroller/native_media_player_impl.cpp +++ b/interfaces/kits/napi/webviewcontroller/native_media_player_impl.cpp @@ -167,144 +167,6 @@ void NWebNativeMediaPlayerBridgeImpl::SuspendMediaPlayer(SuspendType type) NAPI_CALL_RETURN_VOID(env_, napi_call_function(env_, value_, callback, INTEGER_ONE, argv, nullptr)); } -NapiNativeMediaPlayerHandlerImpl::NapiNativeMediaPlayerHandlerImpl( - int32_t nwebId, std::shared_ptr handler) - : nwebId_(nwebId), handler_(handler) -{} - -void NapiNativeMediaPlayerHandlerImpl::HandleStatusChanged(PlaybackStatus status) -{ - WVLOG_D("begin to handle status changed,nweb id is %{public}d", nwebId_); - - if (handler_) { - handler_->HandleStatusChanged(status); - } -} - -void NapiNativeMediaPlayerHandlerImpl::HandleVolumeChanged(double volume) -{ - WVLOG_D("begin to handle volume changed,nweb id is %{public}d", nwebId_); - - if (handler_) { - handler_->HandleVolumeChanged(volume); - } -} - -void NapiNativeMediaPlayerHandlerImpl::HandleMutedChanged(bool isMuted) -{ - WVLOG_D("begin to handle muted changed,nweb id is %{public}d", nwebId_); - - if (handler_) { - handler_->HandleMutedChanged(isMuted); - } -} - -void NapiNativeMediaPlayerHandlerImpl::HandlePlaybackRateChanged(double playbackRate) -{ - WVLOG_D("begin to handle playback rate changed,nweb id is %{public}d", nwebId_); - - if (handler_) { - handler_->HandlePlaybackRateChanged(playbackRate); - } -} - -void NapiNativeMediaPlayerHandlerImpl::HandleDurationChanged(double duration) -{ - WVLOG_D("begin to handle duration changed,nweb id is %{public}d", nwebId_); - - if (handler_) { - handler_->HandleDurationChanged(duration); - } -} - -void NapiNativeMediaPlayerHandlerImpl::HandleTimeUpdate(double playTime) -{ - if (handler_) { - handler_->HandleTimeUpdate(playTime); - } -} - -void NapiNativeMediaPlayerHandlerImpl::HandleBufferedEndTimeChanged(double bufferedEndTime) -{ - WVLOG_D("begin to handle buffered end time changed,nweb id is %{public}d", nwebId_); - - if (handler_) { - handler_->HandleBufferedEndTimeChanged(bufferedEndTime); - } -} - -void NapiNativeMediaPlayerHandlerImpl::HandleEnded() -{ - WVLOG_D("begin to handle end,nweb id is %{public}d", nwebId_); - - if (handler_) { - handler_->HandleEnded(); - } -} - -void NapiNativeMediaPlayerHandlerImpl::HandleNetworkStateChanged(NetworkState state) -{ - WVLOG_D("begin to handle network state changed,nweb id is %{public}d", nwebId_); - - if (handler_) { - handler_->HandleNetworkStateChanged(state); - } -} - -void NapiNativeMediaPlayerHandlerImpl::HandleReadyStateChanged(ReadyState state) -{ - WVLOG_D("begin to handle ready state changed,nweb id is %{public}d", nwebId_); - - if (handler_) { - handler_->HandleReadyStateChanged(state); - } -} - -void NapiNativeMediaPlayerHandlerImpl::HandleFullScreenChanged(bool isFullScreen) -{ - WVLOG_D("begin to handle full screen changed,nweb id is %{public}d", nwebId_); - - if (handler_) { - handler_->HandleFullScreenChanged(isFullScreen); - } -} - -void NapiNativeMediaPlayerHandlerImpl::HandleSeeking() -{ - WVLOG_D("begin to handle seeking,nweb id is %{public}d", nwebId_); - - if (handler_) { - handler_->HandleSeeking(); - } -} - -void NapiNativeMediaPlayerHandlerImpl::HandleSeekFinished() -{ - WVLOG_D("begin to handle seek finished,nweb id is %{public}d", nwebId_); - - if (handler_) { - handler_->HandleSeekFinished(); - } -} - -void NapiNativeMediaPlayerHandlerImpl::HandleError(MediaError error, const std::string& message) -{ - WVLOG_D("begin to handle error,nweb id is %{public}d", nwebId_); - - if (handler_) { - handler_->HandleError(error, message); - } -} - -void NapiNativeMediaPlayerHandlerImpl::HandleVideoSizeChanged(double width, double height) -{ - WVLOG_D("begin to handle video size changed,nweb id is %{public}d", nwebId_); - - if (handler_) { - handler_->HandleVideoSizeChanged(width, height); - } -} - NWebCreateNativeMediaPlayerCallbackImpl::NWebCreateNativeMediaPlayerCallbackImpl( int32_t nwebId, napi_env env, napi_ref callback) : nwebId_(nwebId), env_(env), callback_(callback) diff --git a/interfaces/kits/napi/webviewcontroller/native_media_player_impl.h b/interfaces/kits/napi/webviewcontroller/native_media_player_impl.h index fcca2c5378a0925193f8b6ee730951e8446ac96b..2c968ffb4d5e899b6b5b45b2770dbce836c208e3 100644 --- a/interfaces/kits/napi/webviewcontroller/native_media_player_impl.h +++ b/interfaces/kits/napi/webviewcontroller/native_media_player_impl.h @@ -18,6 +18,7 @@ #include "napi/native_api.h" #include "nweb_native_media_player.h" +#include "napi_native_mediaplayer_handler_impl.h" namespace OHOS::NWeb { @@ -56,46 +57,6 @@ private: napi_value value_ = nullptr; }; -class NapiNativeMediaPlayerHandlerImpl { -public: - NapiNativeMediaPlayerHandlerImpl(int32_t nwebId, std::shared_ptr handler); - ~NapiNativeMediaPlayerHandlerImpl() = default; - - void HandleStatusChanged(PlaybackStatus status); - - void HandleVolumeChanged(double volume); - - void HandleMutedChanged(bool isMuted); - - void HandlePlaybackRateChanged(double playbackRate); - - void HandleDurationChanged(double duration); - - void HandleTimeUpdate(double playTime); - - void HandleBufferedEndTimeChanged(double bufferedEndTime); - - void HandleEnded(); - - void HandleNetworkStateChanged(NetworkState state); - - void HandleReadyStateChanged(ReadyState state); - - void HandleFullScreenChanged(bool isFullScreen); - - void HandleSeeking(); - - void HandleSeekFinished(); - - void HandleError(MediaError error, const std::string& message); - - void HandleVideoSizeChanged(double width, double height); - -private: - int32_t nwebId_ = -1; - std::shared_ptr handler_ = nullptr; -}; - class NWebCreateNativeMediaPlayerCallbackImpl : public NWebCreateNativeMediaPlayerCallback { public: explicit NWebCreateNativeMediaPlayerCallbackImpl(int32_t nwebId, napi_env env, napi_ref callback); diff --git a/interfaces/kits/nativecommon/BUILD.gn b/interfaces/kits/nativecommon/BUILD.gn index 52ac248438faa10ce6dffcf828a8ed0f12033641..2cda0eddfdca00b83c0cd2903f5da1f70f537869 100644 --- a/interfaces/kits/nativecommon/BUILD.gn +++ b/interfaces/kits/nativecommon/BUILD.gn @@ -30,6 +30,8 @@ ohos_shared_library("webview_common") { "web_message_port.h", "web_errors.cpp", "transfer_referenced_count.h", + "napi_native_mediaplayer_handler_impl.cpp", + "napi_native_mediaplayer_handler_impl.h", ] deps = [ @@ -58,4 +60,4 @@ ohos_shared_library("webview_common") { part_name = "webview" subsystem_name = "web" -} \ No newline at end of file +} diff --git a/interfaces/kits/nativecommon/napi_native_mediaplayer_handler_impl.cpp b/interfaces/kits/nativecommon/napi_native_mediaplayer_handler_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0416ff86b621e170885ca5dc7004edb5be33a936 --- /dev/null +++ b/interfaces/kits/nativecommon/napi_native_mediaplayer_handler_impl.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2025 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 "napi_native_mediaplayer_handler_impl.h" +#include "nweb_log.h" + +namespace OHOS::NWeb { + +NapiNativeMediaPlayerHandlerImpl::NapiNativeMediaPlayerHandlerImpl( + int32_t nwebId, std::shared_ptr handler) + : nwebId_(nwebId), handler_(handler) +{} + +void NapiNativeMediaPlayerHandlerImpl::HandleStatusChanged(PlaybackStatus status) +{ + WVLOG_D("begin to handle status changed,nweb id is %{public}d", nwebId_); + + if (handler_) { + handler_->HandleStatusChanged(status); + } +} + +void NapiNativeMediaPlayerHandlerImpl::HandleVolumeChanged(double volume) +{ + WVLOG_D("begin to handle volume changed,nweb id is %{public}d", nwebId_); + + if (handler_) { + handler_->HandleVolumeChanged(volume); + } +} + +void NapiNativeMediaPlayerHandlerImpl::HandleMutedChanged(bool isMuted) +{ + WVLOG_D("begin to handle muted changed,nweb id is %{public}d", nwebId_); + + if (handler_) { + handler_->HandleMutedChanged(isMuted); + } +} + +void NapiNativeMediaPlayerHandlerImpl::HandlePlaybackRateChanged(double playbackRate) +{ + WVLOG_D("begin to handle playback rate changed,nweb id is %{public}d", nwebId_); + + if (handler_) { + handler_->HandlePlaybackRateChanged(playbackRate); + } +} + +void NapiNativeMediaPlayerHandlerImpl::HandleDurationChanged(double duration) +{ + WVLOG_D("begin to handle duration changed,nweb id is %{public}d", nwebId_); + + if (handler_) { + handler_->HandleDurationChanged(duration); + } +} + +void NapiNativeMediaPlayerHandlerImpl::HandleTimeUpdate(double playTime) +{ + if (handler_) { + handler_->HandleTimeUpdate(playTime); + } +} + +void NapiNativeMediaPlayerHandlerImpl::HandleBufferedEndTimeChanged(double bufferedEndTime) +{ + WVLOG_D("begin to handle buffered end time changed,nweb id is %{public}d", nwebId_); + + if (handler_) { + handler_->HandleBufferedEndTimeChanged(bufferedEndTime); + } +} + +void NapiNativeMediaPlayerHandlerImpl::HandleEnded() +{ + WVLOG_D("begin to handle end,nweb id is %{public}d", nwebId_); + + if (handler_) { + handler_->HandleEnded(); + } +} + +void NapiNativeMediaPlayerHandlerImpl::HandleNetworkStateChanged(NetworkState state) +{ + WVLOG_D("begin to handle network state changed,nweb id is %{public}d", nwebId_); + + if (handler_) { + handler_->HandleNetworkStateChanged(state); + } +} + +void NapiNativeMediaPlayerHandlerImpl::HandleReadyStateChanged(ReadyState state) +{ + WVLOG_D("begin to handle ready state changed,nweb id is %{public}d", nwebId_); + + if (handler_) { + handler_->HandleReadyStateChanged(state); + } +} + +void NapiNativeMediaPlayerHandlerImpl::HandleFullScreenChanged(bool isFullScreen) +{ + WVLOG_D("begin to handle full screen changed,nweb id is %{public}d", nwebId_); + + if (handler_) { + handler_->HandleFullScreenChanged(isFullScreen); + } +} + +void NapiNativeMediaPlayerHandlerImpl::HandleSeeking() +{ + WVLOG_D("begin to handle seeking,nweb id is %{public}d", nwebId_); + + if (handler_) { + handler_->HandleSeeking(); + } +} + +void NapiNativeMediaPlayerHandlerImpl::HandleSeekFinished() +{ + WVLOG_D("begin to handle seek finished,nweb id is %{public}d", nwebId_); + + if (handler_) { + handler_->HandleSeekFinished(); + } +} + +void NapiNativeMediaPlayerHandlerImpl::HandleError(MediaError error, const std::string& message) +{ + WVLOG_D("begin to handle error,nweb id is %{public}d", nwebId_); + + if (handler_) { + handler_->HandleError(error, message); + } +} + +void NapiNativeMediaPlayerHandlerImpl::HandleVideoSizeChanged(double width, double height) +{ + WVLOG_D("begin to handle video size changed,nweb id is %{public}d", nwebId_); + + if (handler_) { + handler_->HandleVideoSizeChanged(width, height); + } +} + +} // namespace OHOS::NWeb diff --git a/interfaces/kits/nativecommon/napi_native_mediaplayer_handler_impl.h b/interfaces/kits/nativecommon/napi_native_mediaplayer_handler_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..67c3b5c8e7ece8777d75bd451d5a85e39ac72f35 --- /dev/null +++ b/interfaces/kits/nativecommon/napi_native_mediaplayer_handler_impl.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2025 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 NAPI_NATIVE_MEDIAPLAYER_HANDLER_IMPL_H +#define NAPI_NATIVE_MEDIAPLAYER_HANDLER_IMPL_H + +#include "nweb_native_media_player.h" +#include "napi_native_mediaplayer_handler_impl.h" +#include "transfer_referenced_count.h" + +namespace OHOS::NWeb { + +class NapiNativeMediaPlayerHandlerImpl : public TransferReferencedCount { +public: + NapiNativeMediaPlayerHandlerImpl(int32_t nwebId, std::shared_ptr handler); + ~NapiNativeMediaPlayerHandlerImpl() = default; + + void HandleStatusChanged(PlaybackStatus status); + + void HandleVolumeChanged(double volume); + + void HandleMutedChanged(bool isMuted); + + void HandlePlaybackRateChanged(double playbackRate); + + void HandleDurationChanged(double duration); + + void HandleTimeUpdate(double playTime); + + void HandleBufferedEndTimeChanged(double bufferedEndTime); + + void HandleEnded(); + + void HandleNetworkStateChanged(NetworkState state); + + void HandleReadyStateChanged(ReadyState state); + + void HandleFullScreenChanged(bool isFullScreen); + + void HandleSeeking(); + + void HandleSeekFinished(); + + void HandleError(MediaError error, const std::string& message); + + void HandleVideoSizeChanged(double width, double height); + +private: + int32_t nwebId_ = -1; + std::shared_ptr handler_ = nullptr; +}; + +} // namespace OHOS::NWeb + +#endif // NAPI_NATIVE_MEDIAPLAYER_HANDLER_IMPL_H diff --git a/ohos_adapter/ohos_native_buffer_adapter/src/ohos_native_buffer_adapter_impl.cpp b/ohos_adapter/ohos_native_buffer_adapter/src/ohos_native_buffer_adapter_impl.cpp index fb01ac4d853409afbf4b0825ca96a620a3ccc7ff..1ac6f0e59985f037a5b25a5ed22aa66243fdc5a5 100644 --- a/ohos_adapter/ohos_native_buffer_adapter/src/ohos_native_buffer_adapter_impl.cpp +++ b/ohos_adapter/ohos_native_buffer_adapter/src/ohos_native_buffer_adapter_impl.cpp @@ -82,6 +82,10 @@ int OhosNativeBufferAdapterImpl::GetEGLBuffer(void* buffer, void** eglBuffer) WVLOG_E("native buffer get egl buffer, buffer is null."); return -1; } + if (eglBuffer == nullptr) { + WVLOG_E("native buffer get egl buffer, eglBuffer pointer is null."); + return -1; + } WVLOG_D("native buffer GetEGLBuffer %{private}p.", buffer); OHNativeWindowBuffer* nativeWindowBuffer = @@ -115,6 +119,11 @@ int OhosNativeBufferAdapterImpl::NativeBufferFromNativeWindowBuffer(void* native return -1; } + if (nativeBuffer == nullptr) { + WVLOG_E("output nativeBuffer pointer is null"); + return -1; + } + *nativeBuffer = OH_NativeBufferFromNativeWindowBuffer(static_cast(nativeWindowBuffer)); if (*nativeBuffer == nullptr) { WVLOG_E("native buffer NativeBufferFromNativeWindowBuffer, native buffer is null."); @@ -140,6 +149,10 @@ void OhosNativeBufferAdapterImpl::Allocate( if (bufferConfig == nullptr) { return; } + if (outBuffer == nullptr) { + WVLOG_E("Output buffer pointer is null"); + return; + } int width = bufferConfig->GetBufferWidth(); int height = bufferConfig->GetBufferHeight(); int usage = bufferConfig->GetBufferUsage(); @@ -190,6 +203,11 @@ int OhosNativeBufferAdapterImpl::Lock(void* buffer, uint64_t usage, int32_t fenc return -1; } + if (out_virtual_address == nullptr) { + WVLOG_E("output address pointer is null."); + return -1; + } + if (IsBufferLocked(static_cast(buffer))) { WVLOG_D("native buffer lock - buffer already locked."); return -1; diff --git a/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp index 281462f150c14b18f0c8b59b6e768a415c1ff052..138cf2c076d95de6add1bce4ea77b139982029e8 100644 --- a/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp +++ b/ohos_adapter/sensor_adapter/src/sensor_adapter_impl.cpp @@ -15,6 +15,7 @@ #include "sensor_adapter_impl.h" +#include #include #include @@ -24,7 +25,6 @@ namespace OHOS::NWeb { std::unordered_map> SensorAdapterImpl::sensorCallbackMap; std::mutex SensorAdapterImpl::sensorCallbackMapMutex_; - constexpr double NANOSECONDS_IN_SECOND = 1000000000.0; constexpr double DEFAULT_SAMPLE_PERIOD = 200000000.0; @@ -133,7 +133,7 @@ double SensorAdapterImpl::GetOhosSensorDefaultSupportedFrequency(int32_t sensorT defaultFrequency = NANOSECONDS_IN_SECOND / DEFAULT_SAMPLE_PERIOD; } WVLOG_I("GetOhosSensorDefaultSupportedFrequency sensorTypeId: %{public}d, defaultFrequency: %{public}f", - sensorTypeId, defaultFrequency); + sensorTypeId, defaultFrequency); return defaultFrequency; } @@ -162,7 +162,7 @@ double SensorAdapterImpl::GetOhosSensorMinSupportedFrequency(int32_t sensorTypeI } } WVLOG_I("GetOhosSensorMinSupportedFrequency sensorTypeId: %{public}d, minFrequency: %{public}f", - sensorTypeId, minFrequency); + sensorTypeId, minFrequency); return minFrequency; } @@ -191,7 +191,7 @@ double SensorAdapterImpl::GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeI } } WVLOG_I("GetOhosSensorMaxSupportedFrequency sensorTypeId: %{public}d, maxFrequency: %{public}f", - sensorTypeId, maxFrequency); + sensorTypeId, maxFrequency); return maxFrequency; } @@ -321,15 +321,19 @@ void SensorAdapterImpl::OhosSensorCallback(SensorEvent* event) case SENSOR_TYPE_ID_ACCELEROMETER: handleAccelerometerData(callback, event); break; + case SENSOR_TYPE_ID_GRAVITY: handleGravityData(callback, event); break; + case SENSOR_TYPE_ID_LINEAR_ACCELERATION: handleLinearAccelerometerData(callback, event); break; + case SENSOR_TYPE_ID_GYROSCOPE: handleCyroscopeData(callback, event); break; + case SENSOR_TYPE_ID_MAGNETIC_FIELD: handleMagnetometerData(callback, event); break; @@ -342,6 +346,7 @@ void SensorAdapterImpl::OhosSensorCallback(SensorEvent* event) case SENSOR_TYPE_ID_GAME_ROTATION_VECTOR: handleGameRotationVectorData(callback, event); break; + default: break; } @@ -349,7 +354,8 @@ void SensorAdapterImpl::OhosSensorCallback(SensorEvent* event) int32_t SensorAdapterImpl::SubscribeOhosSensor(int32_t sensorTypeId, int64_t samplingInterval) { - WVLOG_I("SubscribeOhosSensor sensorTypeId: %{public}d", sensorTypeId); + WVLOG_I("SubscribeOhosSensor sensorTypeId: %{public}d, samplingInterval: %{public}" PRId64, + sensorTypeId, samplingInterval); if (samplingInterval <= 0) { WVLOG_E("SubscribeOhosSensor error, samplingInterval is invalid."); return SENSOR_PARAMETER_ERROR; @@ -361,7 +367,10 @@ int32_t SensorAdapterImpl::SubscribeOhosSensor(int32_t sensorTypeId, int64_t sam } std::string userName = SensorTypeToSensorUserName(sensorTypeId); - (void)strcpy_s(mSensorUser.name, sizeof(mSensorUser.name), userName.c_str()); + int cpyret = strcpy_s(mSensorUser.name, sizeof(mSensorUser.name), userName.c_str()); + if (cpyret != 0) { + WVLOG_E("SubscribeOhosSensor error, call strcpy_s ret = %{public}d.", cpyret); + } mSensorUser.userData = nullptr; mSensorUser.callback = &OhosSensorCallback; int32_t ret = SENSOR_SUCCESS; diff --git a/test/fuzztest/ohos_adapter/sensoradapter_fuzzer/sensoradapter_fuzz.cpp b/test/fuzztest/ohos_adapter/sensoradapter_fuzzer/sensoradapter_fuzz.cpp index c8a43ea3c77f1573c0a2520b19e24f5854ab24b7..8c7b783a957cca96a32e4944f5b5f4831e11a0b5 100644 --- a/test/fuzztest/ohos_adapter/sensoradapter_fuzzer/sensoradapter_fuzz.cpp +++ b/test/fuzztest/ohos_adapter/sensoradapter_fuzzer/sensoradapter_fuzz.cpp @@ -62,15 +62,12 @@ bool SensorAdapterFuzzTest(const uint8_t* data, size_t size) sensorAdapterImpl.RegistOhosSensorCallback(sensorTypeId, callbackAdapter); SensorEvent event; event.sensorTypeId = sensorTypeId; - uint8_t *sensorData = 0; - event.data = sensorData; + event.data = nullptr; sensorAdapterImpl.OhosSensorCallback(&event); sensorAdapterImpl.UnsubscribeOhosSensor(sensorTypeId); - delete[] sensorData; } SensorEvent event; - uint8_t *sensorData = 0; - event.data = sensorData; + event.data = nullptr; sensorAdapterImpl.handleAccelerometerData(callback, &event); sensorAdapterImpl.handleLinearAccelerometerData(callback, &event); sensorAdapterImpl.handleGravityData(callback, &event); @@ -79,7 +76,6 @@ bool SensorAdapterFuzzTest(const uint8_t* data, size_t size) sensorAdapterImpl.handleOrientationData(callback, &event); sensorAdapterImpl.handleRotationVectorData(callback, &event); sensorAdapterImpl.handleGameRotationVectorData(callback, &event); - delete[] sensorData; return true; } } // namespace NWeb