Skip to content

Commit

Permalink
Include traces in exception message to possibly hint why it failed.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech committed Jan 7, 2025
1 parent b8b2378 commit 448d3ae
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ public final class RealRxPermission implements RxPermission {

static final String PREF_REQUESTED_PERMISSIONS = "requested-permissions";

static final StringBuffer TRACES = new StringBuffer();

/**
* @param context any context
* @return a Singleton instance of this class
*/
public static RealRxPermission getInstance(final Context context) {
synchronized (RealRxPermission.class) {
if (instance == null) {
TRACES.append("created new instance -> ");
instance = new RealRxPermission((Application) context.getApplicationContext());
}
}
Expand Down Expand Up @@ -131,7 +134,10 @@ public static RealRxPermission getInstance(final Context context) {
if (subject == null) {
unrequestedPermissions.add(permission);
subject = PublishSubject.create();
TRACES.append("putting ").append(permission).append(" -> ");
currentPermissionRequests.put(permission, subject);
} else {
TRACES.append("obtained ").append(permission).append(" -> ");
}

list.add(subject);
Expand Down Expand Up @@ -190,10 +196,11 @@ void onRequestPermissionsResult(@NonNull final int[] grantResults, @NonNull fina

for (int i = 0; i < size; i++) {
final String permission = permissions[i];
TRACES.append("removing ").append(permission).append(" -> ");
final PublishSubject<Permission> subject = currentPermissionRequests.remove(permission);

if (subject == null) {
throw new IllegalStateException("RealRxPermission.onRequestPermissionsResult invoked but didn't find the corresponding permission request for " + permission);
throw new IllegalStateException("RealRxPermission.onRequestPermissionsResult invoked but didn't find the corresponding permission request for " + permission + " debug logs: " + TRACES);
}

final boolean granted = grantResults[i] == PERMISSION_GRANTED;
Expand All @@ -215,6 +222,7 @@ void onRequestPermissionsResult(@NonNull final int[] grantResults, @NonNull fina
}

void cancelPermissionsRequests() {
TRACES.append("cancelPermissionsRequests -> ");
currentPermissionRequests.clear();
}

Expand Down

0 comments on commit 448d3ae

Please sign in to comment.