List of usage examples for android.os Messenger Messenger
public Messenger(IBinder target)
From source file:com.grarak.kerneladiutor.fragments.other.SettingsFragment.java
@Override public boolean onPreferenceClick(Preference preference) { String key = preference.getKey(); switch (key) { case KEY_BANNER_RESIZER: if (Utils.DONATED) { Intent intent = new Intent(getActivity(), BannerResizerActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent);// ww w . j a va 2s . c o m } else { ViewUtils.dialogDonate(getActivity()).show(); } return true; case KEY_ACCENT_COLOR: if (Utils.DONATED) { List<Integer> sColors = new ArrayList<>(); for (int i = 0; i < BorderCircleView.sAccentColors.size(); i++) { sColors.add(BorderCircleView.sAccentColors.keyAt(i)); } for (int i = 0; i < sColors.size(); i++) { sColors.set(i, ContextCompat.getColor(getActivity(), sColors.get(i))); } colorDialog(sColors.indexOf(ViewUtils.getThemeAccentColor(getActivity()))); } else { ViewUtils.dialogDonate(getActivity()).show(); } return true; case KEY_APPLY_ON_BOOT_TEST: if (Utils.isServiceRunning(Service.class, getActivity())) { Utils.toast(R.string.apply_on_boot_running, getActivity()); } else { Intent intent = new Intent(getActivity(), Service.class); intent.putExtra("messenger", new Messenger(new MessengerHandler(getActivity()))); getActivity().startService(intent); } return true; case KEY_LOGCAT: new Execute().execute("logcat -d > /sdcard/logcat.txt"); return true; case KEY_LAST_KMSG: if (Utils.existFile("/proc/last_kmsg")) { new Execute().execute("cat /proc/last_kmsg > /sdcard/last_kmsg.txt"); } else if (Utils.existFile("/sys/fs/pstore/console-ramoops")) { new Execute().execute("cat /sys/fs/pstore/console-ramoops > /sdcard/last_kmsg.txt"); } return true; case KEY_DMESG: new Execute().execute("dmesg > /sdcard/dmesg.txt"); return true; case KEY_SET_PASSWORD: editPasswordDialog(Prefs.getString("password", "", getActivity())); return true; case KEY_DELETE_PASSWORD: deletePasswordDialog(Prefs.getString("password", "", getActivity())); return true; } return false; }
From source file:org.sufficientlysecure.keychain.network.orbot.OrbotHelper.java
/** * checks if Tor is enabled and if it is, that Orbot is installed and running. Generates appropriate dialogs. * * @param middleButton resourceId of string to display as the middle button of install and enable dialogs * @param proxy proxy preferences used to determine if Tor is required to be started * @return true if Tor is not enabled or Tor is enabled and Orbot is installed and running, else false *///from w ww. j ava2 s. co m public static boolean putOrbotInRequiredState(final int middleButton, final DialogActions dialogActions, ParcelableProxy proxy, final FragmentActivity fragmentActivity) { if (!proxy.isTorEnabled()) { return true; } if (!OrbotHelper.isOrbotInstalled(fragmentActivity)) { Handler ignoreTorHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case SupportInstallDialogFragment.MESSAGE_MIDDLE_CLICKED: dialogActions.onNeutralButton(); break; case SupportInstallDialogFragment.MESSAGE_DIALOG_DISMISSED: // both install and cancel buttons mean we don't go ahead with an // operation, so it's okay to cancel dialogActions.onCancel(); break; } } }; OrbotHelper.getInstallDialogFragmentWithThirdButton(new Messenger(ignoreTorHandler), middleButton) .show(fragmentActivity.getSupportFragmentManager(), "OrbotHelperOrbotInstallDialog"); return false; } else if (!OrbotHelper.isOrbotRunning(fragmentActivity)) { final Handler dialogHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case OrbotStartDialogFragment.MESSAGE_MIDDLE_BUTTON: dialogActions.onNeutralButton(); break; case OrbotStartDialogFragment.MESSAGE_DIALOG_CANCELLED: dialogActions.onCancel(); break; case OrbotStartDialogFragment.MESSAGE_ORBOT_STARTED: dialogActions.onOrbotStarted(); break; } } }; new SilentStartManager() { @Override protected void onOrbotStarted() { dialogActions.onOrbotStarted(); } @Override protected void onSilentStartDisabled() { getOrbotStartDialogFragment(new Messenger(dialogHandler), middleButton) .show(fragmentActivity.getSupportFragmentManager(), "OrbotHelperOrbotStartDialog"); } }.startOrbotAndListen(fragmentActivity, true); return false; } else { return true; } }
From source file:org.thialfihar.android.apg.ui.KeyListPublicFragment.java
/** * Show dialog to delete key//from ww w. ja v a 2s .c o m * * @param keyRingRowIds */ @TargetApi(11) public void showDeleteKeyDialog(final ActionMode mode, long[] keyRingRowIds) { // Message is received after key is deleted Handler returnHandler = new Handler() { @Override public void handleMessage(Message message) { if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) { Bundle returnData = message.getData(); if (returnData != null && returnData.containsKey(DeleteKeyDialogFragment.MESSAGE_NOT_DELETED)) { ArrayList<String> notDeleted = returnData .getStringArrayList(DeleteKeyDialogFragment.MESSAGE_NOT_DELETED); String notDeletedMsg = ""; for (String userId : notDeleted) { notDeletedMsg += userId + "\n"; } Toast.makeText(getActivity(), getString(R.string.error_can_not_delete_contacts, notDeletedMsg) + getResources() .getQuantityString(R.plurals.error_can_not_delete_info, notDeleted.size()), Toast.LENGTH_LONG).show(); mode.finish(); } } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger, keyRingRowIds, Id.type.public_key); deleteKeyDialog.show(getActivity().getSupportFragmentManager(), "deleteKeyDialog"); }
From source file:org.thialfihar.android.apg.ui.EncryptFileFragment.java
private void encryptStart() { // Send all information needed to service to edit key in other thread Intent intent = new Intent(getActivity(), ApgIntentService.class); intent.setAction(ApgIntentService.ACTION_ENCRYPT_SIGN); // fill values for this action Bundle data = new Bundle(); data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_URI); if (mEncryptInterface.isModeSymmetric()) { Log.d(Constants.TAG, "Symmetric encryption enabled!"); String passphrase = mEncryptInterface.getPassphrase(); if (passphrase.length() == 0) { passphrase = null;// ww w .j ava2s . c o m } data.putString(ApgIntentService.ENCRYPT_SYMMETRIC_PASSPHRASE, passphrase); } else { data.putLong(ApgIntentService.ENCRYPT_SIGNATURE_KEY_ID, mEncryptInterface.getSignatureKey()); data.putLongArray(ApgIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS, mEncryptInterface.getEncryptionKeys()); } Log.d(Constants.TAG, "mInputFilename=" + mInputFilename + ", mOutputFilename=" + mOutputFilename); data.putString(ApgIntentService.ENCRYPT_INPUT_FILE, mInputFilename); data.putString(ApgIntentService.ENCRYPT_OUTPUT_FILE, mOutputFilename); boolean useAsciiArmor = mAsciiArmor.isChecked(); data.putBoolean(ApgIntentService.ENCRYPT_USE_ASCII_ARMOR, useAsciiArmor); int compressionId = ((Choice) mFileCompression.getSelectedItem()).getId(); data.putInt(ApgIntentService.ENCRYPT_COMPRESSION_ID, compressionId); intent.putExtra(ApgIntentService.EXTRA_DATA, data); // Message is received after encrypting is done in ApgIntentService ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(getActivity(), getString(R.string.progress_encrypting), ProgressDialog.STYLE_HORIZONTAL) { public void handleMessage(Message message) { // handle messages by standard ApgIntentServiceHandler first super.handleMessage(message); if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) { AppMsg.makeText(getActivity(), R.string.encrypt_sign_successful, AppMsg.STYLE_INFO).show(); if (mDeleteAfter.isChecked()) { // Create and show dialog to delete original file DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment .newInstance(mInputFilename); deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog"); } if (mShareAfter.isChecked()) { // Share encrypted file Intent sendFileIntent = new Intent(Intent.ACTION_SEND); sendFileIntent.setType("*/*"); sendFileIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(mOutputFilename)); startActivity(Intent.createChooser(sendFileIntent, getString(R.string.title_share_file))); } } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger); // show progress dialog saveHandler.showProgressDialog(getActivity()); // start service with intent getActivity().startService(intent); }
From source file:org.thialfihar.android.apg.ui.CertifyKeyActivity.java
/** * kicks off the actual signing process on a background thread *///from www . j av a 2s . c om private void startSigning() { // Bail out if there is not at least one user id selected ArrayList<String> userIds = mUserIdsAdapter.getSelectedUserIds(); if (userIds.isEmpty()) { Toast.makeText(CertifyKeyActivity.this, "No User IDs to sign selected!", Toast.LENGTH_SHORT).show(); return; } // Send all information needed to service to sign key in other thread Intent intent = new Intent(this, ApgIntentService.class); intent.setAction(ApgIntentService.ACTION_CERTIFY_KEYRING); // fill values for this action Bundle data = new Bundle(); data.putLong(ApgIntentService.CERTIFY_KEY_MASTER_KEY_ID, mMasterKeyId); data.putLong(ApgIntentService.CERTIFY_KEY_PUB_KEY_ID, mPubKeyId); data.putLong(ApgIntentService.CERTIFY_KEY_PUB_KEY_ID, mPubKeyId); data.putStringArrayList(ApgIntentService.CERTIFY_KEY_UIDS, userIds); intent.putExtra(ApgIntentService.EXTRA_DATA, data); // Message is received after signing is done in ApgService ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this, getString(R.string.progress_signing), ProgressDialog.STYLE_SPINNER) { public void handleMessage(Message message) { // handle messages by standard ApgHandler first super.handleMessage(message); if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) { Toast.makeText(CertifyKeyActivity.this, R.string.key_sign_success, Toast.LENGTH_SHORT).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(ApgIntentService.EXTRA_MESSENGER, messenger); // show progress dialog saveHandler.showProgressDialog(this); // start service with intent startService(intent); }
From source file:org.sufficientlysecure.keychain.ui.EncryptFileFragment.java
private void encryptStart() { // Send all information needed to service to edit key in other thread Intent intent = new Intent(getActivity(), KeychainIntentService.class); intent.setAction(KeychainIntentService.ACTION_ENCRYPT_SIGN); // fill values for this action Bundle data = new Bundle(); data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_URI); if (mEncryptInterface.isModeSymmetric()) { Log.d(Constants.TAG, "Symmetric encryption enabled!"); String passphrase = mEncryptInterface.getPassphrase(); if (passphrase.length() == 0) { passphrase = null;/*w ww .ja va 2 s. com*/ } data.putString(KeychainIntentService.ENCRYPT_SYMMETRIC_PASSPHRASE, passphrase); } else { data.putLong(KeychainIntentService.ENCRYPT_SIGNATURE_KEY_ID, mEncryptInterface.getSignatureKey()); data.putLongArray(KeychainIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS, mEncryptInterface.getEncryptionKeys()); } Log.d(Constants.TAG, "mInputFilename=" + mInputFilename + ", mOutputFilename=" + mOutputFilename); data.putString(KeychainIntentService.ENCRYPT_INPUT_FILE, mInputFilename); data.putString(KeychainIntentService.ENCRYPT_OUTPUT_FILE, mOutputFilename); boolean useAsciiArmor = mAsciiArmor.isChecked(); data.putBoolean(KeychainIntentService.ENCRYPT_USE_ASCII_ARMOR, useAsciiArmor); int compressionId = ((Choice) mFileCompression.getSelectedItem()).getId(); data.putInt(KeychainIntentService.ENCRYPT_COMPRESSION_ID, compressionId); intent.putExtra(KeychainIntentService.EXTRA_DATA, data); // Message is received after encrypting is done in KeychainIntentService KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(), getString(R.string.progress_encrypting), 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(getActivity(), R.string.encrypt_sign_successful, AppMsg.STYLE_INFO).show(); if (mDeleteAfter.isChecked()) { // Create and show dialog to delete original file DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment .newInstance(mInputFilename); deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog"); } if (mShareAfter.isChecked()) { // Share encrypted file Intent sendFileIntent = new Intent(Intent.ACTION_SEND); sendFileIntent.setType("*/*"); sendFileIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(mOutputFilename)); startActivity(Intent.createChooser(sendFileIntent, getString(R.string.title_share_file))); } } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); // show progress dialog saveHandler.showProgressDialog(getActivity()); // start service with intent getActivity().startService(intent); }
From source file:org.sufficientlysecure.keychain.ui.EditKeyFragment.java
private void changePassphrase() { // Intent passIntent = new Intent(getActivity(), PassphraseWizardActivity.class); // passIntent.setAction(PassphraseWizardActivity.CREATE_METHOD); // startActivityForResult(passIntent, 12); // Message is received after passphrase is cached Handler returnHandler = new Handler() { @Override/* w w w.j a v a2s. c o m*/ public void handleMessage(Message message) { if (message.what == SetPassphraseDialogFragment.MESSAGE_OKAY) { Bundle data = message.getData(); // cache new returned passphrase! mSaveKeyringParcel.setNewUnlock(new ChangeUnlockParcel( (Passphrase) data.getParcelable(SetPassphraseDialogFragment.MESSAGE_NEW_PASSPHRASE))); } } }; // 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(getActivity().getSupportFragmentManager(), "setPassphraseDialog"); }
From source file:org.sufficientlysecure.keychain.ui.KeyListFragment.java
/** * Show dialog to delete key//from www.j av a 2s . c om * * @param masterKeyIds * @param hasSecret must contain whether the list of masterKeyIds contains a secret key or not */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void showDeleteKeyDialog(final ActionMode mode, long[] masterKeyIds, boolean hasSecret) { // Can only work on singular secret keys if (hasSecret && masterKeyIds.length > 1) { AppMsg.makeText(getActivity(), R.string.secret_cannot_multiple, AppMsg.STYLE_ALERT).show(); return; } // Message is received after key is deleted Handler returnHandler = new Handler() { @Override public void handleMessage(Message message) { if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) { mode.finish(); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger, masterKeyIds); deleteKeyDialog.show(getActivity().getSupportFragmentManager(), "deleteKeyDialog"); }
From source file:org.sufficientlysecure.keychain.ui.EditKeyActivity.java
/** * Shows the dialog to set a new passphrase *//*from w w w.j av a 2s .com*/ private void showSetPassphraseDialog() { // 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(); // set new returned passphrase! mNewPassphrase = data.getString(SetPassphraseDialogFragment.MESSAGE_NEW_PASSPHRASE); updatePassphraseButtonText(); somethingChanged(); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); // set title based on isPassphraseSet() int title; if (isPassphraseSet()) { title = R.string.title_change_passphrase; } else { title = R.string.title_set_passphrase; } SetPassphraseDialogFragment setPassphraseDialog = SetPassphraseDialogFragment.newInstance(messenger, title); setPassphraseDialog.show(getSupportFragmentManager(), "setPassphraseDialog"); }
From source file:org.sufficientlysecure.privacybox.EncryptedDocument.java
/** * Encrypt and write both the metadata and content sections of this * document, reading the content from the given pipe. Internally uses * {@link ParcelFileDescriptor#checkError()} to verify that content arrives * without errors. Writes to temporary file to keep atomic view of contents, * swapping into place only when write is successful. * <p/>//from ww w.j a v a2 s . com * Pipe is left open, so caller is responsible for calling * {@link ParcelFileDescriptor#close()} or * {@link ParcelFileDescriptor#closeWithError(String)}. * * @param contentIn read end of a pipe. */ public void writeMetadataAndContent(JSONObject meta, ParcelFileDescriptor contentIn) throws IOException, GeneralSecurityException { // Write into temporary file to provide an atomic view of existing // contents during write, and also to recover from failed writes. final String tempName = mFile.getName() + ".tmp_" + Thread.currentThread().getId(); final File tempFile = new File(mFile.getParentFile(), tempName); // RandomAccessFile f = new RandomAccessFile(tempFile, "rw"); try { // TODO: while not == RESULT_CODE_SUCCESS wait notify and stuff... // make this blocking! Intent data = new Intent(); data.setAction(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT); InputStream is; String mimeType = meta.getString(Document.COLUMN_MIME_TYPE); if (Document.MIME_TYPE_DIR.equals(mimeType)) { // this is a directory! write only dir into content... is = new ByteArrayInputStream("dir".getBytes()); /* * combine mime type, display name, and children into one json! */ JSONObject json = new JSONObject(); json.put(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR); json.put(Document.COLUMN_DISPLAY_NAME, meta.getString(Document.COLUMN_DISPLAY_NAME)); json.put(VaultProvider.KEY_CHILDREN, meta.getJSONArray(VaultProvider.KEY_CHILDREN)); Log.d(VaultProvider.TAG, "json: " + json.toString()); // write json into data.putExtra(OpenPgpApi.EXTRA_ORIGINAL_FILENAME, json.toString()); } else { // writing only metadata, no contentIn... if (contentIn == null) { is = new ByteArrayInputStream("write content later".getBytes()); } else { is = new FileInputStream(contentIn.getFileDescriptor()); } // TODO: no possibility to write mime type to pgp header, currently data.putExtra(OpenPgpApi.EXTRA_ORIGINAL_FILENAME, meta.getString(Document.COLUMN_DISPLAY_NAME)); } data.putExtra(OpenPgpApi.EXTRA_USER_IDS, new String[] { "nopass@example.com" }); data.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, "default"); data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); // TODO: fix later to false! OpenPgpApi api = new OpenPgpApi(mContext, mServiceConnection.getService()); Intent result = api.executeApi(data, is, new FileOutputStream(tempFile)); switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) { case OpenPgpApi.RESULT_CODE_SUCCESS: { Log.d(VaultProvider.TAG, "writeMetadataAndContent RESULT_CODE_SUCCESS"); tempFile.renameTo(mFile); break; } case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: { Log.d(VaultProvider.TAG, "writeMetadataAndContent RESULT_CODE_USER_INTERACTION_REQUIRED"); // directly try again, something different needs user interaction again... PendingIntent pi = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT); Handler handler = new Handler(mContext.getMainLooper(), new Handler.Callback() { @Override public boolean handleMessage(Message msg) { Log.d(VaultProvider.TAG, "writeMetadataAndContent handleMessage"); // TODO: start again afterwards!!! return true; } }); Messenger messenger = new Messenger(handler); // start proxy activity and wait here for it finishing... Intent proxy = new Intent(mContext, KeychainProxyActivity.class); proxy.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); proxy.putExtra(KeychainProxyActivity.EXTRA_MESSENGER, messenger); proxy.putExtra(KeychainProxyActivity.EXTRA_PENDING_INTENT, pi); mContext.startActivity(proxy); break; } case OpenPgpApi.RESULT_CODE_ERROR: { Log.d(VaultProvider.TAG, "writeMetadataAndContent RESULT_CODE_ERROR"); // TODO OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR); Log.e(VaultProvider.TAG, "error: " + error.getMessage()); break; } } // Truncate any existing data // f.setLength(0); // Write content first to detect size // if (contentIn != null) { // f.seek(CONTENT_OFFSET); // final int plainLength = writeSection( // f, new FileInputStream(contentIn.getFileDescriptor())); // meta.put(Document.COLUMN_SIZE, plainLength); // // // Verify that remote side of pipe finished okay; if they // // crashed or indicated an error then this throws and we // // leave the original file intact and clean up temp below. // contentIn.checkError(); // } // meta.put(Document.COLUMN_DOCUMENT_ID, mDocId); // meta.put(Document.COLUMN_LAST_MODIFIED, System.currentTimeMillis()); // Rewind and write metadata section // f.seek(0); // f.writeInt(MAGIC_NUMBER); // final ByteArrayInputStream metaIn = new ByteArrayInputStream( // meta.toString().getBytes(StandardCharsets.UTF_8)); // writeSection(f, metaIn); // // if (f.getFilePointer() > CONTENT_OFFSET) { // throw new IOException("Metadata section was too large"); // } // Everything written fine, atomically swap new data into place. // fsync() before close would be overkill, since rename() is an // atomic barrier. // f.close(); } catch (JSONException e) { throw new IOException(e); } finally { // Regardless of what happens, always try cleaning up. // f.close(); tempFile.delete(); } }