Bug 1954534 - Part 1. Move haptic feedback implementation to hal. r=geckoview-reviewers,gsvelto,ohall
Actually, nsIHapticFeedback is called on content process. Then it calls OS APIs on content process. So if is is isolated process, it doesn't work or it will crash. This patch moves haptic feedback implementation to hal to call OS APIs on chrome process, like vibration. Differential Revision: https://phabricator.services.mozilla.com/D241929
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsHapticFeedback.h"
|
||||
#include "mozilla/java/GeckoAppShellWrappers.h"
|
||||
#include "mozilla/Hal.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
@@ -13,6 +13,6 @@ NS_IMPL_ISUPPORTS(nsHapticFeedback, nsIHapticFeedback)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHapticFeedback::PerformSimpleAction(int32_t aType) {
|
||||
java::GeckoAppShell::PerformHapticFeedback(aType == LongPress);
|
||||
hal::PerformHapticFeedback(aType);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -9,3 +9,6 @@ skip-if = [
|
||||
"os == 'android'",
|
||||
"condprof", #: "Only focused window should get the sensor events"
|
||||
]
|
||||
|
||||
["test_HapticFeedback.html"]
|
||||
run-if = ["android"] # Haptic feedback is only supported on Android
|
||||
|
||||
29
dom/system/tests/test_HapticFeedback.html
Normal file
29
dom/system/tests/test_HapticFeedback.html
Normal file
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE HTML>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1954534
|
||||
-->
|
||||
<html>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for HapticFeedback</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1954534">Mozilla Bug 1954534</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
</div>
|
||||
<pre id="test"></pre>
|
||||
<script>
|
||||
add_task(() => {
|
||||
// Don't crash performSimpleAction.
|
||||
const Cc = SpecialPowers.Cc;
|
||||
const Ci = SpecialPowers.Ci;
|
||||
let hapticFeedback = Cc["@mozilla.org/widget/hapticfeedback;1"].getService(Ci.nsIHapticFeedback);
|
||||
hapticFeedback.performSimpleAction(Ci.nsIHapticFeedback.ShortPress);
|
||||
hapticFeedback.performSimpleAction(Ci.nsIHapticFeedback.LongPress);
|
||||
ok(true, "HapticFeedback performed");
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -421,6 +421,10 @@ const Maybe<hal::HeterogeneousCpuInfo>& GetHeterogeneousCpuInfo() {
|
||||
return hal_impl::GetHeterogeneousCpuInfo();
|
||||
}
|
||||
|
||||
void PerformHapticFeedback(int32_t aType) {
|
||||
PROXY_IF_SANDBOXED(PerformHapticFeedback(aType));
|
||||
}
|
||||
|
||||
void Init() {
|
||||
MOZ_ASSERT(!sInitialized);
|
||||
|
||||
|
||||
@@ -250,6 +250,11 @@ UniquePtr<hal::PerformanceHintSession> CreatePerformanceHintSession(
|
||||
*/
|
||||
const Maybe<hal::HeterogeneousCpuInfo>& GetHeterogeneousCpuInfo();
|
||||
|
||||
/**
|
||||
* Perform haptic feedback
|
||||
*/
|
||||
void PerformHapticFeedback(int32_t aType);
|
||||
|
||||
} // namespace MOZ_HAL_NAMESPACE
|
||||
} // namespace mozilla
|
||||
|
||||
|
||||
18
hal/android/AndroidHapticFeedback.cpp
Normal file
18
hal/android/AndroidHapticFeedback.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set sw=2 ts=8 et ft=cpp : */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "Hal.h"
|
||||
#include "mozilla/java/GeckoAppShellWrappers.h"
|
||||
#include "nsIHapticFeedback.h"
|
||||
|
||||
namespace mozilla::hal_impl {
|
||||
|
||||
void PerformHapticFeedback(int32_t aType) {
|
||||
java::GeckoAppShell::PerformHapticFeedback(aType ==
|
||||
nsIHapticFeedback::LongPress);
|
||||
}
|
||||
|
||||
} // namespace mozilla::hal_impl
|
||||
13
hal/fallback/FallbackHapticFeedback.cpp
Normal file
13
hal/fallback/FallbackHapticFeedback.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set sw=2 ts=8 et ft=cpp : */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "Hal.h"
|
||||
|
||||
namespace mozilla::hal_impl {
|
||||
|
||||
void PerformHapticFeedback(int32_t aType) {}
|
||||
|
||||
} // namespace mozilla::hal_impl
|
||||
@@ -37,6 +37,7 @@ if CONFIG["MOZ_WIDGET_TOOLKIT"] == "android":
|
||||
"/widget/android",
|
||||
]
|
||||
UNIFIED_SOURCES += [
|
||||
"android/AndroidHapticFeedback.cpp",
|
||||
"android/AndroidHeterogeneousCpuInfo.cpp",
|
||||
"android/AndroidPerformanceHintManager.cpp",
|
||||
"android/AndroidProcessPriority.cpp",
|
||||
@@ -111,6 +112,7 @@ else:
|
||||
# Fallbacks for backends implemented on Android only.
|
||||
if CONFIG["MOZ_WIDGET_TOOLKIT"] != "android":
|
||||
UNIFIED_SOURCES += [
|
||||
"fallback/FallbackHapticFeedback.cpp",
|
||||
"fallback/FallbackNetwork.cpp",
|
||||
"fallback/FallbackPerformanceHintManager.cpp",
|
||||
]
|
||||
|
||||
@@ -84,6 +84,8 @@ parent:
|
||||
returns (nsresult result);
|
||||
async UnlockScreenOrientation();
|
||||
|
||||
async PerformHapticFeedback(int32_t aType);
|
||||
|
||||
child:
|
||||
async NotifySensorChange(SensorData aSensorData);
|
||||
|
||||
|
||||
@@ -135,6 +135,10 @@ void SetProcessPriority(int aPid, ProcessPriority aPriority) {
|
||||
MOZ_CRASH("Only the main process may set processes' priorities.");
|
||||
}
|
||||
|
||||
void PerformHapticFeedback(int32_t aType) {
|
||||
Hal()->SendPerformHapticFeedback(aType);
|
||||
}
|
||||
|
||||
class HalParent : public PHalParent,
|
||||
public BatteryObserver,
|
||||
public NetworkObserver,
|
||||
@@ -295,6 +299,12 @@ class HalParent : public PHalParent,
|
||||
void Notify(const WakeLockInformation& aWakeLockInfo) override {
|
||||
Unused << SendNotifyWakeLockChange(aWakeLockInfo);
|
||||
}
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvPerformHapticFeedback(
|
||||
const int32_t& aType) override {
|
||||
hal::PerformHapticFeedback(aType);
|
||||
return IPC_OK();
|
||||
}
|
||||
};
|
||||
|
||||
class HalChild : public PHalChild {
|
||||
|
||||
Reference in New Issue
Block a user