Search in sources :

Example 6 with UnpairRequest

use of co.krypt.krypton.protocol.UnpairRequest in project krypton-android by kryptco.

the class Notifications method notifyRejectJob.

private static void notifyRejectJob(Context context, Pairing pairing, Request request, String title) {
    if (!new Settings(context).approvedNotificationsEnabled()) {
        return;
    }
    Intent resultIntent = new Intent(context, MainActivity.class);
    NotificationCompat.Builder mBuilder = buildNotification(context, APPROVED_CHANNEL_ID).setColor(Color.RED).setContentTitle(title).setAutoCancel(true).setPriority(NotificationCompat.PRIORITY_MAX).setCategory(NotificationCompat.CATEGORY_MESSAGE).setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    if (!new Settings(context).silenceNotifications()) {
        mBuilder.setDefaults(Notification.DEFAULT_SOUND).setVibrate(new long[] { 0, 100, 100, 100 });
    }
    request.body.visit(new RequestBody.Visitor<Void, RuntimeException>() {

        @Override
        public Void visit(MeRequest meRequest) throws RuntimeException {
            return null;
        }

        @Override
        public Void visit(SignRequest signRequest) throws RuntimeException {
            mBuilder.setContentText(pairing.workstationName + ": " + signRequest.display());
            return null;
        }

        @Override
        public Void visit(GitSignRequest gitSignRequest) throws RuntimeException {
            mBuilder.setContentTitle(gitSignRequest.title() + " Rejected").setContentText(pairing.workstationName + ": " + gitSignRequest.display());
            RemoteViews remoteViewsSmall = new RemoteViews(context.getPackageName(), R.layout.result_remote);
            remoteViewsSmall.setTextViewText(R.id.workstationName, pairing.workstationName);
            remoteViewsSmall.setTextViewText(R.id.header, "Rejected Request From");
            gitSignRequest.fillShortRemoteViews(remoteViewsSmall, false, null);
            mBuilder.setCustomContentView(remoteViewsSmall);
            RemoteViews remoteViewsBig = new RemoteViews(context.getPackageName(), R.layout.result_remote);
            remoteViewsBig.setTextViewText(R.id.workstationName, pairing.workstationName);
            remoteViewsBig.setTextViewText(R.id.header, "Rejected Request From");
            gitSignRequest.fillRemoteViews(remoteViewsBig, false, null);
            mBuilder.setCustomBigContentView(remoteViewsBig);
            return null;
        }

        @Override
        public Void visit(UnpairRequest unpairRequest) throws RuntimeException {
            return null;
        }

        @Override
        public Void visit(HostsRequest hostsRequest) throws RuntimeException {
            return null;
        }

        @Override
        public Void visit(ReadTeamRequest readTeamRequest) throws RuntimeException {
            return null;
        }

        @Override
        public Void visit(LogDecryptionRequest logDecryptionRequest) throws RuntimeException {
            return null;
        }

        @Override
        public Void visit(TeamOperationRequest teamOperationRequest) throws RuntimeException {
            return null;
        }
    });
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManagerCompat mNotifyMgr = NotificationManagerCompat.from(context);
    mNotifyMgr.notify(0, mBuilder.build());
}
Also used : MeRequest(co.krypt.krypton.protocol.MeRequest) SignRequest(co.krypt.krypton.protocol.SignRequest) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) TeamOperationRequest(co.krypt.krypton.protocol.TeamOperationRequest) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) HostsRequest(co.krypt.krypton.protocol.HostsRequest) UnpairRequest(co.krypt.krypton.protocol.UnpairRequest) ReadTeamRequest(co.krypt.krypton.protocol.ReadTeamRequest) RemoteViews(android.widget.RemoteViews) LogDecryptionRequest(co.krypt.krypton.protocol.LogDecryptionRequest) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) Settings(co.krypt.krypton.settings.Settings) RequestBody(co.krypt.krypton.protocol.RequestBody)

Example 7 with UnpairRequest

use of co.krypt.krypton.protocol.UnpairRequest in project krypton-android by kryptco.

the class ApprovalDialog method showApprovalDialog.

