Don't try to delete contacts if we don't have permission anymore

This commit is contained in:
Vincent Breitmoser 2018-07-18 13:38:04 +02:00
parent 22f4eb3e44
commit f9557cca37
3 changed files with 1 additions and 31 deletions

View file

@ -135,23 +135,6 @@ public class ContactSyncAdapterService extends Service {
ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true); ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
} }
public static void deleteIfSyncDisabled(Context context) {
if (!(ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS)
== PackageManager.PERMISSION_GRANTED)) {
return;
}
Account account = KeychainApplication.createAccountIfNecessary(context);
if (account == null) {
return;
}
// if user has disabled automatic sync, delete linked OpenKeychain contacts
if (!ContentResolver.getSyncAutomatically(account, ContactsContract.AUTHORITY)) {
new ContactHelper(context).deleteAllContacts();
}
}
// TODO: Import is currently disabled, until we implement proper origin management // TODO: Import is currently disabled, until we implement proper origin management
// private static void importKeys() { // private static void importKeys() {
// importDone.set(false); // importDone.set(false);

View file

@ -56,8 +56,6 @@ import org.sufficientlysecure.keychain.compatibility.AppCompatPreferenceActivity
import org.sufficientlysecure.keychain.keyimport.HkpKeyserverAddress; import org.sufficientlysecure.keychain.keyimport.HkpKeyserverAddress;
import org.sufficientlysecure.keychain.keysync.KeyserverSyncManager; import org.sufficientlysecure.keychain.keysync.KeyserverSyncManager;
import org.sufficientlysecure.keychain.network.orbot.OrbotHelper; import org.sufficientlysecure.keychain.network.orbot.OrbotHelper;
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.ui.util.ThemeChanger; import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.Preferences;
@ -86,7 +84,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
BaseActivity.onResumeChecks(this);
if (mThemeChanger.changeTheme()) { if (mThemeChanger.changeTheme()) {
Intent intent = getIntent(); Intent intent = getIntent();
@ -468,8 +465,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
} }
// disable syncs // disable syncs
ContentResolver.setSyncAutomatically(account, authority, false); ContentResolver.setSyncAutomatically(account, authority, false);
// immediately delete any linked contacts
ContactSyncAdapterService.deleteIfSyncDisabled(getActivity());
// cancel any ongoing/pending syncs // cancel any ongoing/pending syncs
ContentResolver.cancelSync(account, authority); ContentResolver.cancelSync(account, authority);
setSummary(syncCheckBox, authority, false); setSummary(syncCheckBox, authority, false);

View file

@ -17,8 +17,8 @@
package org.sufficientlysecure.keychain.ui.base; package org.sufficientlysecure.keychain.ui.base;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
@ -32,7 +32,6 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
import org.sufficientlysecure.keychain.ui.util.ThemeChanger; import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
/** /**
@ -54,7 +53,6 @@ public abstract class BaseActivity extends AppCompatActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
onResumeChecks(this);
if (mThemeChanger != null && mThemeChanger.changeTheme()) { if (mThemeChanger != null && mThemeChanger.changeTheme()) {
Intent intent = getIntent(); Intent intent = getIntent();
@ -75,11 +73,6 @@ public abstract class BaseActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
public static void onResumeChecks(Context context) {
// in case user has disabled sync from Android account settings
ContactSyncAdapterService.deleteIfSyncDisabled(context);
}
protected void initLayout() { protected void initLayout() {
} }
@ -191,5 +184,4 @@ public abstract class BaseActivity extends AppCompatActivity {
getSupportActionBar().setCustomView(customActionBarView, new ActionBar.LayoutParams( getSupportActionBar().setCustomView(customActionBarView, new ActionBar.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
} }
} }