Example usage for android.os Messenger Messenger

List of usage examples for android.os Messenger Messenger

Introduction

In this page you can find the example usage for android.os Messenger Messenger.

Prototype

public Messenger(IBinder target) 

Source Link

Document

Create a Messenger from a raw IBinder, which had previously been retrieved with #getBinder .

Usage

From source file:com.google.android.apps.santatracker.launch.TvStartupActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestPermissionsIfDebugModeEnabled();

    // Glide's pretty aggressive at caching images, so get the 8888 preference in early.
    if (!Glide.isSetup()) {
        Glide.setup(new GlideBuilder(getActivityContext()).setDecodeFormat(DecodeFormat.PREFER_ARGB_8888));
    }// w w w  .  j a v  a2 s.c  o m

    setContentView(R.layout.layout_startup_tv);
    loadResourceFields(getResources());

    mIsDebug = BuildConfig.DEBUG;

    mMessenger = new Messenger(new IncomingHandler(this));

    mCountdown = new LaunchCountdown(this);
    mCountdownView = findViewById(R.id.countdown_container);
    mAudioPlayer = new AudioPlayer(getApplicationContext());

    mVillageView = (VillageView) findViewById(R.id.villageView);
    mVillage = (Village) getSupportFragmentManager().findFragmentByTag(VILLAGE_TAG);
    if (mVillage == null) {
        mVillage = new Village();
        getSupportFragmentManager().beginTransaction().add(mVillage, VILLAGE_TAG).commit();
    }
    mVillageBackdrop = (ImageView) findViewById(R.id.villageBackground);
    mLaunchButton = findViewById(R.id.launch_button);
    mLaunchButton.setOnClickListener(this);

    mMarkers = (VerticalGridView) findViewById(R.id.markers);
    initialiseViews();

    mHaveGooglePlayServices = checkGooglePlayServicesAvailable();

    // App invites
    mInvitesFragment = AppInvitesFragment.getInstance(this);

    // Initialize measurement
    mMeasurement = FirebaseAnalytics.getInstance(this);
    MeasurementManager.recordScreenView(mMeasurement, getString(R.string.analytics_screen_village));

    // [ANALYTICS SCREEN]: Village
    AnalyticsManager.sendScreenView(R.string.analytics_screen_village);
    // set the initial states
    resetLauncherStates();
    // See if it was a voice action which triggered this activity and handle it
    onNewIntent(getIntent());
}

From source file:com.mobilyzer.MeasurementScheduler.java

