diff --git a/app/core/src/main/java/com/fsck/k9/message/AutocryptStatusInteractor.java b/app/core/src/main/java/com/fsck/k9/message/AutocryptStatusInteractor.java index d5692b2bf..24b3418b5 100644 --- a/app/core/src/main/java/com/fsck/k9/message/AutocryptStatusInteractor.java +++ b/app/core/src/main/java/com/fsck/k9/message/AutocryptStatusInteractor.java @@ -5,11 +5,11 @@ import java.io.InputStream; import android.app.PendingIntent; import android.content.Intent; + import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import androidx.annotation.WorkerThread; - +import androidx.core.content.IntentCompat; import org.openintents.openpgp.OpenPgpError; import org.openintents.openpgp.util.OpenPgpApi; import timber.log.Timber; @@ -34,11 +34,19 @@ public class AutocryptStatusInteractor { switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) { case OpenPgpApi.RESULT_CODE_SUCCESS: RecipientAutocryptStatusType type = getRecipientAutocryptStatusFromIntent(result); - PendingIntent pendingIntent = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT); + PendingIntent pendingIntent = IntentCompat.getParcelableExtra( + result, + OpenPgpApi.RESULT_INTENT, + PendingIntent.class + ); return new RecipientAutocryptStatus(type, pendingIntent); case OpenPgpApi.RESULT_CODE_ERROR: - OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR); + OpenPgpError error = IntentCompat.getParcelableExtra( + result, + OpenPgpApi.RESULT_ERROR, + OpenPgpError.class + ); if (error != null) { Timber.w("OpenPGP API Error #%s: %s", error.getErrorId(), error.getMessage()); } else { diff --git a/app/core/src/main/java/com/fsck/k9/message/PgpMessageBuilder.java b/app/core/src/main/java/com/fsck/k9/message/PgpMessageBuilder.java index 61c963836..7fd5349b3 100644 --- a/app/core/src/main/java/com/fsck/k9/message/PgpMessageBuilder.java +++ b/app/core/src/main/java/com/fsck/k9/message/PgpMessageBuilder.java @@ -9,10 +9,11 @@ import java.util.Arrays; import android.app.PendingIntent; import android.content.Intent; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; - +import androidx.core.content.IntentCompat; import com.fsck.k9.CoreResourceProvider; import com.fsck.k9.DI; import com.fsck.k9.K9; @@ -27,7 +28,6 @@ import com.fsck.k9.mail.Message.RecipientType; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.filter.EOLConvertingOutputStream; import com.fsck.k9.mail.internet.BinaryTempFileBody; -import com.fsck.k9.mail.internet.Headers; import com.fsck.k9.mail.internet.MessageIdGenerator; import com.fsck.k9.mail.internet.MimeBodyPart; import com.fsck.k9.mail.internet.MimeHeader; @@ -310,14 +310,22 @@ public class PgpMessageBuilder extends MessageBuilder { return null; case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: - PendingIntent returnedPendingIntent = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT); + PendingIntent returnedPendingIntent = IntentCompat.getParcelableExtra( + result, + OpenPgpApi.RESULT_INTENT, + PendingIntent.class + ); if (returnedPendingIntent == null) { throw new MessagingException("openpgp api needs user interaction, but returned no pendingintent!"); } return returnedPendingIntent; case OpenPgpApi.RESULT_CODE_ERROR: - OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR); + OpenPgpError error = IntentCompat.getParcelableExtra( + result, + OpenPgpApi.RESULT_ERROR, + OpenPgpError.class + ); if (error == null) { throw new MessagingException("internal openpgp api error"); } diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/EditIdentity.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/EditIdentity.kt index e8917cc34..3e42973c5 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/EditIdentity.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/EditIdentity.kt @@ -6,6 +6,8 @@ import android.view.MenuItem import android.view.View import android.widget.CheckBox import android.widget.TextView +import androidx.core.content.IntentCompat +import androidx.core.os.BundleCompat import androidx.core.view.isVisible import androidx.core.widget.doAfterTextChanged import com.fsck.k9.Account @@ -44,8 +46,16 @@ class EditIdentity : K9Activity() { account = Preferences.getPreferences().getAccount(accountUuid) ?: error("Couldn't find account") identity = when { - savedInstanceState != null -> savedInstanceState.getParcelable(EXTRA_IDENTITY) ?: error("Missing state") - identityIndex != -1 -> intent.getParcelableExtra(EXTRA_IDENTITY) ?: error("Missing argument") + savedInstanceState != null -> { + BundleCompat.getParcelable(savedInstanceState, EXTRA_IDENTITY, Identity::class.java) + ?: error("Missing state") + } + + identityIndex != -1 -> { + IntentCompat.getParcelableExtra(intent, EXTRA_IDENTITY, Identity::class.java) + ?: error("Missing argument") + } + else -> Identity() } diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageCompose.java b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageCompose.java index 6bbe90637..97859256f 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageCompose.java +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageCompose.java @@ -45,6 +45,8 @@ import android.widget.Toast; import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.appcompat.app.ActionBar; +import androidx.core.content.IntentCompat; +import androidx.core.os.BundleCompat; import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.fsck.k9.Account; @@ -428,7 +430,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, if (action == Action.FORWARD_AS_ATTACHMENT) { messageLoaderHelper.asyncStartOrResumeLoadingMessageMetadata(relatedMessageReference); } else { - Parcelable cachedDecryptionResult = intent.getParcelableExtra(EXTRA_MESSAGE_DECRYPTION_RESULT); + Parcelable cachedDecryptionResult = IntentCompat.getParcelableExtra( + intent, + EXTRA_MESSAGE_DECRYPTION_RESULT, + Parcelable.class + ); messageLoaderHelper.asyncStartOrResumeLoadingMessage( relatedMessageReference, cachedDecryptionResult); } @@ -536,12 +542,16 @@ public class MessageCompose extends K9Activity implements OnClickListener, String type = intent.getType(); if (Intent.ACTION_SEND.equals(action)) { - Uri stream = intent.getParcelableExtra(Intent.EXTRA_STREAM); + Uri stream = IntentCompat.getParcelableExtra(intent,Intent.EXTRA_STREAM, Uri.class); if (stream != null) { attachmentPresenter.addExternalAttachment(stream, type); } } else { - List list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); + List list = IntentCompat.getParcelableArrayListExtra( + intent, + Intent.EXTRA_STREAM, + Parcelable.class + ); if (list != null) { for (Parcelable parcelable : list) { Uri stream = (Uri) parcelable; @@ -650,7 +660,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, } else { draftMessageId = null; } - identity = savedInstanceState.getParcelable(STATE_IDENTITY); + identity = BundleCompat.getParcelable(savedInstanceState, STATE_IDENTITY, Identity.class); identityChanged = savedInstanceState.getBoolean(STATE_IDENTITY_CHANGED); repliedToMessageId = savedInstanceState.getString(STATE_IN_REPLY_TO); referencedMessageIds = savedInstanceState.getString(STATE_REFERENCES); diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/UpgradeDatabases.java b/app/ui/legacy/src/main/java/com/fsck/k9/activity/UpgradeDatabases.java index 92f9c30af..a3b1e083e 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/UpgradeDatabases.java +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/UpgradeDatabases.java @@ -8,16 +8,17 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.os.Bundle; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; import android.widget.TextView; +import androidx.core.content.IntentCompat; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; import com.fsck.k9.Account; import com.fsck.k9.K9; import com.fsck.k9.Preferences; -import com.fsck.k9.ui.R; import com.fsck.k9.controller.MessagingController; import com.fsck.k9.mailstore.LocalStore; import com.fsck.k9.service.DatabaseUpgradeService; +import com.fsck.k9.ui.R; import com.fsck.k9.ui.base.K9Activity; @@ -137,7 +138,7 @@ public class UpgradeDatabases extends K9Activity { */ private void decodeExtras() { Intent intent = getIntent(); - mStartIntent = intent.getParcelableExtra(EXTRA_START_INTENT); + mStartIntent = IntentCompat.getParcelableExtra(intent, EXTRA_START_INTENT, Intent.class); } /** diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/AttachmentPresenter.java b/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/AttachmentPresenter.java index 02d4720b8..fa06f1bc8 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/AttachmentPresenter.java +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/compose/AttachmentPresenter.java @@ -13,9 +13,10 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.Handler; + +import androidx.core.os.BundleCompat; import androidx.loader.app.LoaderManager; import androidx.loader.content.Loader; - import com.fsck.k9.activity.compose.ComposeCryptoStatus.AttachErrorState; import com.fsck.k9.activity.loader.AttachmentContentLoader; import com.fsck.k9.activity.loader.AttachmentInfoLoader; @@ -286,7 +287,7 @@ public class AttachmentPresenter { new LoaderManager.LoaderCallbacks() { @Override public Loader onCreateLoader(int id, Bundle args) { - Uri uri = args.getParcelable(LOADER_ARG_ATTACHMENT); + Uri uri = BundleCompat.getParcelable(args, LOADER_ARG_ATTACHMENT, Uri.class); return new AttachmentInfoLoader(context, attachments.get(uri)); } @@ -319,7 +320,7 @@ public class AttachmentPresenter { new LoaderManager.LoaderCallbacks() { @Override public Loader onCreateLoader(int id, Bundle args) { - Uri uri = args.getParcelable(LOADER_ARG_ATTACHMENT); + Uri uri = BundleCompat.getParcelable(args, LOADER_ARG_ATTACHMENT, Uri.class); return new AttachmentContentLoader(context, attachments.get(uri)); } @@ -353,7 +354,7 @@ public class AttachmentPresenter { new LoaderManager.LoaderCallbacks() { @Override public Loader onCreateLoader(int id, Bundle args) { - Uri uri = args.getParcelable(LOADER_ARG_ATTACHMENT); + Uri uri = BundleCompat.getParcelable(args, LOADER_ARG_ATTACHMENT, Uri.class); return new AttachmentContentLoader(context, inlineAttachments.get(uri).getAttachment()); } diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java b/app/ui/legacy/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java index fcbf8fcb2..6a30ce138 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/crypto/MessageCryptoHelper.java @@ -13,10 +13,11 @@ import android.app.Activity; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; - +import androidx.core.content.IntentCompat; import com.fsck.k9.autocrypt.AutocryptOperations; import com.fsck.k9.crypto.MessageCryptoStructureDetector; import com.fsck.k9.mail.Address; @@ -537,7 +538,11 @@ public class MessageCryptoHelper { } private void handleUserInteractionRequest() { - PendingIntent pendingIntent = currentCryptoResult.getParcelableExtra(OpenPgpApi.RESULT_INTENT); + PendingIntent pendingIntent = IntentCompat.getParcelableExtra( + currentCryptoResult, + OpenPgpApi.RESULT_INTENT, + PendingIntent.class + ); if (pendingIntent == null) { throw new AssertionError("Expecting PendingIntent on USER_INTERACTION_REQUIRED!"); } @@ -546,22 +551,40 @@ public class MessageCryptoHelper { } private void handleCryptoOperationError() { - OpenPgpError error = currentCryptoResult.getParcelableExtra(OpenPgpApi.RESULT_ERROR); + OpenPgpError error = IntentCompat.getParcelableExtra( + currentCryptoResult, + OpenPgpApi.RESULT_ERROR, + OpenPgpError.class + ); Timber.w("OpenPGP API error: %s", error.getMessage()); onCryptoOperationFailed(error); } private void handleCryptoOperationSuccess(MimeBodyPart outputPart) { - OpenPgpDecryptionResult decryptionResult = - currentCryptoResult.getParcelableExtra(OpenPgpApi.RESULT_DECRYPTION); - OpenPgpSignatureResult signatureResult = - currentCryptoResult.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE); + OpenPgpDecryptionResult decryptionResult = IntentCompat.getParcelableExtra( + currentCryptoResult, + OpenPgpApi.RESULT_DECRYPTION, + OpenPgpDecryptionResult.class + ); + OpenPgpSignatureResult signatureResult = IntentCompat.getParcelableExtra( + currentCryptoResult, + OpenPgpApi.RESULT_SIGNATURE, + OpenPgpSignatureResult.class + ); if (decryptionResult.getResult() == OpenPgpDecryptionResult.RESULT_ENCRYPTED) { parseAutocryptGossipHeadersFromDecryptedPart(outputPart); } - PendingIntent pendingIntent = currentCryptoResult.getParcelableExtra(OpenPgpApi.RESULT_INTENT); - PendingIntent insecureWarningPendingIntent = currentCryptoResult.getParcelableExtra(OpenPgpApi.RESULT_INSECURE_DETAIL_INTENT); + PendingIntent pendingIntent = IntentCompat.getParcelableExtra( + currentCryptoResult, + OpenPgpApi.RESULT_INTENT, + PendingIntent.class + ); + PendingIntent insecureWarningPendingIntent = IntentCompat.getParcelableExtra( + currentCryptoResult, + OpenPgpApi.RESULT_INSECURE_DETAIL_INTENT, + PendingIntent.class + ); boolean overrideCryptoWarning = currentCryptoResult.getBooleanExtra( OpenPgpApi.RESULT_OVERRIDE_CRYPTO_WARNING, false); diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/endtoend/AutocryptSetupMessageLiveEvent.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/endtoend/AutocryptSetupMessageLiveEvent.kt index 90685bc6a..b19a04940 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/endtoend/AutocryptSetupMessageLiveEvent.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/endtoend/AutocryptSetupMessageLiveEvent.kt @@ -2,6 +2,7 @@ package com.fsck.k9.ui.endtoend import android.app.PendingIntent import android.content.Intent +import androidx.core.content.IntentCompat import com.fsck.k9.Account import com.fsck.k9.autocrypt.AutocryptTransferMessageCreator import com.fsck.k9.helper.SingleLiveEvent @@ -36,7 +37,11 @@ class AutocryptSetupMessageLiveEvent( val result = openPgpApi.executeApi(intent, null as InputStream?, baos) val keyData = baos.toByteArray() - val pi: PendingIntent = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT) ?: error("Missing result intent") + val pi: PendingIntent = IntentCompat.getParcelableExtra( + result, + OpenPgpApi.RESULT_INTENT, + PendingIntent::class.java, + ) ?: error("Missing result intent") val setupMessage = messageCreator.createAutocryptTransferMessage(keyData, address) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt index 5d98a47ea..7caac9940 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt @@ -15,6 +15,7 @@ import android.widget.TextView import android.widget.Toast import androidx.annotation.StringRes import androidx.appcompat.view.ActionMode +import androidx.core.os.BundleCompat import androidx.core.os.bundleOf import androidx.core.view.isGone import androidx.core.view.isVisible @@ -207,7 +208,7 @@ class MessageListFragment : val arguments = requireArguments() showingThreadedList = arguments.getBoolean(ARG_THREADED_LIST, false) isThreadDisplay = arguments.getBoolean(ARG_IS_THREAD_DISPLAY, false) - localSearch = arguments.getParcelable(ARG_SEARCH)!! + localSearch = BundleCompat.getParcelable(arguments, ARG_SEARCH, LocalSearch::class.java)!! allAccounts = localSearch.searchAllAccounts() val searchAccounts = localSearch.getAccounts(accountManager) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/settings/export/SettingsExportViewModel.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/settings/export/SettingsExportViewModel.kt index 37ee78d2d..92c93bbbc 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/settings/export/SettingsExportViewModel.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/settings/export/SettingsExportViewModel.kt @@ -3,6 +3,7 @@ package com.fsck.k9.ui.settings.export import android.content.Context import android.net.Uri import android.os.Bundle +import androidx.core.os.BundleCompat import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel @@ -101,7 +102,7 @@ class SettingsExportViewModel( statusText = StatusText.valueOf(savedInstanceState.getString(STATE_STATUS_TEXT, StatusText.HIDDEN.name)) } - contentUri = savedInstanceState.getParcelable(STATE_CONTENT_URI) + contentUri = BundleCompat.getParcelable(savedInstanceState, STATE_CONTENT_URI, Uri::class.java) } fun onExportButtonClicked() { diff --git a/feature/settings/import/src/main/kotlin/app/k9mail/feature/settings/import/ui/SettingsImportViewModel.kt b/feature/settings/import/src/main/kotlin/app/k9mail/feature/settings/import/ui/SettingsImportViewModel.kt index ca33c28cb..c7092b996 100644 --- a/feature/settings/import/src/main/kotlin/app/k9mail/feature/settings/import/ui/SettingsImportViewModel.kt +++ b/feature/settings/import/src/main/kotlin/app/k9mail/feature/settings/import/ui/SettingsImportViewModel.kt @@ -4,6 +4,7 @@ import android.content.Context import android.net.Uri import android.os.Bundle import android.os.Parcelable +import androidx.core.os.BundleCompat import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel @@ -70,7 +71,7 @@ internal class SettingsImportViewModel( } fun initializeFromSavedState(savedInstanceState: Bundle) { - contentUri = savedInstanceState.getParcelable(STATE_CONTENT_URI) + contentUri = BundleCompat.getParcelable(savedInstanceState, STATE_CONTENT_URI, Uri::class.java) currentlyAuthorizingAccountUuid = savedInstanceState.getString(STATE_CURRENTLY_AUTHORIZING_ACCOUNT_UUID) updateUiModel { @@ -204,12 +205,15 @@ internal class SettingsImportViewModel( ImportStatus.NOT_AVAILABLE -> updateUiModel { toggleSettingsListItemSelection(position) } + ImportStatus.IMPORT_SUCCESS_AUTHORIZATION_REQUIRED -> { startAuthorization(settingsListItem as SettingsListItem.Account) } + ImportStatus.IMPORT_SUCCESS_PASSWORD_REQUIRED -> { showPasswordPromptDialog(settingsListItem as SettingsListItem.Account) } + else -> Unit } } diff --git a/plugins/openpgp-api-lib/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpKeyPreference.java b/plugins/openpgp-api-lib/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpKeyPreference.java index 850f76a58..b00ba409e 100644 --- a/plugins/openpgp-api-lib/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpKeyPreference.java +++ b/plugins/openpgp-api-lib/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpKeyPreference.java @@ -24,11 +24,12 @@ import android.content.Context; import android.content.Intent; import android.content.IntentSender; import android.content.res.TypedArray; -import androidx.fragment.app.Fragment; -import androidx.preference.Preference; import android.text.format.DateUtils; import android.util.AttributeSet; +import androidx.core.content.IntentCompat; +import androidx.fragment.app.Fragment; +import androidx.preference.Preference; import org.openintents.openpgp.OpenPgpApiManager; import org.openintents.openpgp.OpenPgpApiManager.OpenPgpApiManagerCallback; import org.openintents.openpgp.OpenPgpApiManager.OpenPgpProviderError; @@ -146,7 +147,11 @@ public class OpenPgpKeyPreference extends Preference implements OpenPgpApiManage switch (resultCode) { case OpenPgpApi.RESULT_CODE_SUCCESS: case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: { - PendingIntent pendingIntentSelectKey = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT); + PendingIntent pendingIntentSelectKey = IntentCompat.getParcelableExtra( + result, + OpenPgpApi.RESULT_INTENT, + PendingIntent.class + ); if (result.hasExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID)) { long keyId = result.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, NO_KEY); @@ -161,7 +166,11 @@ public class OpenPgpKeyPreference extends Preference implements OpenPgpApiManage break; } case OpenPgpApi.RESULT_CODE_ERROR: { - OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR); + OpenPgpError error = IntentCompat.getParcelableExtra( + result, + OpenPgpApi.RESULT_ERROR, + OpenPgpError.class + ); Timber.e("RESULT_CODE_ERROR: %s", error.getMessage()); break;