aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/FidesmoPgpInstallDialog.java
blob: cdf6e5c7c67497558391d235e4a5967f3167740a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.sufficientlysecure.keychain.ui.dialog;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;

import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.util.Log;

public class FidesmoPgpInstallDialog extends DialogFragment {

    // Fidesmo constants
    private static final String FIDESMO_SERVICE_DELIVERY_CARD_ACTION = "com.fidesmo.sec.DELIVER_SERVICE";
    private static final String FIDESMO_SERVICE_URI = "https://api.fidesmo.com/service/";
    private static final String FIDESMO_PGP_APPLICATION_ID = "0cdc651e";
    private static final String FIDESMO_PGP_SERVICE_ID = "OKC-install";

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        CustomAlertDialogBuilder mCustomAlertDialogBuilder = new CustomAlertDialogBuilder(getActivity());
        mCustomAlertDialogBuilder.setTitle(getString(R.string.prompt_fidesmo_pgp_install_title));
        mCustomAlertDialogBuilder.setMessage(getString(R.string.prompt_fidesmo_pgp_install_message));
        mCustomAlertDialogBuilder.setPositiveButton(
                getString(R.string.prompt_fidesmo_pgp_install_button_positive),
                new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dismiss();
                startFidesmoPgpAppletActivity();
            }
        });
        mCustomAlertDialogBuilder.setNegativeButton(
                getString(R.string.prompt_fidesmo_pgp_install_button_negative),
                new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dismiss();
            }
        });

        return mCustomAlertDialogBuilder.show();
    }

    private void startFidesmoPgpAppletActivity() {
        try {
            // Call the Fidesmo app with the PGP applet as parameter to
            // send the user straight to it
            final String mPgpInstallServiceUrl = FIDESMO_SERVICE_URI + FIDESMO_PGP_APPLICATION_ID
                    + "/" + FIDESMO_PGP_SERVICE_ID;
            Intent mPgpServiceIntent = new Intent(FIDESMO_SERVICE_DELIVERY_CARD_ACTION,
                    Uri.parse(mPgpInstallServiceUrl));
            startActivity(mPgpServiceIntent);
        } catch (IllegalArgumentException e) {
            Log.e(Constants.TAG, "Error when parsing URI");
        }
    }
}