Bug 1401871 - Check if menu item(home_add_to_launcher) exists or not before accessing it. r=nechen, a=sledru
authorJing-wei Wu <topwu.tw@gmail.com>
Tue, 26 Sep 2017 16:12:15 +0800
changeset 434371 06cffe71eae8e440915e5b62c80629ed5c539ba7
parent 434370 c7091b22d32efde7e224cb7b7671c121905a52bf
child 434372 f06912ba5bb7ac2951eb184ba8d2f9f2487f1e4d
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnechen, sledru
bugs1401871
milestone57.0
Bug 1401871 - Check if menu item(home_add_to_launcher) exists or not before accessing it. r=nechen, a=sledru We temporarily hide `home_add_to_launcher` in API 26, which means directly accesses it without checking if it exists or not would cause NullPointerException. MozReview-Commit-ID: KXnP81ZZa6u
mobile/android/base/java/org/mozilla/gecko/home/HomeFragment.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/HomeFragment.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/HomeFragment.java
@@ -203,17 +203,21 @@ public abstract class HomeFragment exten
         menu.findItem(R.id.home_set_as_homepage).setVisible(distSetAsHomepage);
 
         // Hide unused menu items for bookmark folder.
         if (info.isFolder) {
             menu.findItem(R.id.home_open_new_tab).setVisible(false);
             menu.findItem(R.id.home_open_private_tab).setVisible(false);
             menu.findItem(R.id.home_copyurl).setVisible(false);
             menu.findItem(R.id.home_share).setVisible(false);
-            menu.findItem(R.id.home_add_to_launcher).setVisible(false);
+
+            final MenuItem addToLauncherItem = menu.findItem(R.id.home_add_to_launcher);
+            if (addToLauncherItem != null) {
+                addToLauncherItem.setVisible(false);
+            }
             menu.findItem(R.id.home_set_as_homepage).setVisible(false);
 
             menu.findItem(R.id.home_as_pin).setVisible(false);
             return;
         }
 
         // If Activity Stream is disabled, simply hide "AS Pin" menu item as classic Top Sites do not
         // support pinning from outside of the Top Site tiles.