improved orbot notify, added periodic sync
This commit is contained in:
@@ -141,9 +141,11 @@ android {
|
|||||||
|
|
||||||
// Reference them in the java files with e.g. BuildConfig.ACCOUNT_TYPE.
|
// Reference them in the java files with e.g. BuildConfig.ACCOUNT_TYPE.
|
||||||
buildConfigField "String", "ACCOUNT_TYPE", "\"org.sufficientlysecure.keychain.account\""
|
buildConfigField "String", "ACCOUNT_TYPE", "\"org.sufficientlysecure.keychain.account\""
|
||||||
|
buildConfigField "String", "PROVIDER_CONTENT_AUTHORITY", "\"org.sufficientlysecure.keychain.provider\""
|
||||||
|
|
||||||
// Reference them in .xml files.
|
// Reference them in .xml files.
|
||||||
resValue "string", "account_type", "org.sufficientlysecure.keychain.account"
|
resValue "string", "account_type", "org.sufficientlysecure.keychain.account"
|
||||||
|
resValue "string", "provider_content_authority", "org.sufficientlysecure.keychain.provider"
|
||||||
}
|
}
|
||||||
|
|
||||||
debug {
|
debug {
|
||||||
@@ -151,9 +153,11 @@ android {
|
|||||||
|
|
||||||
// Reference them in the java files with e.g. BuildConfig.ACCOUNT_TYPE.
|
// Reference them in the java files with e.g. BuildConfig.ACCOUNT_TYPE.
|
||||||
buildConfigField "String", "ACCOUNT_TYPE", "\"org.sufficientlysecure.keychain.debug.account\""
|
buildConfigField "String", "ACCOUNT_TYPE", "\"org.sufficientlysecure.keychain.debug.account\""
|
||||||
|
buildConfigField "String", "PROVIDER_CONTENT_AUTHORITY", "\"org.sufficientlysecure.keychain.debug.provider\""
|
||||||
|
|
||||||
// Reference them in .xml files.
|
// Reference them in .xml files.
|
||||||
resValue "string", "account_type", "org.sufficientlysecure.keychain.debug.account"
|
resValue "string", "account_type", "org.sufficientlysecure.keychain.debug.account"
|
||||||
|
resValue "string", "provider_content_authority", "org.sufficientlysecure.keychain.debug.provider"
|
||||||
|
|
||||||
// Enable code coverage (Jacoco)
|
// Enable code coverage (Jacoco)
|
||||||
testCoverageEnabled true
|
testCoverageEnabled true
|
||||||
|
|||||||
@@ -19,14 +19,9 @@ package org.sufficientlysecure.keychain;
|
|||||||
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
import org.spongycastle.bcpg.HashAlgorithmTags;
|
|
||||||
import org.spongycastle.bcpg.SymmetricKeyAlgorithmTags;
|
|
||||||
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.BuildConfig;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
|
|
||||||
public final class Constants {
|
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 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 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 TEMPSTORAGE_AUTHORITY = BuildConfig.APPLICATION_ID + ".tempstorage";
|
||||||
|
|
||||||
public static final String CLIPBOARD_LABEL = "Keychain";
|
public static final String CLIPBOARD_LABEL = "Keychain";
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import android.graphics.Canvas;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.v4.app.NotificationCompat;
|
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.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
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.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||||
@@ -41,19 +42,49 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
public class KeyserverSyncAdapterService extends Service {
|
public class KeyserverSyncAdapterService extends Service {
|
||||||
|
|
||||||
private static final String ACTION_IGNORE_TOR = "ignore_tor";
|
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
|
@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");
|
Log.e("PHILIP", "Sync adapter service starting");
|
||||||
|
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
switch (intent.getAction()) {
|
switch (intent.getAction()) {
|
||||||
case ACTION_IGNORE_TOR: {
|
case ACTION_IGNORE_TOR: {
|
||||||
updateKeysFromKeyserver(this,
|
updateKeysFromKeyserver(this,
|
||||||
new CryptoInputParcel(ParcelableProxy.getForNoProxy()));
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: correct flag?
|
// TODO: correct flag?
|
||||||
return START_NOT_STICKY;
|
return START_REDELIVER_INTENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AtomicBoolean sCancelled = new AtomicBoolean(false);
|
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_UPDATED_KEYS_MASTER_KEY_ID = 0;
|
||||||
final int INDEX_LAST_UPDATED = 1;
|
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);
|
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(
|
Cursor updatedKeysCursor = context.getContentResolver().query(
|
||||||
KeychainContract.UpdatedKeys.CONTENT_URI,
|
KeychainContract.UpdatedKeys.CONTENT_URI,
|
||||||
new String[]{
|
new String[]{
|
||||||
KeychainContract.UpdatedKeys.MASTER_KEY_ID,
|
KeychainContract.UpdatedKeys.MASTER_KEY_ID,
|
||||||
KeychainContract.UpdatedKeys.LAST_UPDATED
|
KeychainContract.UpdatedKeys.LAST_UPDATED
|
||||||
},
|
},
|
||||||
"? - " + KeychainContract.UpdatedKeys.LAST_UPDATED + " < " + TIME_DAY,
|
"? - " + KeychainContract.UpdatedKeys.LAST_UPDATED + " < " + TIME_MAX,
|
||||||
new String[]{"" + CURRENT_TIME},
|
new String[]{"" + CURRENT_TIME},
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
@@ -110,7 +141,7 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
while (updatedKeysCursor.moveToNext()) {
|
while (updatedKeysCursor.moveToNext()) {
|
||||||
long masterKeyId = updatedKeysCursor.getLong(INDEX_UPDATED_KEYS_MASTER_KEY_ID);
|
long masterKeyId = updatedKeysCursor.getLong(INDEX_UPDATED_KEYS_MASTER_KEY_ID);
|
||||||
Log.d(Constants.TAG, "Keyserver sync: {" + masterKeyId + "} last updated at {"
|
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);
|
ignoreMasterKeyIds.add(masterKeyId);
|
||||||
}
|
}
|
||||||
updatedKeysCursor.close();
|
updatedKeysCursor.close();
|
||||||
@@ -197,7 +228,7 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
ignoreTorIntent.setAction(ACTION_IGNORE_TOR);
|
ignoreTorIntent.setAction(ACTION_IGNORE_TOR);
|
||||||
PendingIntent ignoreTorPi = PendingIntent.getService(
|
PendingIntent ignoreTorPi = PendingIntent.getService(
|
||||||
context,
|
context,
|
||||||
Constants.Notification.KEYSERVER_SYNC_FAIL_ORBOT,
|
0, // security not issue since we're giving this pending intent to Notification Manager
|
||||||
ignoreTorIntent,
|
ignoreTorIntent,
|
||||||
PendingIntent.FLAG_CANCEL_CURRENT
|
PendingIntent.FLAG_CANCEL_CURRENT
|
||||||
);
|
);
|
||||||
@@ -206,9 +237,50 @@ public class KeyserverSyncAdapterService extends Service {
|
|||||||
context.getString(R.string.keyserver_sync_orbot_notif_ignore),
|
context.getString(R.string.keyserver_sync_orbot_notif_ignore),
|
||||||
ignoreTorPi);
|
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();
|
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
|
// from de.azapps.mirakel.helper.Helpers from https://github.com/MirakelX/mirakel-android
|
||||||
private static Bitmap getBitmap(int resId, Context context) {
|
private static Bitmap getBitmap(int resId, Context context) {
|
||||||
int mLargeIconWidth = (int) context.getResources().getDimension(
|
int mLargeIconWidth = (int) context.getResources().getDimension(
|
||||||
|
|||||||
@@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
|
import android.accounts.AccountManager;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
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.PrimaryDrawerItem;
|
||||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.remote.ui.AppsListFragment;
|
import org.sufficientlysecure.keychain.remote.ui.AppsListFragment;
|
||||||
|
import org.sufficientlysecure.keychain.service.KeyserverSyncAdapterService;
|
||||||
import org.sufficientlysecure.keychain.ui.base.BaseNfcActivity;
|
import org.sufficientlysecure.keychain.ui.base.BaseNfcActivity;
|
||||||
import org.sufficientlysecure.keychain.util.FabContainer;
|
import org.sufficientlysecure.keychain.util.FabContainer;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
public class MainActivity extends BaseNfcActivity implements FabContainer, OnBackStackChangedListener {
|
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) {
|
private void setFragment(Fragment fragment, boolean addToBackStack) {
|
||||||
|
|||||||
@@ -1352,10 +1352,10 @@
|
|||||||
<string name="passp_cache_notif_pwd">"Password"</string>
|
<string name="passp_cache_notif_pwd">"Password"</string>
|
||||||
|
|
||||||
<!-- Keyserver sync -->
|
<!-- Keyserver sync -->
|
||||||
<string name="keyserver_sync_orbot_notif_title">"Orbot not running"</string>
|
<string name="keyserver_sync_orbot_notif_title">"Sync From Cloud requires Orbot"</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_msg">"Tap to start orbot"</string>
|
||||||
<string name="keyserver_sync_orbot_notif_start">"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 -->
|
<!-- First Time -->
|
||||||
<string name="first_time_text1">"Take back your privacy with OpenKeychain!"</string>
|
<string name="first_time_text1">"Take back your privacy with OpenKeychain!"</string>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
|
<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:accountType="@string/account_type"
|
||||||
android:supportsUploading="false"
|
android:supportsUploading="false"
|
||||||
android:userVisible="true"
|
android:userVisible="true"
|
||||||
|
|||||||
Reference in New Issue
Block a user