@Test public void returnKeyIdsFromIntent__withNoData__askIfNoData() throws Exception { Intent intent = new Intent(); PendingIntent pendingIntent = mock(PendingIntent.class); setupSelectPubkeyPendingIntentFactoryResult(pendingIntent); KeyIdResult keyIdResult = openPgpServiceKeyIdExtractor.returnKeyIdsFromIntent(intent, true, BuildConfig.APPLICATION_ID); assertEquals(KeyIdResultStatus.NO_KEYS, keyIdResult.getStatus()); assertTrue(keyIdResult.hasKeySelectionPendingIntent()); assertSame(pendingIntent, keyIdResult.getKeySelectionPendingIntent()); }
KeyIdResult returnKeyIdsFromIntent(Intent data, boolean askIfNoUserIdsProvided, String callingPackageName) { boolean hasKeysFromSelectPubkeyActivity = data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS_SELECTED); KeyIdResult result; if (hasKeysFromSelectPubkeyActivity) { HashSet<Long> encryptKeyIds = new HashSet<>(); for (long keyId : data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS_SELECTED)) { encryptKeyIds.add(keyId); } result = createKeysOkResult(encryptKeyIds, false, AutocryptStatus.AUTOCRYPT_PEER_DISABLED); } else if (data.hasExtra(OpenPgpApi.EXTRA_USER_IDS) || askIfNoUserIdsProvided) { String[] userIds = data.getStringArrayExtra(OpenPgpApi.EXTRA_USER_IDS); result = returnKeyIdsFromEmails(data, userIds, callingPackageName); } else { result = createNoKeysResult(); } if (data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS)) { HashSet<Long> explicitKeyIds = new HashSet<>(); for (long keyId : data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS)) { explicitKeyIds.add(keyId); } result = result.withExplicitKeyIds(explicitKeyIds); } return result; }
OpenPgpServiceKeyIdExtractor { KeyIdResult returnKeyIdsFromIntent(Intent data, boolean askIfNoUserIdsProvided, String callingPackageName) { boolean hasKeysFromSelectPubkeyActivity = data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS_SELECTED); KeyIdResult result; if (hasKeysFromSelectPubkeyActivity) { HashSet<Long> encryptKeyIds = new HashSet<>(); for (long keyId : data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS_SELECTED)) { encryptKeyIds.add(keyId); } result = createKeysOkResult(encryptKeyIds, false, AutocryptStatus.AUTOCRYPT_PEER_DISABLED); } else if (data.hasExtra(OpenPgpApi.EXTRA_USER_IDS) || askIfNoUserIdsProvided) { String[] userIds = data.getStringArrayExtra(OpenPgpApi.EXTRA_USER_IDS); result = returnKeyIdsFromEmails(data, userIds, callingPackageName); } else { result = createNoKeysResult(); } if (data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS)) { HashSet<Long> explicitKeyIds = new HashSet<>(); for (long keyId : data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS)) { explicitKeyIds.add(keyId); } result = result.withExplicitKeyIds(explicitKeyIds); } return result; } }
OpenPgpServiceKeyIdExtractor { KeyIdResult returnKeyIdsFromIntent(Intent data, boolean askIfNoUserIdsProvided, String callingPackageName) { boolean hasKeysFromSelectPubkeyActivity = data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS_SELECTED); KeyIdResult result; if (hasKeysFromSelectPubkeyActivity) { HashSet<Long> encryptKeyIds = new HashSet<>(); for (long keyId : data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS_SELECTED)) { encryptKeyIds.add(keyId); } result = createKeysOkResult(encryptKeyIds, false, AutocryptStatus.AUTOCRYPT_PEER_DISABLED); } else if (data.hasExtra(OpenPgpApi.EXTRA_USER_IDS) || askIfNoUserIdsProvided) { String[] userIds = data.getStringArrayExtra(OpenPgpApi.EXTRA_USER_IDS); result = returnKeyIdsFromEmails(data, userIds, callingPackageName); } else { result = createNoKeysResult(); } if (data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS)) { HashSet<Long> explicitKeyIds = new HashSet<>(); for (long keyId : data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS)) { explicitKeyIds.add(keyId); } result = result.withExplicitKeyIds(explicitKeyIds); } return result; } private  OpenPgpServiceKeyIdExtractor(ContentResolver contentResolver,
            ApiPendingIntentFactory apiPendingIntentFactory); }
OpenPgpServiceKeyIdExtractor { KeyIdResult returnKeyIdsFromIntent(Intent data, boolean askIfNoUserIdsProvided, String callingPackageName) { boolean hasKeysFromSelectPubkeyActivity = data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS_SELECTED); KeyIdResult result; if (hasKeysFromSelectPubkeyActivity) { HashSet<Long> encryptKeyIds = new HashSet<>(); for (long keyId : data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS_SELECTED)) { encryptKeyIds.add(keyId); } result = createKeysOkResult(encryptKeyIds, false, AutocryptStatus.AUTOCRYPT_PEER_DISABLED); } else if (data.hasExtra(OpenPgpApi.EXTRA_USER_IDS) || askIfNoUserIdsProvided) { String[] userIds = data.getStringArrayExtra(OpenPgpApi.EXTRA_USER_IDS); result = returnKeyIdsFromEmails(data, userIds, callingPackageName); } else { result = createNoKeysResult(); } if (data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS)) { HashSet<Long> explicitKeyIds = new HashSet<>(); for (long keyId : data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS)) { explicitKeyIds.add(keyId); } result = result.withExplicitKeyIds(explicitKeyIds); } return result; } private  OpenPgpServiceKeyIdExtractor(ContentResolver contentResolver,
            ApiPendingIntentFactory apiPendingIntentFactory);  }
OpenPgpServiceKeyIdExtractor { KeyIdResult returnKeyIdsFromIntent(Intent data, boolean askIfNoUserIdsProvided, String callingPackageName) { boolean hasKeysFromSelectPubkeyActivity = data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS_SELECTED); KeyIdResult result; if (hasKeysFromSelectPubkeyActivity) { HashSet<Long> encryptKeyIds = new HashSet<>(); for (long keyId : data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS_SELECTED)) { encryptKeyIds.add(keyId); } result = createKeysOkResult(encryptKeyIds, false, AutocryptStatus.AUTOCRYPT_PEER_DISABLED); } else if (data.hasExtra(OpenPgpApi.EXTRA_USER_IDS) || askIfNoUserIdsProvided) { String[] userIds = data.getStringArrayExtra(OpenPgpApi.EXTRA_USER_IDS); result = returnKeyIdsFromEmails(data, userIds, callingPackageName); } else { result = createNoKeysResult(); } if (data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS)) { HashSet<Long> explicitKeyIds = new HashSet<>(); for (long keyId : data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS)) { explicitKeyIds.add(keyId); } result = result.withExplicitKeyIds(explicitKeyIds); } return result; } private  OpenPgpServiceKeyIdExtractor(ContentResolver contentResolver,
            ApiPendingIntentFactory apiPendingIntentFactory);   }