Skip to content

Commit

Permalink
include the permissions granted at crash time into the report (which …
Browse files Browse the repository at this point in the history
…the user can choose to send, this is not done automatically)
  • Loading branch information
mathisdt committed Dec 27, 2023
1 parent f17f174 commit 3934c36
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ dependencies {
implementation 'net.sf.supercsv:super-csv:2.4.0'
implementation 'org.tinylog:tinylog:1.3.6'

compileOnly "com.google.auto.service:auto-service-annotations:1.1.1"
annotationProcessor "com.google.auto.service:auto-service:1.1.1"

runtimeOnly 'androidx.lifecycle:lifecycle-viewmodel:2.6.2'
runtimeOnly 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.zephyrsoft.trackworktime.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import androidx.annotation.NonNull;

import com.google.auto.service.AutoService;

import org.acra.builder.ReportBuilder;
import org.acra.collector.Collector;
import org.acra.collector.CollectorException;
import org.acra.config.CoreConfiguration;
import org.acra.data.CrashReportData;
import org.pmw.tinylog.Logger;

import java.util.ArrayList;
import java.util.List;

@AutoService(Collector.class)
public class PermissionCollector implements Collector {

@Override
public void collect(@NonNull Context context, @NonNull CoreConfiguration coreConfiguration, @NonNull ReportBuilder reportBuilder, @NonNull CrashReportData crashReportData) throws CollectorException {
String granted = String.join(", ", getGrantedPermissions(context));
crashReportData.put("GRANTED_PERMISSIONS", granted);
}

private List<String> getGrantedPermissions(Context context) {
List<String> granted = new ArrayList<>();
try {
PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
for (int i = 0; i < pi.requestedPermissions.length; i++) {
if ((pi.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0) {
granted.add(pi.requestedPermissions[i]);
}
}
} catch (Exception e) {
Logger.warn(e, "could not determine the granted permissions");
}
return granted;
}

@Override
public boolean enabled(@NonNull CoreConfiguration config) {
return true;
}
}

0 comments on commit 3934c36

Please sign in to comment.