添加通话音量和系统音量,并将其声音调整放进线程中
authorluozheng <1732036298@qq.com>
Fri, 19 Apr 2024 12:46:23 +0000 (20:46 +0800)
committerluozheng <1732036298@qq.com>
Fri, 19 Apr 2024 12:46:23 +0000 (20:46 +0800)
17 files changed:
code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumePresenter.h
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumeView.h
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingC.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingView.h
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumeView.h
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumeView.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingView.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.cpp
code/sdk/drivers/peripheral/utils/custom_cmd_service.c
code/sdk/drivers/peripheral/utils/custom_utils.c
code/sdk/drivers/peripheral/utils/custom_utils.h

index 7d4794d..73afedd 100644 (file)
@@ -76,6 +76,8 @@
 #include "soundandvibration/include/SoundAndVibrationView.h"
 #include "soundandvibration/include/SystemVolumePresenter.h"
 #include "soundandvibration/include/SystemVolumeView.h"
+#include "soundandvibration/include/CallVolumePresenter.h"
+#include "soundandvibration/include/CallVolumeView.h"
 
 #include "displaybrightness/include/DisplayBrightnessPresenter.h"
 #include "displaybrightness/include/DisplayBrightnessView.h"
@@ -261,6 +263,7 @@ namespace OHOS
         {VIEW_SYSTEM, &NativeLauncher::InitSystemSlice},                              // 系统实例化地址
         {VIEW_SOUND_VIBRATION, &NativeLauncher::InitSoundAndVibrationSlice},          // 声音与震动实例化地址
         {VIEW_SYSTEM_VOLUME, &NativeLauncher::InitSystemVolumeSlice},                 // 系统音量
+        {VIEW_CALL_VOLUME, &NativeLauncher::InitCallVolumeSlice},                 // 系统音量
         {VIEW_CLASSIC_BLUETOOTH, &NativeLauncher::InitClassicBluetoothSlice},         // 经典蓝牙slice
         {VIEW_DISPLAY_BRIGHTNESS, &NativeLauncher::InitDisplayBrightnessSlice},       // 显示与亮度的实例化地址
         {VIEW_SECONDARY_FUNCTION, &NativeLauncher::InitSecondaryFunction},
@@ -707,6 +710,17 @@ namespace OHOS
         NativeAbility::GetInstance().AddSliceProxy(VIEW_SYSTEM_VOLUME, systemvolume);
     }
 
+    void NativeLauncher::InitCallVolumeSlice(void) // 系统音量
+    {
+        SliceProxy *callVolume = new AbilitySliceProxy<CallVolumeView, CallVolumePresenter>;
+        if (callVolume == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "callVolume");
+            return;
+        }
+        NativeAbility::GetInstance().AddSliceProxy(VIEW_CALL_VOLUME, callVolume);
+    }
+
     // DisplayBrightness的实例化
     void NativeLauncher::InitDisplayBrightnessSlice(void)
     {
index e009bcc..918a9e9 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com\r
  * @Date: 2024-01-29 16:24:23\r
  * @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-04-19 09:48:42\r
+ * @LastEditTime: 2024-04-19 15:17:28\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumePresenter.h\r
  */\r
 #ifndef CALL_VOLUME_PRESENTER_H\r
@@ -63,6 +63,7 @@ namespace OHOS
         // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;\r
         bool OnClick(UIView &view, const ClickEvent &event) override;\r
         bool OnDrag(UIView &view, const DragEvent &event) override;\r
+        bool OnDragEnd(UIView &view, const DragEvent &event);\r
         bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件\r
     };\r
 } // namespace OHOS\r
index ab271c7..14562a9 100644 (file)
@@ -2,11 +2,11 @@
  * @Author: luozheng 1732036298@qq.com\r
  * @Date: 2024-01-29 15:37:44\r
  * @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-04-19 09:41:56\r
+ * @LastEditTime: 2024-04-19 15:11:50\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumeView.h\r
  */\r
-#ifndef SYSTEM_VOLUME_VIEW_H\r
-#define SYSTEM_VOLUME_VIEW_H\r
+#ifndef CALL_VOLUME_VIEW_H\r
+#define CALL_VOLUME_VIEW_H\r
 \r
 #include "BaseView.h"\r
 #include "View.h"\r
