Search in sources :

Example 1 with OnboardingProgress

use of co.krypt.krypton.onboarding.OnboardingProgress in project krypton-android by kryptco.

the class Notifications method requestApprovalJob.

private static void requestApprovalJob(Context context, Pairing pairing, Request request) {
    long temporaryApprovalSeconds = Policy.temporaryApprovalSeconds(context, request);
    boolean temporaryApprovalEnabled = temporaryApprovalSeconds > 0;
    String temporaryApprovalDuration = Policy.temporaryApprovalDuration(context, request);
    Intent approveOnceIntent = new Intent(context, UnlockScreenDummyActivity.class);
    approveOnceIntent.setAction(Policy.APPROVE_ONCE + "-" + request.requestID);
    approveOnceIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    approveOnceIntent.putExtra("action", Policy.APPROVE_ONCE);
    approveOnceIntent.putExtra("requestID", request.requestID);
    PendingIntent approveOncePendingIntent = PendingIntent.getActivity(context, (Policy.APPROVE_ONCE + "-" + request.requestID).hashCode(), approveOnceIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action.Builder approveOnceBuilder = new NotificationCompat.Action.Builder(R.drawable.ic_notification_checkmark, "Once", approveOncePendingIntent);
    // Same as appoveOnceBuilder but shows text as "Approve"
    NotificationCompat.Action.Builder approveOnceTextApproveBuilder = new NotificationCompat.Action.Builder(R.drawable.ic_notification_checkmark, "Approve", approveOncePendingIntent);
    Intent approveTemporarilyIntent = new Intent(context, UnlockScreenDummyActivity.class);
    approveTemporarilyIntent.setAction(Policy.APPROVE_THIS_TEMPORARILY + "-" + request.requestID);
    approveTemporarilyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    approveTemporarilyIntent.putExtra("action", Policy.APPROVE_THIS_TEMPORARILY);
    approveTemporarilyIntent.putExtra("requestID", request.requestID);
    PendingIntent approveTemporarilyPendingIntent = PendingIntent.getActivity(context, (Policy.APPROVE_THIS_TEMPORARILY + "-" + request.requestID).hashCode(), approveTemporarilyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action.Builder approveTemporarilyBuilder = new NotificationCompat.Action.Builder(R.drawable.ic_notification_stopwatch, "This host for " + temporaryApprovalDuration, approveTemporarilyPendingIntent);
    Intent approveAllTemporarilyIntent = new Intent(context, UnlockScreenDummyActivity.class);
    approveAllTemporarilyIntent.setAction(Policy.APPROVE_ALL_TEMPORARILY + "-" + request.requestID);
    approveAllTemporarilyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    approveAllTemporarilyIntent.putExtra("action", Policy.APPROVE_ALL_TEMPORARILY);
    approveAllTemporarilyIntent.putExtra("requestID", request.requestID);
    PendingIntent approveAllTemporarilyPendingIntent = PendingIntent.getActivity(context, (Policy.APPROVE_ALL_TEMPORARILY + "-" + request.requestID).hashCode(), approveAllTemporarilyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action.Builder approveAllTemporarilyBuilder = new NotificationCompat.Action.Builder(R.drawable.ic_notification_stopwatch, "All for " + temporaryApprovalDuration, approveAllTemporarilyPendingIntent);
    Intent rejectIntent = new Intent(context, NoAuthReceiver.class);
    rejectIntent.setAction(Policy.REJECT + "-" + request.requestID);
    rejectIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    rejectIntent.putExtra("action", Policy.REJECT);
    rejectIntent.putExtra("requestID", request.requestID);
    PendingIntent rejectPendingIntent = PendingIntent.getBroadcast(context, (Policy.REJECT + "-" + request.requestID).hashCode(), rejectIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Intent clickIntent = new Intent(context, MainActivity.class);
    if (new OnboardingProgress(context).inProgress()) {
        clickIntent.setClass(context, OnboardingActivity.class);
    }
    clickIntent.setAction("CLICK-" + request.requestID);
    clickIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    clickIntent.putExtra("requestID", request.requestID);
    PendingIntent clickPendingIntent = PendingIntent.getActivity(context, ("CLICK-" + request.requestID).hashCode(), clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder mBuilder = buildNotification(context, ACTION_REQUIRED_CHANNEL_ID).setColor(ContextCompat.getColor(context, R.color.colorPrimary)).setPriority(NotificationCompat.PRIORITY_MAX).setCategory(NotificationCompat.CATEGORY_MESSAGE).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setDeleteIntent(rejectPendingIntent).setContentIntent(clickPendingIntent).setAutoCancel(true);
    RemoteViews remoteViewsBig = new RemoteViews(context.getPackageName(), R.layout.request_remote);
    remoteViewsBig.setTextViewText(R.id.workstationName, pairing.workstationName);
    request.fillRemoteViews(remoteViewsBig, null, null);
    remoteViewsBig.setOnClickPendingIntent(R.id.allowOnce, approveOncePendingIntent);
    remoteViewsBig.setTextViewText(R.id.allowAllTemporarily, "All for " + temporaryApprovalDuration);
    remoteViewsBig.setOnClickPendingIntent(R.id.allowAllTemporarily, approveAllTemporarilyPendingIntent);
    if (!temporaryApprovalEnabled) {
        remoteViewsBig.setViewVisibility(R.id.allowTemporarily, View.INVISIBLE);
        remoteViewsBig.setViewVisibility(R.id.allowAllTemporarily, View.INVISIBLE);
    }
    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.setContentTitle("Allow SSH Login?").setContentText(pairing.workstationName + ": " + signRequest.display());
            RemoteViews remoteViewsSmall = new RemoteViews(context.getPackageName(), R.layout.request_no_action_remote);
            remoteViewsSmall.setTextViewText(R.id.workstationName, pairing.workstationName);
            request.fillShortRemoteViews(remoteViewsSmall, null, null);
            mBuilder.setContent(remoteViewsSmall);
            remoteViewsBig.setOnClickPendingIntent(R.id.allowTemporarily, approveTemporarilyPendingIntent);
            remoteViewsBig.setTextViewText(R.id.allowTemporarily, "This host for " + temporaryApprovalDuration);
            mBuilder.setCustomBigContentView(remoteViewsBig);
            mBuilder.addAction(approveOnceBuilder.build());
            if (temporaryApprovalEnabled) {
                mBuilder.addAction(approveTemporarilyBuilder.build()).addAction(approveAllTemporarilyBuilder.build());
            }
            return null;
        }

        @Override
        public Void visit(GitSignRequest gitSignRequest) throws RuntimeException {
            mBuilder.setContentTitle("Allow " + gitSignRequest.title() + "?").setContentText(pairing.workstationName + ": " + gitSignRequest.display());
            RemoteViews remoteViewsSmall = new RemoteViews(context.getPackageName(), R.layout.request_no_action_remote);
            remoteViewsSmall.setTextViewText(R.id.workstationName, pairing.workstationName);
            gitSignRequest.fillShortRemoteViews(remoteViewsSmall, null, null);
            mBuilder.setContent(remoteViewsSmall);
            remoteViewsBig.setTextViewText(R.id.allowTemporarily, "");
            mBuilder.setCustomBigContentView(remoteViewsBig);
            mBuilder.addAction(approveOnceBuilder.build());
            if (temporaryApprovalEnabled) {
                mBuilder.addAction(approveAllTemporarilyBuilder.build());
            }
            return null;
        }

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

        @Override
        public Void visit(HostsRequest hostsRequest) throws RuntimeException {
            mBuilder.setContentTitle("Send user@hostname records?").setContentText(pairing.workstationName + " is requesting your SSH login records.");
            mBuilder.addAction(approveOnceBuilder.build());
            if (temporaryApprovalEnabled) {
                mBuilder.addAction(approveAllTemporarilyBuilder.build());
            }
            return null;
        }

        @Override
        public Void visit(ReadTeamRequest readTeamRequest) throws RuntimeException {
            mBuilder.setContentTitle("Load team data?").setContentText(pairing.workstationName + " is requesting to load team data.");
            mBuilder.addAction(approveAllTemporarilyBuilder.build());
            return null;
        }

        @Override
        public Void visit(LogDecryptionRequest logDecryptionRequest) throws RuntimeException {
            mBuilder.setContentTitle("Decrypt team logs?").setContentText(pairing.workstationName + " is requesting to decrypt team logs.");
            mBuilder.addAction(approveAllTemporarilyBuilder.build());
            return null;
        }

        @Override
        public Void visit(TeamOperationRequest teamOperationRequest) throws RuntimeException {
            try {
                Sigchain.NativeResult<Sigchain.FormattedRequestableOp> format = TeamDataProvider.formatRequestableOp(context, teamOperationRequest.operation);
                if (format.success != null) {
                    mBuilder.setContentTitle(format.success.header).setContentText(format.success.body + "?");
                    mBuilder.addAction(approveOnceTextApproveBuilder.build());
                } else {
                    mBuilder.setContentTitle("Invalid team operation request.");
                }
            } catch (Native.NotLinked notLinked) {
                notLinked.printStackTrace();
                mBuilder.setContentTitle("Teams not supported on this phone");
            }
            return null;
        }
    });
    if (!new Settings(context).silenceNotifications()) {
        mBuilder.setDefaults(Notification.DEFAULT_SOUND).setVibrate(new long[] { 0, 100, 100, 100 });
    }
    NotificationManagerCompat mNotifyMgr = NotificationManagerCompat.from(context);
    mNotifyMgr.notify(request.requestID, 0, mBuilder.build());
}
Also used : MeRequest(co.krypt.krypton.protocol.MeRequest) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) TeamOperationRequest(co.krypt.krypton.protocol.TeamOperationRequest) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) NotificationCompat(android.support.v4.app.NotificationCompat) OnboardingProgress(co.krypt.krypton.onboarding.OnboardingProgress) Settings(co.krypt.krypton.settings.Settings) RequestBody(co.krypt.krypton.protocol.RequestBody) SignRequest(co.krypt.krypton.protocol.SignRequest) GitSignRequest(co.krypt.krypton.protocol.GitSignRequest) Sigchain(co.krypt.krypton.team.Sigchain) 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) PendingIntent(android.app.PendingIntent)

