List of usage examples for android.os Messenger Messenger
public Messenger(IBinder target)
From source file:org.sufficientlysecure.keychain.ui.keyview.ViewKeyActivity.java
private void changePassword() { CryptoOperationHelper.Callback<ChangeUnlockParcel, EditKeyResult> editKeyCallback = new CryptoOperationHelper.Callback<ChangeUnlockParcel, EditKeyResult>() { @Override//from w w w .ja va2s.c o m public ChangeUnlockParcel createOperationInput() { return mChangeUnlockParcel; } @Override public void onCryptoOperationSuccess(EditKeyResult result) { displayResult(result); } @Override public void onCryptoOperationCancelled() { } @Override public void onCryptoOperationError(EditKeyResult result) { displayResult(result); } @Override public boolean onCryptoSetProgress(String msg, int progress, int max) { return false; } }; mEditOpHelper = new CryptoOperationHelper<>(2, this, editKeyCallback, R.string.progress_building_key); // Message is received after passphrase is cached Handler returnHandler = new Handler() { @Override public void handleMessage(Message message) { if (message.what == SetPassphraseDialogFragment.MESSAGE_OKAY) { Bundle data = message.getData(); // use new passphrase! mChangeUnlockParcel = ChangeUnlockParcel.createChangeUnlockParcel(mMasterKeyId, mFingerprint, (Passphrase) data.getParcelable(SetPassphraseDialogFragment.MESSAGE_NEW_PASSPHRASE)); mEditOpHelper.cryptoOperation(); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); SetPassphraseDialogFragment setPassphraseDialog = SetPassphraseDialogFragment.newInstance(messenger, R.string.title_change_passphrase); setPassphraseDialog.show(getSupportFragmentManager(), "setPassphraseDialog"); }
From source file:com.cttapp.bby.mytlc.layer8apps.MyTlc.java
/************ * PURPOSE: Handles creating our intial setup when * we run things in the background. * ARGUMENTS: null//from www. j a va 2 s. co m * RETURNS: void * AUTHOR: Devin Collins <agent14709@gmail.com> *************/ private void runEvents() { results.setText(""); // This is our background service. We create it and assign // variables that we'll be using. Intent intent = new Intent(this, CalendarHandler.class); Messenger messenger = new Messenger(mHandler); intent.putExtra("handler", messenger); intent.putExtra("username", username); intent.putExtra("password", password); intent.putExtra("calendarID", calID); // Start the service startService(intent); // Show the progress dialog showProgress(); }
From source file:org.sufficientlysecure.keychain.ui.CertifyKeyActivity.java
/** * kicks off the actual signing process on a background thread *///w ww. j av a2s .com private void startRevokation() { // Bail out if there is not at least one user id selected ArrayList<String> userIds = mUserIdsAdapter.getSelectedUserIds(); if (userIds.isEmpty()) { AppMsg.makeText(CertifyKeyActivity.this, "No User IDs to sign selected!", AppMsg.STYLE_ALERT).show(); return; } // Send all information needed to service to sign key in other thread Intent intent = new Intent(this, KeychainIntentService.class); intent.setAction(KeychainIntentService.ACTION_REVOKE_KEYRING); // fill values for this action Bundle data = new Bundle(); data.putLong(KeychainIntentService.CERTIFY_KEY_MASTER_KEY_ID, mMasterKeyId); data.putLong(KeychainIntentService.CERTIFY_KEY_PUB_KEY_ID, mPubKeyId); data.putStringArrayList(KeychainIntentService.CERTIFY_KEY_UIDS, userIds); intent.putExtra(KeychainIntentService.EXTRA_DATA, data); // Message is received after signing is done in KeychainIntentService KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this, getString(R.string.progress_signing), ProgressDialog.STYLE_SPINNER) { public void handleMessage(Message message) { // handle messages by standard KeychainIntentServiceHandler first super.handleMessage(message); if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { AppMsg.makeText(CertifyKeyActivity.this, R.string.key_certify_success, AppMsg.STYLE_INFO) .show(); // check if we need to send the key to the server or not if (mUploadKeyCheckbox.isChecked()) { // upload the newly signed key to the keyserver uploadKey(); } else { setResult(RESULT_OK); finish(); } } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); // show progress dialog saveHandler.showProgressDialog(this); // start service with intent startService(intent); }
From source file:org.sufficientlysecure.keychain.ui.EditKeyFragment.java
private void editSubkey(final int position) { final long keyId = mSubkeysAdapter.getKeyId(position); Handler returnHandler = new Handler() { @Override/*w w w. jav a 2 s . c om*/ public void handleMessage(Message message) { switch (message.what) { case EditSubkeyDialogFragment.MESSAGE_CHANGE_EXPIRY: editSubkeyExpiry(position); break; case EditSubkeyDialogFragment.MESSAGE_REVOKE: // toggle if (mSaveKeyringParcel.mRevokeSubKeys.contains(keyId)) { mSaveKeyringParcel.mRevokeSubKeys.remove(keyId); } else { mSaveKeyringParcel.mRevokeSubKeys.add(keyId); } break; case EditSubkeyDialogFragment.MESSAGE_STRIP: { SecretKeyType secretKeyType = mSubkeysAdapter.getSecretKeyType(position); if (secretKeyType == SecretKeyType.GNU_DUMMY) { // Key is already stripped; this is a no-op. break; } SubkeyChange change = mSaveKeyringParcel.getSubkeyChange(keyId); if (change == null) { mSaveKeyringParcel.mChangeSubKeys.add(new SubkeyChange(keyId, true, false)); break; } // toggle change.mDummyStrip = !change.mDummyStrip; if (change.mDummyStrip && change.mMoveKeyToSecurityToken) { // User had chosen to divert key, but now wants to strip it instead. change.mMoveKeyToSecurityToken = false; } break; } case EditSubkeyDialogFragment.MESSAGE_MOVE_KEY_TO_SECURITY_TOKEN: { SecretKeyType secretKeyType = mSubkeysAdapter.getSecretKeyType(position); if (secretKeyType == SecretKeyType.DIVERT_TO_CARD || secretKeyType == SecretKeyType.GNU_DUMMY) { Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_stripped, Notify.Style.ERROR).show(); break; } switch (mSubkeysAdapter.getAlgorithm(position)) { case PublicKeyAlgorithmTags.RSA_GENERAL: case PublicKeyAlgorithmTags.RSA_ENCRYPT: case PublicKeyAlgorithmTags.RSA_SIGN: if (mSubkeysAdapter.getKeySize(position) < 2048) { Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_size, Notify.Style.ERROR).show(); } break; case PublicKeyAlgorithmTags.ECDH: case PublicKeyAlgorithmTags.ECDSA: final ASN1ObjectIdentifier curve = NISTNamedCurves .getOID(mSubkeysAdapter.getCurveOid(position)); if (!curve.equals(NISTNamedCurves.getByName("P-256")) && !curve.equals(NISTNamedCurves.getByName("P-384")) && !curve.equals(NISTNamedCurves.getByName("P-521"))) { Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_curve, Notify.Style.ERROR).show(); } break; default: Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_algo, Notify.Style.ERROR).show(); break; } SubkeyChange change; change = mSaveKeyringParcel.getSubkeyChange(keyId); if (change == null) { mSaveKeyringParcel.mChangeSubKeys.add(new SubkeyChange(keyId, false, true)); break; } // toggle change.mMoveKeyToSecurityToken = !change.mMoveKeyToSecurityToken; if (change.mMoveKeyToSecurityToken && change.mDummyStrip) { // User had chosen to strip key, but now wants to divert it. change.mDummyStrip = false; } break; } } getLoaderManager().getLoader(LOADER_ID_SUBKEYS).forceLoad(); } }; // Create a new Messenger for the communication back final Messenger messenger = new Messenger(returnHandler); DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() { public void run() { EditSubkeyDialogFragment dialogFragment = EditSubkeyDialogFragment.newInstance(messenger); dialogFragment.show(getActivity().getSupportFragmentManager(), "editSubkeyDialog"); } }); }
From source file:org.sufficientlysecure.keychain.ui.CertifyKeyActivity.java
private void uploadKey() { // Send all information needed to service to upload key in other thread Intent intent = new Intent(this, KeychainIntentService.class); intent.setAction(KeychainIntentService.ACTION_UPLOAD_KEYRING); // set data uri as path to keyring Uri blobUri = KeychainContract.KeyRingData.buildPublicKeyRingUri(mDataUri); intent.setData(blobUri);//from w ww . java 2s . com // fill values for this action Bundle data = new Bundle(); Spinner keyServer = (Spinner) findViewById(R.id.upload_key_keyserver); String server = (String) keyServer.getSelectedItem(); data.putString(KeychainIntentService.UPLOAD_KEY_SERVER, server); intent.putExtra(KeychainIntentService.EXTRA_DATA, data); // Message is received after uploading is done in KeychainIntentService KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this, getString(R.string.progress_exporting), ProgressDialog.STYLE_HORIZONTAL) { public void handleMessage(Message message) { // handle messages by standard KeychainIntentServiceHandler first super.handleMessage(message); if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { AppMsg.makeText(CertifyKeyActivity.this, R.string.key_send_success, AppMsg.STYLE_INFO).show(); setResult(RESULT_OK); finish(); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); // show progress dialog saveHandler.showProgressDialog(this); // start service with intent startService(intent); }
From source file:org.sufficientlysecure.keychain.ui.EditKeyFragment.java
private void editSubkeyExpiry(final int position) { final long keyId = mSubkeysAdapter.getKeyId(position); final Long creationDate = mSubkeysAdapter.getCreationDate(position); final Long expiryDate = mSubkeysAdapter.getExpiryDate(position); Handler returnHandler = new Handler() { @Override// w ww.j a v a 2 s. c o m public void handleMessage(Message message) { switch (message.what) { case EditSubkeyExpiryDialogFragment.MESSAGE_NEW_EXPIRY: mSaveKeyringParcel.getOrCreateSubkeyChange(keyId).mExpiry = (Long) message.getData() .getSerializable(EditSubkeyExpiryDialogFragment.MESSAGE_DATA_EXPIRY); break; } getLoaderManager().getLoader(LOADER_ID_SUBKEYS).forceLoad(); } }; // Create a new Messenger for the communication back final Messenger messenger = new Messenger(returnHandler); DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() { public void run() { EditSubkeyExpiryDialogFragment dialogFragment = EditSubkeyExpiryDialogFragment .newInstance(messenger, creationDate, expiryDate); dialogFragment.show(getActivity().getSupportFragmentManager(), "editSubkeyExpiryDialog"); } }); }
From source file:org.thialfihar.android.apg.ui.EditKeyActivity.java
private void finallySaveClicked() { try {//from www. j a va2s.c o m // Send all information needed to service to edit key in other thread Intent intent = new Intent(this, ApgIntentService.class); intent.setAction(ApgIntentService.ACTION_SAVE_KEYRING); SaveKeyringParcel saveParams = new SaveKeyringParcel(); saveParams.userIds = getUserIds(mUserIdsView); saveParams.originalIDs = mUserIdsView.getOriginalIDs(); saveParams.deletedIDs = mUserIdsView.getDeletedIDs(); saveParams.newIDs = toPrimitiveArray(mUserIdsView.getNewIDFlags()); saveParams.primaryIDChanged = mUserIdsView.primaryChanged(); saveParams.moddedKeys = toPrimitiveArray(mKeysView.getNeedsSavingArray()); saveParams.deletedKeys = mKeysView.getDeletedKeys(); saveParams.keysExpiryDates = getKeysExpiryDates(mKeysView); saveParams.keysUsages = getKeysUsages(mKeysView); saveParams.newPassphrase = mNewPassphrase; saveParams.oldPassphrase = mCurrentPassphrase; saveParams.newKeys = toPrimitiveArray(mKeysView.getNewKeysArray()); saveParams.keys = getKeys(mKeysView); saveParams.originalPrimaryID = mUserIdsView.getOriginalPrimaryID(); // fill values for this action Bundle data = new Bundle(); data.putBoolean(ApgIntentService.SAVE_KEYRING_CAN_SIGN, mMasterCanSign); data.putParcelable(ApgIntentService.SAVE_KEYRING_PARCEL, saveParams); intent.putExtra(ApgIntentService.EXTRA_DATA, data); // Message is received after saving is done in ApgIntentService ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this, getString(R.string.progress_saving), ProgressDialog.STYLE_HORIZONTAL) { public void handleMessage(Message message) { // handle messages by standard ApgIntentServiceHandler first super.handleMessage(message); if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) { Intent data = new Intent(); // return uri pointing to new created key Uri uri = ApgContract.KeyRings.buildGenericKeyRingUri(String.valueOf(getMasterKeyId())); data.setData(uri); setResult(RESULT_OK, data); finish(); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger); saveHandler.showProgressDialog(this); // start service with intent startService(intent); } catch (PgpGeneralException e) { Log.e(Constants.TAG, getString(R.string.error_message, e.getMessage())); AppMsg.makeText(this, getString(R.string.error_message, e.getMessage()), AppMsg.STYLE_ALERT).show(); } }
From source file:org.sufficientlysecure.keychain.ui.EditKeyActivity.java
private void finallySaveClicked() { try {/*from w ww .j av a2 s .c o m*/ // Send all information needed to service to edit key in other thread Intent intent = new Intent(this, KeychainIntentService.class); intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING); OldSaveKeyringParcel saveParams = new OldSaveKeyringParcel(); saveParams.userIds = getUserIds(mUserIdsView); saveParams.originalIDs = mUserIdsView.getOriginalIDs(); saveParams.deletedIDs = mUserIdsView.getDeletedIDs(); saveParams.newIDs = toPrimitiveArray(mUserIdsView.getNewIDFlags()); saveParams.primaryIDChanged = mUserIdsView.primaryChanged(); saveParams.moddedKeys = toPrimitiveArray(mKeysView.getNeedsSavingArray()); saveParams.deletedKeys = mKeysView.getDeletedKeys(); saveParams.keysExpiryDates = getKeysExpiryDates(mKeysView); saveParams.keysUsages = getKeysUsages(mKeysView); saveParams.newPassphrase = mNewPassphrase; saveParams.oldPassphrase = mCurrentPassphrase; saveParams.newKeys = toPrimitiveArray(mKeysView.getNewKeysArray()); saveParams.keys = getKeys(mKeysView); saveParams.originalPrimaryID = mUserIdsView.getOriginalPrimaryID(); // fill values for this action Bundle data = new Bundle(); data.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, mMasterCanSign); data.putParcelable(KeychainIntentService.SAVE_KEYRING_PARCEL, saveParams); intent.putExtra(KeychainIntentService.EXTRA_DATA, data); // Message is received after saving is done in KeychainIntentService KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this, getString(R.string.progress_saving), ProgressDialog.STYLE_HORIZONTAL) { public void handleMessage(Message message) { // handle messages by standard KeychainIntentServiceHandler first super.handleMessage(message); if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { Intent data = new Intent(); // return uri pointing to new created key Uri uri = KeyRings.buildGenericKeyRingUri(getMasterKeyId()); data.setData(uri); setResult(RESULT_OK, data); finish(); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); saveHandler.showProgressDialog(this); // start service with intent startService(intent); } catch (PgpGeneralException e) { Log.e(Constants.TAG, getString(R.string.error_message, e.getMessage())); AppMsg.makeText(this, getString(R.string.error_message, e.getMessage()), AppMsg.STYLE_ALERT).show(); } }
From source file:com.roymam.android.nilsplus.ui.NiLSActivity.java
private void checkNiLSPlusLicense() { // if so - request a license Intent licenseService = new Intent(); licenseService.setComponent(/*from w w w . j a va2 s . co m*/ new ComponentName("com.roymam.android.nilsplus", "com.roymam.android.nilsplus.LicenseService")); mLicenseServiceConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { mService = new Messenger(service); try { // request a license from NiLSPlus app Message msg = Message.obtain(null, MSG_REQUEST_LICENSE); msg.replyTo = mMessenger; mService.send(msg); } catch (RemoteException e) { } } public void onServiceDisconnected(ComponentName className) { mService = null; } }; try { bindService(licenseService, mLicenseServiceConnection, Context.BIND_AUTO_CREATE); } catch (Exception exp) { Log.d("NiLS", "cannot communicate with NiLS Unlocker"); exp.printStackTrace(); } }
From source file:au.org.intersect.faims.android.ui.activity.ShowModuleActivity.java
public void downloadDatabaseFromServer(final String callback) { if (serverDiscovery.isServerHostValid()) { showBusyDownloadDatabaseDialog(); // start service Intent intent = new Intent(ShowModuleActivity.this, DownloadDatabaseService.class); Module module = ModuleUtil.getModule(moduleKey); DownloadDatabaseHandler handler = new DownloadDatabaseHandler(ShowModuleActivity.this, callback); Messenger messenger = new Messenger(handler); intent.putExtra("MESSENGER", messenger); intent.putExtra("module", module); ShowModuleActivity.this.startService(intent); } else {//from ww w. j a v a 2 s. c o m showBusyLocatingServerDialog(); locateTask = new LocateServerTask(serverDiscovery, new ITaskListener() { @Override public void handleTaskCompleted(Object result) { ShowModuleActivity.this.busyDialog.dismiss(); if ((Boolean) result) { downloadDatabaseFromServer(callback); } else { showLocateServerDownloadDatabaseFailureDialog(callback); } } }).execute(); } }