Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
Add the @IntRange annotation to requestCode to prevent invalid input (#…
Browse files Browse the repository at this point in the history
…325)

Co-authored-by: gaopengfei <[email protected]>
  • Loading branch information
tall-nuts and gaopengfei authored Apr 26, 2021
1 parent 8952eac commit 1d8c6e0
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1d8c6e0

Please sign in to comment.