@Override
public void onCreate() {
    Logger.d("MeasurementScheduler -> onCreate called");
    PhoneUtils.setGlobalContext(this.getApplicationContext());

    phoneUtils = PhoneUtils.getPhoneUtils();
    phoneUtils.registerSignalStrengthListener();

    this.measurementExecutor = Executors.newSingleThreadExecutor();
    this.mainQueue = new PriorityBlockingQueue<MeasurementTask>(Config.MAX_TASK_QUEUE_SIZE,
            new TaskComparator());
    this.waitingTasksQueue = new PriorityBlockingQueue<MeasurementTask>(Config.MAX_TASK_QUEUE_SIZE,
            new WaitingTasksComparator());
    this.pendingTasks = new ConcurrentHashMap<MeasurementTask, Future<MeasurementResult[]>>();
    this.tasksStatus = new ConcurrentHashMap<String, MeasurementScheduler.TaskStatus>();
    this.alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    this.resourceCapManager = new ResourceCapManager(Config.DEFAULT_BATTERY_THRESH_PRECENT, this);

    this.serverTasks = new HashMap<String, Date>();
    // this.currentSchedule = new HashMap<String, MeasurementTask>();

    this.idToClientKey = new ConcurrentHashMap<String, String>();

    messenger = new Messenger(new APIRequestHandler(this));

    gcmManager = new GCMManager(this.getApplicationContext());

    this.setCurrentTask(null);
    this.setCurrentTaskStartTime(null);

    this.checkin = new Checkin(this);
    this.checkinRetryIntervalSec = Config.MIN_CHECKIN_RETRY_INTERVAL_SEC;
    this.checkinRetryCnt = 0;
    this.checkinTask = new CheckinTask();

    this.batteryThreshold = -1;
    this.checkinIntervalSec = -1;
    this.dataUsageProfile = DataUsageProfile.NOTASSIGNED;

    //    loadSchedulerState();//TODO(ASHKAN)

    // Register activity specific BroadcastReceiver here
    IntentFilter filter = new IntentFilter();
    filter.addAction(UpdateIntent.CHECKIN_ACTION);
    filter.addAction(UpdateIntent.CHECKIN_RETRY_ACTION);
    filter.addAction(UpdateIntent.MEASUREMENT_ACTION);
    filter.addAction(UpdateIntent.MEASUREMENT_PROGRESS_UPDATE_ACTION);
    filter.addAction(UpdateIntent.GCM_MEASUREMENT_ACTION);
    filter.addAction(UpdateIntent.PLT_MEASUREMENT_ACTION);

    broadcastReceiver = new BroadcastReceiver() {

        @Override// w  w w  .j av  a2s .com
        public void onReceive(Context context, Intent intent) {
            Logger.d(intent.getAction() + " RECEIVED");
            if (intent.getAction().equals(UpdateIntent.MEASUREMENT_ACTION)) {
                handleMeasurement();

            } else if (intent.getAction().equals(UpdateIntent.GCM_MEASUREMENT_ACTION)) {
                try {
                    JSONObject json = new JSONObject(
                            intent.getExtras().getString(UpdateIntent.MEASUREMENT_TASK_PAYLOAD));
                    Logger.d("MeasurementScheduler -> GCMManager: json task Value is " + json);
                    if (json != null && MeasurementTask.getMeasurementTypes().contains(json.get("type"))) {

                        try {
                            MeasurementTask task = MeasurementJsonConvertor.makeMeasurementTaskFromJson(json);
                            task.getDescription().priority = MeasurementTask.GCM_PRIORITY;
                            task.getDescription().startTime = new Date(System.currentTimeMillis() - 1000);
                            task.getDescription().endTime = new Date(System.currentTimeMillis() + (600 * 1000));
                            task.generateTaskID();
                            task.getDescription().key = Config.SERVER_TASK_CLIENT_KEY;
                            submitTask(task);
                        } catch (IllegalArgumentException e) {
                            Logger.w("MeasurementScheduler -> GCM : Could not create task from JSON: " + e);
                        }
                    }

                } catch (JSONException e) {
                    Logger.e(
                            "MeasurementSchedule -> GCMManager : Got exception during converting GCM json to MeasurementTask",
                            e);
                }

            } else if (intent.getAction().equals(UpdateIntent.MEASUREMENT_PROGRESS_UPDATE_ACTION)) {
                String taskid = intent.getStringExtra(UpdateIntent.TASKID_PAYLOAD);
                String taskKey = intent.getStringExtra(UpdateIntent.CLIENTKEY_PAYLOAD);
                int priority = intent.getIntExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD,
                        MeasurementTask.INVALID_PRIORITY);

                Logger.e(
                        intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD) + " " + taskid + " " + taskKey);
                if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD).equals(Config.TASK_FINISHED)) {
                    tasksStatus.put(taskid, TaskStatus.FINISHED);
                    Parcelable[] results = intent.getParcelableArrayExtra(UpdateIntent.RESULT_PAYLOAD);
                    if (results != null) {
                        sendResultToClient(results, priority, taskKey, taskid);

                        for (Object obj : results) {
                            try {
                                MeasurementResult result = (MeasurementResult) obj;
                                /**
                                 * Nullify the additional parameters in MeasurmentDesc, or the results won't be
                                 * accepted by GAE server
                                 */
                                result.getMeasurementDesc().parameters = null;
                                String jsonResult = MeasurementJsonConvertor.encodeToJson(result).toString();
                                saveResultToFile(jsonResult);
                            } catch (JSONException e) {
                                Logger.e("Error converting results to json format", e);
                            }
                        }
                    }
                    handleMeasurement();
                } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD).equals(Config.TASK_PAUSED)) {
                    tasksStatus.put(taskid, TaskStatus.PAUSED);
                } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD)
                        .equals(Config.TASK_STOPPED)) {
                    tasksStatus.put(taskid, TaskStatus.SCHEDULED);
                } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD)
                        .equals(Config.TASK_CANCELED)) {
                    tasksStatus.put(taskid, TaskStatus.CANCELLED);
                    Parcelable[] results = intent.getParcelableArrayExtra(UpdateIntent.RESULT_PAYLOAD);
                    if (results != null) {
                        sendResultToClient(results, priority, taskKey, taskid);
                    }
                } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD)
                        .equals(Config.TASK_STARTED)) {
                    tasksStatus.put(taskid, TaskStatus.RUNNING);
                } else if (intent.getStringExtra(UpdateIntent.TASK_STATUS_PAYLOAD)
                        .equals(Config.TASK_RESUMED)) {
                    tasksStatus.put(taskid, TaskStatus.RUNNING);
                }
            } else if (intent.getAction().equals(UpdateIntent.CHECKIN_ACTION)
                    || intent.getAction().equals(UpdateIntent.CHECKIN_RETRY_ACTION)) {
                Logger.d("Checkin intent received");
                handleCheckin();
            }
        }
    };
    this.registerReceiver(broadcastReceiver, filter);
}

