导航菜单

页面标题

页面副标题

St.John's v1.0.9 - YubiKeyPromptActivity.java 源代码

正在查看: St.John's v1.0.9 应用的 YubiKeyPromptActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.yubico.yubikit.android.ui;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.yubico.yubikit.android.R;
import com.yubico.yubikit.android.YubiKitManager;
import com.yubico.yubikit.android.transport.nfc.NfcConfiguration;
import com.yubico.yubikit.android.transport.nfc.NfcNotAvailable;
import com.yubico.yubikit.android.transport.nfc.NfcYubiKeyDevice;
import com.yubico.yubikit.android.transport.nfc.NfcYubiKeyManager;
import com.yubico.yubikit.android.transport.usb.UsbConfiguration;
import com.yubico.yubikit.android.transport.usb.UsbYubiKeyDevice;
import com.yubico.yubikit.android.ui.YubiKeyPromptActivity;
import com.yubico.yubikit.core.YubiKeyDevice;
import com.yubico.yubikit.core.application.CommandState;
import com.yubico.yubikit.core.util.Callback;
import com.yubico.yubikit.core.util.Pair;
import java.util.Objects;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class YubiKeyPromptActivity extends Activity {
    public static final String ARG_ACTION_CLASS = "ACTION_CLASS";
    public static final String ARG_ALLOW_NFC = "ALLOW_NFC";
    public static final String ARG_ALLOW_USB = "ALLOW_USB";
    public static final String ARG_CANCEL_BUTTON_ID = "CANCEL_BUTTON_ID";
    public static final String ARG_CONTENT_VIEW_ID = "CONTENT_VIEW_ID";
    public static final String ARG_ENABLE_NFC_BUTTON_ID = "ENABLE_NFC_BUTTON_ID";
    public static final String ARG_HELP_TEXT_VIEW_ID = "HELP_TEXT_VIEW_ID";
    public static final String ARG_TITLE_ID = "TITLE_ID";
    private static final Logger logger = LoggerFactory.getLogger(YubiKeyPromptActivity.class);
    private YubiKeyPromptAction action;
    private boolean allowNfc;
    private boolean allowUsb;
    protected Button cancelButton;
    protected Button enableNfcButton;
    protected TextView helpTextView;
    private YubiKitManager yubiKit;
    private final MyCommandState commandState = new MyCommandState();
    private boolean hasNfc = true;
    private int usbSessionCounter = 0;
    private boolean isDone = false;

    public static Intent createIntent(Context context, Class<? extends YubiKeyPromptAction> cls, int i) {
        Intent createIntent = createIntent(context, cls);
        createIntent.putExtra(ARG_TITLE_ID, i);
        return createIntent;
    }

    public static Intent createIntent(Context context, Class<? extends YubiKeyPromptAction> cls) {
        Intent intent = new Intent(context, (Class<?>) YubiKeyPromptActivity.class);
        intent.putExtra(ARG_ACTION_CLASS, cls);
        return intent;
    }

    protected YubiKitManager getYubiKitManager() {
        return this.yubiKit;
    }

    protected CommandState getCommandState() {
        return this.commandState;
    }

    protected boolean isNfcEnabled() {
        return this.hasNfc;
    }

    protected void onYubiKeyDevice(YubiKeyDevice yubiKeyDevice, final Runnable runnable) {
        this.action.onYubiKey(yubiKeyDevice, getIntent().getExtras(), this.commandState, new Callback() {
            @Override
            public final void invoke(Object obj) {
                YubiKeyPromptActivity.this.m61xda7cc33f(runnable, (Pair) obj);
            }
        });
    }

    void m61xda7cc33f(Runnable runnable, Pair pair) {
        if (((Integer) pair.first).intValue() == 101) {
            if (this.commandState.awaitingTouch) {
                runOnUiThread(new Runnable() {
                    @Override
                    public final void run() {
                        YubiKeyPromptActivity.this.m60x4d4211be();
                    }
                });
                this.commandState.awaitingTouch = false;
            }
        } else {
            provideResult(((Integer) pair.first).intValue(), (Intent) pair.second);
        }
        runnable.run();
    }

    void m60x4d4211be() {
        this.helpTextView.setText(this.hasNfc ? R.string.yubikit_prompt_plug_in_or_tap : R.string.yubikit_prompt_plug_in);
    }

    protected void provideResult(int i, Intent intent) {
        setResult(i, intent);
        this.isDone = true;
    }

    @Override
    protected void onCreate(@Nullable Bundle bundle) {
        super.onCreate(bundle);
        Bundle bundle2 = (Bundle) Objects.requireNonNull(getIntent().getExtras());
        this.allowUsb = bundle2.getBoolean(ARG_ALLOW_USB, true);
        this.allowNfc = bundle2.getBoolean(ARG_ALLOW_NFC, true);
        Class cls = (Class) bundle2.getSerializable(ARG_ACTION_CLASS);
        if (cls != null) {
            try {
            } catch (IllegalAccessException | IllegalStateException | InstantiationException e) {
                com.yubico.yubikit.core.internal.Logger.error(logger, "Unable to instantiate ConnectionAction", e);
                finish();
            }
            if (YubiKeyPromptAction.class.isAssignableFrom(cls)) {
                this.action = (YubiKeyPromptAction) cls.newInstance();
                setContentView(bundle2.getInt(ARG_CONTENT_VIEW_ID, R.layout.yubikit_yubikey_prompt_content));
                if (bundle2.containsKey(ARG_TITLE_ID)) {
                    setTitle(bundle2.getInt(ARG_TITLE_ID));
                }
                TextView textView = (TextView) findViewById(R.id.yubikit_prompt_title);
                if (textView != null) {
                    textView.setText(getTitle());
                }
                this.helpTextView = (TextView) findViewById(bundle2.getInt(ARG_HELP_TEXT_VIEW_ID, R.id.yubikit_prompt_help_text_view));
                Button button = (Button) findViewById(bundle2.getInt(ARG_CANCEL_BUTTON_ID, R.id.yubikit_prompt_cancel_btn));
                this.cancelButton = button;
                button.setFocusable(false);
                this.cancelButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public final void onClick(View view) {
                        YubiKeyPromptActivity.this.m51xbc7af142(view);
                    }
                });
                YubiKitManager yubiKitManager = new YubiKitManager(this);
                this.yubiKit = yubiKitManager;
                if (this.allowUsb) {
                    yubiKitManager.startUsbDiscovery(new UsbConfiguration(), new Callback() {
                        @Override
                        public final void invoke(Object obj) {
                            YubiKeyPromptActivity.this.m55xf165b746((UsbYubiKeyDevice) obj);
                        }
                    });
                }
                if (this.allowNfc) {
                    Button button2 = (Button) findViewById(bundle2.getInt(ARG_ENABLE_NFC_BUTTON_ID, R.id.yubikit_prompt_enable_nfc_btn));
                    this.enableNfcButton = button2;
                    button2.setFocusable(false);
                    this.enableNfcButton.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public final void onClick(View view) {
                            YubiKeyPromptActivity.this.m56x7ea068c7(view);
                        }
                    });
                    return;
                }
                return;
            }
        }
        throw new IllegalStateException("Missing or invalid ConnectionAction class");
    }

    void m51xbc7af142(View view) {
        this.commandState.cancel();
        setResult(0);
        finish();
    }

    void m55xf165b746(UsbYubiKeyDevice usbYubiKeyDevice) {
        this.usbSessionCounter++;
        usbYubiKeyDevice.setOnClosed(new Runnable() {
            @Override
            public final void run() {
                YubiKeyPromptActivity.this.m53xd6f05444();
            }
        });
        runOnUiThread(new Runnable() {
            @Override
            public final void run() {
                YubiKeyPromptActivity.this.m54x642b05c5();
            }
        });
        onYubiKeyDevice(usbYubiKeyDevice, new YubiKeyPromptActivity$$ExternalSyntheticLambda11(this));
    }

    void m53xd6f05444() {
        int i = this.usbSessionCounter - 1;
        this.usbSessionCounter = i;
        if (i == 0) {
            runOnUiThread(new Runnable() {
                @Override
                public final void run() {
                    YubiKeyPromptActivity.this.m52x49b5a2c3();
                }
            });
        }
    }

    void m52x49b5a2c3() {
        this.helpTextView.setText(this.hasNfc ? R.string.yubikit_prompt_plug_in_or_tap : R.string.yubikit_prompt_plug_in);
    }

    void m54x642b05c5() {
        this.helpTextView.setText(R.string.yubikit_prompt_wait);
    }

    void m56x7ea068c7(View view) {
        startActivity(new Intent(NfcYubiKeyManager.NFC_SETTINGS_ACTION));
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (this.allowNfc) {
            this.enableNfcButton.setVisibility(8);
            try {
                this.yubiKit.startNfcDiscovery(new NfcConfiguration(), this, new Callback() {
                    @Override
                    public final void invoke(Object obj) {
                        YubiKeyPromptActivity.this.m57x87bcc236((NfcYubiKeyDevice) obj);
                    }
                });
            } catch (NfcNotAvailable e) {
                this.hasNfc = false;
                this.helpTextView.setText(R.string.yubikit_prompt_plug_in);
                if (e.isDisabled()) {
                    this.enableNfcButton.setVisibility(0);
                }
            }
        }
    }

    void m57x87bcc236(final NfcYubiKeyDevice nfcYubiKeyDevice) {
        onYubiKeyDevice(nfcYubiKeyDevice, new Runnable() {
            @Override
            public final void run() {
                YubiKeyPromptActivity.this.m59xb61f043a(nfcYubiKeyDevice);
            }
        });
    }

    void m58x28e452b9() {
        this.helpTextView.setText(R.string.yubikit_prompt_remove);
    }

    void m59xb61f043a(NfcYubiKeyDevice nfcYubiKeyDevice) {
        runOnUiThread(new Runnable() {
            @Override
            public final void run() {
                YubiKeyPromptActivity.this.m58x28e452b9();
            }
        });
        nfcYubiKeyDevice.remove(new YubiKeyPromptActivity$$ExternalSyntheticLambda11(this));
    }

    @Override
    protected void onPause() {
        if (this.allowNfc) {
            this.yubiKit.stopNfcDiscovery(this);
        }
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        if (this.allowUsb) {
            this.yubiKit.stopUsbDiscovery();
        }
        super.onDestroy();
    }

    public void finishIfDone() {
        if (this.isDone) {
            finish();
        }
    }

    class MyCommandState extends CommandState {
        boolean awaitingTouch;

        private MyCommandState() {
            this.awaitingTouch = false;
        }

        @Override
        public void onKeepAliveStatus(byte b) {
            if (this.awaitingTouch || b != 2) {
                return;
            }
            this.awaitingTouch = true;
            YubiKeyPromptActivity.this.runOnUiThread(new Runnable() {
                @Override
                public final void run() {
                    YubiKeyPromptActivity.MyCommandState.this.m62x84bc17b0();
                }
            });
        }

        void m62x84bc17b0() {
            YubiKeyPromptActivity.this.helpTextView.setText(R.string.yubikit_prompt_uv);
        }
    }
}