From 310b94e280565bd3b3b567407d99c37d4809b8e4 Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Sat, 25 Mar 2017 20:12:08 +0100 Subject: [PATCH] Add more debug information * power saving status * permissions * address book accounts --- .../syncadapter/ui/DebugInfoActivity.java | 37 +++++++++++++++++-- .../syncadapter/ui/StartupDialogFragment.java | 2 +- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/DebugInfoActivity.java b/app/src/main/java/com/etesync/syncadapter/ui/DebugInfoActivity.java index b9fc1d00..838b0dff 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/DebugInfoActivity.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/DebugInfoActivity.java @@ -8,6 +8,7 @@ package com.etesync.syncadapter.ui; +import android.Manifest; import android.accounts.Account; import android.accounts.AccountManager; import android.annotation.SuppressLint; @@ -20,8 +21,10 @@ import android.content.Loader; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; +import android.os.PowerManager; import android.provider.CalendarContract; import android.provider.ContactsContract; +import android.support.v4.content.ContextCompat; import android.support.v4.content.FileProvider; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; @@ -50,7 +53,9 @@ import com.etesync.syncadapter.model.EntryEntity; import com.etesync.syncadapter.model.JournalEntity; import com.etesync.syncadapter.model.ServiceDB; import com.etesync.syncadapter.model.ServiceEntity; +import com.etesync.syncadapter.resource.LocalAddressBook; +import at.bitfire.vcard4android.ContactsStorageException; import io.requery.Persistable; import io.requery.sql.EntityDataStore; import lombok.Cleanup; @@ -215,9 +220,25 @@ public class DebugInfoActivity extends AppCompatActivity implements LoaderManage App.log.log(Level.SEVERE, "Couldn't get software information", ex); } - report.append( - "CONFIGURATION\n" + - "System-wide synchronization: ").append(ContentResolver.getMasterSyncAutomatically() ? "automatically" : "manually").append("\n"); + report.append("CONFIGURATION\n"); + // power saving + PowerManager powerManager = (PowerManager)getContext().getSystemService(Context.POWER_SERVICE); + if (powerManager != null && Build.VERSION.SDK_INT >= 23) + report.append("Power saving disabled: ") + .append(powerManager.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID) ? "yes" : "no") + .append("\n"); + // permissions + for (String permission : new String[] { Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS, + Manifest.permission.READ_CALENDAR, Manifest.permission.WRITE_CALENDAR, + PermissionsActivity.PERMISSION_READ_TASKS, PermissionsActivity.PERMISSION_WRITE_TASKS }) + report.append(permission).append(" permission: ") + .append(ContextCompat.checkSelfPermission(getContext(), permission) == PackageManager.PERMISSION_GRANTED ? "granted" : "denied") + .append("\n"); + // system-wide sync settings + report.append("System-wide synchronization: ") + .append(ContentResolver.getMasterSyncAutomatically() ? "automatically" : "manually") + .append("\n"); + // main accounts AccountManager accountManager = AccountManager.get(getContext()); for (Account acct : accountManager.getAccountsByType(Constants.ACCOUNT_TYPE)) try { @@ -235,6 +256,16 @@ public class DebugInfoActivity extends AppCompatActivity implements LoaderManage } catch(InvalidAccountException e) { report.append(acct).append(" is invalid (unsupported settings version) or does not exist\n"); } + // address book accounts + for (Account acct : accountManager.getAccountsByType(getContext().getString(R.string.account_type_address_book))) + try { + LocalAddressBook addressBook = new LocalAddressBook(getContext(), acct, null); + report.append("Address book account: ").append(acct.name).append("\n" + + " Main account: ").append(addressBook.getMainAccount()).append("\n" + + " URL: ").append(addressBook.getURL()).append("\n"); + } catch(ContactsStorageException e) { + report.append(acct).append(" is invalid: ").append(e.getMessage()).append("\n"); + } report.append("\n"); report.append("SQLITE DUMP\n"); diff --git a/app/src/main/java/com/etesync/syncadapter/ui/StartupDialogFragment.java b/app/src/main/java/com/etesync/syncadapter/ui/StartupDialogFragment.java index e04cfa0c..4c39fdd1 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/StartupDialogFragment.java +++ b/app/src/main/java/com/etesync/syncadapter/ui/StartupDialogFragment.java @@ -52,7 +52,7 @@ public class StartupDialogFragment extends DialogFragment { // battery optimization whitelisting if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !HintManager.getHintSeen(context, HINT_BATTERY_OPTIMIZATIONS)) { PowerManager powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); - if (!powerManager.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID)) + if (powerManager != null && !powerManager.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID)) dialogs.add(StartupDialogFragment.instantiate(Mode.BATTERY_OPTIMIZATIONS)); }