Example 2 with OnboardingProgress

use of co.krypt.krypton.onboarding.OnboardingProgress in project krypton-android by kryptco.

the class Notifications method notifyTeamUpdateJob.

private static void notifyTeamUpdateJob(Context context, String teamName, Sigchain.FormattedBlock block) {
    Intent clickIntent = new Intent(context, MainActivity.class);
    if (new OnboardingProgress(context).inProgress()) {
        clickIntent.setClass(context, OnboardingActivity.class);
    }
    clickIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent clickPendingIntent = PendingIntent.getActivity(context, ("CLICK-TEAM-UPDATE").hashCode(), clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder mBuilder = buildNotification(context, APPROVED_CHANNEL_ID).setContentTitle("[" + teamName + "] " + block.header).setContentText(block.body).setColor(ContextCompat.getColor(context, R.color.colorPrimary)).setPriority(NotificationCompat.PRIORITY_MAX).setCategory(NotificationCompat.CATEGORY_MESSAGE).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setContentIntent(clickPendingIntent).setAutoCancel(true);
    if (!new Settings(context).silenceNotifications()) {
        mBuilder.setDefaults(Notification.DEFAULT_SOUND).setVibrate(new long[] { 0, 100, 100, 100 });
    }
    NotificationManagerCompat mNotifyMgr = NotificationManagerCompat.from(context);
    mNotifyMgr.notify(Arrays.hashCode(block.hash), mBuilder.build());
}
Also used : NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) OnboardingProgress(co.krypt.krypton.onboarding.OnboardingProgress) Settings(co.krypt.krypton.settings.Settings)

