com.btchip.comm.android.BTChipTransportAndroid Java Examples

The following examples show how to use com.btchip.comm.android.BTChipTransportAndroid. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RequestLoginActivity.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
protected void onUsbAttach(final UsbDevice usb) {
    Log.d(TAG, "onUsbAttach");
    mUsb = usb;
    if (usb == null)
        return;

    mVendorId = usb.getVendorId();
    Log.d(TAG, "Vendor: " + mVendorId + " Product: " + usb.getProductId());

    if (mVendorId == VENDOR_TREZOR || mVendorId == VENDOR_TREZOR_V2) {
        onTrezor();
    } else if (mVendorId == VENDOR_BTCHIP || mVendorId == VENDOR_LEDGER) {
        if (BTChipTransportAndroid.isLedgerWithScreen(usb)) {
            // User entered PIN on-device
            setupLedgerConnection();
        } else {
            // Prompt for PIN to unlock device before setting it up
            runOnUiThread(new Runnable() { public void run() { showPinDialog(); }});
        }
    }
}
 
Example #2
Source File: RequestLoginActivity.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
private void onUsbAttach(final UsbDevice usb) {
    Log.d(TAG, "onUsbAttach");
    if (mUsb != null && mUsb == usb) {
        Log.d(TAG, "onUsbAttach with existing USB");
        return;
    }
    mUsb = usb;
    mInLedgerDashboard = false;
    if (usb == null)
        return;

    final ImageView hardwareIcon = UI.find(this, R.id.hardwareIcon);
    mVendorId = usb.getVendorId();
    Log.d(TAG, "Vendor: " + mVendorId + " Product: " + usb.getProductId());

    switch (mVendorId) {
    case VENDOR_TREZOR:
    case VENDOR_TREZOR_V2:
        hardwareIcon.setImageResource(R.drawable.ic_trezor);
        onTrezor();
        return;
    case VENDOR_BTCHIP:
    case VENDOR_LEDGER:
        hardwareIcon.setImageResource(R.drawable.ic_ledger);
        if (BTChipTransportAndroid.isLedgerWithScreen(usb)) {
            // User entered PIN on-device
            onLedger(true);
        } else {
            // Prompt for PIN to unlock device before setting it up
            showPinDialog();
        }
    }
}
 
Example #3
Source File: LedgerTransportTEEProxy.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Future<byte[]> exchange(byte[] command) throws BTChipException {
	ServiceResult result;
			
	if (debug) {
		Log.d(BTChipTransportAndroid.LOG_STRING, "=> " + Dump.dump(command));
	}
	if (service == null) {
		throw new BTChipException("Service is not available");
	}		
	if (session == null) {
		throw new BTChipException("Session is not open");
	}
	try {
		if (needExternalUI(command)) {
			result = service.exchangeExtendedUI(session, command);						
		}
		else {
			result = service.exchange(session, command);
		}
	}
	catch(Exception e) {
		throw new BTChipException("Exception calling service", e);
	}
	if (result.getExceptionMessage() != null) {
		Log.d(TAG, "Exchange failed " + result.getExceptionMessage());
		return null;
	}
	Log.d(BTChipTransportAndroid.LOG_STRING, "<= " + Dump.dump(result.getResult()));		
	return FutureUtils.getDummyFuture(result.getResult());
}
 
Example #4
Source File: GreenAddressIt.java    From WalletCordova with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void onNewIntent(Intent intent) {
    lastIntent = intent;
    UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
    if (device != null) {
        System.out.println("Dongle detected");
        UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
        BTChip.transport = BTChipTransportAndroid.open(manager, device);
    }
    processView(intent);
    super.onNewIntent(intent);
    setIntent(intent);
}
 
Example #5
Source File: RequestLoginActivity.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
private void setupLedgerConnection() {
    showInstructions(R.string.logging_in);
    final String pin = mPin;
    mPin = null;

    final BTChipTransport transport;
    if (mUsb != null) {
        transport = BTChipTransportAndroid.open(mUsbManager, mUsb);
        if (transport == null) {
            showInstructions(R.string.hw_wallet_reconnect);
            return;
        }
    } else if ((transport = getTransport(mTag)) == null) {
        showInstructions(R.string.hw_wallet_headline);

        // Prompt the user to tap
        runOnUiThread(new Runnable() {
            public void run() {
                mNfcWaitDialog = new MaterialDialog.Builder(RequestLoginActivity.this)
                    .title(R.string.btchip).content(R.string.please_tap_card).build();
                mNfcWaitDialog.show();
            }
        });
        return;
    }

    transport.setDebug(BuildConfig.DEBUG);
    try {
        final BTChipFirmware fw = (new BTChipDongle(transport, true)).getFirmwareVersion();
        final int major = fw.getMajor(), minor = fw.getMinor(), patch = fw.getPatch();

        Log.d(TAG, "BTChip/Ledger firmware version " + fw.toString() + '(' +
                major + '.' + minor + '.' + patch + ')');

        boolean isFirmwareOutdated = false;
        if (mVendorId == VENDOR_BTCHIP) {
            isFirmwareOutdated = major < 0x2001 ||
                (major == 0x2001 && minor < 0) || // Just for consistency in checking code
                (major == 0x2001 && minor == 0 && patch < 4);
        } else if (mVendorId == VENDOR_LEDGER) {
            isFirmwareOutdated = major < 0x3001 ||
                (major == 0x3001 && minor < 2) ||
                (major == 0x3001 && minor == 2 && patch < 5);
        }

        if (!isFirmwareOutdated) {
            onLedgerConnected(transport, pin);
            return;
        }

        showFirmwareOutdated(R.string.ledger_firmware_outdated,
                             new Runnable() { public void run() { onLedgerConnected(transport, pin); } });
    } catch (final BTChipException e) {
        if (e.getSW() != BTChipConstants.SW_INS_NOT_SUPPORTED)
            e.printStackTrace();
        // We are in dashboard mode, prompt the user to open the btcoin app.
        showInstructions(R.string.ledger_open_bitcoin_app);
    }
}