Skip to content

Add file send/receive on Android #1809

Closed

Description

@bradfitz

Tracking bug for sending/receiving files on Android.

Sending:

  • add intent filter, e.g.
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="application/*" />
            <data android:mimeType="audio/*" />
            <data android:mimeType="image/*" />
            <data android:mimeType="message/*" />
            <data android:mimeType="multipart/*" />
            <data android:mimeType="text/*" />
            <data android:mimeType="video/*" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND_MULTIPLE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="application/*" />
            <data android:mimeType="audio/*" />
            <data android:mimeType="image/*" />
            <data android:mimeType="message/*" />
            <data android:mimeType="multipart/*" />
            <data android:mimeType="text/*" />
            <data android:mimeType="video/*" />
            <data android:mimeType="text/plain" />
        </intent-filter>
  • upon starting that intent activity, choose a target device to share with (see tailscale push --targets implementation in func runPushTargets and how it calls tailscale.FileTargets):
    func runPushTargets(ctx context.Context, args []string) error {

Then either do the HTTP PUT to the peer's peerapi URL directly (e.g.

dstURL := peerAPIBase + "/v0/put/" + url.PathEscape(name)
) or if it's easier, using the localhost tailscale API ("localapi") handler to do it for you
func (h *Handler) serveFilePut(w http.ResponseWriter, r *http.Request) {
(the latter was added for iOS/macOS which live in a network sandbox and it was tedious for Swift code to do the sockopts to get out of the sandbox)

Activity

  1. added
    OS-android
    on Apr 27, 2021
  2. bradfitz commented on Apr 27, 2021

    @bradfitz
    MemberAuthor

    For recieving:

    • listen for ipn.Notify messages with the new FilesWaiting bit (to say new files have fully arrived) and optionally IncomingFiles (for progress bars of incoming files):
      // FilesWaiting if non-nil means that files are buffered in

    Once a file is fully arrived; fetch it from the "inbox" (app-owned scratch dir) and copy it to the sdcard files/photos area with

    if debugArgs.file != "" {
    (tailscale.WaitingFiles, tailscale.GetWaitingFile, tailscale.DeleteWaitingFile)

  3. bradfitz commented on Apr 27, 2021

    @bradfitz
    MemberAuthor

    If you have any questions on UI, @rosszurowski can answer questions or share resources from other platforms.

  4. eliasnaur commented on Apr 27, 2021

    @eliasnaur
    Contributor

    Thanks. @rosszurowski if you have iOS designs I'd like to see them so that our implementations won't needlessly differ.

  5. rosszurowski commented on Apr 27, 2021

    @rosszurowski
    Contributor

    Yep! Best to get in sync up-front :)

    Our general approach for this feature is using as much native UI as possible.

    For sending files, we'll want to hook into Android's native share menu. It looks like apps get to open up a custom view with the selected media/files as an input. We'll leverage that system and introduce a custom view that looks something like the iOS view:

    taildrop-ios

    Notes on this design:

    • We list all personal devices, online and offline that we know about. The thinking here is that we want to avoid shuffling this list around on users. If a device disappears or appears, the list shouldn't shuffle order and potentially change what you're tapping on. If a device transitions from online to offline, it should go offline, but its position shouldn't change. On iOS, I believe we implemented this view with a 5-second poll approach to updating online/offline status, but @soniaappasamy can give more context.
    • The list of device is composed of the device name, device OS, connected status, and an icon representing the device. I have variations for phone, tablet, and desktop devices, but the specific heuristic we use here is up to you.
    • Tapping a device will trigger a transfer. Tapping a row with an in-progress transfer will cancel that transfer. For most transfers of small files, it'll end before you can tap again, but that's okay, because cancelling is more relevant for large file transfers.
    • I believe progress is calculated as the "bytes transferred / total bytes for all files being sent", but if you'd like to confirm what we do on iOS, @soniaappasamy can help.
    • Upon completion of a file send, we change the progress circle into a checkmark, which persists for the duration of the share modal staying open. We foresee transferring to a single device being the most common case, but this design allows for the possibility to send to multiple devices. In the future, we may introduce a "sending" state that gives more details about each file being sent, but that's not in scope for the first version.
    • Right now, we don't auto-close the share dialog on a successful transfer. This might change in the future, but the primary way to close the dialog is via the "Done" action in the top-right. On Android, it seems the more common pattern is an "X" in the top-left of the view, so let's go with that instead.
    • For errors, we display a warning icon in place of the progress indicator, but we share specific language around the failure via a notification. Again, @soniaappasamy can give details the notification implementation (eg. how long it should persist for, what cases we need to include), but the general approach should minimize the amount of UI we have to build.
    • I have some in-progress designs for empty states and error states which I'll share here in the next day. Broadly, there are five states we need to account for: (1) error connecting to the localapi, (2) error getting file information, (3) not connected to tailscale, (4) no devices available to be transferred to, (5) the network doesn't allow file sharing (ie. CapabilityFileSharing isn't present on the MapResponse)

    For receiving files, the ideal UI is… practically no UI. Since file transfers are restricted to your own devices for now (no inter-user file transfers), it's fine to automatically accept files and put them in the relevant places.

    Here are our iOS designs:

    ios-receive

    Notes:

    • We show a notification on file receipt. We'll want that on Android too. It'd be nice to leverage Android's ability to show progress in a notification to show that a transfer is in-progress and then notify when it's done. However, if that's difficult, we can do what iOS does and only notify on completion. Tapping the notification should open the file in it's end destination.
    • An open question for Android: where should we send files? We'd like to integrate with the system as best possible. I'm happy to defer to you on what the best "native" location for different file types might be. If you'd rather not decide this, let me know and I can do some research. On iOS we have three categories: (1) photos/videos go to the camera roll, (2) URLs open directly in the browser, (3) and all other files go to the Files app. On macOS they land in ~/Downloads, and on iOS they land in On My iPhone/Tailscale/.
    • Ideally, we'd show files directly in their destination as we're downloading them. On macOS, we initially had it appear in the downloads folder with a progress indicator. However, in the end we needed to fall back to a buffered approach where we download to a tmp folder and move to the destination once completed. If we need to buffer on Android too, that's perfectly okay :)
    • The designs above show a white page with a spinner. That's because on iOS, the app needs to be in the foreground to take certain actions. Because Android doesn't have that limitation, we shouldn't need a page like that. However, if there are unforeseen complexities to building this on Android, please let me know — I'm happy to whip up some designs or jump on a call to work through some options.

    Phew. Let me know if you have questions or need more context. If there's any piece of this that introduces a lot of complexity, we can figure out a way to scope it down.

    I'll let @bradfitz speak to timing, but we're not planning on including this in the v1.8 launch happening soon. This will likely be part of a follow-up patch release or v1.10, so there should be some time to work through the details.

  6. bradfitz commented on Apr 27, 2021

    @bradfitz
    MemberAuthor

    Note that online/offline is via the new tailcfg.Node.Online *bool field. It's nil for devices whose online/offline you're not allowed to know. But it should generally be non-nil for your own devices (the only ones that are valid file sharing targets for now).

  7. soniaappasamy commented on May 4, 2021

    @soniaappasamy
    Member

    On iOS, I believe we implemented this view with a 5-second poll approach to updating online/offline status, but @soniaappasamy can give more context.

    We actually have not brought this in on iOS yet, but will probably do so in a future release (unless it makes it in time for 1.8.0). The plan is to do a 5-second poll approach, like Ross said.

    • I believe progress is calculated as the "bytes transferred / total bytes for all files being sent", but if you'd like to confirm what we do on iOS, @soniaappasamy can help.

    Yep, we show the "combined" progress of all of the selected files - so total bytes transferred / total bytes to send.

    Again, @soniaappasamy can give details the notification implementation (eg. how long it should persist for, what cases we need to include), but the general approach should minimize the amount of UI we have to build.

    Yeah, on the iOS side, we show a notification in two cases currently: 1. when a send fails (we notify you that your files could not send) or 2. when receiving files. Both are just using the default iOS persistence length (they dismiss themselves, but are still accessible from the notification center).

    Let me know if you need any more context here!

  8. DentonGentry commented on May 18, 2021

    @DentonGentry
    Contributor

    Is there anything more needed to support this for Android?

  9. eliasnaur commented on May 19, 2021

    @eliasnaur
    Contributor

    Nope, the ball is in my court @DentonGentry.

    However, now that I'm working on the feature, I'd like to get the device icons for the share dialog and the status icons (error, checkmark). Can you help me here, @rosszurowski? Thanks.

  10. added a commit that references this issue on May 31, 2021
  11. eliasnaur commented on May 31, 2021

    @eliasnaur
    Contributor

    I'm stuck. Connection attempts to the peerapi HTTP service seems to be dropped on Android if I connect from Tailscale peers. Local connections to the service does work. Help or pointers are greatly appreciated.

    Details:

    I'm working on the https://github.com/tailscale/tailscale-android/tree/file-sharing branch, which has a replace to a debugging branch of tailscale.

    Netcat works locally:

    $ adb shell
    $  nc 100.86.189.59 45761
    asd
    HTTP/1.1 400 Bad Request
    Content-Type: text/plain; charset=utf-8
    Connection: close
    
    400 Bad Request
    

    but not from my tailscaled Linux:

    $ nc 100.86.189.59 45761
    <hang>
    

    Packages do arrive for remote connections:

    05-31 18:43:25.645  8895  8916 I com.tailscale.ipn: 6.2M/148.6M magicsock: want call-me-maybe but endpoints stale; restunning
    05-31 18:43:25.655  8895  8920 I com.tailscale.ipn: decode4: TCP{100.81.132.94:46808 > 100.86.189.59:45761} [69 0 0 60 48 99 64 0 64 6 0 24 100 81 132 94 100 86 189 59 182 216 178 193 68 33 142 209 0 0 0 0 160 2 251 224 232 142 0 0 2 4 4 216 4 2 8 10 251 176 33 237 0 0 0 0 1 3 3 7]
    05-31 18:43:25.656  8895  8920 I com.tailscale.ipn: 6.4M/148.6M Accept: TCP{100.81.132.94:46808 > 100.86.189.59:45761} 60 tcp ok
    05-31 18:43:25.656  8895  8920 I com.tailscale.ipn: multiTUN.runDevice: [4 0 0 0 174 166 9 79 0 0 0 0 0 0 0 0 69 0 0 60 48 99 64 0 64 6 0 24 100 81 132 94 100 86 189 59 182 216 178 193 68 33 142 209 0 0 0 0 160 2 251 224 232 142 0 0 2 4 4 216 4 2 8 10 251 176 33 237 0 0 0 0 1 3 3 7] err: <nil> written: 60
    05-31 18:43:25.656  8895  8920 I com.tailscale.ipn: multiTun.Write: [4 0 0 0 174 166 9 79 0 0 0 0 0 0 0 0 69 0 0 60 48 99 64 0 64 6 0 24 100 81 132 94 100 86 189 59 182 216 178 193 68 33 142 209 0 0 0 0 160 2 251 224 232 142 0 0 2 4 4 216 4 2 8 10 251 176 33 237 0 0 0 0 1 3 3 7] err: <nil>
    05-31 18:43:25.938  8895  8916 I com.tailscale.ipn: 6.6M/148.6M magicsock: STUN done; sending call-me-maybe to d:34f1c627d101af68 [/Vk0h]
    05-31 18:43:26.684  8895  8919 I com.tailscale.ipn: decode4: TCP{100.81.132.94:46808 > 100.86.189.59:45761} [69 0 0 60 48 100 64 0 64 6 0 23 100 81 132 94 100 86 189 59 182 216 178 193 68 33 142 209 0 0 0 0 160 2 251 224 228 124 0 0 2 4 4 216 4 2 8 10 251 176 37 255 0 0 0 0 1 3 3 7]
    05-31 18:43:26.684  8895  8919 I com.tailscale.ipn: 6.6M/148.6M Accept: TCP{100.81.132.94:46808 > 100.86.189.59:45761} 60 tcp ok
    05-31 18:43:26.685  8895  8919 I com.tailscale.ipn: multiTUN.runDevice: [4 0 0 0 174 166 9 79 1 0 0 0 0 0 0 0 69 0 0 60 48 100 64 0 64 6 0 23 100 81 132 94 100 86 189 59 182 216 178 193 68 33 142 209 0 0 0 0 160 2 251 224 228 124 0 0 2 4 4 216 4 2 8 10 251 176 37 255 0 0 0 0 1 3 3 7] err: <nil> written: 60
    05-31 18:43:26.685  8895  8919 I com.tailscale.ipn: multiTun.Write: [4 0 0 0 174 166 9 79 1 0 0 0 0 0 0 0 69 0 0 60 48 100 64 0 64 6 0 23 100 81 132 94 100 86 189 59 182 216 178 193 68 33 142 209 0 0 0 0 160 2 251 224 228 124 0 0 2 4 4 216 4 2 8 10 251 176 37 255 0 0 0 0 1 3 3 7] err: <nil>
    

    but apparently they never reach the listener.

  12. 31 remaining items

  13. added 8 commits that reference this issue on Jun 26, 2021
    88794c4
    fc99302
    3c4ed10
    fa63f58
    805779d
    022ec63
    3d7b9de
    10ded1b
  14. Maltahl commented on Jun 30, 2021

    @Maltahl

    The update broke tailscale on my phone. GUI wont load like on #1965
    OnePlus 8T running Android 11

  15. danackerson commented on Jun 30, 2021

    @danackerson

    The update broke tailscale on my phone. GUI wont load like on #1965
    OnePlus 8T running Android 11

    Ditto on Pixel 4 XL running Android 11.

  16. DentonGentry commented on Jun 30, 2021

    @DentonGentry
    Contributor

    We'll look at the issue with the 1.10.1 release in #2290.

    I had built an APK locally containing the file sharing code tailscale/tailscale-android#14 and didn't run into the issue, presumably the problem is something not directly related to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

L2 FewOS-androidOS-chromeosP2 AggravatingT0 New feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions