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>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>

View file

@ -457,46 +457,53 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
intent.removeExtra("action");
}
private void handleDeeplink() {
private void handleIncomingIntent() {
if (!_vaultManager.isVaultLoaded()) {
return;
}
Intent intent = getIntent();
Uri uri = intent.getData();
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()) {
if (intent.getAction() == null) {
return;
}
Intent intent = getIntent();
String action = intent.getAction();
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
Uri uri;
switch (intent.getAction()) {
case Intent.ACTION_VIEW:
uri = intent.getData();
if (uri != null) {
intent.setData(null);
intent.setAction(null);
if (Intent.ACTION_SEND.equals(action) && uri != null) {
intent.setAction(null);
intent.removeExtra(Intent.EXTRA_STREAM);
GoogleAuthInfo info;
try {
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();
}
handleDeeplink();
handleSharedImage();
handleIncomingIntent();
updateLockIcon();
doShortcutActions();
updateErrorBar();