[Android] [PATCH V2] benchmark: ask write permission before screenshots

Duncan McNamara dcn.mcnamara at gmail.com
Wed Jul 18 11:22:17 CEST 2018


Adds the permission denied scenario
---
 .../gui/video/benchmark/BenchActivity.java    | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java
index f5e8b6727..57a62f936 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java
@@ -20,9 +20,11 @@

 package org.videolan.vlc.gui.video.benchmark;

+import android.Manifest;
 import android.annotation.TargetApi;
 import android.content.Intent;
 import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
 import android.graphics.Bitmap;
 import android.graphics.PixelFormat;
 import android.graphics.Point;
@@ -34,6 +36,8 @@ import android.media.projection.MediaProjectionManager;
 import android.os.Bundle;
 import android.os.Environment;
 import android.os.Handler;
+import android.support.annotation.NonNull;
+import android.support.v4.app.ActivityCompat;
 import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.View;
@@ -77,6 +81,8 @@ public class BenchActivity extends ShallowVideoPlayer {

     private static final int VIRTUAL_DISPLAY_FLAGS = 0;

+    private static final int PERMISSION_REQUEST_WRITE = 1;
+
     private Runnable mTimeOut = null;

     private int mWidth;
@@ -116,6 +122,16 @@ public class BenchActivity extends ShallowVideoPlayer {
         super.loadMedia();
     }

+    @Override
+    final public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+        // checking for permission other than granted
+        if ((requestCode == PERMISSION_REQUEST_WRITE) &&
+                grantResults.length >= 1 && grantResults[0] != PackageManager.PERMISSION_GRANTED) {
+            errorFinish("Failed to get write permission for screenshots");
+        }
+    }
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         /* Crash handler setup */
@@ -129,6 +145,9 @@ public class BenchActivity extends ShallowVideoPlayer {
         }
         mIsBenchmark = true;

+        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
+            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_WRITE);
+
         if (!intent.hasExtra(INTENT_SCREENSHOT_DIR)) {
             errorFinish("Failed to get screenshot directory location");
         }
--
2.18.0



More information about the Android mailing list