Task #2084

bootstrapping via bluetooth

Added by hans over 4 years ago. Updated almost 4 years ago.

Status:ClosedStart date:10/15/2013
Priority:ImmediateDue date:
Assignee:pd0x% Done:

0%

Category:-
Target version:0.2 - ChatSecure/Bluetooth
Component:

Description

bazaar needs some way to bootstrap one device from a device that is already setup on bazaar. It is possible to bluetooth files, but Android restricts the types of files that you can easily send via Bluetooth (e.g. .apk, etc.)

This app was able to directly send an APK from my Xoom tablet's SD card to my Note 2: https://play.google.com/store/apps/details?id=it.medieval.blueftp


Related issues

Related to Bazaar - Feature #2594: Bluetooth data channel for accessing p2p repos Closed 11/21/2013
Related to Bazaar - Bug #2905: bootstrapping via Android Beam Closed 01/24/2014
Related to Bazaar - Feature #2906: bootstrapping via Samsung/HTC SBeam New 01/24/2014
Related to Bazaar - Feature #2907: bootstrapping via removable SD cards New 01/24/2014
Related to Bazaar - Bug #2966: probe for Bluetooth Activity for sending FDroid.apk Closed 02/15/2014
Related to Bazaar - Bug #2967: after sending FDroid.apk via bluetooth, it should turn it... New 02/15/2014

History

#1 Updated by hans over 4 years ago

BlueFTP can directly send APKs on custom ROMs that have disabled the filter that stock Android ROMs have when sending files via bluetooth. It is possible to rename the file, like foo.apk.jpg and it'll go thru on a stock phone. It is also possible to zip up an APK and it'll go thru, i.e. foo.apk.zip.

#2 Updated by hans about 4 years ago

  • Target version set to 0.2 - ChatSecure/Bluetooth

#3 Updated by hans about 4 years ago

  • Priority changed from Normal to High

#4 Updated by hans almost 4 years ago

If there is a standard location where incoming bluetooth file transfers are put, perhaps in /sdcard/downloads or elsewhere, then this can be used to detect whether F-Droid was just installed via bluetooth. Then it can prompt the user to go thru the p2p repo setup with the person who just send the APK over.

#6 Updated by hans almost 4 years ago

  • Status changed from New to In Progress
  • Assignee set to hans
  • Priority changed from High to Immediate

something to play with:
https://developer.android.com/reference/android/nfc/NfcAdapter.html#setBeamPushUris(android.net.Uri%5B%5D%2C%20android.app.Activity)

It provides an automated way to step up to bluetooth, so it should be useful for sending APKs on ROMs that let you do that.

#7 Updated by hans almost 4 years ago

Android Beam support for FDroid is included in this merge request, it works well and doesn't disallow sending APKs:
https://gitorious.org/f-droid/fdroidclient/merge_requests/59

Standard bluetooth is a different story. I tested with a CM 10.1 Samsung Note2 and a stock Google Nexus 7. The Nexus 7 would neither send nor receive an APK via standard Bluetooth file transfer. It also failed both ways between Note2/CM10.1 and a Motorola Xoom running TeamEOS ROM, which is based on AOSP.

#8 Updated by hans almost 4 years ago

Made some progress. I got stock Android to send an APK, but it still rejects receiving. CyanogenMod does both just fine. In order to get stock Android to send the APK, I just had to set the MIME type for .zip rather than .apk. I.e.:

intent.setType("application/zip");

Instead of:

intent.setType("application/vnd.android.package-archive");

#9 Updated by hans almost 4 years ago

my working example:
https://stackoverflow.com/questions/16277593/bluetooth-file-transfer-on-androideven-restricted-types/21790899#21790899

    PackageManager pm = getPackageManager();
    ApplicationInfo appInfo;
    try {
        appInfo = pm.getApplicationInfo("org.fdroid.fdroid",
                PackageManager.GET_META_DATA);
        Intent sendBt = new Intent(Intent.ACTION_SEND);
        // NOT THIS! sendBt.setType("application/vnd.android.package-archive");
        sendBt.setType("application/zip");
        sendBt.putExtra(Intent.EXTRA_STREAM,
                Uri.parse("file://" + appInfo.publicSourceDir));
        sendBt.setClassName("com.android.bluetooth",
                "com.android.bluetooth.opp.BluetoothOppLauncherActivity");
        startActivity(sendBt);
    } catch (NameNotFoundException e1) {
        e1.printStackTrace();
    }

