Show notification when READ_CONTACTS permission is denied in sync service, hide linked contact card if permission is denied
This commit is contained in:
@@ -133,7 +133,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource(R.xml.cloud_search_prefs);
|
||||
addPreferencesFromResource(R.xml.cloud_search_preferences);
|
||||
|
||||
mKeyServerPreference = (PreferenceScreen) findPreference(Constants.Pref.KEY_SERVERS);
|
||||
mKeyServerPreference.setSummary(keyserverSummary(getActivity()));
|
||||
@@ -238,11 +238,11 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
if (mFragment != null) {
|
||||
Preferences.setPreferenceManagerFileAndMode(mFragment.getPreferenceManager());
|
||||
// Load the preferences from an XML resource
|
||||
mFragment.addPreferencesFromResource(R.xml.proxy_prefs);
|
||||
mFragment.addPreferencesFromResource(R.xml.proxy_preferences);
|
||||
} else {
|
||||
Preferences.setPreferenceManagerFileAndMode(mActivity.getPreferenceManager());
|
||||
// Load the preferences from an XML resource
|
||||
mActivity.addPreferencesFromResource(R.xml.proxy_prefs);
|
||||
mActivity.addPreferencesFromResource(R.xml.proxy_preferences);
|
||||
}
|
||||
|
||||
mUseTor = (SwitchPreference) automaticallyFindPreference(Constants.Pref.USE_TOR_PROXY);
|
||||
@@ -509,9 +509,9 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
// permission granted -> enable contact linking
|
||||
AccountManager manager = AccountManager.get(getActivity());
|
||||
final Account account = manager.getAccountsByType(Constants.ACCOUNT_TYPE)[0];
|
||||
SwitchPreference pref = (SwitchPreference) findPreference(Constants.Pref.SYNC_KEYSERVER);
|
||||
ContentResolver.setSyncAutomatically(account, Constants.PROVIDER_AUTHORITY, true);
|
||||
setSummary(pref, Constants.PROVIDER_AUTHORITY, true);
|
||||
SwitchPreference pref = (SwitchPreference) findPreference(Constants.Pref.SYNC_CONTACTS);
|
||||
ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
|
||||
setSummary(pref, ContactsContract.AUTHORITY, true);
|
||||
pref.setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -855,8 +855,8 @@ public class ViewKeyActivity extends BaseNfcActivity implements
|
||||
AsyncTask<Long, Void, Bitmap> photoTask =
|
||||
new AsyncTask<Long, Void, Bitmap>() {
|
||||
protected Bitmap doInBackground(Long... mMasterKeyId) {
|
||||
return ContactHelper.loadPhotoByMasterKeyId(getContentResolver(),
|
||||
mMasterKeyId[0], true);
|
||||
return ContactHelper.loadPhotoByMasterKeyId(ViewKeyActivity.this,
|
||||
getContentResolver(), mMasterKeyId[0], true);
|
||||
}
|
||||
|
||||
protected void onPostExecute(Bitmap photo) {
|
||||
|
||||
@@ -22,10 +22,12 @@ package org.sufficientlysecure.keychain.ui;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
@@ -35,6 +37,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v7.widget.CardView;
|
||||
@@ -241,9 +244,9 @@ public class ViewKeyFragment extends LoaderFragment implements
|
||||
|
||||
Bitmap picture;
|
||||
if (mIsSecret) {
|
||||
picture = ContactHelper.loadMainProfilePhoto(resolver, false);
|
||||
picture = ContactHelper.loadMainProfilePhoto(getActivity(), resolver, false);
|
||||
} else {
|
||||
picture = ContactHelper.loadPhotoByContactId(resolver, contactId, false);
|
||||
picture = ContactHelper.loadPhotoByContactId(getActivity(), resolver, contactId, false);
|
||||
}
|
||||
if (picture != null) mSystemContactPicture.setImageBitmap(picture);
|
||||
|
||||
@@ -419,13 +422,7 @@ public class ViewKeyFragment extends LoaderFragment implements
|
||||
getLoaderManager().initLoader(LOADER_ID_LINKED_IDS, null, this);
|
||||
}
|
||||
|
||||
|
||||
Bundle linkedContactData = new Bundle();
|
||||
linkedContactData.putLong(LOADER_EXTRA_LINKED_CONTACT_MASTER_KEY_ID, masterKeyId);
|
||||
linkedContactData.putBoolean(LOADER_EXTRA_LINKED_CONTACT_IS_SECRET, mIsSecret);
|
||||
|
||||
// initialises loader for contact query so we can listen to any updates
|
||||
getLoaderManager().initLoader(LOADER_ID_LINKED_CONTACT, linkedContactData, this);
|
||||
initLinkedContactLoader(masterKeyId, mIsSecret);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -465,6 +462,22 @@ public class ViewKeyFragment extends LoaderFragment implements
|
||||
}
|
||||
}
|
||||
|
||||
private void initLinkedContactLoader(long masterKeyId, boolean isSecret) {
|
||||
if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_CONTACTS)
|
||||
== PackageManager.PERMISSION_DENIED) {
|
||||
Log.w(Constants.TAG, "loading linked system contact not possible READ_CONTACTS permission denied!");
|
||||
hideLinkedSystemContact();
|
||||
return;
|
||||
}
|
||||
|
||||
Bundle linkedContactData = new Bundle();
|
||||
linkedContactData.putLong(LOADER_EXTRA_LINKED_CONTACT_MASTER_KEY_ID, masterKeyId);
|
||||
linkedContactData.putBoolean(LOADER_EXTRA_LINKED_CONTACT_IS_SECRET, isSecret);
|
||||
|
||||
// initialises loader for contact query so we can listen to any updates
|
||||
getLoaderManager().initLoader(LOADER_ID_LINKED_CONTACT, linkedContactData, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the last Cursor provided to onLoadFinished() above is about to be closed.
|
||||
* We need to make sure we are no longer using it.
|
||||
|
||||
Reference in New Issue
Block a user