aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src
diff options
context:
space:
mode:
authorAdithya Abraham Philip <adithyaphilip@gmail.com>2015-07-30 04:39:38 +0530
committerAdithya Abraham Philip <adithyaphilip@gmail.com>2015-08-20 21:02:29 +0530
commit448657602ce5baa5b2a99e26ab2eb2fb8061778f (patch)
treeee3e0382a60585cb22ef324db2ea10163349e871 /OpenKeychain/src
parent1ef6f883e34a08dc916ad7dfabd7f892964aff54 (diff)
downloadopen-keychain-448657602ce5baa5b2a99e26ab2eb2fb8061778f.tar.gz
open-keychain-448657602ce5baa5b2a99e26ab2eb2fb8061778f.tar.bz2
open-keychain-448657602ce5baa5b2a99e26ab2eb2fb8061778f.zip
improved orbot notify, added periodic sync
Diffstat (limited to 'OpenKeychain/src')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java7
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java88
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java19
-rw-r--r--OpenKeychain/src/main/res/values/strings.xml6
-rw-r--r--OpenKeychain/src/main/res/xml/keyserver_sync_adapter_desc.xml2
5 files changed, 104 insertions, 18 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java
index c66c33453..03d39f6be 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java
@@ -19,14 +19,9 @@ package org.sufficientlysecure.keychain;
import android.os.Environment;
-import org.spongycastle.bcpg.HashAlgorithmTags;
-import org.spongycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.spongycastle.jce.provider.BouncyCastleProvider;
-import org.sufficientlysecure.keychain.BuildConfig;
-
import java.io.File;
-import java.net.InetSocketAddress;
import java.net.Proxy;
public final class Constants {
@@ -43,7 +38,7 @@ public final class Constants {
public static final String ACCOUNT_TYPE = BuildConfig.ACCOUNT_TYPE;
public static final String CUSTOM_CONTACT_DATA_MIME_TYPE = "vnd.android.cursor.item/vnd.org.sufficientlysecure.keychain.key";
- public static final String PROVIDER_AUTHORITY = BuildConfig.APPLICATION_ID + ".provider";
+ public static final String PROVIDER_AUTHORITY = BuildConfig.PROVIDER_CONTENT_AUTHORITY;
public static final String TEMPSTORAGE_AUTHORITY = BuildConfig.APPLICATION_ID + ".tempstorage";
public static final String CLIPBOARD_LABEL = "Keychain";
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java
index 4a7e2942e..a08797e6d 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java
@@ -16,6 +16,7 @@ import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
+import android.os.Handler;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
@@ -27,7 +28,7 @@ import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
-import org.sufficientlysecure.keychain.ui.MainActivity;
+import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ParcelableProxy;
@@ -41,19 +42,49 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class KeyserverSyncAdapterService extends Service {
private static final String ACTION_IGNORE_TOR = "ignore_tor";
+ private static final String ACTION_DISMISS_NOTIFICATION = "cancel_sync";
+ private static final String ACTION_START_ORBOT = "start_orbot";
@Override
- public int onStartCommand(Intent intent, int flags, int startId) {
+ public int onStartCommand(Intent intent, int flags, final int startId) {
Log.e("PHILIP", "Sync adapter service starting");
+ NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
switch (intent.getAction()) {
case ACTION_IGNORE_TOR: {
updateKeysFromKeyserver(this,
new CryptoInputParcel(ParcelableProxy.getForNoProxy()));
+ manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT);
+ stopSelf(startId);
+ break;
+ }
+ case ACTION_START_ORBOT: {
+ Intent startOrbot = new Intent(this, OrbotRequiredDialogActivity.class);
+ startOrbot.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startOrbot.setAction(OrbotRequiredDialogActivity.ACTION_START_ORBOT);
+ startActivity(startOrbot);
+ new Handler().postDelayed(
+ new Runnable() {
+ @Override
+ public void run() {
+ updateKeysFromKeyserver(KeyserverSyncAdapterService.this,
+ new CryptoInputParcel());
+ stopSelf(startId);
+ }
+ },
+ 30000 // shouldn't take longer for orbot to start
+ );
+
+ manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT);
+ break;
+ }
+ case ACTION_DISMISS_NOTIFICATION: {
+ manager.cancel(Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT);
+ stopSelf(startId);
break;
}
}
// TODO: correct flag?
- return START_NOT_STICKY;
+ return START_REDELIVER_INTENT;
}
private static AtomicBoolean sCancelled = new AtomicBoolean(false);
@@ -92,16 +123,16 @@ public class KeyserverSyncAdapterService extends Service {
final int INDEX_UPDATED_KEYS_MASTER_KEY_ID = 0;
final int INDEX_LAST_UPDATED = 1;
- final long TIME_DAY = TimeUnit.DAYS.toSeconds(1);
+ final long TIME_MAX = TimeUnit.DAYS.toSeconds(7);
final long CURRENT_TIME = GregorianCalendar.getInstance().get(GregorianCalendar.SECOND);
- Log.e("PHILIP", "day: " + TIME_DAY);
+ Log.e("PHILIP", "week: " + TIME_MAX);
Cursor updatedKeysCursor = context.getContentResolver().query(
KeychainContract.UpdatedKeys.CONTENT_URI,
new String[]{
KeychainContract.UpdatedKeys.MASTER_KEY_ID,
KeychainContract.UpdatedKeys.LAST_UPDATED
},
- "? - " + KeychainContract.UpdatedKeys.LAST_UPDATED + " < " + TIME_DAY,
+ "? - " + KeychainContract.UpdatedKeys.LAST_UPDATED + " < " + TIME_MAX,
new String[]{"" + CURRENT_TIME},
null
);
@@ -110,7 +141,7 @@ public class KeyserverSyncAdapterService extends Service {
while (updatedKeysCursor.moveToNext()) {
long masterKeyId = updatedKeysCursor.getLong(INDEX_UPDATED_KEYS_MASTER_KEY_ID);
Log.d(Constants.TAG, "Keyserver sync: {" + masterKeyId + "} last updated at {"
- + updatedKeysCursor.getLong(INDEX_LAST_UPDATED) + "}s");
+ + updatedKeysCursor.getLong(INDEX_LAST_UPDATED) + "}s");
ignoreMasterKeyIds.add(masterKeyId);
}
updatedKeysCursor.close();
@@ -197,7 +228,7 @@ public class KeyserverSyncAdapterService extends Service {
ignoreTorIntent.setAction(ACTION_IGNORE_TOR);
PendingIntent ignoreTorPi = PendingIntent.getService(
context,
- Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT,
+ 0, // security not issue since we're giving this pending intent to Notification Manager
ignoreTorIntent,
PendingIntent.FLAG_CANCEL_CURRENT
);
@@ -206,9 +237,50 @@ public class KeyserverSyncAdapterService extends Service {
context.getString(R.string.keyserver_sync_orbot_notif_ignore),
ignoreTorPi);
+ // not enough space to show it
+ Intent dismissIntent = new Intent(context, KeyserverSyncAdapterService.class);
+ dismissIntent.setAction(ACTION_DISMISS_NOTIFICATION);
+ PendingIntent dismissPi = PendingIntent.getService(
+ context,
+ 0, // security not issue since we're giving this pending intent to Notification Manager
+ dismissIntent,
+ PendingIntent.FLAG_CANCEL_CURRENT
+ );
+
+ /*builder.addAction(R.drawable.abc_ic_clear_mtrl_alpha,
+ context.getString(android.R.string.cancel),
+ dismissPi
+ );*/
+
+ Intent startOrbotIntent = new Intent(context, KeyserverSyncAdapterService.class);
+ startOrbotIntent.setAction(ACTION_START_ORBOT);
+ PendingIntent startOrbotPi = PendingIntent.getService(
+ context,
+ 0, // security not issue since we're giving this pending intent to Notification Manager
+ startOrbotIntent,
+ PendingIntent.FLAG_CANCEL_CURRENT
+ );
+
+ builder.addAction(R.drawable.abc_ic_clear_mtrl_alpha,
+ context.getString(R.string.keyserver_sync_orbot_notif_start),
+ startOrbotPi
+ );
+ builder.setContentIntent(startOrbotPi);
+
return builder.build();
}
+ /**
+ * will perform a staggered update of user's keys using delays to ensure new Tor circuits, as
+ * performed by parcimonie
+ *
+ * @return result of the sync
+ */
+ private static ImportKeyResult staggeredSync() {
+ // TODO: WIP
+ return null;
+ }
+
// from de.azapps.mirakel.helper.Helpers from https://github.com/MirakelX/mirakel-android
private static Bitmap getBitmap(int resId, Context context) {
int mLargeIconWidth = (int) context.getResources().getDimension(
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java
index 6f5d98afd..0fa6566f8 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java
@@ -19,6 +19,9 @@
package org.sufficientlysecure.keychain.ui;
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.content.ContentResolver;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
@@ -37,11 +40,14 @@ import com.mikepenz.materialdrawer.DrawerBuilder;
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
+import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.operations.results.OperationResult;
import org.sufficientlysecure.keychain.remote.ui.AppsListFragment;
+import org.sufficientlysecure.keychain.service.KeyserverSyncAdapterService;
import org.sufficientlysecure.keychain.ui.base.BaseNfcActivity;
import org.sufficientlysecure.keychain.util.FabContainer;
+import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Preferences;
public class MainActivity extends BaseNfcActivity implements FabContainer, OnBackStackChangedListener {
@@ -164,6 +170,19 @@ public class MainActivity extends BaseNfcActivity implements FabContainer, OnBac
}
}
+ enablePeriodicKeyserverSync();
+
+ }
+
+ private void enablePeriodicKeyserverSync() {
+ // TODO: Increase periodic update time after testing
+ Log.e("PHILIP", "enabled periodic keyserversybc");
+ ContentResolver.addPeriodicSync(
+ new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE),
+ Constants.PROVIDER_AUTHORITY,
+ new Bundle(),
+ 2*60
+ );
}
private void setFragment(Fragment fragment, boolean addToBackStack) {
diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml
index 6309faf85..67a727645 100644
--- a/OpenKeychain/src/main/res/values/strings.xml
+++ b/OpenKeychain/src/main/res/values/strings.xml
@@ -1352,10 +1352,10 @@
<string name="passp_cache_notif_pwd">"Password"</string>
<!-- Keyserver sync -->
- <string name="keyserver_sync_orbot_notif_title">"Orbot not running"</string>
- <string name="keyserver_sync_orbot_notif_msg">"Keyserver sync failed since Orbot is not running. What would you like to do?"</string>
+ <string name="keyserver_sync_orbot_notif_title">"Sync From Cloud requires Orbot"</string>
+ <string name="keyserver_sync_orbot_notif_msg">"Tap to start orbot"</string>
<string name="keyserver_sync_orbot_notif_start">"Start Orbot"</string>
- <string name="keyserver_sync_orbot_notif_ignore">"Don't use Tor"</string>
+ <string name="keyserver_sync_orbot_notif_ignore">"Direct"</string>
<!-- First Time -->
<string name="first_time_text1">"Take back your privacy with OpenKeychain!"</string>
diff --git a/OpenKeychain/src/main/res/xml/keyserver_sync_adapter_desc.xml b/OpenKeychain/src/main/res/xml/keyserver_sync_adapter_desc.xml
index 76211aaf1..3923fae59 100644
--- a/OpenKeychain/src/main/res/xml/keyserver_sync_adapter_desc.xml
+++ b/OpenKeychain/src/main/res/xml/keyserver_sync_adapter_desc.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
- android:contentAuthority="org.sufficientlysecure.keychain.debug.provider"
+ android:contentAuthority="@string/provider_content_authority"
android:accountType="@string/account_type"
android:supportsUploading="false"
android:userVisible="true"