Bug 938827 - Part 5: Remove querySql reflection. r=rnewman
authorMichael Comella <michael.l.comella@gmail.com>
Fri, 06 Dec 2013 11:43:11 -0800
changeset 174919 334bc44411df112e7538715e3816d3e50447e62d
parent 174918 fc610be8d6754483a55e00c883e24832c50946cf
child 174920 dc0e2b5947dd0fe012e812a2121391fb44108306
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs938827
milestone28.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 938827 - Part 5: Remove querySql reflection. r=rnewman
build/mobile/robocop/FennecNativeActions.java
mobile/android/base/RobocopAPI.java
mobile/android/base/mozglue/GeckoLoader.java.in
mobile/android/base/sqlite/SQLiteBridge.java
--- a/build/mobile/robocop/FennecNativeActions.java
+++ b/build/mobile/robocop/FennecNativeActions.java
@@ -1,14 +1,17 @@
 /* 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/. */
 
 package org.mozilla.gecko;
 
+import org.mozilla.gecko.mozglue.GeckoLoader;
+import org.mozilla.gecko.sqlite.SQLiteBridge;
+
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.lang.reflect.InvocationHandler;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
 import java.util.ArrayList;
@@ -27,57 +30,56 @@ import android.view.ViewConfiguration;
 
 import com.jayway.android.robotium.solo.Solo;
 
 import static org.mozilla.gecko.FennecNativeDriver.LogLevel;
 
 public class FennecNativeActions implements Actions {
     private Solo mSolo;
     private Instrumentation mInstr;
-    private Activity mGeckoApp;
     private Assert mAsserter;
 
     // Objects for reflexive access of fennec classes.
     private ClassLoader mClassLoader;
     private Class mApiClass;
     private Class mEventListenerClass;
     private Class mDrawListenerClass;
     private Method mRegisterEventListener;
     private Method mUnregisterEventListener;
     private Method mBroadcastEvent;
     private Method mPreferencesGetEvent;
     private Method mPreferencesObserveEvent;
     private Method mPreferencesRemoveObserversEvent;
     private Method mSetDrawListener;
-    private Method mQuerySql;
     private Object mRobocopApi;
 
     private static final String LOGTAG = "FennecNativeActions";
 
     public FennecNativeActions(Activity activity, Solo robocop, Instrumentation instrumentation, Assert asserter) {
         mSolo = robocop;
         mInstr = instrumentation;
-        mGeckoApp = activity;
         mAsserter = asserter;
+
+        GeckoLoader.loadSQLiteLibs(activity, activity.getApplication().getPackageResourcePath());
+
         // Set up reflexive access of java classes and methods.
         try {
             mClassLoader = activity.getClassLoader();
 
             mApiClass = mClassLoader.loadClass("org.mozilla.gecko.RobocopAPI");
             mEventListenerClass = mClassLoader.loadClass("org.mozilla.gecko.util.GeckoEventListener");
             mDrawListenerClass = mClassLoader.loadClass("org.mozilla.gecko.gfx.GeckoLayerClient$DrawListener");
 
             mRegisterEventListener = mApiClass.getMethod("registerEventListener", String.class, mEventListenerClass);
             mUnregisterEventListener = mApiClass.getMethod("unregisterEventListener", String.class, mEventListenerClass);
             mBroadcastEvent = mApiClass.getMethod("broadcastEvent", String.class, String.class);
             mPreferencesGetEvent = mApiClass.getMethod("preferencesGetEvent", Integer.TYPE, String[].class);
             mPreferencesObserveEvent = mApiClass.getMethod("preferencesObserveEvent", Integer.TYPE, String[].class);
             mPreferencesRemoveObserversEvent = mApiClass.getMethod("preferencesRemoveObserversEvent", Integer.TYPE);
             mSetDrawListener = mApiClass.getMethod("setDrawListener", mDrawListenerClass);
-            mQuerySql = mApiClass.getMethod("querySql", String.class, String.class);
 
             mRobocopApi = mApiClass.getConstructor(Activity.class).newInstance(activity);
         } catch (Exception e) {
             FennecNativeDriver.log(LogLevel.ERROR, e);
         }
     }
 
     class wakeInvocationHandler implements InvocationHandler {
@@ -490,19 +492,12 @@ public class FennecNativeActions impleme
     public void sendKeys(String input) {
         mInstr.sendStringSync(input);
     }
 
     public void drag(int startingX, int endingX, int startingY, int endingY) {
         mSolo.drag(startingX, endingX, startingY, endingY, 10);
     }
 
-    public Cursor querySql(String dbPath, String sql) {
-        try {
-            return (Cursor)mQuerySql.invoke(mRobocopApi, dbPath, sql);
-        } catch(InvocationTargetException ex) {
-            Log.e(LOGTAG, "Error invoking method", ex);
-        } catch(IllegalAccessException ex) {
-            Log.e(LOGTAG, "Error using field", ex);
-        }
-        return null;
+    public Cursor querySql(final String dbPath, final String sql) {
+        return new SQLiteBridge(dbPath).rawQuery(sql, null);
     }
 }
--- a/mobile/android/base/RobocopAPI.java
+++ b/mobile/android/base/RobocopAPI.java
@@ -1,18 +1,16 @@
 /* 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/. */
 
 package org.mozilla.gecko;
 
 import org.mozilla.gecko.gfx.GeckoLayerClient;
-import org.mozilla.gecko.mozglue.GeckoLoader;
 import org.mozilla.gecko.mozglue.RobocopTarget;
-import org.mozilla.gecko.sqlite.SQLiteBridge;
 import org.mozilla.gecko.util.GeckoEventListener;
 
 import android.app.Activity;
 import android.database.Cursor;
 import android.view.View;
 
 import java.nio.IntBuffer;
 import java.util.List;
@@ -65,14 +63,9 @@ public class RobocopAPI {
 
     public void preferencesRemoveObserversEvent(int requestId) {
         GeckoAppShell.sendEventToGecko(GeckoEvent.createPreferencesRemoveObserversEvent(requestId));
     }
 
     public void setDrawListener(GeckoLayerClient.DrawListener listener) {
         GeckoAppShell.getLayerView().getLayerClient().setDrawListener(listener);
     }
-
-    public Cursor querySql(String dbPath, String query) {
-        GeckoLoader.loadSQLiteLibs(mGeckoApp, mGeckoApp.getApplication().getPackageResourcePath());
-        return new SQLiteBridge(dbPath).rawQuery(query, null);
-    }
 }
--- a/mobile/android/base/mozglue/GeckoLoader.java.in
+++ b/mobile/android/base/mozglue/GeckoLoader.java.in
@@ -212,16 +212,17 @@ public final class GeckoLoader {
         if (cacheDir.isDirectory()) {
             cacheDir.setWritable(true, false);
             cacheDir.setExecutable(true, false);
             cacheDir.setReadable(true, false);
         }
 #endif
     }
 
+    @RobocopTarget
     public static void loadSQLiteLibs(Context context, String apkName) {
         synchronized (sLibLoadingLock) {
             if (sSQLiteLibsLoaded) {
                 return;
             }
             sSQLiteLibsLoaded = true;
         }
 
--- a/mobile/android/base/sqlite/SQLiteBridge.java
+++ b/mobile/android/base/sqlite/SQLiteBridge.java
@@ -46,16 +46,17 @@ public class SQLiteBridge {
                                                             String[] aParams,
                                                             long[] aUpdateResult)
         throws SQLiteBridgeException;
     private static native long openDatabase(String aDb)
         throws SQLiteBridgeException;
     private static native void closeDatabase(long aDb);
 
     // Takes the path to the database we want to access.
+    @RobocopTarget
     public SQLiteBridge(String aDb) throws SQLiteBridgeException {
         mDb = aDb;
     }
 
     // Executes a simple line of sql.
     public void execSQL(String sql)
                 throws SQLiteBridgeException {
         internalQuery(sql, null);