public static void showApprovalDialog(final Activity activity, final String requestID) {
    Pair<Pairing, Request> pendingRequestAndPairing = Policy.getPendingRequestAndPairing(requestID);
    if (pendingRequestAndPairing == null) {
        Log.e(TAG, "user clicked notification for unknown request");
        return;
    }
    Pairing pairing = pendingRequestAndPairing.first;
    Request request = pendingRequestAndPairing.second;
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setIcon(R.mipmap.ic_launcher);
    // setPositiveButton: right button
    // setNeutralButton: left button
    // setNegativeButton: middle button
    long temporaryApprovalSeconds = Policy.temporaryApprovalSeconds(activity, request);
    boolean temporaryApprovalEnabled = temporaryApprovalSeconds > 0;
    String temporaryApprovalDuration = Policy.temporaryApprovalDuration(activity, request);
    request.body.visit(new RequestBody.Visitor<Void, RuntimeException>() {

        @Override
        public Void visit(MeRequest meRequest) throws RuntimeException {
            return null;
        }

        @Override
        public Void visit(SignRequest signRequest) throws RuntimeException {
            builder.setPositiveButton("Once", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
            if (temporaryApprovalEnabled) {
                builder.setNeutralButton("All for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
                if (signRequest.hostNameVerified) {
                    builder.setNegativeButton("This host for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_THIS_TEMPORARILY));
                }
            }
            return null;
        }

        @Override
        public Void visit(GitSignRequest gitSignRequest) throws RuntimeException {
            builder.setPositiveButton("Once", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
            if (temporaryApprovalEnabled) {
                builder.setNeutralButton("All for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
            }
            return null;
        }

        @Override
        public Void visit(UnpairRequest unpairRequest) throws RuntimeException {
            return null;
        }

        @Override
        public Void visit(HostsRequest hostsRequest) throws RuntimeException {
            builder.setPositiveButton("Allow", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
            if (temporaryApprovalEnabled) {
                builder.setNeutralButton("All for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
            }
            return null;
        }

        @Override
        public Void visit(ReadTeamRequest readTeamRequest) throws RuntimeException {
            builder.setPositiveButton("Allow for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
            return null;
        }

        @Override
        public Void visit(LogDecryptionRequest logDecryptionRequest) throws RuntimeException {
            builder.setPositiveButton("Allow for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
            return null;
        }

        @Override
        public Void visit(TeamOperationRequest teamOperationRequest) throws RuntimeException {
            builder.setPositiveButton("Allow", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
            return null;
        }
    });
    builder.setOnDismissListener(dialogInterface -> {
        Policy.onAction(activity.getApplicationContext(), requestID, Policy.REJECT);
    });
    View requestView = activity.getLayoutInflater().inflate(R.layout.request, null);
    TextView workstationNameText = (TextView) requestView.findViewById(R.id.workstationName);
    workstationNameText.setText(pairing.workstationName);
    ConstraintLayout content = (ConstraintLayout) requestView.findViewById(R.id.content);
    request.fillView(content);
    builder.setView(requestView);
    builder.create().show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ReadTeamRequest(co.krypt.krypton.protocol.ReadTeamRequest) UnpairRequest(co.krypt.krypton.protocol.UnpairRequest) HostsRequest(co.krypt.krypton.protocol.HostsRequest) SignRequest(co.krypt.krypton.protocol.SignRequest) Pairing(co.krypt.krypton.pairing.Pairing) MeRequest(co.krypt.krypton.protocol.MeRequest) Request(co.krypt.krypton.protocol.Request) RequestBody(co.krypt.krypton.protocol.RequestBody) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) Pair(android.support.v4.util.Pair) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) View(android.view.View) LogDecryptionRequest(co.krypt.krypton.protocol.LogDecryptionRequest) ConstraintLayout(android.support.constraint.ConstraintLayout) Activity(android.app.Activity) R(co.krypt.krypton.R) Policy(co.krypt.krypton.policy.Policy) TeamOperationRequest(co.krypt.krypton.protocol.TeamOperationRequest) Log(android.util.Log) MeRequest(co.krypt.krypton.protocol.MeRequest) TeamOperationRequest(co.krypt.krypton.protocol.TeamOperationRequest) ConstraintLayout(android.support.constraint.ConstraintLayout) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) TextView(android.widget.TextView) Pairing(co.krypt.krypton.pairing.Pairing) RequestBody(co.krypt.krypton.protocol.RequestBody) SignRequest(co.krypt.krypton.protocol.SignRequest) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) ReadTeamRequest(co.krypt.krypton.protocol.ReadTeamRequest) UnpairRequest(co.krypt.krypton.protocol.UnpairRequest) HostsRequest(co.krypt.krypton.protocol.HostsRequest) SignRequest(co.krypt.krypton.protocol.SignRequest) MeRequest(co.krypt.krypton.protocol.MeRequest) Request(co.krypt.krypton.protocol.Request) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) LogDecryptionRequest(co.krypt.krypton.protocol.LogDecryptionRequest) TeamOperationRequest(co.krypt.krypton.protocol.TeamOperationRequest) HostsRequest(co.krypt.krypton.protocol.HostsRequest) UnpairRequest(co.krypt.krypton.protocol.UnpairRequest) TextView(android.widget.TextView) View(android.view.View) ReadTeamRequest(co.krypt.krypton.protocol.ReadTeamRequest) LogDecryptionRequest(co.krypt.krypton.protocol.LogDecryptionRequest)

Aggregations

UnpairRequest (co.krypt.krypton.protocol.UnpairRequest)7 GitSignRequest (co.krypt.krypton.protocol.GitSignRequest)6 HostsRequest (co.krypt.krypton.protocol.HostsRequest)6 LogDecryptionRequest (co.krypt.krypton.protocol.LogDecryptionRequest)6 MeRequest (co.krypt.krypton.protocol.MeRequest)6 ReadTeamRequest (co.krypt.krypton.protocol.ReadTeamRequest)6 RequestBody (co.krypt.krypton.protocol.RequestBody)6 SignRequest (co.krypt.krypton.protocol.SignRequest)6 TeamOperationRequest (co.krypt.krypton.protocol.TeamOperationRequest)6 Intent (android.content.Intent)4 PendingIntent (android.app.PendingIntent)3 NotificationCompat (android.support.v4.app.NotificationCompat)3 NotificationManagerCompat (android.support.v4.app.NotificationManagerCompat)3 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)3 RemoteViews (android.widget.RemoteViews)3 Analytics (co.krypt.krypton.analytics.Analytics)3 Log (android.util.Log)2 ProtocolException (co.krypt.krypton.exception.ProtocolException)2 Unrecoverable (co.krypt.krypton.exception.Unrecoverable)2 CommitInfo (co.krypt.krypton.git.CommitInfo)2