Example 3 with OnboardingProgress

use of co.krypt.krypton.onboarding.OnboardingProgress in project krypton-android by kryptco.

the class Notifications method notifyPGPKeyExportJob.

private static void notifyPGPKeyExportJob(Context context, PGPPublicKey pubkey) {
    Intent clickIntent = new Intent(context, MainActivity.class);
    if (new OnboardingProgress(context).inProgress()) {
        clickIntent.setClass(context, OnboardingActivity.class);
    }
    clickIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent clickPendingIntent = PendingIntent.getActivity(context, ("CLICK-PGPPUBKEY").hashCode(), clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    String userIDs = "";
    for (SignedPublicKeySelfCertification signedIdentity : pubkey.signedIdentities) {
        userIDs += signedIdentity.certification.userIDPacket.userID.toString() + "\n";
    }
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    inboxStyle.setBigContentTitle("Exported PGP Public Key");
    for (SignedPublicKeySelfCertification signedIdentity : pubkey.signedIdentities) {
        inboxStyle.addLine(signedIdentity.certification.userIDPacket.userID.toString());
    }
    NotificationCompat.Builder mBuilder = buildNotification(context, APPROVED_CHANNEL_ID).setContentTitle("Exported PGP Public Key").setContentText(userIDs.trim()).setColor(ContextCompat.getColor(context, R.color.colorPrimary)).setPriority(NotificationCompat.PRIORITY_MAX).setCategory(NotificationCompat.CATEGORY_MESSAGE).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setContentIntent(clickPendingIntent).setAutoCancel(true).setStyle(inboxStyle);
    if (!new Settings(context).silenceNotifications()) {
        mBuilder.setDefaults(Notification.DEFAULT_SOUND).setVibrate(new long[] { 0, 100, 100, 100 });
    }
    NotificationManagerCompat mNotifyMgr = NotificationManagerCompat.from(context);
    mNotifyMgr.notify(1, mBuilder.build());
}
Also used : NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) OnboardingProgress(co.krypt.krypton.onboarding.OnboardingProgress) SignedPublicKeySelfCertification(co.krypt.krypton.pgp.publickey.SignedPublicKeySelfCertification) Settings(co.krypt.krypton.settings.Settings)