#10 Updated by n8fr8 almost 4 years ago

But will the receiving end open an APK installer if the mime type is for zip?

#11 Updated by hans almost 4 years ago

Works fine for me, but I've only tested on CM10.1 so far. My guess is that the MIME type info is not sent via Bluetooth.

#12 Updated by hans almost 4 years ago

Works fine for me, but I've only tested on CM10.1 so far. My guess is that the MIME type info is not sent via Bluetooth.

I did a quick test from stock 4.4.2 Nexus 7 to a stock Samsung Galaxy Player 5.0, and the Player 5.0 received the file and installed it! So it seems that even some Samsung ROMs don't include that block.

#13 Updated by hans almost 4 years ago

  • Status changed from In Progress to Resolved
  • Assignee changed from hans to pd0x
Ok, its actually working pretty well on my devices!

#14 Updated by pd0x almost 4 years ago

When I try to send FDroid from a Nexus 7 running stock to a Nexus 4 running CM nightlies I see the transfer fail and the following logcat output on the N7 after selecting the N4 as the transfer endpoint:

othDiscoveryReceiver V Received: android.bluetooth.adapter.action.DISCOVERY_FINISHED
ocalBluetoothManager D setting foreground activity to null
FDroid D Category 'What's New' selected.
BtOppService D insertShare parsed URI: file:///data/app/org.fdroid.fdroid-2.apk
BluetoothOppUtility D getSendFileInfo: uri=file:///data/app/org.fdroid.fdroid-2.apk
BluetoothAdapter W getBluetoothService() called with no BluetoothManagerCallback
BTIF_SOCK D service_uuid: 00001105-0000-1000-8000-00805f9b34fb
BluetoothSocket D connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[97]}
bt-sdp W SDP - Rcvd conn cnf with error: 0x4 CID 0x42
bt-btif E DISCOVERY_COMP_EVT slot id:5, failed to find channle, status:1,scn:0
bt-btif W invalid rfc slot id: 5
BtOppTransfer E Rfcomm socket connect exception
BtOppTransfer E java.io.IOException: read failed, socket might closed or timeout, read ret: -1
BtOppTransfer E at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:505)
BtOppTransfer E at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:516)
BtOppTransfer E at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:320)
BtOppTransfer E at com.android.bluetooth.opp.BluetoothOppTransfer$SocketConnectThread.run(BluetoothOppTransfer.java:627)
BtOppTransfer D Mark all ShareInfo in the batch as failed
BluetoothOppUtility D getSendFileInfo: uri=file:///data/app/org.fdroid.fdroid-2.apk
BluetoothOppUtility D closeSendFileInfo: uri=file:///data/app/org.fdroid.fdroid-2.apk

I don't see anything in the N4's logcat. No notifications or messages about an incoming file transfer.

#15 Updated by pd0x almost 4 years ago

Scratch the above report & stack trace. I selected a hex address as the destination assuming it was the Nexus4 and I hadn't set a Bluetooth name. Turns out I have some neighbours broadcasting bluetooth nearby.

Bluetooth is enabled on the Nexus4 but I had to launch F-Droid, choose the "Bluetooth F-Droid apk" and then click "allow" on the "An app wants to make your device bluetooth visible for the next ..." popup before the N4 would show up in the N7's Bluetooth device scan.

Is there a setting to enable broadcast somewhere else? I'm not sure how I'd have done that on the N4 if I didn't already have the F-Droid app.

#16 Updated by pd0x almost 4 years ago

  • Status changed from Resolved to Closed

Ok, now that I understand the Bluetooth pairing flow for both devices I was able to verify that everything is working.

Also available in: Atom PDF