From source file:org.sufficientlysecure.keychain.ui.CreateKeyEmailFragment.java

/**
 * Displays a dialog fragment for the user to input a valid email.
 *///from ww w . j a va2 s  . c  o  m
private void addEmail() {
    Handler returnHandler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            if (message.what == AddEmailDialogFragment.MESSAGE_OKAY) {
                Bundle data = message.getData();

                String email = data.getString(AddEmailDialogFragment.MESSAGE_DATA_EMAIL);

                if (checkEmail(email, true)) {
                    // add new user id
                    mEmailAdapter.add(email);
                }
            }
        }
    };
    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(returnHandler);

    AddEmailDialogFragment addEmailDialog = AddEmailDialogFragment.newInstance(messenger);
    addEmailDialog.show(getActivity().getSupportFragmentManager(), "addEmailDialog");
}

From source file:org.sufficientlysecure.keychain.ui.SettingsSmartPGPAuthorityFragment.java

private void startEditAuthorityDialog(AddEditSmartPGPAuthorityDialogFragment.Action action,
        final String old_alias, final Uri uri, final int position) {
    Handler returnHandler = new Handler() {
        @Override/*from w  ww  .  j a  v a2 s .co  m*/
        public void handleMessage(Message message) {
            Bundle data = message.getData();
            final String new_alias = data.getString(AddEditSmartPGPAuthorityDialogFragment.OUT_ALIAS);
            final int position = data.getInt(AddEditSmartPGPAuthorityDialogFragment.OUT_POSITION);
            final String uri = data.getString(AddEditSmartPGPAuthorityDialogFragment.OUT_URI);

            final AddEditSmartPGPAuthorityDialogFragment.Action action = (AddEditSmartPGPAuthorityDialogFragment.Action) data
                    .getSerializable(AddEditSmartPGPAuthorityDialogFragment.OUT_ACTION);

            switch (action) {
            case ADD:
                if (editAuthority(old_alias, new_alias, position, uri)) {
                    Notify.create(getActivity(), "Authority " + new_alias + " added", Notify.LENGTH_SHORT,
                            Notify.Style.OK).show();
                }
                break;

            case EDIT:
                if (editAuthority(old_alias, new_alias, position, uri)) {
                    Notify.create(getActivity(), "Authority " + old_alias + " modified", Notify.LENGTH_SHORT,
                            Notify.Style.OK).show();
                }
                break;

            case DELETE:
                if (deleteAuthority(position)) {
                    Notify.create(getActivity(), "Authority " + old_alias + " deleted", Notify.LENGTH_SHORT,
                            Notify.Style.OK).show();
                }
                break;

            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(returnHandler);
    AddEditSmartPGPAuthorityDialogFragment dialogFragment = AddEditSmartPGPAuthorityDialogFragment
            .newInstance(messenger, action, old_alias, uri, position);
    dialogFragment.show(getFragmentManager(), "addSmartPGPAuthorityDialog");
}

From source file:fr.julienvermet.bugdroid.ui.BugFragment.java

public void loadBug(boolean fromCache) {
    Intent intent = BugIntentService.getIntent(getActivity(), mInstance, mBugId, fromCache);
    Messenger messenger = new Messenger(onBugReceivedHandler);
    intent.putExtra(BugIntentService.MESSENGER, messenger);
    getActivity().startService(intent);/*from www  . j av  a2  s.  c  o  m*/
}

From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvUserIdsFragment.java

private void editUserId(final int position) {
    final String userId = mUserIdsAdapter.getUserId(position);
    final boolean isRevoked = mUserIdsAdapter.getIsRevoked(position);
    final boolean isRevokedPending = mUserIdsAdapter.getIsRevokedPending(position);

    Handler returnHandler = new Handler() {
        @Override//from  w  w  w  .j av  a2 s .c o m
        public void handleMessage(Message message) {
            switch (message.what) {
            case EditUserIdDialogFragment.MESSAGE_CHANGE_PRIMARY_USER_ID:
                // toggle
                if (mEditModeSaveKeyringParcel.mChangePrimaryUserId != null
                        && mEditModeSaveKeyringParcel.mChangePrimaryUserId.equals(userId)) {
                    mEditModeSaveKeyringParcel.mChangePrimaryUserId = null;
                } else {
                    mEditModeSaveKeyringParcel.mChangePrimaryUserId = userId;
                }
                break;
            case EditUserIdDialogFragment.MESSAGE_REVOKE:
                // toggle
                if (mEditModeSaveKeyringParcel.mRevokeUserIds.contains(userId)) {
                    mEditModeSaveKeyringParcel.mRevokeUserIds.remove(userId);
                } else {
                    mEditModeSaveKeyringParcel.mRevokeUserIds.add(userId);
                    // not possible to revoke and change to primary user id
                    if (mEditModeSaveKeyringParcel.mChangePrimaryUserId != null
                            && mEditModeSaveKeyringParcel.mChangePrimaryUserId.equals(userId)) {
                        mEditModeSaveKeyringParcel.mChangePrimaryUserId = null;
                    }
                }
                break;
            }
            getLoaderManager().getLoader(LOADER_ID_USER_IDS).forceLoad();
        }
    };

    // Create a new Messenger for the communication back
    final Messenger messenger = new Messenger(returnHandler);

    DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
        public void run() {
            EditUserIdDialogFragment dialogFragment = EditUserIdDialogFragment.newInstance(messenger, isRevoked,
                    isRevokedPending);
            dialogFragment.show(getActivity().getSupportFragmentManager(), "editUserIdDialog");
        }
    });
}

From source file:org.sufficientlysecure.keychain.ui.EncryptFileFragment.java

private void showOutputFileDialog() {
    // Message is received after file is selected
    Handler returnHandler = new Handler() {
        @Override/*from  w w w .  j av  a 2  s . c  o  m*/
        public void handleMessage(Message message) {
            if (message.what == FileDialogFragment.MESSAGE_OKAY) {
                Bundle data = message.getData();
                mOutputFilename = data.getString(FileDialogFragment.MESSAGE_DATA_FILENAME);
                encryptStart();
            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(returnHandler);

    mFileDialog = FileDialogFragment.newInstance(messenger, getString(R.string.title_encrypt_to_file),
            getString(R.string.specify_file_to_encrypt_to), mOutputFilename, null);

    mFileDialog.show(getActivity().getSupportFragmentManager(), "fileDialog");
}

From source file:org.sufficientlysecure.keychain.ui.SettingsKeyserverFragment.java

private void startEditKeyserverDialog(AddEditKeyserverDialogFragment.DialogAction action,
        ParcelableHkpKeyserver keyserver, final int position) {
    Handler returnHandler = new Handler() {
        @Override//from   w w w . java  2s .  co  m
        public void handleMessage(Message message) {
            Bundle data = message.getData();
            switch (message.what) {
            case AddEditKeyserverDialogFragment.MESSAGE_OKAY: {
                boolean deleted = data.getBoolean(AddEditKeyserverDialogFragment.MESSAGE_KEYSERVER_DELETED,
                        false);
                if (deleted) {
                    Notify.create(getActivity(), getActivity().getString(R.string.keyserver_preference_deleted,
                            mKeyservers.get(position)), Notify.Style.OK).show();
                    deleteKeyserver(position);
                    return;
                }
                boolean verified = data.getBoolean(AddEditKeyserverDialogFragment.MESSAGE_VERIFIED);
                if (verified) {
                    Notify.create(getActivity(), R.string.add_keyserver_connection_verified, Notify.Style.OK)
                            .show();
                } else {
                    Notify.create(getActivity(), R.string.add_keyserver_without_verification, Notify.Style.WARN)
                            .show();
                }
                ParcelableHkpKeyserver keyserver = data
                        .getParcelable(AddEditKeyserverDialogFragment.MESSAGE_KEYSERVER);

                AddEditKeyserverDialogFragment.DialogAction dialogAction = (AddEditKeyserverDialogFragment.DialogAction) data
                        .getSerializable(AddEditKeyserverDialogFragment.MESSAGE_DIALOG_ACTION);
                switch (dialogAction) {
                case ADD:
                    addKeyserver(keyserver);
                    break;
                case EDIT:
                    editKeyserver(keyserver, position);
                    break;
                }
                break;
            }
            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(returnHandler);
    AddEditKeyserverDialogFragment dialogFragment = AddEditKeyserverDialogFragment.newInstance(messenger,
            action, keyserver, position);
    dialogFragment.show(getFragmentManager(), "addKeyserverDialog");
}

From source file:org.anhonesteffort.flock.RegisterAccountFragment.java

private void registerAccountAsync() {
    if (messageHandler != null && messageHandler.serviceStarted)
        return;/* w w  w  . ja  v  a 2s .  co m*/
    else if (messageHandler == null)
        messageHandler = new MessageHandler(setupActivity, this);

    Bundle result = new Bundle();
    String username = ((EditText) getActivity().findViewById(R.id.account_username)).getText().toString()
            .trim();
    String password = ((EditText) getActivity().findViewById(R.id.cipher_passphrase)).getText().toString()
            .trim();
    String passwordRepeat = ((EditText) getActivity().findViewById(R.id.cipher_passphrase_repeat)).getText()
            .toString().trim();

    if (StringUtils.isEmpty(username)) {
        result.putInt(ErrorToaster.KEY_STATUS_CODE, ErrorToaster.CODE_EMPTY_ACCOUNT_ID);
        ErrorToaster.handleDisplayToastBundledError(getActivity(), result);
        return;
    }

    if (StringUtils.isEmpty(password)) {
        result.putInt(ErrorToaster.KEY_STATUS_CODE, ErrorToaster.CODE_SHORT_PASSWORD);
        ErrorToaster.handleDisplayToastBundledError(getActivity(), result);
        ((TextView) getActivity().findViewById(R.id.cipher_passphrase)).setText("");
        ((TextView) getActivity().findViewById(R.id.cipher_passphrase_repeat)).setText("");
        return;
    }

    if (StringUtils.isEmpty(passwordRepeat) || !password.equals(passwordRepeat)) {
        result.putInt(ErrorToaster.KEY_STATUS_CODE, ErrorToaster.CODE_PASSWORDS_DO_NOT_MATCH);
        ErrorToaster.handleDisplayToastBundledError(getActivity(), result);
        ((TextView) getActivity().findViewById(R.id.cipher_passphrase)).setText("");
        ((TextView) getActivity().findViewById(R.id.cipher_passphrase_repeat)).setText("");
        return;
    }

    username = DavAccountHelper.correctUsername(getActivity(), username);
    Intent importService = new Intent(getActivity(), RegisterAccountService.class);

    importService.putExtra(RegisterAccountService.KEY_MESSENGER, new Messenger(messageHandler));
    importService.putExtra(RegisterAccountService.KEY_ACCOUNT_ID, username);
    importService.putExtra(RegisterAccountService.KEY_MASTER_PASSPHRASE, password);

    getActivity().startService(importService);
    messageHandler.serviceStarted = true;

    setupActivity.setNavigationDisabled(true);
    getActivity().setProgressBarIndeterminateVisibility(true);
    getActivity().setProgressBarVisibility(true);
}

From source file:org.sufficientlysecure.privacybox.EncryptedDocument.java

/**
 * Decrypt and return parsed metadata section from this document.
 *
 * @throws DigestException if metadata fails MAC check, or if
 *                         {@link Document#COLUMN_DOCUMENT_ID} recorded in metadata is
 *                         unexpected./*from   w ww  .jav  a 2  s. co m*/
 */
public JSONObject readMetadata() throws IOException, GeneralSecurityException {
    InputStream fis = new FileInputStream(mFile);

    try {
        Intent data = new Intent();
        data.setAction(OpenPgpApi.ACTION_DECRYPT_METADATA);
        data.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, "default");
        OpenPgpApi api = new OpenPgpApi(mContext, mServiceConnection.getService());
        Intent result = api.executeApi(data, fis, null);

        switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
        case OpenPgpApi.RESULT_CODE_SUCCESS: {
            Log.d(VaultProvider.TAG, "readMetadata RESULT_CODE_SUCCESS");

            //                    tempFile.renameTo(mFile);

            // TODO: better handling of errors
            OpenPgpMetadata openPgpMeta;
            if (result.hasExtra(OpenPgpApi.RESULT_METADATA)) {
                openPgpMeta = result.getParcelableExtra(OpenPgpApi.RESULT_METADATA);
            } else {
                throw new IOException();
            }

            Log.d(TAG, "metadata for " + mDocId + ": " + openPgpMeta);

            String filenameHeader = openPgpMeta.getFilename();
            long size = openPgpMeta.getOriginalSize();
            long modTime = openPgpMeta.getModificationTime();

            final JSONObject meta = new JSONObject();

            /*
             * If the filename header of the encrypted pgp file contains
             * JSON, we are dealing with a directory.
             * Instead of the actual filename, directories include JSON encoded mime type
             * and an array of all child documents.
             */
            if (filenameHeader.contains("{")) { // JSON with high probability
                meta.put(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR);

                JSONObject json = new JSONObject(filenameHeader);
                final String name = json.getString(Document.COLUMN_DISPLAY_NAME);
                final JSONArray children = json.getJSONArray(VaultProvider.KEY_CHILDREN);

                Log.d(VaultProvider.TAG, "json from filename header: " + json);
                Log.d(VaultProvider.TAG, "name: " + name);
                Log.d(VaultProvider.TAG, "children: " + children);

                meta.put(Document.COLUMN_DISPLAY_NAME, name);
                meta.put(VaultProvider.KEY_CHILDREN, children);
            } else {
                String mimeType = openPgpMeta.getMimeType();
                meta.put(Document.COLUMN_MIME_TYPE, mimeType);

                meta.put(Document.COLUMN_DISPLAY_NAME, filenameHeader);
            }
            meta.put(Document.COLUMN_DOCUMENT_ID, mDocId);
            meta.put(Document.COLUMN_SIZE, size);
            meta.put(Document.COLUMN_LAST_MODIFIED, modTime);

            return meta;
        }
        case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: {
            Log.d(VaultProvider.TAG, "readMetadata 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, "readMetadata RESULT_CODE_ERROR");

            // TODO
            OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
            Log.e(VaultProvider.TAG, "error: " + error.getMessage());

            //                handleError(error);
            break;
        }
        }

        return null;
    } catch (JSONException e) {
        throw new IOException(e);
    } finally {
        fis.close();
    }
}