Compare commits
2 Commits
4d972bfab0
...
92a7853258
| Author | SHA1 | Date | |
|---|---|---|---|
| 92a7853258 | |||
| 14f22b4ebf |
@@ -45,6 +45,9 @@
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="application/octet-stream" />
|
||||
<data android:mimeType="application/x-keepass2" />
|
||||
<data android:mimeType="application/vnd.keepass" />
|
||||
<data android:scheme="content" android:pathPattern=".*\\.kdbx" />
|
||||
<data android:scheme="file" android:pathPattern=".*\\.kdbx" />
|
||||
</intent-filter>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.julianfamily.keepassgo;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
@@ -10,9 +11,11 @@ import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public final class SharedVaultImportActivity extends Activity {
|
||||
private static final String TAG = "KeePassGOImport";
|
||||
@@ -36,6 +39,7 @@ public final class SharedVaultImportActivity extends Activity {
|
||||
}
|
||||
|
||||
private void handleIntent(Intent intent) {
|
||||
logIntent(intent);
|
||||
Uri uri = resolveSharedUri(intent);
|
||||
if (uri == null) {
|
||||
Log.i(TAG, "no shared vault URI on intent");
|
||||
@@ -55,10 +59,29 @@ public final class SharedVaultImportActivity extends Activity {
|
||||
}
|
||||
String action = intent.getAction();
|
||||
if (Intent.ACTION_SEND.equals(action)) {
|
||||
return intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||
Uri extraStream = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||
if (extraStream != null) {
|
||||
return extraStream;
|
||||
}
|
||||
}
|
||||
if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
|
||||
ArrayList<Uri> streams = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||
if (streams != null && !streams.isEmpty()) {
|
||||
return streams.get(0);
|
||||
}
|
||||
}
|
||||
if (Intent.ACTION_VIEW.equals(action)) {
|
||||
return intent.getData();
|
||||
Uri data = intent.getData();
|
||||
if (data != null) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
ClipData clipData = intent.getClipData();
|
||||
if (clipData != null && clipData.getItemCount() > 0) {
|
||||
Uri clipUri = clipData.getItemAt(0).getUri();
|
||||
if (clipUri != null) {
|
||||
return clipUri;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -69,7 +92,7 @@ public final class SharedVaultImportActivity extends Activity {
|
||||
throw new IOException("failed to create " + dir.getAbsolutePath());
|
||||
}
|
||||
File pendingFile = new File(dir, "pending-shared-vault.kdbx");
|
||||
try (InputStream in = getContentResolver().openInputStream(uri)) {
|
||||
try (InputStream in = openSharedInputStream(uri)) {
|
||||
if (in == null) {
|
||||
throw new IOException("failed to open shared vault stream");
|
||||
}
|
||||
@@ -88,6 +111,17 @@ public final class SharedVaultImportActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
private InputStream openSharedInputStream(Uri uri) throws IOException {
|
||||
if ("file".equalsIgnoreCase(uri.getScheme())) {
|
||||
String path = uri.getPath();
|
||||
if (path == null || path.trim().isEmpty()) {
|
||||
throw new IOException("file URI is missing a path");
|
||||
}
|
||||
return new FileInputStream(new File(path));
|
||||
}
|
||||
return getContentResolver().openInputStream(uri);
|
||||
}
|
||||
|
||||
private String resolveDisplayName(Uri uri) {
|
||||
String displayName = queryDisplayName(uri);
|
||||
if (!displayName.isEmpty()) {
|
||||
@@ -123,6 +157,20 @@ public final class SharedVaultImportActivity extends Activity {
|
||||
return "";
|
||||
}
|
||||
|
||||
private void logIntent(Intent intent) {
|
||||
if (intent == null) {
|
||||
return;
|
||||
}
|
||||
Log.i(TAG, "intent action=" + intent.getAction()
|
||||
+ " type=" + intent.getType()
|
||||
+ " data=" + intent.getData()
|
||||
+ " flags=0x" + Integer.toHexString(intent.getFlags()));
|
||||
ClipData clipData = intent.getClipData();
|
||||
if (clipData != null) {
|
||||
Log.i(TAG, "intent clip items=" + clipData.getItemCount());
|
||||
}
|
||||
}
|
||||
|
||||
private void launchMainActivity() {
|
||||
Intent launch = new Intent();
|
||||
launch.setClassName(this, "org.gioui.GioActivity");
|
||||
|
||||
@@ -4,7 +4,7 @@ go 1.26
|
||||
|
||||
replace gioui.org => git.julianfamily.org/joejulian/gio-patched v0.9.1-0.20260416220049-9bfa6bc1c2dc
|
||||
|
||||
replace gioui.org/cmd => git.julianfamily.org/joejulian/gio-cmd-patched v0.9.1-0.20260416154203-192acd9d09b0
|
||||
replace gioui.org/cmd => git.julianfamily.org/joejulian/gio-cmd-patched v0.9.1-0.20260417040456-1762d36ddecc
|
||||
|
||||
require (
|
||||
gioui.org v0.9.0
|
||||
|
||||
@@ -42,8 +42,8 @@ gioui.org/shader v1.0.8 h1:6ks0o/A+b0ne7RzEqRZK5f4Gboz2CfG+mVliciy6+qA=
|
||||
gioui.org/shader v1.0.8/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM=
|
||||
gioui.org/x v0.8.0 h1:RhIlQNOFKKn8D8FeaKKaXCo7vB3x+fq4VcD10HW/YpA=
|
||||
gioui.org/x v0.8.0/go.mod h1:aXtQb+kyqoUOjDl5/uMqAopjzVzMkeHBbMQOGT5KnSE=
|
||||
git.julianfamily.org/joejulian/gio-cmd-patched v0.9.1-0.20260416154203-192acd9d09b0 h1:jZmX7CRuev3KrOW0yB2VQDtCrzRa4Q+qWcl3CGXq2sE=
|
||||
git.julianfamily.org/joejulian/gio-cmd-patched v0.9.1-0.20260416154203-192acd9d09b0/go.mod h1:RBQfFU8JCgMjQ2wKU9DG3zMC38TnY97E5MKoBGhGl3s=
|
||||
git.julianfamily.org/joejulian/gio-cmd-patched v0.9.1-0.20260417040456-1762d36ddecc h1:jyfCTx9wk/uLaEMkdKsg491C/kjfbG2EKAVTORhZxHo=
|
||||
git.julianfamily.org/joejulian/gio-cmd-patched v0.9.1-0.20260417040456-1762d36ddecc/go.mod h1:RBQfFU8JCgMjQ2wKU9DG3zMC38TnY97E5MKoBGhGl3s=
|
||||
git.julianfamily.org/joejulian/gio-patched v0.9.1-0.20260416220049-9bfa6bc1c2dc h1:p2AaZUAXa/ExPybNyeB05+GjTSZGA9lCfDpWz49IT5Y=
|
||||
git.julianfamily.org/joejulian/gio-patched v0.9.1-0.20260416220049-9bfa6bc1c2dc/go.mod h1:BdI7mF5DCa3kxlo3G93XHL7khtZnk1gu4335pExk8gs=
|
||||
git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0 h1:bGG/g4ypjrCJoSvFrP5hafr9PPB5aw8SjcOWWila7ZI=
|
||||
|
||||
Reference in New Issue
Block a user