Example 4 with OnboardingProgress

use of co.krypt.krypton.onboarding.OnboardingProgress in project krypton-android by kryptco.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.AppTheme);
    super.onCreate(savedInstanceState);
    CrashReporting.startANRReporting();
    Notifications.setupNotificationChannels(getApplicationContext());
    silo = Silo.shared(getApplicationContext());
    startService(new Intent(this, BluetoothService.class));
    OnboardingProgress progress = new OnboardingProgress(getApplicationContext());
    if (new MeStorage(getApplicationContext()).load() == null || progress.inProgress()) {
        startActivity(new Intent(this, OnboardingActivity.class));
        finish();
        return;
    }
    if (ConnectionResult.SUCCESS != GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(getApplicationContext())) {
    // TODO: warn about no push notifications, prompt to install google play services
    }
    setContentView(R.layout.activity_main);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setOffscreenPageLimit(4);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    ImageButton settingsButton = (ImageButton) findViewById(R.id.settingsButton);
    settingsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            SettingsFragment settingsFragment = new SettingsFragment();
            transaction.setCustomAnimations(R.anim.enter_from_bottom, R.anim.exit_to_bottom, R.anim.enter_from_bottom, R.anim.exit_to_bottom).addToBackStack(null).replace(R.id.fragmentOverlay, settingsFragment).commit();
            new Analytics(getApplicationContext()).postPageView("About");
        }
    });
    ImageButton infoButton = (ImageButton) findViewById(R.id.infoButton);
    infoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            HelpFragment helpFragment = new HelpFragment();
            transaction.setCustomAnimations(R.anim.enter_from_bottom, R.anim.exit_to_bottom, R.anim.enter_from_bottom, R.anim.exit_to_bottom).addToBackStack(null).replace(R.id.fragmentOverlay, helpFragment).commit();
            new Analytics(getApplicationContext()).postPageView("Help");
        }
    });
    if (getIntent() != null) {
        onNewIntent(getIntent());
    }
}
Also used : OnboardingActivity(co.krypt.krypton.onboarding.OnboardingActivity) TeamOnboardingActivity(co.krypt.krypton.team.onboarding.TeamOnboardingActivity) Intent(android.content.Intent) HelpFragment(co.krypt.krypton.help.HelpFragment) View(android.view.View) Analytics(co.krypt.krypton.analytics.Analytics) SettingsFragment(co.krypt.krypton.settings.SettingsFragment) ImageButton(android.widget.ImageButton) BluetoothService(co.krypt.krypton.transport.BluetoothService) FragmentTransaction(android.support.v4.app.FragmentTransaction) TabLayout(android.support.design.widget.TabLayout) MeStorage(co.krypt.krypton.me.MeStorage) OnboardingProgress(co.krypt.krypton.onboarding.OnboardingProgress)

Aggregations

Intent (android.content.Intent)4 OnboardingProgress (co.krypt.krypton.onboarding.OnboardingProgress)4 PendingIntent (android.app.PendingIntent)3 NotificationCompat (android.support.v4.app.NotificationCompat)3 NotificationManagerCompat (android.support.v4.app.NotificationManagerCompat)3 Settings (co.krypt.krypton.settings.Settings)3 TabLayout (android.support.design.widget.TabLayout)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 RemoteViews (android.widget.RemoteViews)1 Analytics (co.krypt.krypton.analytics.Analytics)1 HelpFragment (co.krypt.krypton.help.HelpFragment)1 MeStorage (co.krypt.krypton.me.MeStorage)1 OnboardingActivity (co.krypt.krypton.onboarding.OnboardingActivity)1 SignedPublicKeySelfCertification (co.krypt.krypton.pgp.publickey.SignedPublicKeySelfCertification)1 GitSignRequest (co.krypt.krypton.protocol.GitSignRequest)1 HostsRequest (co.krypt.krypton.protocol.HostsRequest)1 LogDecryptionRequest (co.krypt.krypton.protocol.LogDecryptionRequest)1