Merge-73 Record user-action when screenshot with no storage permission.

TBR=sebsg@chromium.org

(cherry picked from commit c18bad54fd63d51cd40a214790daee6e9f641477)

Bug: 920663
Change-Id: I3b597293d48c74bfb82989aec84fce6214694ef3
Reviewed-on: https://chromium-review.googlesource.com/c/1440090
Commit-Queue: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Reviewed-by: David Trainor <dtrainor@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#628009}
Reviewed-on: https://chromium-review.googlesource.com/c/1450867
Reviewed-by: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/branch-heads/3683@{#149}
Cr-Branched-From: e51029943e0a38dd794b73caaf6373d5496ae783-refs/heads/master@{#625896}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/feature_engagement/ScreenshotMonitor.java b/chrome/android/java/src/org/chromium/chrome/browser/feature_engagement/ScreenshotMonitor.java
index e157129..c95295d 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/feature_engagement/ScreenshotMonitor.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/feature_engagement/ScreenshotMonitor.java
@@ -4,13 +4,16 @@
 
 package org.chromium.chrome.browser.feature_engagement;
 
+import android.Manifest;
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.database.ContentObserver;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.Handler;
 import android.provider.MediaStore;
 import android.provider.MediaStore.Images.Media;
+import android.support.v4.content.ContextCompat;
 import android.util.DisplayMetrics;
 import android.view.WindowManager;
 
@@ -18,6 +21,7 @@
 import org.chromium.base.Log;
 import org.chromium.base.ThreadUtils;
 import org.chromium.base.VisibleForTesting;
+import org.chromium.base.metrics.RecordUserAction;
 
 /**
  * This class detects screenshots by monitoring the screenshots directory on internal and external
@@ -102,6 +106,15 @@
         String[] mediaProjection = new String[] {MediaStore.Images.ImageColumns.DATE_TAKEN,
                 MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.HEIGHT,
                 MediaStore.MediaColumns.WIDTH, MediaStore.MediaColumns._ID};
+
+        // Check if READ_EXTERNAL_STORAGE permission are enabled.
+        if (ContextCompat.checkSelfPermission(
+                    ContextUtils.getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE)
+                != PackageManager.PERMISSION_GRANTED) {
+            RecordUserAction.record("Tab.Screenshot.WithoutStoragePermission");
+            return false;
+        }
+
         try {
             cursor = ContextUtils.getApplicationContext().getContentResolver().query(
                     storeUri, mediaProjection, null, null, null);