Bug 710330 - Add simple settings function to trigger import. r=lucasr
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Tue, 26 Jun 2012 00:31:02 +0200
changeset 102904 75c4ef84ea2469767901d930165a734b591eeb9f
parent 102903 6d5067a298dd440ad8fddcd008fa174228536918
child 102905 34302be5af12c7704475f71818d3e120151874c7
push id191
push userlsblakk@mozilla.com
push dateFri, 05 Oct 2012 17:12:53 +0000
treeherdermozilla-release@ddb22ac6c03b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs710330
milestone16.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 710330 - Add simple settings function to trigger import. r=lucasr
mobile/android/base/AndroidImport.java
mobile/android/base/AndroidImportPreference.java
mobile/android/base/AndroidManifest.xml.in
mobile/android/base/Makefile.in
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/resources/values/arrays.xml
mobile/android/base/resources/xml/preferences.xml.in
mobile/android/base/strings.xml.in
--- a/mobile/android/base/AndroidImport.java
+++ b/mobile/android/base/AndroidImport.java
@@ -5,17 +5,16 @@
 
 package org.mozilla.gecko;
 
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.db.BrowserContract.Bookmarks;
 import org.mozilla.gecko.db.LocalBrowserDB;
 import org.mozilla.gecko.R;
 
-import android.app.ProgressDialog;
 import android.content.ContentResolver;
 import android.content.ContentProviderResult;
 import android.content.ContentProviderOperation;
 import android.content.Context;
 import android.content.OperationApplicationException;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteConstraintException;
 import android.net.Uri;
@@ -31,23 +30,28 @@ import java.util.Collections;
 
 class AndroidImport implements Runnable {
     static final private String LOGTAG = "AndroidImport";
     private Context mContext;
     private Runnable mOnDoneRunnable;
     private ArrayList<ContentProviderOperation> mOperations;
     private ContentResolver mCr;
     private LocalBrowserDB mDB;
+    private boolean mImportBookmarks;
+    private boolean mImportHistory;
 
-    public AndroidImport(Context context, Runnable onDoneRunnable) {
+    public AndroidImport(Context context, Runnable onDoneRunnable,
+                         boolean doBookmarks, boolean doHistory) {
         mContext = context;
         mOnDoneRunnable = onDoneRunnable;
         mOperations = new ArrayList<ContentProviderOperation>();
         mCr = mContext.getContentResolver();
         mDB = new LocalBrowserDB(GeckoProfile.get(context).getName());
+        mImportBookmarks = doBookmarks;
+        mImportHistory = doHistory;
     }
 
     public void mergeBookmarks() {
         Cursor cursor = mCr.query(Browser.BOOKMARKS_URI,
                                   null,
                                   Browser.BookmarkColumns.BOOKMARK + " = 1",
                                   null,
                                   null);
@@ -129,14 +133,18 @@ class AndroidImport implements Runnable 
             // Bug 716729 means this happens even in normal circumstances
             Log.d(LOGTAG, "Error while applying database updates: ", e);
         }
         mOperations.clear();
     }
 
     @Override
     public void run() {
-        mergeBookmarks();
-        mergeHistory();
+        if (mImportBookmarks) {
+            mergeBookmarks();
+        }
+        if (mImportHistory) {
+            mergeHistory();
+        }
 
         mOnDoneRunnable.run();
     }
 }
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/AndroidImportPreference.java
@@ -0,0 +1,106 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
+ * 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 android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
+import android.app.ProgressDialog;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.preference.DialogPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.util.SparseBooleanArray;
+
+import org.mozilla.gecko.R;
+
+class AndroidImportPreference extends DialogPreference {
+    static final private String LOGTAG = "AndroidImport";
+    private Context mContext;
+    private boolean mBookmarksChecked;
+    private boolean mHistoryChecked;
+
+    public AndroidImportPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        mContext = context;
+    }
+
+    protected void runImport(final boolean doBookmarks, final boolean doHistory) {
+        Log.i(LOGTAG, "Importing Android history/bookmarks");
+        if (!doBookmarks && !doHistory) {
+            return;
+        }
+
+        final String dialogTitle;
+        if (doBookmarks && doHistory) {
+            dialogTitle = mContext.getString(R.string.bookmarkhistory_import_both);
+        } else if (doBookmarks) {
+            dialogTitle = mContext.getString(R.string.bookmarkhistory_import_bookmarks);
+        } else {
+            dialogTitle = mContext.getString(R.string.bookmarkhistory_import_history);
+        }
+
+        final ProgressDialog dialog =
+            ProgressDialog.show(mContext,
+                                dialogTitle,
+                                mContext.getString(R.string.bookmarkhistory_import_wait),
+                                true);
+
+        final Runnable stopCallback = new Runnable() {
+            public void run() {
+                GeckoApp.mAppContext.runOnUiThread(new Runnable() {
+                    public void run() {
+                        dialog.dismiss();
+                    }
+                });
+            }
+        };
+
+        GeckoBackgroundThread.getHandler().post(
+            // Constructing AndroidImport may need finding the profile,
+            // which hits disk, so it needs to go into a Runnable too.
+            new Runnable() {
+                public void run() {
+                    new AndroidImport(mContext, stopCallback, doBookmarks, doHistory).run();
+                }
+            }
+        );
+    }
+
+    @Override
+    protected void onPrepareDialogBuilder(Builder builder) {
+        super.onPrepareDialogBuilder(builder);
+        mBookmarksChecked = true;
+        mHistoryChecked = true;
+        builder.setMultiChoiceItems(R.array.pref_android_import_select,
+                                    new boolean[] { mBookmarksChecked, mHistoryChecked },
+            new DialogInterface.OnMultiChoiceClickListener() {
+                @Override
+                public void onClick(DialogInterface dialog,
+                                    int which,
+                                    boolean isChecked) {
+                    Log.i(LOGTAG, "which = " + which + ", checked=" + isChecked);
+                    if (which == 0) {
+                        mBookmarksChecked = isChecked;
+                    } else if (which == 1) {
+                        mHistoryChecked = isChecked;
+                    }
+                }
+            }
+       );
+    }
+
+    @Override
+    protected void onDialogClosed(boolean positiveResult) {
+        if (!positiveResult)
+            return;
+        runImport(mBookmarksChecked, mHistoryChecked);
+    }
+}
--- a/mobile/android/base/AndroidManifest.xml.in
+++ b/mobile/android/base/AndroidManifest.xml.in
@@ -15,16 +15,17 @@
 #include ../sync/manifests/SyncAndroidManifest_permissions.xml.in
 
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
     <uses-permission android:name="android.permission.INTERNET"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
     <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
     <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
