Replace getParcelable calls with their counterparts from BundleCompat and IntentCompat

This commit is contained in:
Wolf-Martell Montwé 2024-02-08 17:30:37 +01:00
parent a863974bda
commit fd8d038bc7
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
12 changed files with 119 additions and 38 deletions

View file

@ -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 {

View file

@ -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");
}

View file

@ -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()
}

View file

@ -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<Parcelable> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
List<Parcelable> 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);

View file

@ -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);
}
/**

View file

@ -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<Attachment>() {
@Override
public Loader<Attachment> 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<Attachment>() {
@Override
public Loader<Attachment> 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<Attachment>() {
@Override
public Loader<Attachment> 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());
}

View file

@ -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);

View file

@ -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)

View file

@ -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)

View file

@ -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() {

View file

@ -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
}
}

View file

@ -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;