Allow sharing multiple QR code images to Aegis through a single intent

This also refactors the logic for handling incoming intents a bit
This commit is contained in:
Alexander Bakker 2022-08-10 17:47:17 +02:00
parent e46857a26e
commit 6fd8a3b6b4
2 changed files with 39 additions and 34 deletions

View file

@ -52,9 +52,8 @@
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.SEND" /> <action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" /> <data android:mimeType="image/*" />
</intent-filter> </intent-filter>
</activity> </activity>

View file

@ -457,46 +457,53 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
intent.removeExtra("action"); intent.removeExtra("action");
} }
private void handleDeeplink() { private void handleIncomingIntent() {
if (!_vaultManager.isVaultLoaded()) { if (!_vaultManager.isVaultLoaded()) {
return; return;
} }
Intent intent = getIntent(); Intent intent = getIntent();
Uri uri = intent.getData(); if (intent.getAction() == null) {
if (Intent.ACTION_VIEW.equals(intent.getAction()) && uri != null) {
intent.setData(null);
intent.setAction(null);
GoogleAuthInfo info = null;
try {
info = GoogleAuthInfo.parseUri(uri);
} catch (GoogleAuthInfoException e) {
e.printStackTrace();
Dialogs.showErrorDialog(this, R.string.unable_to_process_deeplink, e);
}
if (info != null) {
VaultEntry entry = new VaultEntry(info);
startEditEntryActivityForNew(CODE_ADD_ENTRY, entry);
}
}
}
private void handleSharedImage() {
if (!_vaultManager.isVaultLoaded()) {
return; return;
} }
Intent intent = getIntent(); Uri uri;
String action = intent.getAction(); switch (intent.getAction()) {
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); case Intent.ACTION_VIEW:
uri = intent.getData();
if (uri != null) {
intent.setData(null);
intent.setAction(null);
if (Intent.ACTION_SEND.equals(action) && uri != null) { GoogleAuthInfo info;
intent.setAction(null); try {
intent.removeExtra(Intent.EXTRA_STREAM); info = GoogleAuthInfo.parseUri(uri);
} catch (GoogleAuthInfoException e) {
e.printStackTrace();
Dialogs.showErrorDialog(this, R.string.unable_to_process_deeplink, e);
break;
}
startDecodeQrCodeImages(Collections.singletonList(uri)); VaultEntry entry = new VaultEntry(info);
startEditEntryActivityForNew(CODE_ADD_ENTRY, entry);
}
break;
case Intent.ACTION_SEND:
uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) {
intent.setAction(null);
intent.removeExtra(Intent.EXTRA_STREAM);
startDecodeQrCodeImages(Collections.singletonList(uri));
}
break;
case Intent.ACTION_SEND_MULTIPLE:
List<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (uris != null) {
intent.setAction(null);
intent.removeExtra(Intent.EXTRA_STREAM);
startDecodeQrCodeImages(uris);
}
break;
} }
} }
@ -534,8 +541,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
checkTimeSyncSetting(); checkTimeSyncSetting();
} }
handleDeeplink(); handleIncomingIntent();
handleSharedImage();
updateLockIcon(); updateLockIcon();
doShortcutActions(); doShortcutActions();
updateErrorBar(); updateErrorBar();