@@ -14,7 +14,6 @@
 #include "soundandvibration/include/SoundAndVibrationVolumeSettingView.h"\r
 namespace OHOS\r
 {\r
-    static const char *SYSTEM_VOLUME_SLIDER = "CallVolumeSlider";\r
 \r
     class SoundAndVibrationVolumeSettingView;\r
     class CallVolumePresenter;\r
diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingC.h b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingC.h
new file mode 100644 (file)
index 0000000..0c06486
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-19 18:59:49
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-04-19 19:08:01
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingC.h
+ */
+#ifndef SOUND_AND_VIBRATION_VOLUME_SETTINGC_H
+#define SOUND_AND_VIBRATION_VOLUME_SETTINGC_H
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C"
+{
+#endif
+#endif
+#include <stdint.h>
+
+    void SystemVolumeSet(int16_t sounding);
+    void CallVolumeSet(int16_t sounding);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+#endif
index aad267d..30eb50f 100644 (file)
@@ -2,13 +2,16 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-19 10:08:21
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-19 10:22:53
+ * @LastEditTime: 2024-04-19 19:01:46
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h
  */
 #ifndef SOUND_AND_VIBRATION_VOLUME_SETTING_PRESENTER_H
 #define SOUND_AND_VIBRATION_VOLUME_SETTING_PRESENTER_H
 #include <cstdint>
 #include "components/ui_slider.h"
+#include "soundandvibration/include/SoundAndVibrationVolumeSettingView.h"
+#include "map"
+#include "memory"
 namespace OHOS
 {
     typedef enum : uint8_t
@@ -18,6 +21,15 @@ namespace OHOS
         OTHER = 2,        // 其他
     } VolumeStatusChange;
 
+    // 步骤 1: 定义策略接口.定义一个策略接口,所有的声音调整策略都需要实现这个接口
+    class SoundAndVibrationVolumeSettingView;
+    class VolumeChangeStrategy
+    {
+    public:
+        virtual void ApplyChange(SoundAndVibrationVolumeSettingView *view, UISlider *slider, uint8_t value) = 0;
+        virtual ~VolumeChangeStrategy() = default;
+    };
+
     /*
      * @brief 声音进度条的事件监听类
      */
@@ -30,15 +42,13 @@ namespace OHOS
         ~VoumeProcessSliderEventListener();
         static VoumeProcessSliderEventListener *GetInstance(void);
         void ChangeVolumeValue(uint8_t status, uint8_t value);
-        void LocalVolumeSet(int16_t sounding);
         void OnChange(int32_t value) override;
         void OnRelease(int32_t value) override;
         bool OnClick(UIView &view, const ClickEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
 
     private:
-        int32_t VolumeValue; // 声音值
-        uint8_t m_VolumeType;
+        std::map<uint8_t, std::shared_ptr<VolumeChangeStrategy>> strategyMap;
     };
 }
 
index bd17b2e..04f2fda 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-01-29 15:41:49
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-19 10:40:30
+ * @LastEditTime: 2024-04-19 15:22:04
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingView.h
  */
 #ifndef SOUND_AND_VIBRATION_VOLUME_SETTING_H
@@ -37,6 +37,7 @@ namespace OHOS
         UIScrollView *SetUpVolumeProcess(void);
         void ClearAll(void);
         UISlider *GetVolumeProcess(void);
+        int GetVolumeType(void);
         int CurrentVolumeValue{0};
 
     private:
index 9e802cc..b8b70da 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com\r
  * @Date: 2024-01-29 15:37:44\r
  * @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-04-19 10:17:28\r
+ * @LastEditTime: 2024-04-19 15:11:54\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumeView.h\r
  */\r
 #ifndef SYSTEM_VOLUME_VIEW_H\r
@@ -14,7 +14,6 @@
 #include "soundandvibration/include/SoundAndVibrationVolumeSettingView.h"\r
 namespace OHOS\r
 {\r
-    static const char *SYSTEM_VOLUME_SLIDER = "SystemVolumeSlider";\r
 \r
     class SoundAndVibrationVolumeSettingView;\r
     class SystemVolumePresenter;\r
index 748e8ad..04b3606 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com\r
  * @Date: 2024-03-30 09:14:38\r
  * @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-04-19 10:24:13\r
+ * @LastEditTime: 2024-04-19 15:17:16\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumePresenter.cpp\r
  */\r
 #include "AppViewIDs.h"\r
@@ -67,6 +67,7 @@ namespace OHOS
     bool CallVolumePresenter::OnDrag(UIView &view, const DragEvent &event)\r
     {\r
         UNUSED(view);\r
+        UNUSED(event);\r
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT &&\r
             (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY()))))\r
         {\r
@@ -75,6 +76,17 @@ namespace OHOS
         return true;\r
     }\r
 \r
