Add vibration capabilities in PWRT 67/190167/11
authorsurya.kumar7 <surya.kumar7@samsung.com>
Thu, 27 Sep 2018 13:30:44 +0000 (19:00 +0530)
committerjaekuk lee <juku1999@samsung.com>
Fri, 28 Sep 2018 09:44:34 +0000 (09:44 +0000)
PWRT as the client is responsible for listening to events from
VibrationManager and call appropriate system APIs for vibration
without which tct-vibration-w3c-tests fails

Depends on https://review.tizen.org/gerrit/#/c/190168/

Change-Id: I2964136795a04adeb26e45c3b32797dd6a0aee08
Signed-off-by: surya.kumar7 <surya.kumar7@samsung.com>
efl/build/system.gyp
packaging/electron-efl.spec
tizen/browser/tizen_browser_parts.cc
tizen/browser/vibration_manager.cc [new file with mode: 0644]
tizen/browser/vibration_manager.h [new file with mode: 0644]
wrt.gyp

index 4b56c0d9a188594e1f8e7e5bb8a787a0e5a012d2..3b40764969eddbd400796bcfd29dcbf42459e14c 100644 (file)
         }],
       ],
     }, # tts
+    {
+      'target_name': 'capi-system-device',
+      'type': 'none',
+      'conditions': [
+        ['is_tizen==1', {
+          'direct_dependent_settings': {
+            'cflags': [
+              '<!@(<(pkg-config) --cflags capi-system-device)',
+            ],
+          },
+          'link_settings': {
+            'ldflags': [
+              '<!@(<(pkg-config) --libs-only-L --libs-only-other capi-system-device)',
+            ],
+            'libraries': [
+              '<!@(<(pkg-config) --libs-only-l capi-system-device)',
+            ],
+          },
+        }],
+      ],
+    }, # capi-system-device
   ],
 }
index 137348edcfa83b9bd03adc4b81bbb23f7b41c661..a9d599e1b23cbdeee5caf6cc40c615f4441e1aae 100755 (executable)
@@ -23,6 +23,7 @@ BuildRequires: pkgconfig(bundle)
 BuildRequires: pkgconfig(capi-appfw-application)
 BuildRequires: pkgconfig(capi-appfw-app-manager)
 BuildRequires: pkgconfig(capi-appfw-package-manager)
+BuildRequires: pkgconfig(capi-system-device)
 BuildRequires: pkgconfig(capi-system-system-settings)
 BuildRequires: pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(chromium-efl)
index d7c882ad593d49df90a9d54d7c0e2cb43e98b634..afae16881921ebe81605fee1c96edad7963e9b2b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
 #include "atom/common/api/api_messages.h"
 #include "common/string_utils.h"
 #include "tizen/browser/tizen_browser_parts.h"
+#include "tizen/browser/vibration_manager.h"
 
 #if defined(TIZEN_VIDEO_HOLE)
 #include "atom/browser/native_window_efl.h"
@@ -82,6 +83,7 @@ void TizenBrowserParts::Initialize() {
   } else {
     security_model_version_ = 1;
   }
