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:
Makoto Kato
2025-03-26 10:16:25 +00:00
parent b3f32df67e
commit 736f125c7e
10 changed files with 88 additions and 2 deletions

View File

@@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsHapticFeedback.h" #include "nsHapticFeedback.h"
#include "mozilla/java/GeckoAppShellWrappers.h" #include "mozilla/Hal.h"
using namespace mozilla; using namespace mozilla;
@@ -13,6 +13,6 @@ NS_IMPL_ISUPPORTS(nsHapticFeedback, nsIHapticFeedback)
NS_IMETHODIMP NS_IMETHODIMP
nsHapticFeedback::PerformSimpleAction(int32_t aType) { nsHapticFeedback::PerformSimpleAction(int32_t aType) {
java::GeckoAppShell::PerformHapticFeedback(aType == LongPress); hal::PerformHapticFeedback(aType);
return NS_OK; return NS_OK;
} }

View File

@@ -9,3 +9,6 @@ skip-if = [
"os == 'android'", "os == 'android'",
"condprof", #: "Only focused window should get the sensor events" "condprof", #: "Only focused window should get the sensor events"
] ]
["test_HapticFeedback.html"]
run-if = ["android"] # Haptic feedback is only supported on Android

View 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>

View File

@@ -421,6 +421,10 @@ const Maybe<hal::HeterogeneousCpuInfo>& GetHeterogeneousCpuInfo() {
return hal_impl::GetHeterogeneousCpuInfo(); return hal_impl::GetHeterogeneousCpuInfo();
} }
void PerformHapticFeedback(int32_t aType) {
PROXY_IF_SANDBOXED(PerformHapticFeedback(aType));
}
void Init() { void Init() {
MOZ_ASSERT(!sInitialized); MOZ_ASSERT(!sInitialized);

View File

@@ -250,6 +250,11 @@ UniquePtr<hal::PerformanceHintSession> CreatePerformanceHintSession(
*/ */
const Maybe<hal::HeterogeneousCpuInfo>& GetHeterogeneousCpuInfo(); const Maybe<hal::HeterogeneousCpuInfo>& GetHeterogeneousCpuInfo();
/**
* Perform haptic feedback
*/
void PerformHapticFeedback(int32_t aType);
} // namespace MOZ_HAL_NAMESPACE } // namespace MOZ_HAL_NAMESPACE
} // namespace mozilla } // namespace mozilla

View 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

View 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

View File

@@ -37,6 +37,7 @@ if CONFIG["MOZ_WIDGET_TOOLKIT"] == "android":
"/widget/android", "/widget/android",
] ]
UNIFIED_SOURCES += [ UNIFIED_SOURCES += [
"android/AndroidHapticFeedback.cpp",
"android/AndroidHeterogeneousCpuInfo.cpp", "android/AndroidHeterogeneousCpuInfo.cpp",
"android/AndroidPerformanceHintManager.cpp", "android/AndroidPerformanceHintManager.cpp",
"android/AndroidProcessPriority.cpp", "android/AndroidProcessPriority.cpp",
@@ -111,6 +112,7 @@ else:
# Fallbacks for backends implemented on Android only. # Fallbacks for backends implemented on Android only.
if CONFIG["MOZ_WIDGET_TOOLKIT"] != "android": if CONFIG["MOZ_WIDGET_TOOLKIT"] != "android":
UNIFIED_SOURCES += [ UNIFIED_SOURCES += [
"fallback/FallbackHapticFeedback.cpp",
"fallback/FallbackNetwork.cpp", "fallback/FallbackNetwork.cpp",
"fallback/FallbackPerformanceHintManager.cpp", "fallback/FallbackPerformanceHintManager.cpp",
] ]

View File

@@ -84,6 +84,8 @@ parent:
returns (nsresult result); returns (nsresult result);
async UnlockScreenOrientation(); async UnlockScreenOrientation();
async PerformHapticFeedback(int32_t aType);
child: child:
async NotifySensorChange(SensorData aSensorData); async NotifySensorChange(SensorData aSensorData);

View File

@@ -135,6 +135,10 @@ void SetProcessPriority(int aPid, ProcessPriority aPriority) {
MOZ_CRASH("Only the main process may set processes' priorities."); MOZ_CRASH("Only the main process may set processes' priorities.");
} }
void PerformHapticFeedback(int32_t aType) {
Hal()->SendPerformHapticFeedback(aType);
}
class HalParent : public PHalParent, class HalParent : public PHalParent,
public BatteryObserver, public BatteryObserver,
public NetworkObserver, public NetworkObserver,
@@ -295,6 +299,12 @@ class HalParent : public PHalParent,
void Notify(const WakeLockInformation& aWakeLockInfo) override { void Notify(const WakeLockInformation& aWakeLockInfo) override {
Unused << SendNotifyWakeLockChange(aWakeLockInfo); Unused << SendNotifyWakeLockChange(aWakeLockInfo);
} }
virtual mozilla::ipc::IPCResult RecvPerformHapticFeedback(
const int32_t& aType) override {
hal::PerformHapticFeedback(aType);
return IPC_OK();
}
}; };
class HalChild : public PHalChild { class HalChild : public PHalChild {