Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 34 additions & 32 deletions android/capacitor/src/main/java/com/getcapacitor/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -1214,42 +1214,44 @@ protected boolean validatePermissions(Plugin plugin, PluginCall savedCall, Map<S
protected Map<String, PermissionState> getPermissionStates(Plugin plugin) {
Map<String, PermissionState> permissionsResults = new HashMap<>();
CapacitorPlugin annotation = plugin.getPluginHandle().getPluginAnnotation();
for (Permission perm : annotation.permissions()) {
// If a permission is defined with no permission constants, return GRANTED for it.
// Otherwise, get its true state.
if (perm.strings().length == 0 || (perm.strings().length == 1 && perm.strings()[0].isEmpty())) {
String key = perm.alias();
if (!key.isEmpty()) {
PermissionState existingResult = permissionsResults.get(key);

// auto set permission state to GRANTED if the alias is empty.
if (existingResult == null) {
permissionsResults.put(key, PermissionState.GRANTED);
}
}
} else {
for (String permString : perm.strings()) {
String key = perm.alias().isEmpty() ? permString : perm.alias();
PermissionState permissionStatus;
if (ActivityCompat.checkSelfPermission(this.getContext(), permString) == PackageManager.PERMISSION_GRANTED) {
permissionStatus = PermissionState.GRANTED;
} else {
permissionStatus = PermissionState.PROMPT;

// Check if there is a cached permission state for the "Never ask again" state
SharedPreferences prefs = getContext().getSharedPreferences(PERMISSION_PREFS_NAME, Activity.MODE_PRIVATE);
String state = prefs.getString(permString, null);

if (state != null) {
permissionStatus = PermissionState.byState(state);
if (annotation != null) {
for (Permission perm : annotation.permissions()) {
// If a permission is defined with no permission constants, return GRANTED for it.
// Otherwise, get its true state.
if (perm.strings().length == 0 || (perm.strings().length == 1 && perm.strings()[0].isEmpty())) {
String key = perm.alias();
if (!key.isEmpty()) {
PermissionState existingResult = permissionsResults.get(key);

// auto set permission state to GRANTED if the alias is empty.
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline comment is misleading: this block only executes when key (the alias) is not empty, but the comment says the alias is empty. Please update the comment to match the actual condition (or adjust the condition if the comment reflects intended behavior).

Suggested change
// auto set permission state to GRANTED if the alias is empty.
// Auto-set permission state to GRANTED for non-empty aliases with no permission strings.

Copilot uses AI. Check for mistakes.
if (existingResult == null) {
permissionsResults.put(key, PermissionState.GRANTED);
}
}
} else {
for (String permString : perm.strings()) {
String key = perm.alias().isEmpty() ? permString : perm.alias();
PermissionState permissionStatus;
if (ActivityCompat.checkSelfPermission(this.getContext(), permString) == PackageManager.PERMISSION_GRANTED) {
permissionStatus = PermissionState.GRANTED;
} else {
permissionStatus = PermissionState.PROMPT;

// Check if there is a cached permission state for the "Never ask again" state
SharedPreferences prefs = getContext().getSharedPreferences(PERMISSION_PREFS_NAME, Activity.MODE_PRIVATE);
String state = prefs.getString(permString, null);

if (state != null) {
permissionStatus = PermissionState.byState(state);
}
}

PermissionState existingResult = permissionsResults.get(key);
PermissionState existingResult = permissionsResults.get(key);

// multiple permissions with the same alias must all be true, otherwise all false.
if (existingResult == null || existingResult == PermissionState.GRANTED) {
permissionsResults.put(key, permissionStatus);
// multiple permissions with the same alias must all be true, otherwise all false.
if (existingResult == null || existingResult == PermissionState.GRANTED) {
permissionsResults.put(key, permissionStatus);
}
}
}
}
Expand Down
Loading