+    bool CallVolumePresenter::OnDragEnd(UIView &view, const DragEvent &event)\r
+    {\r
+        UNUSED(view);\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnDragEnd");\r
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)\r
+        {\r
+            NativeAbility::GetInstance().Back();\r
+        }\r
+        return true;\r
+    }\r
+\r
     bool CallVolumePresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件\r
     {\r
         UNUSED(view);\r
index fb34437..1f32219 100644 (file)
@@ -2,6 +2,8 @@
 #include "soundandvibration/include/CallVolumePresenter.h"\r
 #include "wearable_log.h"\r
 #include <audio_manager.h>\r
+#include "phoneservice/include/PhoneAudio.h"\r
+#include "phoneservice/include/PhoneService.h"\r
 \r
 namespace OHOS\r
 {\r
@@ -63,8 +65,10 @@ namespace OHOS
             return nullptr;\r
         }\r
 \r
-        p_SoundAndVibrationVolumeSettingView->GetVolumeProcess()->SetValue(Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC));\r
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC) = %d",Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC));\r
+        // p_SoundAndVibrationVolumeSettingView->GetVolumeProcess()->SetValue(PhoneAudioGetVolume());\r
+        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallVolume = %d", PhoneAudioGetVolume());\r
+        p_SoundAndVibrationVolumeSettingView->GetVolumeProcess()->SetValue(GetCallCurrVolume());\r
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallVolume = %d", GetCallCurrVolume());\r
 \r
         initViewStatus = true;\r
         return CallVolumeScrollView;\r
@@ -73,7 +77,7 @@ namespace OHOS
     void CallVolumeView::OnStart()\r
     {\r
         View<CallVolumePresenter>::OnStart();\r
-        \r
+\r
         CallVolumeViewInit();\r
 \r
         RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::CallVolumePresenter::GetInstance();\r
index 8e5caf0..a6eac76 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com\r
  * @Date: 2024-02-19 10:39:11\r
  * @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-04-19 14:53:16\r
+ * @LastEditTime: 2024-04-19 15:10:49\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp\r
  */\r
 \r
@@ -124,7 +124,7 @@ namespace OHOS
         }\r
         else if (strcmp(view.GetViewId(), CALL_VOLUME_BUTTON) == 0)\r
         {\r
-            NativeAbility::GetInstance().EnterSlice(VIEW_SYSTEM_VOLUME);\r
+            NativeAbility::GetInstance().EnterSlice(VIEW_CALL_VOLUME);\r
         }\r
         else if (strcmp(view.GetViewId(), VIBRATION_REMINDER_BUTTON) == 0)\r
         {\r
index 094bca6..5752ebf 100644 (file)
@@ -2,23 +2,92 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-19 10:08:31
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-19 10:14:03
+ * @LastEditTime: 2024-04-19 19:01:17
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp
  */
 #include "soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h"
-#include "soundandvibration/include/SoundAndVibrationVolumeSettingView.h"
+#include "soundandvibration/include/SoundAndVibrationVolumeSettingC.h"
 #include "wearable_log.h"
 #include <audio_manager.h>
+#include <custom_utils.h>
+#include "phoneservice/include/PhoneAudio.h"
+#include "phoneservice/include/PhoneService.h"
 namespace OHOS
 {
 
-    /* --------------------- VoumeProcessSliderEventListener -------------------- */
-    constexpr int16_t VOLUMEVALUE_CHANGE = 10;
+    static constexpr int16_t VOLUMEVALUE_CHANGE = 10;
+    // 步骤 2: 实现具体的策略
+    class LowerVolumeStrategy : public VolumeChangeStrategy
+    {
+    public:
+        void ApplyChange(SoundAndVibrationVolumeSettingView *view, UISlider *slider, uint8_t value) override
+        {
+            uint16_t newVolumeValue = slider->GetValue() - VOLUMEVALUE_CHANGE;
+            if (newVolumeValue < VOLUME_MIN)
+            {
+                newVolumeValue = VOLUME_MIN;
+            }
+            if (view->GetVolumeType() == SYSTEM_VOLUME)
+            {
+                do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME, (void *)(value), sizeof(value));
+            }
+            else if (view->GetVolumeType() == CALL_VOLUME)
+            {
+                do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME, (void *)(value), sizeof(value));
+            }
+            slider->SetValue(newVolumeValue);
+        }
+    };
+
+    class ElevateVolumeStrategy : public VolumeChangeStrategy
+    {
+    public:
+        void ApplyChange(SoundAndVibrationVolumeSettingView *view, UISlider *slider, uint8_t value) override
+        {
+            uint16_t newVolumeValue = slider->GetValue() + VOLUMEVALUE_CHANGE;
+            if (newVolumeValue > VOLUME_MAX)
+            {
+                newVolumeValue = VOLUME_MAX;
+            }
+            if (view->GetVolumeType() == SYSTEM_VOLUME)
+            {
+                do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME, (void *)(value), sizeof(value));
+            }
+            else if (view->GetVolumeType() == CALL_VOLUME)
+            {
+                do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME, (void *)(value), sizeof(value));
+            }
+            slider->SetValue(newVolumeValue);
+        }
+    };
 
