Bug 1531679 Search Widget for Fennec Part 3 - Make it discoverable through Leanplum r=petru
authorAndrei Lazar <andrei.a.lazar@softvision.ro>
Fri, 08 Mar 2019 15:05:02 +0000
changeset 521248 a32961795869161ee5ff9f101aea845b7aeb9a2a
parent 521247 0368c4ca4ecec9d8ce18d9e474731f2faeb92f00
child 521249 3dfbf1afd9a717cf19bee20e4ba5521919982793
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspetru
bugs1531679
milestone67.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 1531679 Search Widget for Fennec Part 3 - Make it discoverable through Leanplum r=petru Provided a deep link for the add widget intent. Differential Revision: https://phabricator.services.mozilla.com/D21685
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/LauncherActivity.java
mobile/android/base/java/org/mozilla/gecko/deeplink/DeepLinkContract.java
mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
mobile/android/base/java/org/mozilla/gecko/search/SearchWidgetProvider.java
mobile/android/docs/mma.rst
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -183,16 +183,17 @@ import java.util.List;
 import java.util.Locale;
 import java.util.regex.Pattern;
 
 import static org.mozilla.gecko.Tabs.LOADURL_DELAY_LOAD;
 import static org.mozilla.gecko.Tabs.LOADURL_EXTERNAL;
 import static org.mozilla.gecko.Tabs.LOADURL_PINNED;
 import static org.mozilla.gecko.Tabs.LOADURL_START_EDITING;
 import static org.mozilla.gecko.Tabs.TabEvents.LOADED;
+import static org.mozilla.gecko.mma.MmaDelegate.INTERACT_WITH_SEARCH_WIDGET_URL_AREA;
 import static org.mozilla.gecko.mma.MmaDelegate.NEW_TAB;
 import static org.mozilla.gecko.search.SearchWidgetProvider.INPUT_TYPE_KEY;
 import static org.mozilla.gecko.util.JavaUtil.getBundleSizeInBytes;
 
 public class BrowserApp extends GeckoApp
                         implements ActionModePresenter,
                                    AnchoredPopup.OnVisibilityChangeListener,
                                    BookmarkEditFragment.Callbacks,
@@ -887,16 +888,18 @@ public class BrowserApp extends GeckoApp
         SearchWidgetProvider.InputType input = (SearchWidgetProvider.InputType) (intent == null ?
                 safeStartingIntent.getUnsafe().getSerializableExtra(INPUT_TYPE_KEY) :
                 intent.getSerializableExtra(INPUT_TYPE_KEY));
 
         if (input == null) {
             return false;
         }
 
