reworked keyserversyncadapterservice flow
This commit is contained in:
@@ -18,13 +18,9 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
@@ -64,13 +60,14 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.ConsolidateInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.KeyserverSyncAdapterService;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.util.FabContainer;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
@@ -78,6 +75,10 @@ import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;
|
||||
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Public key list with sticky list headers. It does _not_ extend ListFragment because it uses
|
||||
* StickyListHeaders library which does not extend upon ListView.
|
||||
@@ -520,9 +521,7 @@ public class KeyListFragment extends LoaderFragment
|
||||
}
|
||||
|
||||
private void updateAllKeys() {
|
||||
// TODO: PHILIP just for testing, remove!
|
||||
KeyserverSyncAdapterService.updateKeysFromKeyserver(getActivity(), new CryptoInputParcel());
|
||||
/*Activity activity = getActivity();
|
||||
Activity activity = getActivity();
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
@@ -536,7 +535,7 @@ public class KeyListFragment extends LoaderFragment
|
||||
);
|
||||
|
||||
if (cursor == null) {
|
||||
Notify.create(activity, R.string.error_loading_keys, Style.ERROR);
|
||||
Notify.create(activity, R.string.error_loading_keys, Notify.Style.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -563,7 +562,7 @@ public class KeyListFragment extends LoaderFragment
|
||||
|
||||
mImportOpHelper = new CryptoOperationHelper<>(1, this,
|
||||
this, R.string.progress_updating);
|
||||
mImportOpHelper.cryptoOperation();*/
|
||||
mImportOpHelper.cryptoOperation();
|
||||
}
|
||||
|
||||
private void consolidate() {
|
||||
@@ -647,18 +646,6 @@ public class KeyListFragment extends LoaderFragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
KeyserverSyncAdapterService.preventAndCancelUpdates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
KeyserverSyncAdapterService.allowUpdates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fabMoveUp(int height) {
|
||||
ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, "translationY", 0, -height);
|
||||
|
||||
@@ -19,9 +19,6 @@
|
||||
|
||||
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;
|
||||
@@ -40,14 +37,11 @@ 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 {
|
||||
@@ -170,19 +164,6 @@ 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) {
|
||||
|
||||
@@ -18,12 +18,20 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.os.RemoteException;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
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.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
|
||||
@@ -34,8 +42,14 @@ import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
public class OrbotRequiredDialogActivity extends FragmentActivity
|
||||
implements OrbotHelper.DialogActions {
|
||||
|
||||
public static final int MESSAGE_ORBOT_STARTED = 1;
|
||||
public static final int MESSAGE_ORBOT_IGNORE = 2;
|
||||
public static final int MESSAGE_DIALOG_CANCEL = 3;
|
||||
|
||||
// if suppplied and true will start Orbot directly without showing dialog
|
||||
public static final String EXTRA_START_ORBOT = "start_orbot";
|
||||
// used for communicating results when triggered from a service
|
||||
public static final String EXTRA_MESSENGER = "messenger";
|
||||
|
||||
// to provide any previous crypto input into which proxy preference is merged
|
||||
public static final String EXTRA_CRYPTO_INPUT = "extra_crypto_input";
|
||||
@@ -43,6 +57,9 @@ public class OrbotRequiredDialogActivity extends FragmentActivity
|
||||
public static final String RESULT_CRYPTO_INPUT = "result_crypto_input";
|
||||
|
||||
private CryptoInputParcel mCryptoInputParcel;
|
||||
private Messenger mMessenger;
|
||||
|
||||
private ProgressDialog mShowOrbotProgressDialog;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -54,9 +71,15 @@ public class OrbotRequiredDialogActivity extends FragmentActivity
|
||||
mCryptoInputParcel = new CryptoInputParcel();
|
||||
}
|
||||
|
||||
mMessenger = getIntent().getParcelableExtra(EXTRA_MESSENGER);
|
||||
|
||||
boolean startOrbotDirect = getIntent().getBooleanExtra(EXTRA_START_ORBOT, false);
|
||||
if (startOrbotDirect) {
|
||||
OrbotHelper.bestPossibleOrbotStart(this, this);
|
||||
mShowOrbotProgressDialog = new ProgressDialog(this);
|
||||
mShowOrbotProgressDialog.setTitle(R.string.progress_starting_orbot);
|
||||
mShowOrbotProgressDialog.setCancelable(false);
|
||||
mShowOrbotProgressDialog.show();
|
||||
OrbotHelper.bestPossibleOrbotStart(this, this, false);
|
||||
} else {
|
||||
showDialog();
|
||||
}
|
||||
@@ -84,13 +107,32 @@ public class OrbotRequiredDialogActivity extends FragmentActivity
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
switch (requestCode) {
|
||||
case OrbotHelper.START_TOR_RESULT: {
|
||||
onOrbotStarted(); // assumption that orbot was started, no way to tell for sure
|
||||
dismissOrbotProgressDialog();
|
||||
// unfortunately, this result is returned immediately and not when Orbot is started
|
||||
// 10s is approximately the longest time Orbot has taken to start
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onOrbotStarted(); // assumption that orbot was started
|
||||
}
|
||||
}, 10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* for when Orbot is started without showing the dialog by the EXTRA_START_ORBOT intent extra
|
||||
*/
|
||||
private void dismissOrbotProgressDialog() {
|
||||
if (mShowOrbotProgressDialog != null) {
|
||||
mShowOrbotProgressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOrbotStarted() {
|
||||
dismissOrbotProgressDialog();
|
||||
sendMessage(MESSAGE_ORBOT_STARTED);
|
||||
Intent intent = new Intent();
|
||||
// send back unmodified CryptoInputParcel for a retry
|
||||
intent.putExtra(RESULT_CRYPTO_INPUT, mCryptoInputParcel);
|
||||
@@ -100,6 +142,7 @@ public class OrbotRequiredDialogActivity extends FragmentActivity
|
||||
|
||||
@Override
|
||||
public void onNeutralButton() {
|
||||
sendMessage(MESSAGE_ORBOT_IGNORE);
|
||||
Intent intent = new Intent();
|
||||
mCryptoInputParcel.addParcelableProxy(ParcelableProxy.getForNoProxy());
|
||||
intent.putExtra(RESULT_CRYPTO_INPUT, mCryptoInputParcel);
|
||||
@@ -109,6 +152,19 @@ public class OrbotRequiredDialogActivity extends FragmentActivity
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
sendMessage(MESSAGE_DIALOG_CANCEL);
|
||||
finish();
|
||||
}
|
||||
|
||||
private void sendMessage(int what) {
|
||||
if (mMessenger != null) {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = what;
|
||||
try {
|
||||
mMessenger.send(msg);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "Could not deliver message", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.service.KeyserverSyncAdapterService;
|
||||
import org.sufficientlysecure.keychain.ui.util.ThemeChanger;
|
||||
|
||||
/**
|
||||
@@ -51,6 +52,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
KeyserverSyncAdapterService.cancelUpdates(this);
|
||||
|
||||
if (mThemeChanger.changeTheme()) {
|
||||
Intent intent = getIntent();
|
||||
|
||||
Reference in New Issue
Block a user