Bug 1289208 - Move gamepad methods out of GeckoAppShell; r=snorp
authorJim Chen <nchen@mozilla.com>
Thu, 04 Aug 2016 09:16:05 -0400
changeset 308202 10231cdd4c76ed742f12b021547768817bf4e748
parent 308201 388d4af4b1b15ef552462555bb180881bf04bf07
child 308203 c016f9d74449dbafc76c8bcd207c37794f72cb56
push id31092
push usercbook@mozilla.com
push dateFri, 05 Aug 2016 10:16:59 +0000
treeherderautoland@b97dd7dd3cb9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1289208
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1289208 - Move gamepad methods out of GeckoAppShell; r=snorp Move gamepad methods called by native code out of GeckoAppShell and into AndroidGamepadManager.
dom/gamepad/android/AndroidGamepad.cpp
mobile/android/geckoview/src/main/java/org/mozilla/gecko/AndroidGamepadManager.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
widget/android/nsAppShell.cpp
--- a/dom/gamepad/android/AndroidGamepad.cpp
+++ b/dom/gamepad/android/AndroidGamepad.cpp
@@ -6,18 +6,18 @@
 
 #include "GeneratedJNIWrappers.h"
 
 namespace mozilla {
 namespace dom {
 
 void StartGamepadMonitoring()
 {
-  java::GeckoAppShell::StartMonitoringGamepad();
+  java::AndroidGamepadManager::Start();
 }
 
 void StopGamepadMonitoring()
 {
-  java::GeckoAppShell::StopMonitoringGamepad();
+  java::AndroidGamepadManager::Stop();
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/AndroidGamepadManager.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/AndroidGamepadManager.java
@@ -132,36 +132,66 @@ public class AndroidGamepadManager {
     private static final SparseArray<Gamepad> sGamepads = new SparseArray<>();
     private static final SparseArray<List<KeyEvent>> sPendingGamepads = new SparseArray<>();
     private static InputManager.InputDeviceListener sListener;
     private static Timer sPollTimer;
 
     private AndroidGamepadManager() {
     }
 
-    public static void startup() {
+    @WrapForJNI(allowMultithread = true)
+    private static void start() {
+        ThreadUtils.postToUiThread(new Runnable() {
+            @Override
+            public void run() {
+                doStart();
+            }
+        });
+    }
+
+    /* package */ static void doStart() {
         ThreadUtils.assertOnUiThread();
         if (!sStarted) {
             scanForGamepads();
             addDeviceListener();
             sStarted = true;
         }
     }
 
-    public static void shutdown() {
+    @WrapForJNI(allowMultithread = true)
+    private static void stop() {
+        ThreadUtils.postToUiThread(new Runnable() {
+            @Override
+            public void run() {
+                doStop();
+            }
+        });
+    }
+
+    /* package */ static void doStop() {
         ThreadUtils.assertOnUiThread();
         if (sStarted) {
             removeDeviceListener();
             sPendingGamepads.clear();
             sGamepads.clear();
             sStarted = false;
         }
     }
 
-    public static void gamepadAdded(int deviceId, int serviceId) {
+    @WrapForJNI
+    private static void onGamepadAdded(final int device_id, final int service_id) {
+        ThreadUtils.postToUiThread(new Runnable() {
+            @Override
+            public void run() {
+                handleGamepadAdded(device_id, service_id);
+            }
+        });
+    }
+
+    /* package */ static void handleGamepadAdded(int deviceId, int serviceId) {
         ThreadUtils.assertOnUiThread();
         if (!sStarted) {
             return;
         }
 
         final List<KeyEvent> pending = sPendingGamepads.get(deviceId);
         if (pending == null) {
             removeGamepad(deviceId);
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -856,46 +856,16 @@ public class GeckoAppShell
             }
             break;
         default:
             Log.w(LOGTAG, "Error! Can't disable unknown SENSOR type " + aSensortype);
         }
     }
 
     @WrapForJNI
-    public static void startMonitoringGamepad() {
-        ThreadUtils.postToUiThread(new Runnable() {
-                @Override
-                public void run() {
-                    AndroidGamepadManager.startup();
-                }
-            });
-    }
-
-    @WrapForJNI
-    public static void stopMonitoringGamepad() {
-        ThreadUtils.postToUiThread(new Runnable() {
-                @Override
-                public void run() {
-                    AndroidGamepadManager.shutdown();
-                }
-            });
-    }
-
-    @WrapForJNI
-    public static void gamepadAdded(final int device_id, final int service_id) {
-        ThreadUtils.postToUiThread(new Runnable() {
-                @Override
-                public void run() {
-                    AndroidGamepadManager.gamepadAdded(device_id, service_id);
-                }
-            });
-    }
-
-    @WrapForJNI
     public static void moveTaskToBack() {
         if (getGeckoInterface() != null)
             getGeckoInterface().getActivity().moveTaskToBack(true);
     }
 
     @WrapForJNI
     public static void scheduleRestart() {
         getGeckoInterface().doRestart();
--- a/widget/android/nsAppShell.cpp
+++ b/widget/android/nsAppShell.cpp
@@ -701,17 +701,17 @@ nsAppShell::LegacyGeckoEvent::Run()
             if (!service) {
               break;
             }
             if (curEvent->Action() == AndroidGeckoEvent::ACTION_GAMEPAD_ADDED) {
               int svc_id = service->AddGamepad("android",
                                                dom::GamepadMappingType::Standard,
                                                dom::kStandardGamepadButtons,
                                                dom::kStandardGamepadAxes);
-              java::GeckoAppShell::GamepadAdded(curEvent->ID(), svc_id);
+              java::AndroidGamepadManager::OnGamepadAdded(curEvent->ID(), svc_id);
             } else if (curEvent->Action() == AndroidGeckoEvent::ACTION_GAMEPAD_REMOVED) {
               service->RemoveGamepad(curEvent->ID());
             }
 #endif
         break;
     }
 
     case AndroidGeckoEvent::GAMEPAD_DATA: {