+    <uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
 
     <uses-permission android:name="android.permission.WAKE_LOCK"/>
     <uses-permission android:name="android.permission.VIBRATE"/>
     <uses-permission android:name="@ANDROID_PACKAGE_NAME@.permissions.PASSWORD_PROVIDER"/>
     <uses-permission android:name="@ANDROID_PACKAGE_NAME@.permissions.BROWSER_PROVIDER"/>
     <uses-permission android:name="@ANDROID_PACKAGE_NAME@.permissions.FORMHISTORY_PROVIDER"/>
 
 #ifdef MOZ_WEBSMS_BACKEND
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -18,16 +18,18 @@ include $(topsrcdir)/mobile/android/base
 
 #These SYNC_ variables could be moved to android-sync/fennec-copy-code.sh
 SYNC_RES_XML=res/xml/sync_authenticator.xml
 SYNC_PP_RES_XML=res/xml/sync_syncadapter.xml res/xml/sync_options.xml
 
 FENNEC_JAVA_FILES = \
   AboutHomeContent.java \
   AboutHomeSection.java \
+  AndroidImport.java \
+  AndroidImportPreference.java \
   AlertNotification.java \
   AwesomeBar.java \
   AwesomeBarTabs.java \
   BrowserApp.java \
   BrowserToolbar.java \
   ConfirmPreference.java \
   SyncPreference.java \
   db/AndroidBrowserDB.java \
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -55,16 +55,17 @@
 <!ENTITY num_tabs "&#037;d tabs">
 <!ENTITY new_tab_opened "New tab opened">
 
 <!ENTITY settings "Settings">
 <!ENTITY settings_title "Settings">
 <!ENTITY pref_category_general "General">
 <!ENTITY pref_category_privacy "Privacy &amp; Security">
 <!ENTITY pref_category_content "Content">
+<!ENTITY pref_category_importexport "Import &amp; Export">
 <!ENTITY pref_about_firefox "About &brandShortName;">
 <!ENTITY pref_do_not_track "Tell sites not to track me">
 <!ENTITY pref_telemetry "Send performance data">
 <!ENTITY pref_remember_signons "Remember passwords">
 <!ENTITY pref_cookies "Enable cookies">
 <!ENTITY pref_char_encoding "Character encoding">
 <!ENTITY pref_char_encoding_on "Show menu">
 <!ENTITY pref_char_encoding_off "Don\'t show menu">
@@ -80,16 +81,17 @@
 <!ENTITY pref_font_size_tiny "Tiny">
 <!ENTITY pref_font_size_small "Small">
 <!ENTITY pref_font_size_medium "Medium">
 <!ENTITY pref_font_size_large "Large">
 <!ENTITY pref_font_size_xlarge "Extra Large">
 <!ENTITY pref_use_master_password "Use master password">
 <!ENTITY pref_sync "Sync">
 <!ENTITY pref_search_suggestions "Show search suggestions">
+<!ENTITY pref_import_android "Import from Android">
 
 <!ENTITY quit "Quit">
 
 <!ENTITY addons "Add-ons">
 <!ENTITY downloads "Downloads">
 <!ENTITY char_encoding "Character Encoding">
 
 <!ENTITY share "Share">
@@ -167,8 +169,17 @@ example.com
 which is run by
 Example Enterprises, Inc.
 
 The layout of the identity dialog prevents combining this into a single string with
 substitution variables.  If it is difficult to translate the sense of the string
 with that structure, consider a translation which ignores the preceding domain and
 just addresses the organization to follow, e.g. "This site is run by " -->
 <!ENTITY identity_run_by "which is run by">
