diff --git a/android/src/main/java/com/tailscale/ipn/ShareActivity.kt b/android/src/main/java/com/tailscale/ipn/ShareActivity.kt index 64e6302..899b9d3 100644 --- a/android/src/main/java/com/tailscale/ipn/ShareActivity.kt +++ b/android/src/main/java/com/tailscale/ipn/ShareActivity.kt @@ -9,6 +9,7 @@ import android.os.Build import android.os.Bundle import android.provider.OpenableColumns import android.util.Log +import android.webkit.MimeTypeMap import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.material3.MaterialTheme @@ -21,6 +22,7 @@ import com.tailscale.ipn.ui.util.universalFit import com.tailscale.ipn.ui.view.TaildropView import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow +import kotlin.random.Random // ShareActivity is the entry point for Taildrop share intents class ShareActivity : ComponentActivity() { @@ -92,7 +94,20 @@ class ShareActivity : ComponentActivity() { val nameCol = c.getColumnIndex(OpenableColumns.DISPLAY_NAME) val sizeCol = c.getColumnIndex(OpenableColumns.SIZE) c.moveToFirst() - val name = c.getString(nameCol) + val name: String = + c.getString(nameCol) + ?: run { + // For some reason, some content resolvers don't return a name. + // Try to build a name from a random integer plus file extension + // (if type can be determined), else just a random integer. + val rand = Random.nextLong() + contentResolver.getType(it)?.let { mimeType -> + MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType)?.let { + extension -> + "$rand.$extension" + } ?: "$rand" + } ?: "$rand" + } val size = c.getLong(sizeCol) c.close() val file = Ipn.OutgoingFile(Name = name, DeclaredSize = size) diff --git a/go.mod b/go.mod index 69febf6..38b54bd 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( golang.org/x/mobile v0.0.0-20240319015410-c58ccf4b0c87 golang.org/x/sys v0.22.0 inet.af/netaddr v0.0.0-20220617031823-097006376321 - tailscale.com v1.71.0-pre.0.20240807163715-1ed958fe231c + tailscale.com v1.71.0-pre.0.20240814172840-74b9fa134866 ) require ( diff --git a/go.sum b/go.sum index 299dfa1..347b086 100644 --- a/go.sum +++ b/go.sum @@ -258,5 +258,5 @@ nhooyr.io/websocket v1.8.10 h1:mv4p+MnGrLDcPlBoWsvPP7XCzTYMXP9F9eIGoKbgx7Q= nhooyr.io/websocket v1.8.10/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c= software.sslmate.com/src/go-pkcs12 v0.4.0 h1:H2g08FrTvSFKUj+D309j1DPfk5APnIdAQAB8aEykJ5k= software.sslmate.com/src/go-pkcs12 v0.4.0/go.mod h1:Qiz0EyvDRJjjxGyUQa2cCNZn/wMyzrRJ/qcDXOQazLI= -tailscale.com v1.71.0-pre.0.20240807163715-1ed958fe231c h1:V7LIZUfBT9xtynZlh8lqkkGrrzyiiQV8BZ07VRGnukk= -tailscale.com v1.71.0-pre.0.20240807163715-1ed958fe231c/go.mod h1:rRq+xvgprFys8sZbJgcAMMqpiP6r+Y75CJRhCRmXrd0= +tailscale.com v1.71.0-pre.0.20240814172840-74b9fa134866 h1:UIWKu+0sjhWFrtISxxC5XWPjpUu4OBddOHi6mKFd0ak= +tailscale.com v1.71.0-pre.0.20240814172840-74b9fa134866/go.mod h1:BDv4yIh/aregu3Noq8iazPuxbKoa6ooy+QA2QWC8W64=