From 1d8c6e0854e6f0d1ea4482b7cffc416004f67e41 Mon Sep 17 00:00:00 2001 From: coder1024 Date: Mon, 26 Apr 2021 18:45:27 +0800 Subject: [PATCH] Add the @IntRange annotation to requestCode to prevent invalid input (#325) Co-authored-by: gaopengfei --- .../java/pub/devrel/easypermissions/EasyPermissions.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/easypermissions/src/main/java/pub/devrel/easypermissions/EasyPermissions.java b/easypermissions/src/main/java/pub/devrel/easypermissions/EasyPermissions.java index 54cd9dea..dfc20d0e 100644 --- a/easypermissions/src/main/java/pub/devrel/easypermissions/EasyPermissions.java +++ b/easypermissions/src/main/java/pub/devrel/easypermissions/EasyPermissions.java @@ -20,18 +20,17 @@ import android.content.Context; import android.content.pm.PackageManager; import android.os.Build; +import androidx.annotation.IntRange; import androidx.annotation.NonNull; import androidx.annotation.Size; import androidx.core.app.ActivityCompat; import androidx.fragment.app.Fragment; import androidx.core.content.ContextCompat; import android.util.Log; - import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; - import pub.devrel.easypermissions.helper.PermissionHelper; /** @@ -108,7 +107,7 @@ public static boolean hasPermissions(@NonNull Context context, */ public static void requestPermissions( @NonNull Activity host, @NonNull String rationale, - int requestCode, @Size(min = 1) @NonNull String... perms) { + @IntRange(from = 0, to = 255) int requestCode, @Size(min = 1) @NonNull String... perms) { requestPermissions( new PermissionRequest.Builder(host, requestCode, perms) .setRationale(rationale) @@ -122,7 +121,7 @@ public static void requestPermissions( */ public static void requestPermissions( @NonNull Fragment host, @NonNull String rationale, - int requestCode, @Size(min = 1) @NonNull String... perms) { + @IntRange(from = 0, to = 255) int requestCode, @Size(min = 1) @NonNull String... perms) { requestPermissions( new PermissionRequest.Builder(host, requestCode, perms) .setRationale(rationale) @@ -169,7 +168,7 @@ public static void requestPermissions(PermissionRequest request) { * @param receivers an array of objects that have a method annotated with {@link * AfterPermissionGranted} or implement {@link PermissionCallbacks}. */ - public static void onRequestPermissionsResult(int requestCode, + public static void onRequestPermissionsResult(@IntRange(from = 0, to = 255) int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults, @NonNull Object... receivers) {