mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 02:57:38 +00:00
Bug 1885936 - Part 3: Implement data collection for gamepads. r=tschuster
Differential Revision: https://phabricator.services.mozilla.com/D207981
This commit is contained in:
parent
42a0516b08
commit
9569667862
@ -40,13 +40,45 @@ export class UserCharacteristicsChild extends JSWindowActorChild {
|
||||
// that requires loading time.
|
||||
async collectUserCharacteristicsDataWithDelay() {
|
||||
lazy.console.debug("Calling collectUserCharacteristicsDataWithDelay()");
|
||||
|
||||
await this.populateGamepadsInfo();
|
||||
}
|
||||
|
||||
async populateGamepadsInfo() {
|
||||
lazy.console.debug("Calling populateGamepadsInfo()");
|
||||
let gamepads = await this.contentWindow.navigator.requestAllGamepads();
|
||||
|
||||
lazy.console.debug(`Found ${gamepads.length} gamepads`);
|
||||
|
||||
let gamepadsInfo = [];
|
||||
|
||||
for (const gamepad of gamepads) {
|
||||
// We use an array to represent a gamepad device because it uses less size
|
||||
// then an object when convert to a JSON string. So, we can fit the string
|
||||
// into a Glean string which has a 100 size limitation.
|
||||
let data = [];
|
||||
data.push(gamepad.id);
|
||||
data.push(gamepad?.hand ?? "");
|
||||
data.push(gamepad.buttons.length);
|
||||
data.push(gamepad.axes?.length ?? 0);
|
||||
data.push(gamepad.hapticActuators?.length ?? 0);
|
||||
data.push(gamepad.lightIndicators?.length ?? 0);
|
||||
data.push(gamepad.touchEvents?.length ?? 0);
|
||||
|
||||
gamepadsInfo.push(JSON.stringify(data));
|
||||
}
|
||||
|
||||
lazy.console.debug(`Reporting gamepad: ${gamepadsInfo}`);
|
||||
this.userDataDetails.output.gamepads = gamepadsInfo;
|
||||
}
|
||||
|
||||
async handleEvent(event) {
|
||||
lazy.console.debug("Got ", event.type);
|
||||
switch (event.type) {
|
||||
case "UserCharacteristicsDataDone":
|
||||
this.userDataDetails = event.detail;
|
||||
// Clone the data so we can modify it. Otherwise, we cannot change it
|
||||
// because it's behind Xray wrapper.
|
||||
this.userDataDetails = structuredClone(event.detail);
|
||||
|
||||
await this.collectUserCharacteristicsData();
|
||||
|
||||
|
@ -181,6 +181,10 @@ export class UserCharacteristicsPageService {
|
||||
lazy.console.debug("Populating Glean metrics...");
|
||||
Glean.characteristics.timezone.set(data.output.foo);
|
||||
|
||||
for (let gamepad of data.output.gamepads) {
|
||||
Glean.characteristics.gamepads.add(gamepad);
|
||||
}
|
||||
|
||||
lazy.console.debug("Unregistering actor");
|
||||
Services.obs.notifyObservers(
|
||||
null,
|
||||
|
@ -25,6 +25,17 @@ function debug(...args) {
|
||||
debug("Debug Line");
|
||||
debug("Another debug line, with", { an: "object" });
|
||||
|
||||
// A hacky way to ensure all GamePad related services are running by the time we
|
||||
// want to know about GamePads. This will attach a listener for this window to
|
||||
// the GamePadManager, creating it if it doesn't exist. When GamePadManager is
|
||||
// created (either now or earlier) it will also create a GamePadEventChannel
|
||||
// between the GamePadManager and the parent process. When that's created, the
|
||||
// Parent will create a GamePadPlatformService if it's not already created, and
|
||||
// when that Service gets created it kicks off a background thread to monitor
|
||||
// for gamepads attached to the machine. We need to give that background thread
|
||||
// time to run so all the data is there when we request it.
|
||||
navigator.getGamepads();
|
||||
|
||||
// The first time we put a real value in here, please update browser_usercharacteristics.js
|
||||
let output = {
|
||||
foo: "Hello World",
|
||||
|
@ -534,6 +534,33 @@ characteristics:
|
||||
data_sensitivity:
|
||||
- technical
|
||||
|
||||
gamepads:
|
||||
type: string_list
|
||||
description: >
|
||||
The information of the gamepads inserted on the user device. Each string
|
||||
represents one gamepad. We use a JSON array to describe a gamepad, every
|
||||
value represents one property of the gamepad. Following are the details:
|
||||
index 0: The ID of the game pad
|
||||
index 1: Which hand for the gamepad.
|
||||
index 2: Number of buttons
|
||||
index 3: Number of axes
|
||||
index 4: Number of haptics
|
||||
index 5: Number of lights
|
||||
index 6: Number of touches
|
||||
lifetime: application
|
||||
send_in_pings:
|
||||
- user-characteristics
|
||||
notification_emails:
|
||||
- tom@mozilla.com
|
||||
- tihuang@mozilla.com
|
||||
bugs:
|
||||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1885936
|
||||
data_reviews:
|
||||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1885936#c2
|
||||
expires: never
|
||||
data_sensitivity:
|
||||
- technical
|
||||
|
||||
prefs_intl_accept_languages:
|
||||
type: string
|
||||
description: >
|
||||
|
Loading…
Reference in New Issue
Block a user