Search in sources :

Example 1 with Pairings

use of co.krypt.krypton.pairing.Pairings in project krypton-android by kryptco.

the class DeviceDetailFragment method onCheckedChanged.

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if (isChecked) {
        Pairings pairings = Silo.shared(getContext()).pairings();
        Analytics analytics = new Analytics(getContext());
        if (buttonView == manualButton) {
            pairings.setApproved(pairingUUID, false);
            analytics.postEvent("manual approval", String.valueOf(true), null, null, false);
        }
        if (buttonView == automaticButton) {
            pairings.setApproved(pairingUUID, true);
            analytics.postEvent("manual approval", String.valueOf(false), null, null, false);
        }
        updateApprovalButtons();
    }
}
Also used : Pairings(co.krypt.krypton.pairing.Pairings) Analytics(co.krypt.krypton.analytics.Analytics)

Example 2 with Pairings

use of co.krypt.krypton.pairing.Pairings in project krypton-android by kryptco.

the class DeviceDetailFragment method updateApprovalButtons.

private synchronized void updateApprovalButtons() {
    new Handler(Looper.getMainLooper()).post(() -> {
        manualButton.setOnCheckedChangeListener(null);
        automaticButton.setOnCheckedChangeListener(null);
        Pairings pairings = Silo.shared(getContext()).pairings();
        if (pairings.getApproved(pairingUUID)) {
            automaticButton.setChecked(true);
            manualButton.setChecked(false);
        } else {
            manualButton.setChecked(true);
            automaticButton.setChecked(false);
        }
        manualButton.setOnCheckedChangeListener(this);
        automaticButton.setOnCheckedChangeListener(this);
    });
    if (attachedContext != null) {
        try {
            boolean hasApprovals = Approval.hasTemporaryApprovals(Silo.shared(attachedContext).pairings().dbHelper.getApprovalDao(), Policy.temporaryApprovalSeconds(getContext(), Approval.ApprovalType.SSH_USER_HOST), UUID.fromString(pairingUUID));
            new Handler(Looper.getMainLooper()).post(() -> {
                if (hasApprovals) {
                    for (int i = 0; i < temporaryApprovalsContainer.getChildCount(); i++) {
                        temporaryApprovalsContainer.getChildAt(i).setVisibility(View.VISIBLE);
                    }
                } else {
                    // views below do not adjust correctly if container is GONE
                    for (int i = 0; i < temporaryApprovalsContainer.getChildCount(); i++) {
                        temporaryApprovalsContainer.getChildAt(i).setVisibility(View.GONE);
                    }
                }
            });
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
Also used : Pairings(co.krypt.krypton.pairing.Pairings) SQLException(java.sql.SQLException) Handler(android.os.Handler)

Example 3 with Pairings

use of co.krypt.krypton.pairing.Pairings in project krypton-android by kryptco.

the class DeviceDetailFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_device_detail, container, false);
    final Pairing pairing = Silo.shared(getContext()).pairings().getPairing(pairingUUID);
    if (pairing == null) {
        return view;
    }
    View deviceCardView = inflater.inflate(R.layout.device_card, container, false);
    TextView deviceName = (TextView) deviceCardView.findViewById(R.id.deviceName);
    deviceName.setText(pairing.workstationName);
    manualButton = (RadioButton) deviceCardView.findViewById(R.id.alwaysAsk);
    automaticButton = (RadioButton) deviceCardView.findViewById(R.id.automaticApprovalButton);
    viewTemporaryApprovalsButton = deviceCardView.findViewById(R.id.temporaryApprovalsViewButton);
    viewTemporaryApprovalsButton.setOnClickListener(v -> {
        ApprovalsFragment f = ApprovalsFragment.newInstance(pairing.uuid);
        getFragmentManager().beginTransaction().setCustomAnimations(R.anim.enter_from_right_fast, R.anim.exit_to_right_fast, R.anim.enter_from_right_fast, R.anim.exit_to_right_fast).addToBackStack(null).add(R.id.childFragmentContainer, f).commit();
    });
    resetTemporaryApprovalsButton = deviceCardView.findViewById(R.id.temporaryApprovalsResetButton);
    resetTemporaryApprovalsButton.setOnClickListener(v -> {
        try {
            Approval.deleteApprovalsForPairing(Silo.shared(v.getContext()).pairings().dbHelper.getApprovalDao(), pairing.uuid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    });
    temporaryApprovalsContainer = deviceCardView.findViewById(R.id.temporaryApprovalsContainer);
    updateApprovalButtons();
    unpairButton = (Button) deviceCardView.findViewById(R.id.unpairButton);
    unpairButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Silo.shared(v.getContext()).unpair(pairing, true);
            new Analytics(getContext()).postEvent("device", "unpair", null, null, false);
            getFragmentManager().popBackStackImmediate();
        }
    });
    final SwitchCompat askUnknownHostsSwitch = (SwitchCompat) deviceCardView.findViewById(R.id.requireUnknownHostApprovalSwitch);
    askUnknownHostsSwitch.setChecked(new Pairings(getContext()).requireUnknownHostManualApproval(pairing));
    askUnknownHostsSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            new Pairings(getContext()).setRequireUnknownHostManualApproval(pairing, isChecked);
        }
    });
    signatureLogAdapter.deviceCardView.set(deviceCardView);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
    Context context = recyclerView.getContext();
    if (mColumnCount <= 1) {
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
    } else {
        recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
    }
    recyclerView.setAdapter(signatureLogAdapter);
    onDeviceLogReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            signatureLogAdapter.setLogs(Silo.shared(getContext()).pairings().getAllLogsTimeDescending(pairingUUID));
        }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(Pairings.ON_DEVICE_LOG_ACTION);
    LocalBroadcastManager.getInstance(context).registerReceiver(onDeviceLogReceiver, filter);
    Silo.shared(getContext()).pairings().registerOnSharedPreferenceChangedListener(this);
    return view;
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) ApprovalsFragment(co.krypt.krypton.approval.ApprovalsFragment) SQLException(java.sql.SQLException) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BroadcastReceiver(android.content.BroadcastReceiver) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Analytics(co.krypt.krypton.analytics.Analytics) Pairings(co.krypt.krypton.pairing.Pairings) GridLayoutManager(android.support.v7.widget.GridLayoutManager) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) Pairing(co.krypt.krypton.pairing.Pairing) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Aggregations

Pairings (co.krypt.krypton.pairing.Pairings)3 Analytics (co.krypt.krypton.analytics.Analytics)2 SQLException (java.sql.SQLException)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Handler (android.os.Handler)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SwitchCompat (android.support.v7.widget.SwitchCompat)1 View (android.view.View)1 CompoundButton (android.widget.CompoundButton)1 TextView (android.widget.TextView)1 ApprovalsFragment (co.krypt.krypton.approval.ApprovalsFragment)1 Pairing (co.krypt.krypton.pairing.Pairing)1