+
+<!ENTITY bookmarkhistory_button_import "Import">
+<!ENTITY bookmarkhistory_import_both "Importing bookmarks and history
+                                      from Android">
+<!ENTITY bookmarkhistory_import_bookmarks "Importing bookmarks
+                                           from Android">
+<!ENTITY bookmarkhistory_import_history "Importing history
+                                         from Android">
+<!ENTITY bookmarkhistory_import_wait "Please wait...">
--- a/mobile/android/base/resources/values/arrays.xml
+++ b/mobile/android/base/resources/values/arrays.xml
@@ -32,9 +32,13 @@
     <string-array name="pref_char_encoding_entries">
         <item>@string/pref_char_encoding_on</item>
         <item>@string/pref_char_encoding_off</item>
     </string-array>
     <string-array name="pref_char_encoding_values">
         <item>true</item>
         <item>false</item>
     </string-array>
+    <string-array name="pref_android_import_select">
+        <item>@string/awesomebar_bookmarks_title</item>
+        <item>@string/awesomebar_history_title</item>
+    </string-array>
 </resources>
--- a/mobile/android/base/resources/xml/preferences.xml.in
+++ b/mobile/android/base/resources/xml/preferences.xml.in
@@ -79,9 +79,19 @@
 
         <CheckBoxPreference android:key="browser.search.suggest.enabled"
                             android:title="@string/pref_search_suggestions"
                             android:defaultValue="true"
                             android:persistent="false" />
 
     </PreferenceCategory>
 
+    <PreferenceCategory android:title="@string/pref_category_importexport">
+
+      <org.mozilla.gecko.AndroidImportPreference
+          android:title="@string/pref_import_android"
+          android:positiveButtonText="@string/bookmarkhistory_button_import"
+          android:negativeButtonText="@string/button_cancel"
+          android:persistent="false" />
+
+    </PreferenceCategory>
+
 </PreferenceScreen>
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -65,16 +65,17 @@
   <string name="find_next">&find_next;</string>
   <string name="find_close">&find_close;</string>
 
   <string name="settings">&settings;</string>
   <string name="settings_title">&settings_title;</string>
   <string name="pref_category_general">&pref_category_general;</string>
   <string name="pref_category_privacy">&pref_category_privacy;</string>
   <string name="pref_category_content">&pref_category_content;</string>
+  <string name="pref_category_importexport">&pref_category_importexport;</string>
   <string name="pref_about_firefox">&pref_about_firefox;</string>
   <string name="pref_do_not_track">&pref_do_not_track;</string>
   <string name="pref_telemetry">&pref_telemetry;</string>
   <string name="pref_remember_signons">&pref_remember_signons;</string>
   <string name="pref_cookies">&pref_cookies;</string>
   <string name="pref_char_encoding">&pref_char_encoding;</string>
   <string name="pref_char_encoding_on">&pref_char_encoding_on;</string>
   <string name="pref_char_encoding_off">&pref_char_encoding_off;</string>
@@ -89,16 +90,17 @@
   <string name="pref_text_size">&pref_text_size;</string>
   <string name="pref_font_size_tiny">&pref_font_size_tiny;</string>
   <string name="pref_font_size_small">&pref_font_size_small;</string>
   <string name="pref_font_size_medium">&pref_font_size_medium;</string>
   <string name="pref_font_size_large">&pref_font_size_large;</string>
   <string name="pref_font_size_xlarge">&pref_font_size_xlarge;</string>
   <string name="pref_sync">&pref_sync;</string>
   <string name="pref_search_suggestions">&pref_search_suggestions;</string>
+  <string name="pref_import_android">&pref_import_android;</string>
 
   <string name="reload">&reload;</string>
   <string name="forward">&forward;</string>
   <string name="close_tab">&close_tab;</string>
   <string name="new_tab">&new_tab;</string>
   <string name="new_tab_opened">&new_tab_opened;</string>
   <string name="num_tabs">&num_tabs;</string>
   <string name="addons">&addons;</string>
@@ -172,9 +174,17 @@
   <string name="bookmarkdefaults_url_support">http://support.mozilla.org/@AB_CD@/mobile</string>
 
   <string name="bookmarkdefaults_title_abouthome">@bookmarks_aboutHome@</string>
   <string name="bookmarkdefaults_url_abouthome">about:home</string>
 
   <!-- Site identity popup -->
   <string name="identity_connected_to">&identity_connected_to;</string>
   <string name="identity_run_by">&identity_run_by;</string>
+
+  <!-- Bookmark import/export -->
+  <string name="bookmarkhistory_button_import">&bookmarkhistory_button_import;</string>
+  <string name="bookmarkhistory_import_both">&bookmarkhistory_import_both;</string>
+  <string name="bookmarkhistory_import_bookmarks">&bookmarkhistory_import_bookmarks;</string>
+  <string name="bookmarkhistory_import_history">&bookmarkhistory_import_history;</string>
+  <string name="bookmarkhistory_import_wait">&bookmarkhistory_import_wait;</string>
+
 </resources>