+    class DragVolumeStrategy : public VolumeChangeStrategy
+    {
+    public:
+        void ApplyChange(SoundAndVibrationVolumeSettingView *view, UISlider *slider, uint8_t value) override
+        {
+            if (view->GetVolumeType() == SYSTEM_VOLUME)
+            {
+                do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME, (void *)(value), sizeof(value));
+            }
+            else if (view->GetVolumeType() == CALL_VOLUME)
+            {
+
+                do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME, (void *)(value), sizeof(value));
+            }
+            slider->SetValue(value);
+        }
+    };
+
+    /* --------------------- VoumeProcessSliderEventListener -------------------- */
     static VoumeProcessSliderEventListener *g_pVoumeProcessSliderEventListener{nullptr};
     VoumeProcessSliderEventListener::VoumeProcessSliderEventListener()
     {
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::VoumeProcessSliderEventListener");
+        // 步骤 3: 创建一个映射表将状态映射到策略
+        strategyMap[VOLUMEREDUCE] = std::make_shared<LowerVolumeStrategy>();
+        strategyMap[VOLUMEADD] = std::make_shared<ElevateVolumeStrategy>();
+        strategyMap[OTHER] = std::make_shared<DragVolumeStrategy>();
         g_pVoumeProcessSliderEventListener = this;
     }
 
@@ -35,70 +104,21 @@ namespace OHOS
 
     void VoumeProcessSliderEventListener::ChangeVolumeValue(uint8_t status, uint8_t value)
     {
-
-        SoundAndVibrationVolumeSettingView *p_SoundAndVibrationVolumeSettingView = SoundAndVibrationVolumeSettingView::GetInstance();
-        if (p_SoundAndVibrationVolumeSettingView == nullptr)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationVolumeSettingView GetInstance fail!!");
-            return;
-        }
-        UISlider *progress = p_SoundAndVibrationVolumeSettingView->GetVolumeProcess();
-        if (progress == nullptr)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_SoundAndVibrationVolumeSettingView->GetVolumeProcess() fail");
-            return;
-        }
-
-        VolumeValue = p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue;
-
-        switch (status)
+        auto it = strategyMap.find(status);
+        if (it != strategyMap.end())
         {
-        case VOLUMEREDUCE:
-            /* code */
-            p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = progress->GetValue() - VOLUMEVALUE_CHANGE;
-            if (p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue < VOLUME_MIN)
+            SoundAndVibrationVolumeSettingView *view = SoundAndVibrationVolumeSettingView::GetInstance();
+            UISlider *slider = view ? view->GetVolumeProcess() : nullptr;
+            if (view && slider)
             {
-                p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = VOLUME_MIN;
+                it->second->ApplyChange(view, slider, value);
             }
-            break;
-        case VOLUMEADD:
-            p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = progress->GetValue() + VOLUMEVALUE_CHANGE;
-            if (p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue > VOLUME_MAX)
-            {
-                p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = VOLUME_MAX;
-            }
-            break;
-        case OTHER:
-            p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = value;
-            if (p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue < VOLUME_MIN)
-            {
-                p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = VOLUME_MIN;
-            }
-            else if (p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue > VOLUME_MAX)
-            {
-                p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = VOLUME_MAX;
-            }
-            break;
-        default:
-            break;
         }
