Bug 1241887 - (Part 3) Show snackbar to ask for Storage permission if updater is enabled. r? draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Fri, 22 Jan 2016 17:02:22 +0100
changeset 324385 2a1b9e24ac08ae1287b3e66bb90449bf680059e9
parent 324384 0bc6647400cbe214c5d471c941ab77bba38ebf5c
child 513368 56ba31ca4dd7b96e3f96688bc0a48e4386fb73f5
push id9891
push users.kaspari@gmail.com
push dateFri, 22 Jan 2016 16:22:19 +0000
bugs1241887
milestone46.0a1
Bug 1241887 - (Part 3) Show snackbar to ask for Storage permission if updater is enabled. r?
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/permissions/PermissionBlock.java
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/strings.xml.in
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -62,16 +62,17 @@ import org.mozilla.gecko.tabs.TabHistory
 import org.mozilla.gecko.tabs.TabHistoryFragment;
 import org.mozilla.gecko.tabs.TabHistoryPage;
 import org.mozilla.gecko.tabs.TabsPanel;
 import org.mozilla.gecko.toolbar.AutocompleteHandler;
 import org.mozilla.gecko.toolbar.BrowserToolbar;
 import org.mozilla.gecko.toolbar.BrowserToolbar.TabEditingState;
 import org.mozilla.gecko.toolbar.ToolbarProgressView;
 import org.mozilla.gecko.trackingprotection.TrackingProtectionPrompt;
+import org.mozilla.gecko.updater.UpdateServiceHelper;
 import org.mozilla.gecko.util.ActivityUtils;
 import org.mozilla.gecko.util.Clipboard;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.FloatUtils;
 import org.mozilla.gecko.util.GamepadUtils;
 import org.mozilla.gecko.util.GeckoEventListener;
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.MenuUtils;
@@ -751,16 +752,33 @@ public class BrowserApp extends GeckoApp
             public void onScreenshotTaken(String data, String title) {
                 // Treat screenshots as a sharing method.
                 Telemetry.sendUIEvent(TelemetryContract.Event.SHARE, TelemetryContract.Method.BUTTON, "screenshot");
             }
         });
 
         // Set the maximum bits-per-pixel the favicon system cares about.
         IconDirectoryEntry.setMaxBPP(GeckoAppShell.getScreenDepth());
+
+        if (UpdateServiceHelper.isUpdaterEnabled()) {
+            SnackbarHelper.SnackbarCallback allowCallback = new SnackbarHelper.SnackbarCallback() {
+                @Override
+                public void onClick(View v) {
+                    Permissions.from(BrowserApp.this)
+                            .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
+                            .run();
+                }
+            };
+
+            SnackbarHelper.showSnackbarWithAction(this,
+                    getString(R.string.updater_permission_text),
+                    Snackbar.LENGTH_INDEFINITE,
+                    getString(R.string.updater_permission_allow),
+                    allowCallback);
+        }
     }
 
     private void conditionallyNotifyHCEOL() {
         final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
         try {
             final SharedPreferences prefs = GeckoSharedPrefs.forProfile(this);
             if (!prefs.getBoolean(HONEYCOMB_EOL_NOTIFIED, false)) {
 
--- a/mobile/android/base/java/org/mozilla/gecko/permissions/PermissionBlock.java
+++ b/mobile/android/base/java/org/mozilla/gecko/permissions/PermissionBlock.java
@@ -61,20 +61,27 @@ public class PermissionBlock {
         if (condition) {
             doNotPrompt();
         }
 
         return this;
     }
 
     /**
+     * Execute this permission block. Calling this method will prompt the user if needed.
+     */
+    public void run() {
+        run(null);
+    }
+
+    /**
      * Execute the specified runnable if the app has been granted all permissions. Calling this method will prompt the
      * user if needed.
      */
-    public void run(@NonNull Runnable onPermissionsGranted) {
+    public void run(Runnable onPermissionsGranted) {
         if (!doNotPrompt && !(context instanceof Activity)) {
             throw new IllegalStateException("You need to either specify doNotPrompt() or pass in an Activity context");
         }
 
         this.onPermissionsGranted = onPermissionsGranted;
 
         if (hasPermissions(context)) {
             onPermissionsGranted();
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -664,16 +664,18 @@ just addresses the organization to follo
 <!ENTITY updater_downloading_retry2 "Touch to retry">
 
 <!ENTITY updater_apply_title2 "Update available for &brandShortName;">
 <!ENTITY updater_apply_select2 "Touch to update">
 
 <!-- Localization note (updater_permission_text): This text is shown in a notification and as a snackbar
      if the app requires a runtime permission to downloads updates (Nightly/Aurora).-->
 <!ENTITY updater_permission_text "To download files and updates, allow &brandShortName; permission to access storage.">
+<!-- LOCALIZATION NOTE (updater_permission_allow): This action is shown in a snackbar along with updater_permission_text. -->
+<!ENTITY updater_permission_allow "Allow">
 
     <!-- Guest mode -->
 <!ENTITY new_guest_session "New Guest Session">
 <!ENTITY exit_guest_session "Exit Guest Session">
 <!ENTITY guest_session_dialog_continue "Continue">
 <!ENTITY guest_session_dialog_cancel "Cancel">
 <!ENTITY new_guest_session_title "&brandShortName; will now restart">
 <!ENTITY new_guest_session_text2 "The person using it will not be able to see any of your personal browsing data (like saved logins, history or bookmarks).\n\nWhen your guest is done, their browsing data will be deleted and your session will be restored.">
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -533,16 +533,17 @@
   <string name="updater_downloading_select">&updater_downloading_select2;</string>
   <string name="updater_downloading_retry">&updater_downloading_retry2;</string>
 
   <string name="updater_apply_title">&updater_apply_title2;</string>
   <string name="updater_apply_select">&updater_apply_select2;</string>
 
   <string name="updater_permission_title">&brandShortName;</string>
   <string name="updater_permission_text">&updater_permission_text;</string>
+  <string name="updater_permission_allow">&updater_permission_allow;</string>
 
   <!-- Awesomescreen screen -->
   <string name="suggestions_prompt">&suggestions_prompt3;</string>
   <string name="search_bar_item_desc">&search_bar_item_desc;</string>
 
   <string name="suggestion_for_engine">&suggestion_for_engine;</string>
 
   <!-- Set Image Notifications -->