+  tizen::VibrationManager::CreateInstance();
 }
 
 void TizenBrowserParts::GetCSP(std::string &csp_rule, std::string &csp_report_rule) {
diff --git a/tizen/browser/vibration_manager.cc b/tizen/browser/vibration_manager.cc
new file mode 100644 (file)
index 0000000..edc1889
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    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 "base/logging.h"
+#include "device/vibration/vibration_manager_impl_efl.h"
+#include "tizen/browser/vibration_manager.h"
+
+namespace tizen {
+
+VibrationManager::VibrationManager() : handle_(0) {
+  device::VibrationManagerImplEfl::RegisterProviderClient(this);
+}
+
+void VibrationManager::CreateInstance() {
+  static VibrationManager* vibration_provider_client = NULL;
+  // vibration_provider_client is deleted by device::VibrationProviderClient
+  if (!vibration_provider_client)
+    vibration_provider_client = new VibrationManager;
+}
+
+VibrationManager::~VibrationManager() {
+  LOG(INFO) << "~VibrationManager";
+  if (handle_ != 0) {
+    device_haptic_close(handle_);
+    handle_ = 0;
+  }
+}
+
+bool VibrationManager::Initialize() {
+  if (handle_ != 0)
+    return true;
+
+  int ret = device_haptic_open(0, &handle_);
+  if (ret != DEVICE_ERROR_NONE) {
+    LOG(ERROR) << "Fail to open haptic device";
+    handle_ = 0;
+    return false;
+  }
+  LOG(INFO) << "Device Haptic open successful";
+  return true;
+}
+
+void VibrationManager::Vibrate(uint64_t ms) {
+  if (Initialize()) {
+    LOG(INFO) << "Device Vibration Start";
+    device_haptic_vibrate(handle_, ms, 100, NULL);
+  }
+}
+
+void VibrationManager::CancelVibration() {
+  if (Initialize()) {
+    LOG(INFO) << "Device Vibration Stop";
+    device_haptic_stop(handle_, NULL);
+  }
+}
+
+} // namespace tizen
\ No newline at end of file
diff --git a/tizen/browser/vibration_manager.h b/tizen/browser/vibration_manager.h
new file mode 100644 (file)
index 0000000..57c3108
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    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 TIZEN_BROWSER_VIBRATION_MANAGER_H_
+#define TIZEN_BROWSER_VIBRATION_MANAGER_H_
+
+#include <device/haptic.h>
+#include "device/vibration/vibration_provider_client.h"
+
+namespace tizen {
+
+class VibrationManager : public device::VibrationProviderClient {
+ public:
+ static void CreateInstance();
+  VibrationManager();
+  /**
+   * Starts the vibration for the given amount of time
+   *
+   * @param vibrationTime amount of time for which vibration should happen
+   */
+  void Vibrate(uint64_t vibrationTime) override;
+
+  /**
+   * Cancels the vibration
+   */
+  void CancelVibration() override;
+  virtual ~VibrationManager();
+ private:
+  bool Initialize();
+  // haptic_devce_h was declared as int
+  haptic_device_h handle_;
+};
+
+} // namespace tizen
+
+#endif  // TIZEN_BROWSER_VIBRATION_MANAGER_H_
diff --git a/wrt.gyp b/wrt.gyp
index 9fef526387d27ad58ffd4d81285cbd5b916e423d..89ca83312d74ff6e6227f110ef418bcbee1e6b4b 100644 (file)
--- a/wrt.gyp
+++ b/wrt.gyp
@@ -18,6 +18,7 @@
         '<(DEPTH)/efl/build/system.gyp:ecore',
         '<(DEPTH)/efl/build/system.gyp:launchpad',
         '<(DEPTH)/efl/build/system.gyp:capi-appfw-application',
+        '<(DEPTH)/efl/build/system.gyp:capi-system-device',
         '<(DEPTH)/efl/build/system.gyp:elementary',
         '<(DEPTH)/efl/build/system.gyp:tts',
         'electron_shell_copy',
@@ -55,6 +56,7 @@
       'dependencies': [
         'wrt_lib',
         '<(DEPTH)/efl/build/system.gyp:capi-appfw-application',
+        '<(DEPTH)/efl/build/system.gyp:capi-system-device',
         '<(DEPTH)/tizen/common/common.gyp:wrt_common',
       ],
       'sources': [
         'tizen/src/browser/wrt_service.h',
         'tizen/browser/tizen_browser_parts.cc',
         'tizen/browser/tizen_browser_parts.h',
+        'tizen/browser/vibration_manager.cc',
+        'tizen/browser/vibration_manager.h',
       ],
       'sources/': [
         # chromium-efl supports only tizen webrtc using CAPI