-
-        progress->SetValue(p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue);
-        LocalVolumeSet(p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue);
-    }
-
-    /*
-     * @brief 本地音量设置
-     */
-    void VoumeProcessSliderEventListener::LocalVolumeSet(int16_t sounding)
-    {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LocalVolumeSet %d", sounding);
-        Audio::AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, sounding); // 本地音量设置
     }
 
     void VoumeProcessSliderEventListener::OnChange(int32_t value)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnChange %d", value);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnChange %d", value);
         ChangeVolumeValue(OTHER, value);
     }
 
@@ -121,5 +141,35 @@ namespace OHOS
         UNUSED(view);
         return true;
     }
+}
+#ifdef __cplusplus
+#if __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+    /*
+     * @brief 系统音量设置
+     */
+    void SystemVolumeSet(int16_t sounding)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemVolumeSet %d", sounding);
+        Audio::AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, sounding); // 系统音量设置
+    }
+
+    /*
+     * @brief 通话音量设置
+     */
+    void CallVolumeSet(int16_t sounding)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallVolumeSet %d", sounding);
+        // PhoneAudioSetVolume(sounding); // 通话音量音量设置
+        SetSpeakerVolume(sounding);
+    }
 
-}
\ No newline at end of file
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
\ No newline at end of file
index b2c1106..4b99b23 100644 (file)
@@ -8,7 +8,7 @@ namespace OHOS
 
     SoundAndVibrationVolumeSettingView::SoundAndVibrationVolumeSettingView(uint8_t VolumeType)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationVolumeSettingView::SoundAndVibrationVolumeSettingView,VolumeType = %d",VolumeType);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationVolumeSettingView::SoundAndVibrationVolumeSettingView,VolumeType = %d", VolumeType);
         m_VolumeType = VolumeType;
         g_pSoundAndVibrationVolumeSettingView = this;
     }
@@ -53,6 +53,15 @@ namespace OHOS
         return VolumeProcess;
     }
 
+    /*
+     * @brief 获取声音类型
+     * @return 返回 0 系统音量,返回 1 通话音量
+     */
+    int SoundAndVibrationVolumeSettingView::GetVolumeType(void)
+    {
+        return m_VolumeType;
+    }
+
     UIScrollView *SoundAndVibrationVolumeSettingView::SetUpVolumeProcess(void)
     {
         ScrollView = new UIScrollView();
index c5fab20..038860f 100644 (file)
@@ -68,8 +68,8 @@ namespace OHOS
         }\r
 \r
         p_SoundAndVibrationVolumeSettingView->GetVolumeProcess()->SetValue(Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC));\r
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC) = %d", Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC)); \r
-        \r
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemVolume = %d", Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC));\r
+\r
         initViewStatus = true;\r
         return SystemVolumeScrollView;\r
     }\r
index 984ee9c..8b1fa5e 100644 (file)
@@ -104,7 +104,7 @@ void cat1_ring_isr_callback(pin_t pin, uintptr_t param)
 {
     WEARABLE_LOGW(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1_ring_isr_callback %d 0x%X\n",pin,param);
     uapi_cat1_add_cat1_vote();
-    do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_REMOVE_CAT1VOTE);
+    do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_REMOVE_CAT1VOTE,NULL,0);
 }
 
 void uapi_cat1_wakeup_cat1(uint8_t wakeup)
