use WorkManager for key sync
This commit is contained in:
@@ -17,7 +17,11 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@@ -25,14 +29,17 @@ import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.os.RemoteException;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.view.ContextThemeWrapper;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.network.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.ResourceUtils;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
@@ -169,4 +176,36 @@ public class OrbotRequiredDialogActivity extends FragmentActivity
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void showOrbotRequiredNotification(Context context) {
|
||||
NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
|
||||
if (manager != null) {
|
||||
manager.notify(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT, createOrbotNotification(context));
|
||||
}
|
||||
}
|
||||
|
||||
private static Notification createOrbotNotification(Context context) {
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||
builder.setSmallIcon(R.drawable.ic_stat_notify_24dp)
|
||||
.setLargeIcon(ResourceUtils.getDrawableAsNotificationBitmap(context, R.mipmap.ic_launcher))
|
||||
.setContentTitle(context.getString(R.string.keyserver_sync_orbot_notif_title))
|
||||
.setContentText(context.getString(R.string.keyserver_sync_orbot_notif_msg))
|
||||
.setAutoCancel(true);
|
||||
|
||||
Intent startOrbotIntent = new Intent(context, OrbotRequiredDialogActivity.class);
|
||||
startOrbotIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startOrbotIntent.putExtra(OrbotRequiredDialogActivity.EXTRA_START_ORBOT, true);
|
||||
PendingIntent startOrbotPi = PendingIntent.getActivity(
|
||||
context, 0, startOrbotIntent, PendingIntent.FLAG_CANCEL_CURRENT
|
||||
);
|
||||
|
||||
builder.addAction(R.drawable.ic_stat_tor,
|
||||
context.getString(R.string.keyserver_sync_orbot_notif_start),
|
||||
startOrbotPi
|
||||
);
|
||||
builder.setContentIntent(startOrbotPi);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,11 @@
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.Manifest;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
@@ -48,20 +53,16 @@ import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.KeychainApplication;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.compatibility.AppCompatPreferenceActivity;
|
||||
import org.sufficientlysecure.keychain.keyimport.HkpKeyserverAddress;
|
||||
import org.sufficientlysecure.keychain.keysync.KeyserverSyncManager;
|
||||
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.ThemeChanger;
|
||||
import org.sufficientlysecure.keychain.keyimport.HkpKeyserverAddress;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.network.orbot.OrbotHelper;
|
||||
import timber.log.Timber;
|
||||
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
|
||||
public static final int REQUEST_CODE_KEYSERVER_PREF = 0x00007005;
|
||||
@@ -398,6 +399,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
* This fragment shows the keyserver/wifi-only-sync/contacts sync preferences
|
||||
*/
|
||||
public static class SyncPrefsFragment extends PresetPreferenceFragment {
|
||||
boolean syncPrefChanged = false;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -405,6 +407,22 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource(R.xml.sync_preferences);
|
||||
|
||||
findPreference(Constants.Pref.SYNC_KEYSERVER).setOnPreferenceChangeListener(
|
||||
(preference, newValue) -> {
|
||||
syncPrefChanged = true;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
if (syncPrefChanged) {
|
||||
KeyserverSyncManager.updateKeyserverSyncSchedule(getActivity(), true);
|
||||
syncPrefChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -413,12 +431,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
// this needs to be done in onResume since the user can change sync values from Android
|
||||
// settings and we need to reflect that change when the user navigates back
|
||||
final Account account = KeychainApplication.createAccountIfNecessary(getActivity());
|
||||
// for keyserver sync
|
||||
initializeSyncCheckBox(
|
||||
(SwitchPreference) findPreference(Constants.Pref.SYNC_KEYSERVER),
|
||||
account,
|
||||
Constants.PROVIDER_AUTHORITY
|
||||
);
|
||||
// for contacts sync
|
||||
initializeSyncCheckBox(
|
||||
(SwitchPreference) findPreference(Constants.Pref.SYNC_CONTACTS),
|
||||
|
||||
@@ -33,7 +33,6 @@ import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
|
||||
import org.sufficientlysecure.keychain.service.KeyserverSyncAdapterService;
|
||||
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
|
||||
|
||||
/**
|
||||
@@ -77,7 +76,6 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
public static void onResumeChecks(Context context) {
|
||||
KeyserverSyncAdapterService.cancelUpdates(context);
|
||||
// in case user has disabled sync from Android account settings
|
||||
ContactSyncAdapterService.deleteIfSyncDisabled(context);
|
||||
}
|
||||
|
||||
@@ -363,6 +363,11 @@ public class KeyFormattingUtils {
|
||||
return idHex;
|
||||
}
|
||||
|
||||
public static String beautifyKeyId(byte[] fingerprint) {
|
||||
long keyId = KeyFormattingUtils.convertFingerprintToKeyId(fingerprint);
|
||||
return beautifyKeyId(keyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a human-readable version of a key ID, which is usually 64 bits: lower-case, no
|
||||
* leading 0x, space-separated quartets (for keys whose length in hex is divisible by 4)
|
||||
|
||||
Reference in New Issue
Block a user