Don't allow importing contacts to accounts passed in by intent unless it is valid Test: Manual installing PoC app and running through repro steps Bug: 278556954 (cherry picked from commit 7d35065bec2df401369bae7988533f6f14799b43) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:c8c222bc6cfb29c12f540fe404c259760b454f1a) Merged-In: If36958e9ed2e9423b9c67ac635c9a7f65469e917 Change-Id: If36958e9ed2e9423b9c67ac635c9a7f65469e917
diff --git a/src/com/android/contacts/vcard/ImportVCardActivity.java b/src/com/android/contacts/vcard/ImportVCardActivity.java index 6ddb8fa..3eb7bdb 100644 --- a/src/com/android/contacts/vcard/ImportVCardActivity.java +++ b/src/com/android/contacts/vcard/ImportVCardActivity.java
@@ -586,31 +586,39 @@ String accountName = null; String accountType = null; String dataSet = null; + boolean isNullAccount = false; final Intent intent = getIntent(); - if (intent != null) { + if (intent != null + && intent.hasExtra(SelectAccountActivity.ACCOUNT_NAME) + && intent.hasExtra(SelectAccountActivity.ACCOUNT_TYPE) + && intent.hasExtra(SelectAccountActivity.DATA_SET)) { accountName = intent.getStringExtra(SelectAccountActivity.ACCOUNT_NAME); accountType = intent.getStringExtra(SelectAccountActivity.ACCOUNT_TYPE); dataSet = intent.getStringExtra(SelectAccountActivity.DATA_SET); + isNullAccount = TextUtils.isEmpty(accountName) && TextUtils.isEmpty(accountType) + && TextUtils.isEmpty(dataSet); } else { Log.e(LOG_TAG, "intent does not exist"); } - if (!TextUtils.isEmpty(accountName) && !TextUtils.isEmpty(accountType)) { - mAccount = new AccountWithDataSet(accountName, accountType, dataSet); - } else { - final AccountTypeManager accountTypes = AccountTypeManager.getInstance(this); - final List<AccountWithDataSet> accountList = accountTypes.blockForWritableAccounts(); - if (accountList.size() == 0) { - mAccount = null; - } else if (accountList.size() == 1) { - mAccount = accountList.get(0); - } else { - startActivityForResult(new Intent(this, SelectAccountActivity.class), - SELECT_ACCOUNT); - return; + final AccountTypeManager accountTypes = AccountTypeManager.getInstance(this); + final List<AccountWithDataSet> accountList = accountTypes.blockForWritableAccounts(); + if ((!TextUtils.isEmpty(accountName) && !TextUtils.isEmpty(accountType)) || isNullAccount) { + AccountWithDataSet selected = new AccountWithDataSet(accountName, accountType, + dataSet); + if (accountList.contains(selected)) { + mAccount = selected; } } + if (accountList.isEmpty()) { + mAccount = null; + } else if (mAccount == null) { + startActivityForResult(new Intent(this, SelectAccountActivity.class), + SELECT_ACCOUNT); + return; + } + if (isCallerSelf(this)) { startImport(sourceUri, sourceDisplayName); } else {