index 6574e81..3110e1c 100644 (file)
@@ -34,7 +34,7 @@
 typedef struct
 {
     uint8_t cmd;
-    // uint8_t data[2];
+    uint8_t data[50];
 } custom_cmd_cmd_t;
 /***
  * 其他cmd在Header里定义,对外开放
@@ -43,18 +43,28 @@ typedef struct
 static bool g_bat_timer_is_running = false;
 static unsigned long g_custom_cmd_queue;
 
-
-
 static bool custom_cmd_service_running_stat = false;
 
-void do_custom_cmd_service_check_msg(int cmd)
+void do_custom_cmd_service_check_msg(int cmd, void *params, int paramlen)
 {
     int ret;
 
+    // 检查参数长度是否合法
+    if (paramlen > sizeof(custom_cmd_cmd_t) - sizeof(uint8_t))
+    {
+        PRINT("Error: 参数长度超过最大限制! \r\n");
+        return;
+    }
+
     custom_cmd_cmd_t mail = {0};
-    mail.cmd = cmd;
-    // mail.data[0] = data[0];
-    // mail.data[1] = data[1];
+    mail.cmd = (uint8_t)cmd;
+
+    // 将参数数据复制到结构体中
+    if (params && paramlen > 0)
+    {
+        memcpy(mail.data, params, paramlen);
+    }
+
     ret = osal_msg_queue_write_copy(g_custom_cmd_queue, (void *)&mail, sizeof(custom_cmd_cmd_t), 0);
     if (ret != OSAL_SUCCESS)
     {
@@ -64,12 +74,12 @@ void do_custom_cmd_service_check_msg(int cmd)
 
 static void custom_cmd_service_check_task(void const *arg)
 {
-    unused(arg);
+
     int32_t ret;
     custom_cmd_cmd_t mail;
     uint32_t msgsize = (uint32_t)sizeof(custom_cmd_cmd_t);
     custom_cmd_service_running_stat = true;
-    
+
     while (1)
     {
         ret = osal_msg_queue_read_copy(g_custom_cmd_queue, (void *)&mail, &msgsize,
@@ -79,14 +89,24 @@ static void custom_cmd_service_check_task(void const *arg)
             continue;
         }
 
-        if (mail.cmd == CUSTOM_CMD_MSG_TYPE_REMOVE_CAT1VOTE)
+        // 根据邮件中的命令进行相应的处理
+        switch (mail.cmd)
         {
+        case CUSTOM_CMD_MSG_TYPE_REMOVE_CAT1VOTE:
             restart_sleep_cat1_timer();
+            break;
+        case CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME:
+            //printf("mail.data: %d\n", *mail.data);
+            uapi_systemVolumeSet(mail.data);
+            break;
+        case CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME:
+            //printf("mail.data: %d\n", *mail.data);
+            uapi_callVolumeSet(mail.data);
+            break;
+        default:
+            PRINT("Unknown CUSTOM_CMD_MSG cmd 0x%02X \r\n", mail.cmd);
+            break;
         }
-        else 
-        {
-            PRINT("unknown CUSTOM_CMD_MSG cmd 0x%2X \r\n",mail.cmd);
-        }   
     }
 }
 #define CUSTOM_CMD_APP_BOARD_MSG_COUNT 10
index 76a1827..71207dd 100644 (file)
@@ -23,6 +23,7 @@
 #include "errcode.h"
 #include "power_display_service.h"
 #include "config/include/ConfigModelC.h"
+#include "soundandvibration/include/SoundAndVibrationVolumeSettingC.h"
 
 #define SUPPORT_NV
 
@@ -602,6 +603,18 @@ int32_t uapi_get_screen_state(void)
     return display_api->get_screen_state();
 }
 
+/*系统声音设置*/
+void uapi_systemVolumeSet(int16_t sounding)
+{
+    SystemVolumeSet(sounding);
+}
+
+//通话音量设置
+void uapi_callVolumeSet(int16_t sounding)
+{
+    CallVolumeSet(sounding);
+}
+
 #include "bts_le_gap.h"
 
 
index 606da3a..38d0842 100644 (file)
@@ -57,6 +57,9 @@ void uapi_setScreenDuration(int32_t time);
 
 int32_t uapi_get_screen_state(void);
 
+void uapi_systemVolumeSet(int16_t sounding);
+void uapi_callVolumeSet(int16_t sounding);
+
 errcode_t uapi_get_btaddr(uint8_t *buf_btaddr, uint32_t *len_btaddr);
 errcode_t uapi_get_btname(uint8_t *buf_btname, uint32_t *len_btname);
 errcode_t uapi_get_nv_btaddr(uint8_t *buf_btaddr, uint32_t *len_btaddr);
@@ -133,8 +136,10 @@ uint32_t uapi_calendar_store_date(void);
 
 
 #define CUSTOM_CMD_MSG_TYPE_REMOVE_CAT1VOTE 0x01
+#define CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME 0x02
+#define CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME 0x03
 errcode_t uapi_custom_cmd_service_init(void);
-void do_custom_cmd_service_check_msg(int cmd);
+void do_custom_cmd_service_check_msg(int cmd, void *params, int paramlen);
 
 #ifdef __cplusplus
 }