mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-31 22:26:06 +02:00
Debug: list all permissions
This commit is contained in:
@@ -26,6 +26,7 @@ import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PermissionGroupInfo;
|
||||
import android.content.pm.PermissionInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.database.sqlite.SQLiteDatabaseCorruptException;
|
||||
@@ -175,6 +176,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
private Button btnFontMap;
|
||||
private Button btnCiphers;
|
||||
private Button btnFiles;
|
||||
private Button btnAllPermissions;
|
||||
private TextView tvPermissions;
|
||||
|
||||
private Group grpUpdates;
|
||||
@@ -327,6 +329,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
btnFontMap = view.findViewById(R.id.btnFontMap);
|
||||
btnCiphers = view.findViewById(R.id.btnCiphers);
|
||||
btnFiles = view.findViewById(R.id.btnFiles);
|
||||
btnAllPermissions = view.findViewById(R.id.btnAllPermissions);
|
||||
tvPermissions = view.findViewById(R.id.tvPermissions);
|
||||
|
||||
grpUpdates = view.findViewById(R.id.grpUpdates);
|
||||
@@ -1275,6 +1278,66 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
}
|
||||
});
|
||||
|
||||
btnAllPermissions.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new SimpleTask<Spanned>() {
|
||||
@Override
|
||||
protected Spanned onExecute(Context context, Bundle args) throws Throwable {
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilderEx();
|
||||
|
||||
PackageManager pm = context.getPackageManager();
|
||||
List<PermissionGroupInfo> groups = pm.getAllPermissionGroups(0);
|
||||
groups.add(0, null); // Ungrouped
|
||||
|
||||
for (PermissionGroupInfo group : groups) {
|
||||
String name = (group == null ? null : group.name);
|
||||
int start = ssb.length();
|
||||
ssb.append(name == null ? "Ungrouped" : name);
|
||||
ssb.setSpan(new StyleSpan(Typeface.BOLD), start, ssb.length(), 0);
|
||||
ssb.append("\n\n");
|
||||
|
||||
try {
|
||||
for (PermissionInfo permission : pm.queryPermissionsByGroup(name, 0)) {
|
||||
start = ssb.length();
|
||||
ssb.append(permission.name);
|
||||
ssb.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL), start, ssb.length(), 0);
|
||||
ssb.append("\n");
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException ex) {
|
||||
ssb.append(ex.toString()).append("\n")
|
||||
.append(android.util.Log.getStackTraceString(ex)).append("\n");
|
||||
}
|
||||
|
||||
ssb.append("\n");
|
||||
}
|
||||
|
||||
return ssb;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, Spanned ssb) {
|
||||
new AlertDialog.Builder(v.getContext())
|
||||
.setIcon(R.drawable.twotone_info_24)
|
||||
.setTitle(R.string.title_advanced_all_permissions)
|
||||
.setMessage(ssb)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// Do nothing
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(FragmentOptionsMisc.this, new Bundle(), "misc:permissions");
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize
|
||||
FragmentDialogTheme.setBackground(getContext(), view, false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user