+        MmaDelegate.track(INTERACT_WITH_SEARCH_WIDGET_URL_AREA);
+
         switch (input) {
             case TEXT:
                 handleTabEditingMode(false);
                 return true;
             case VOICE:
                 handleTabEditingMode(true);
                 return true;
             default:
--- a/mobile/android/base/java/org/mozilla/gecko/LauncherActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/LauncherActivity.java
@@ -1,26 +1,31 @@
 /* -*- 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.Activity;
+import android.app.PendingIntent;
+import android.appwidget.AppWidgetManager;
+import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.net.Uri;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.customtabs.CustomTabsIntent;
 import android.util.Log;
 
 import org.mozilla.gecko.home.HomeConfig;
 import org.mozilla.gecko.mma.MmaDelegate;
+import org.mozilla.gecko.search.SearchWidgetConfigurationActivity;
+import org.mozilla.gecko.search.SearchWidgetProvider;
 import org.mozilla.gecko.webapps.WebAppActivity;
 import org.mozilla.gecko.webapps.WebAppIndexer;
 import org.mozilla.gecko.customtabs.CustomTabsActivity;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.mozglue.SafeIntent;
 import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.tabqueue.TabQueueHelper;
 import org.mozilla.gecko.tabqueue.TabQueueService;
@@ -34,16 +39,17 @@ import static org.mozilla.gecko.deeplink
 import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_PREFERENCES_HOME;
 import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_PREFERENCES;
 import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_PREFERENCES_ACCESSIBILITY;
 import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_PREFERENCES_GENERAL;
 import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_PREFERENCES_NOTIFICATIONS;
 import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_PREFERENCES_PRIAVACY;
 import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_PREFERENCES_SEARCH;
 import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_SAVE_AS_PDF;
+import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_SEARCH_WIDGET;
 import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_SIGN_UP;
 import static org.mozilla.gecko.deeplink.DeepLinkContract.SUMO_DEFAULT_BROWSER;
 import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_FXA_SIGNIN;
 import static org.mozilla.gecko.deeplink.DeepLinkContract.URL_PARAM;
 import static org.mozilla.gecko.util.FileUtils.isContentUri;
 
 import org.mozilla.gecko.deeplink.DeepLinkContract;
 
@@ -218,16 +224,37 @@ public class LauncherActivity extends Ac
                     // link to a SUMO page but on new Android versions we can link to the default app settings where
                     // the user can actually set a default browser (Bug 1312686).
                     final Intent changeDefaultApps = new Intent("android.settings.MANAGE_DEFAULT_APPS_SETTINGS");
                     startActivity(changeDefaultApps);
                 } else {
                     dispatchUrlIntent(SUMO_DEFAULT_BROWSER);
                 }
                 break;
+            case LINK_SEARCH_WIDGET:
+                if (AppConstants.Versions.feature26Plus) {
+                    AppWidgetManager appWidgetManager = getApplicationContext().getSystemService(AppWidgetManager.class);
+                    ComponentName componentName = new ComponentName(this, SearchWidgetProvider.class);
+
+                    if (appWidgetManager != null && appWidgetManager.isRequestPinAppWidgetSupported()) {
+                        // Create the PendingIntent object only if your app needs to be notified
+                        // that the user allowed the widget to be pinned. Note that, if the pinning
+                        // operation fails, your app isn't notified.
+                        Intent pinnedWidgetCallbackIntent = new Intent(getApplicationContext(), SearchWidgetConfigurationActivity.class);
+                        pinnedWidgetCallbackIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
+
+                        // Configure the intent so that your app's broadcast receiver gets
+                        // the callback successfully. This callback receives the ID of the
+                        // newly-pinned widget (EXTRA_APPWIDGET_ID).
+                        PendingIntent successCallback = PendingIntent.getBroadcast(this, 0,
+                                pinnedWidgetCallbackIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+                        appWidgetManager.requestPinAppWidget(componentName, null, successCallback);
+                    }
+                }
+                break;
             case LINK_SAVE_AS_PDF:
                 EventDispatcher.getInstance().dispatch("SaveAs:PDF", null);
                 break;
             case LINK_BOOKMARK_LIST:
                 String bookmarks = AboutPages.getURLForBuiltinPanelType(HomeConfig.PanelType.BOOKMARKS);
                 dispatchUrlIntent(bookmarks);
                 break;
             case LINK_HISTORY_LIST:
--- a/mobile/android/base/java/org/mozilla/gecko/deeplink/DeepLinkContract.java
+++ b/mobile/android/base/java/org/mozilla/gecko/deeplink/DeepLinkContract.java
@@ -11,16 +11,17 @@ public class DeepLinkContract {
     // Sumo page for setting Fennec as default browser
     public static final String SUMO_DEFAULT_BROWSER = "https://support.mozilla.org/kb/make-firefox-default-browser-android?utm_source=inproduct&amp;utm_medium=settings&amp;utm_campaign=mobileandroid";
     public static final String DEEP_LINK_SCHEME = "firefox";
 
     public static final String LINK_FXA_SIGNIN = "fxa-signin";
 
     public static final String LINK_OPEN = "open";
     public static final String LINK_DEFAULT_BROWSER = "default_browser";
+    public static final String LINK_SEARCH_WIDGET = "search_widget";
     public static final String LINK_SAVE_AS_PDF = "save_as_pdf";
     public static final String LINK_BOOKMARK_LIST = "bookmark_list";
     public static final String LINK_HISTORY_LIST = "history_list";
     public static final String LINK_SIGN_UP = "sign_up";
     public static final String LINK_PREFERENCES_GENERAL = "preferences_general";
     public static final String LINK_PREFERENCES = "preferences";
     public static final String LINK_PREFERENCES_PRIAVACY = "preferences_privacy";
     public static final String LINK_PREFERENCES_SEARCH = "preferences_search";
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
@@ -40,16 +40,18 @@ import static android.content.Context.MO
 public class MmaDelegate {
 
     public static final String READER_AVAILABLE = "E_Reader_Available";
     public static final String DOWNLOAD_MEDIA_SAVED_IMAGE = "E_Download_Media_Saved_Image";
     public static final String CLEARED_PRIVATE_DATA = "E_Cleared_Private_Data";
     public static final String SAVED_BOOKMARK = "E_Saved_Bookmark";
     public static final String OPENED_BOOKMARK = "E_Opened_Bookmark";
     public static final String INTERACT_WITH_SEARCH_URL_AREA = "E_Interact_With_Search_URL_Area";
+    public static final String INTERACT_WITH_SEARCH_WIDGET_URL_AREA = "E_Interact_With_Search_Widget";
+    public static final String ADDED_SEARCH_WIDGET = "E_Search_Widget_Added";
     public static final String SCREENSHOT = "E_Screenshot";
     public static final String SAVED_LOGIN_AND_PASSWORD = "E_Saved_Login_And_Password";
     public static final String RESUMED_FROM_BACKGROUND = "E_Resumed_From_Background";
     public static final String NEW_TAB = "E_Opened_New_Tab";
     public static final String DISMISS_ONBOARDING = "E_Dismiss_Onboarding";
     public static final String ONBOARDING_DEFAULT_VALUES = "E_Onboarding_With_Default_Values";
     public static final String ONBOARDING_REMOTE_VALUES = "E_Onboarding_With_Remote_Values";
 
--- a/mobile/android/base/java/org/mozilla/gecko/search/SearchWidgetProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/search/SearchWidgetProvider.java
@@ -12,16 +12,17 @@ import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.net.Uri;
 import android.os.Bundle;
 import android.widget.RemoteViews;
 
 import org.mozilla.gecko.LauncherActivity;
 import org.mozilla.gecko.R;
+import org.mozilla.gecko.mma.MmaDelegate;
 
 public final class SearchWidgetProvider extends AppWidgetProvider {
     private static final int VOICE_INTENT_RC = 1;
     private static final int TEXT_INTENT_RC = 0;
     public static String INPUT_TYPE_KEY = "input";
 
     public enum InputType {
         VOICE,
@@ -39,16 +40,21 @@ public final class SearchWidgetProvider 
             setVoicePendingIntent(context, remoteViews);
             setTextPendingIntent(context, remoteViews);
 
             appWidgetManager.updateAppWidget(widgetId, remoteViews);
         }
     }
 
     @Override
+    public void onEnabled(Context context) {
+        MmaDelegate.track(MmaDelegate.ADDED_SEARCH_WIDGET);
+    }
+
+    @Override
     public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) {
         final Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
         final int minWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
 
         // Obtain appropriate widget and update it.
         appWidgetManager.updateAppWidget(appWidgetId, getRemoteViews(context, minWidth));
         super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions);
     }
--- a/mobile/android/docs/mma.rst
+++ b/mobile/android/docs/mma.rst
@@ -131,16 +131,20 @@ List of current Events related data that
 * Load the bookmark from home panel
 {
   "event" : "E_Opened_Bookmark"
 }
 * Interact with search url area
 {
   "event" : "E_Interact_With_Search_URL_Area"
 }
+* Interact with search widget
+{
+  "event" : "E_Interact_With_Search_Widget"
+}
 * When a screenshot is taken
 {
   "event" : "E_Screenshot"
 }
 * Open a new tab
 {
   "event" : "E_Opened_New_Tab"
 }