fix: Deprecated parcelable

This commit is contained in:
J-Jamet 2023-06-18 10:08:58 +02:00
parent f02b7c16d2
commit d5310e5c58
65 changed files with 425 additions and 265 deletions

View file

@ -41,6 +41,8 @@ import com.kunzisoft.keepass.database.helper.SearchHelper
import com.kunzisoft.keepass.model.RegisterInfo
import com.kunzisoft.keepass.model.SearchInfo
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableExtraCompat
import com.kunzisoft.keepass.utils.WebDomain
@RequiresApi(api = Build.VERSION_CODES.O)
@ -70,10 +72,10 @@ class AutofillLauncherActivity : DatabaseModeActivity() {
// To pass extra inline request
var compatInlineSuggestionsRequest: CompatInlineSuggestionsRequest? = null
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
compatInlineSuggestionsRequest = bundle.getParcelable(KEY_INLINE_SUGGESTION)
compatInlineSuggestionsRequest = bundle.getParcelableCompat(KEY_INLINE_SUGGESTION)
}
// Build search param
bundle.getParcelable<SearchInfo>(KEY_SEARCH_INFO)?.let { searchInfo ->
bundle.getParcelableCompat<SearchInfo>(KEY_SEARCH_INFO)?.let { searchInfo ->
WebDomain.getConcreteWebDomain(
this,
searchInfo.webDomain
@ -100,7 +102,7 @@ class AutofillLauncherActivity : DatabaseModeActivity() {
}
SpecialMode.REGISTRATION -> {
// To register info
val registerInfo = intent.getParcelableExtra<RegisterInfo>(KEY_REGISTER_INFO)
val registerInfo = intent.getParcelableExtraCompat<RegisterInfo>(KEY_REGISTER_INFO)
val searchInfo = SearchInfo(registerInfo?.searchInfo)
WebDomain.getConcreteWebDomain(this, searchInfo.webDomain) { concreteWebDomain ->
searchInfo.webDomain = concreteWebDomain

View file

@ -67,6 +67,7 @@ import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.tasks.AttachmentFileBinderManager
import com.kunzisoft.keepass.timeout.TimeoutHelper
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableExtraCompat
import com.kunzisoft.keepass.utils.UriUtil.openUrl
import com.kunzisoft.keepass.utils.UuidUtil
import com.kunzisoft.keepass.view.changeControlColor
@ -180,7 +181,7 @@ class EntryActivity : DatabaseLockActivity() {
// Get Entry from UUID
try {
intent.getParcelableExtra<NodeId<UUID>?>(KEY_ENTRY)?.let { mainEntryId ->
intent.getParcelableExtraCompat<NodeId<UUID>>(KEY_ENTRY)?.let { mainEntryId ->
intent.removeExtra(KEY_ENTRY)
val historyPosition = intent.getIntExtra(KEY_ENTRY_HISTORY_POSITION, -1)
intent.removeExtra(KEY_ENTRY_HISTORY_POSITION)

View file

@ -90,6 +90,7 @@ import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.tasks.AttachmentFileBinderManager
import com.kunzisoft.keepass.timeout.TimeoutHelper
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableExtraCompat
import com.kunzisoft.keepass.utils.UriUtil.getDocumentFile
import com.kunzisoft.keepass.view.ToolbarAction
import com.kunzisoft.keepass.view.asError
@ -179,14 +180,14 @@ class EntryEditActivity : DatabaseLockActivity(),
// Entry is retrieve, it's an entry to update
var entryId: NodeId<UUID>? = null
intent.getParcelableExtra<NodeId<UUID>>(KEY_ENTRY)?.let { entryToUpdate ->
intent.getParcelableExtraCompat<NodeId<UUID>>(KEY_ENTRY)?.let { entryToUpdate ->
intent.removeExtra(KEY_ENTRY)
entryId = entryToUpdate
}
// Parent is retrieve, it's a new entry to create
var parentId: NodeId<*>? = null
intent.getParcelableExtra<NodeId<*>>(KEY_PARENT)?.let { parent ->
intent.getParcelableExtraCompat<NodeId<*>>(KEY_PARENT)?.let { parent ->
intent.removeExtra(KEY_PARENT)
parentId = parent
}
@ -752,7 +753,7 @@ class EntryEditActivity : DatabaseLockActivity(),
return fragment.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
entryAddedOrUpdatedListener.invoke(
result.data?.getParcelableExtra(ADD_OR_UPDATE_ENTRY_KEY)
result.data?.getParcelableExtraCompat(ADD_OR_UPDATE_ENTRY_KEY)
)
} else {
entryAddedOrUpdatedListener.invoke(null)
@ -765,7 +766,7 @@ class EntryEditActivity : DatabaseLockActivity(),
return activity.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
entryAddedOrUpdatedListener.invoke(
result.data?.getParcelableExtra(ADD_OR_UPDATE_ENTRY_KEY)
result.data?.getParcelableExtraCompat(ADD_OR_UPDATE_ENTRY_KEY)
)
} else {
entryAddedOrUpdatedListener.invoke(null)

View file

@ -31,6 +31,7 @@ import com.kunzisoft.keepass.database.helper.SearchHelper
import com.kunzisoft.keepass.magikeyboard.MagikeyboardService
import com.kunzisoft.keepass.model.SearchInfo
import com.kunzisoft.keepass.otp.OtpEntryFields
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
import com.kunzisoft.keepass.utils.WebDomain
/**
@ -54,7 +55,7 @@ class EntrySelectionLauncherActivity : DatabaseModeActivity() {
if (keySelectionBundle != null) {
// To manage package name
var searchInfo = SearchInfo()
keySelectionBundle.getParcelable<SearchInfo>(KEY_SEARCH_INFO)?.let { mSearchInfo ->
keySelectionBundle.getParcelableCompat<SearchInfo>(KEY_SEARCH_INFO)?.let { mSearchInfo ->
searchInfo = mSearchInfo
}
launch(database, searchInfo)

View file

@ -68,6 +68,7 @@ import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.utils.DexUtil
import com.kunzisoft.keepass.utils.MagikeyboardUtil
import com.kunzisoft.keepass.utils.MenuUtil
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
import com.kunzisoft.keepass.utils.UriHelper.parseUri
import com.kunzisoft.keepass.utils.UriUtil.isContributingUser
import com.kunzisoft.keepass.utils.UriUtil.openUrl
@ -194,7 +195,7 @@ class FileDatabaseSelectActivity : DatabaseModeActivity(),
// Retrieve the database URI provided by file manager after an orientation change
if (savedInstanceState != null
&& savedInstanceState.containsKey(EXTRA_DATABASE_URI)) {
mDatabaseFileUri = savedInstanceState.getParcelable(EXTRA_DATABASE_URI)
mDatabaseFileUri = savedInstanceState.getParcelableCompat(EXTRA_DATABASE_URI)
}
// Observe list of databases
@ -252,9 +253,9 @@ class FileDatabaseSelectActivity : DatabaseModeActivity(),
when (actionTask) {
ACTION_DATABASE_CREATE_TASK,
ACTION_DATABASE_LOAD_TASK -> {
result.data?.getParcelable<Uri?>(DATABASE_URI_KEY)?.let { databaseUri ->
result.data?.getParcelableCompat<Uri>(DATABASE_URI_KEY)?.let { databaseUri ->
val mainCredential =
result.data?.getParcelable(DatabaseTaskNotificationService.MAIN_CREDENTIAL_KEY)
result.data?.getParcelableCompat(DatabaseTaskNotificationService.MAIN_CREDENTIAL_KEY)
?: MainCredential()
databaseFilesViewModel.addDatabaseFile(
databaseUri,

View file

@ -100,6 +100,11 @@ import com.kunzisoft.keepass.settings.SettingsActivity
import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.timeout.TimeoutHelper
import com.kunzisoft.keepass.utils.BACK_PREVIOUS_KEYBOARD_ACTION
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableExtraCompat
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableList
import com.kunzisoft.keepass.utils.ParcelableUtil.putParcelableList
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import com.kunzisoft.keepass.utils.UriUtil.openUrl
import com.kunzisoft.keepass.view.AddNodeButtonView
import com.kunzisoft.keepass.view.NavigationDatabaseView
@ -386,7 +391,7 @@ class GroupActivity : DatabaseLockActivity(),
savedInstanceState.remove(REQUEST_STARTUP_SEARCH_KEY)
}
if (savedInstanceState.containsKey(OLD_GROUP_TO_UPDATE_KEY)) {
mOldGroupToUpdate = savedInstanceState.getParcelable(OLD_GROUP_TO_UPDATE_KEY)
mOldGroupToUpdate = savedInstanceState.getParcelableCompat(OLD_GROUP_TO_UPDATE_KEY)
savedInstanceState.remove(OLD_GROUP_TO_UPDATE_KEY)
}
}
@ -394,9 +399,8 @@ class GroupActivity : DatabaseLockActivity(),
// Retrieve previous groups
if (savedInstanceState != null && savedInstanceState.containsKey(PREVIOUS_GROUPS_IDS_KEY)) {
try {
mPreviousGroupsIds =
(savedInstanceState.getParcelableArray(PREVIOUS_GROUPS_IDS_KEY)
?.map { it as GroupState })?.toMutableList() ?: mutableListOf()
mPreviousGroupsIds = savedInstanceState.getParcelableList(PREVIOUS_GROUPS_IDS_KEY)
?: mutableListOf()
} catch (e: Exception) {
Log.e(TAG, "Unable to retrieve previous groups", e)
}
@ -733,7 +737,7 @@ class GroupActivity : DatabaseLockActivity(),
private fun manageIntent(intent: Intent?) {
intent?.let {
if (intent.extras?.containsKey(GROUP_STATE_KEY) == true) {
mMainGroupState = intent.getParcelableExtra(GROUP_STATE_KEY)
mMainGroupState = intent.getParcelableExtraCompat(GROUP_STATE_KEY)
intent.removeExtra(GROUP_STATE_KEY)
}
// To transform KEY_SEARCH_INFO in ACTION_SEARCH
@ -764,7 +768,7 @@ class GroupActivity : DatabaseLockActivity(),
}
override fun onSaveInstanceState(outState: Bundle) {
outState.putParcelableArray(PREVIOUS_GROUPS_IDS_KEY, mPreviousGroupsIds.toTypedArray())
outState.putParcelableList(PREVIOUS_GROUPS_IDS_KEY, mPreviousGroupsIds)
mOldGroupToUpdate?.let {
outState.putParcelable(OLD_GROUP_TO_UPDATE_KEY, it)
}
@ -1410,8 +1414,7 @@ class GroupActivity : DatabaseLockActivity(),
) : Parcelable {
private constructor(parcel: Parcel) : this(
parcel.readParcelable<SearchParameters>
(SearchParameters::class.java.classLoader) ?: SearchParameters(),
parcel.readParcelableCompat<SearchParameters>() ?: SearchParameters(),
parcel.readInt()
)
@ -1439,7 +1442,7 @@ class GroupActivity : DatabaseLockActivity(),
) : Parcelable {
private constructor(parcel: Parcel) : this(
parcel.readParcelable<NodeId<*>>(NodeId::class.java.classLoader),
parcel.readParcelableCompat<NodeId<*>>(),
parcel.readInt()
)

View file

@ -46,6 +46,8 @@ import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.tasks.BinaryDatabaseManager
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableExtraCompat
import com.kunzisoft.keepass.utils.UriUtil.getDocumentFile
import com.kunzisoft.keepass.utils.UriUtil.openUrl
import com.kunzisoft.keepass.view.asError
@ -102,7 +104,7 @@ class IconPickerActivity : DatabaseLockActivity() {
lockAndExit()
}
intent?.getParcelableExtra<IconImage>(EXTRA_ICON)?.let {
intent?.getParcelableExtraCompat<IconImage>(EXTRA_ICON)?.let {
mIconImage = it
}
@ -118,7 +120,7 @@ class IconPickerActivity : DatabaseLockActivity() {
), ICON_PICKER_FRAGMENT_TAG)
}
} else {
mIconImage = savedInstanceState.getParcelable(EXTRA_ICON) ?: mIconImage
mIconImage = savedInstanceState.getParcelableCompat(EXTRA_ICON) ?: mIconImage
}
iconPickerViewModel.standardIconPicked.observe(this) { iconStandard ->
@ -342,7 +344,7 @@ class IconPickerActivity : DatabaseLockActivity() {
listener: (icon: IconImage) -> Unit): ActivityResultLauncher<Intent> {
return context.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
listener.invoke(result.data?.getParcelableExtra(EXTRA_ICON) ?: IconImage())
listener.invoke(result.data?.getParcelableExtraCompat(EXTRA_ICON) ?: IconImage())
}
}
}

View file

@ -36,6 +36,7 @@ import com.kunzisoft.keepass.activities.legacy.DatabaseLockActivity
import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.Attachment
import com.kunzisoft.keepass.tasks.BinaryDatabaseManager
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableExtraCompat
import kotlin.math.max
class ImageViewerActivity : DatabaseLockActivity() {
@ -105,7 +106,7 @@ class ImageViewerActivity : DatabaseLockActivity() {
try {
progressView.visibility = View.VISIBLE
intent.getParcelableExtra<Attachment>(IMAGE_ATTACHMENT_TAG)?.let { attachment ->
intent.getParcelableExtraCompat<Attachment>(IMAGE_ATTACHMENT_TAG)?.let { attachment ->
supportActionBar?.title = attachment.name

View file

@ -72,6 +72,8 @@ import com.kunzisoft.keepass.settings.SettingsAdvancedUnlockActivity
import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.utils.BACK_PREVIOUS_KEYBOARD_ACTION
import com.kunzisoft.keepass.utils.MenuUtil
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableExtraCompat
import com.kunzisoft.keepass.utils.UriUtil.getUri
import com.kunzisoft.keepass.view.MainCredentialView
import com.kunzisoft.keepass.view.asError
@ -305,13 +307,13 @@ class MainCredentialActivity : DatabaseModeActivity(), AdvancedUnlockFragment.Bu
var cipherEncryptDatabase: CipherEncryptDatabase? = null
result.data?.let { resultData ->
databaseUri = resultData.getParcelable(DATABASE_URI_KEY)
databaseUri = resultData.getParcelableCompat(DATABASE_URI_KEY)
mainCredential =
resultData.getParcelable(MAIN_CREDENTIAL_KEY)
resultData.getParcelableCompat(MAIN_CREDENTIAL_KEY)
?: mainCredential
readOnly = resultData.getBoolean(READ_ONLY_KEY)
cipherEncryptDatabase =
resultData.getParcelable(CIPHER_DATABASE_KEY)
resultData.getParcelableCompat(CIPHER_DATABASE_KEY)
}
databaseUri?.let { databaseFileUri ->
@ -349,8 +351,8 @@ class MainCredentialActivity : DatabaseModeActivity(), AdvancedUnlockFragment.Bu
)
} else {
fillCredentials(
intent?.getParcelableExtra(KEY_FILENAME),
intent?.getParcelableExtra(KEY_KEYFILE),
intent?.getParcelableExtraCompat(KEY_FILENAME),
intent?.getParcelableExtraCompat(KEY_KEYFILE),
HardwareKey.getHardwareKeyFromString(intent?.getStringExtra(KEY_HARDWARE_KEY))
)
}

View file

@ -25,6 +25,7 @@ import android.text.SpannableStringBuilder
import androidx.appcompat.app.AlertDialog
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.model.SnapFileDatabaseInfo
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
class DatabaseChangedDialogFragment : DatabaseDialogFragment() {
@ -40,8 +41,8 @@ class DatabaseChangedDialogFragment : DatabaseDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
activity?.let { activity ->
val oldSnapFileDatabaseInfo: SnapFileDatabaseInfo? = arguments?.getParcelable(OLD_FILE_DATABASE_INFO)
val newSnapFileDatabaseInfo: SnapFileDatabaseInfo? = arguments?.getParcelable(NEW_FILE_DATABASE_INFO)
val oldSnapFileDatabaseInfo: SnapFileDatabaseInfo? = arguments?.getParcelableCompat(OLD_FILE_DATABASE_INFO)
val newSnapFileDatabaseInfo: SnapFileDatabaseInfo? = arguments?.getParcelableCompat(NEW_FILE_DATABASE_INFO)
if (oldSnapFileDatabaseInfo != null && newSnapFileDatabaseInfo != null) {
// Use the Builder class for convenient dialog construction

View file

@ -35,6 +35,7 @@ import com.google.android.material.textfield.TextInputLayout
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Field
import com.kunzisoft.keepass.database.element.security.ProtectedString
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
class EntryCustomFieldDialogFragment: DatabaseDialogFragment() {
@ -72,7 +73,7 @@ class EntryCustomFieldDialogFragment: DatabaseDialogFragment() {
customFieldDeleteButton = root?.findViewById(R.id.entry_custom_field_delete)
customFieldProtectionButton = root?.findViewById(R.id.entry_custom_field_protection)
oldField = arguments?.getParcelable(KEY_FIELD)
oldField = arguments?.getParcelableCompat(KEY_FIELD)
oldField?.let { oldCustomField ->
customFieldLabel?.text = oldCustomField.name
customFieldProtectionButton?.isChecked = oldCustomField.protectedValue.isProtected

View file

@ -27,6 +27,7 @@ import android.text.SpannableStringBuilder
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
/**
* Custom Dialog to confirm big file to upload
@ -62,7 +63,7 @@ class FileTooBigDialogFragment : DialogFragment() {
})
builder.setPositiveButton(android.R.string.ok) { _, _ ->
mActionChooseListener?.onValidateUploadFileTooBig(
arguments?.getParcelable(KEY_FILE_URI),
arguments?.getParcelableCompat(KEY_FILE_URI),
arguments?.getString(KEY_FILE_NAME))
}
builder.setNegativeButton(android.R.string.cancel) { _, _ ->

View file

@ -35,6 +35,7 @@ import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.model.GroupInfo
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
import com.kunzisoft.keepass.utils.TimeUtil.getDateTimeString
import com.kunzisoft.keepass.utils.UuidUtil
import com.kunzisoft.keepass.view.DateTimeFieldView
@ -113,11 +114,11 @@ class GroupDialogFragment : DatabaseDialogFragment() {
if (savedInstanceState != null
&& savedInstanceState.containsKey(KEY_GROUP_INFO)) {
mGroupInfo = savedInstanceState.getParcelable(KEY_GROUP_INFO) ?: mGroupInfo
mGroupInfo = savedInstanceState.getParcelableCompat(KEY_GROUP_INFO) ?: mGroupInfo
} else {
arguments?.apply {
if (containsKey(KEY_GROUP_INFO)) {
mGroupInfo = getParcelable(KEY_GROUP_INFO) ?: mGroupInfo
mGroupInfo = getParcelableCompat(KEY_GROUP_INFO) ?: mGroupInfo
}
}
}

View file

@ -39,6 +39,7 @@ import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.DateInstant
import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.model.GroupInfo
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
import com.kunzisoft.keepass.view.DateTimeEditFieldView
import com.kunzisoft.keepass.view.InheritedCompletionView
import com.kunzisoft.keepass.view.TagsCompletionView
@ -174,13 +175,13 @@ class GroupEditDialogFragment : DatabaseDialogFragment() {
&& savedInstanceState.containsKey(KEY_ACTION_ID)
&& savedInstanceState.containsKey(KEY_GROUP_INFO)) {
mEditGroupDialogAction = EditGroupDialogAction.getActionFromOrdinal(savedInstanceState.getInt(KEY_ACTION_ID))
mGroupInfo = savedInstanceState.getParcelable(KEY_GROUP_INFO) ?: mGroupInfo
mGroupInfo = savedInstanceState.getParcelableCompat(KEY_GROUP_INFO) ?: mGroupInfo
} else {
arguments?.apply {
if (containsKey(KEY_ACTION_ID))
mEditGroupDialogAction = EditGroupDialogAction.getActionFromOrdinal(getInt(KEY_ACTION_ID))
if (containsKey(KEY_GROUP_INFO)) {
mGroupInfo = getParcelable(KEY_GROUP_INFO) ?: mGroupInfo
mGroupInfo = getParcelableCompat(KEY_GROUP_INFO) ?: mGroupInfo
}
}
}

View file

@ -31,6 +31,7 @@ import com.kunzisoft.keepass.database.ContextualDatabase
import com.kunzisoft.keepass.database.element.DateInstant
import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
import com.kunzisoft.keepass.viewmodels.IconPickerViewModel
class IconEditDialogFragment : DatabaseDialogFragment() {
@ -63,11 +64,11 @@ class IconEditDialogFragment : DatabaseDialogFragment() {
if (savedInstanceState != null
&& savedInstanceState.containsKey(KEY_CUSTOM_ICON_ID)) {
mCustomIcon = savedInstanceState.getParcelable(KEY_CUSTOM_ICON_ID) ?: mCustomIcon
mCustomIcon = savedInstanceState.getParcelableCompat(KEY_CUSTOM_ICON_ID) ?: mCustomIcon
} else {
arguments?.apply {
if (containsKey(KEY_CUSTOM_ICON_ID)) {
mCustomIcon = getParcelable(KEY_CUSTOM_ICON_ID) ?: mCustomIcon
mCustomIcon = getParcelableCompat(KEY_CUSTOM_ICON_ID) ?: mCustomIcon
}
}
}

View file

@ -28,6 +28,7 @@ import androidx.appcompat.app.AlertDialog
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.helpers.ExternalFileHelper
import com.kunzisoft.keepass.database.MainCredential
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
import com.kunzisoft.keepass.utils.UriUtil.getDocumentFile
import com.kunzisoft.keepass.view.MainCredentialView
@ -65,7 +66,7 @@ class MainCredentialDialogFragment : DatabaseDialogFragment() {
var databaseUri: Uri? = null
arguments?.apply {
if (containsKey(KEY_ASK_CREDENTIAL_URI))
databaseUri = getParcelable(KEY_ASK_CREDENTIAL_URI)
databaseUri = getParcelableCompat(KEY_ASK_CREDENTIAL_URI)
}
val builder = AlertDialog.Builder(activity)

View file

@ -27,6 +27,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.MainCredential
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
class PasswordEncodingDialogFragment : DialogFragment() {
@ -49,8 +50,8 @@ class PasswordEncodingDialogFragment : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val databaseUri: Uri? = savedInstanceState?.getParcelable(DATABASE_URI_KEY)
val mainCredential: MainCredential = savedInstanceState?.getParcelable(MAIN_CREDENTIAL) ?: MainCredential()
val databaseUri: Uri? = savedInstanceState?.getParcelableCompat(DATABASE_URI_KEY)
val mainCredential: MainCredential = savedInstanceState?.getParcelableCompat(MAIN_CREDENTIAL) ?: MainCredential()
activity?.let { activity ->
val builder = AlertDialog.Builder(activity)

View file

@ -27,6 +27,7 @@ import android.text.SpannableStringBuilder
import androidx.appcompat.app.AlertDialog
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Attachment
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
/**
* Custom Dialog to confirm big file to upload
@ -62,8 +63,8 @@ class ReplaceFileDialogFragment : DatabaseDialogFragment() {
})
builder.setPositiveButton(android.R.string.ok) { _, _ ->
mActionChooseListener?.onValidateReplaceFile(
arguments?.getParcelable(KEY_FILE_URI),
arguments?.getParcelable(KEY_ENTRY_ATTACHMENT))
arguments?.getParcelableCompat(KEY_FILE_URI),
arguments?.getParcelableCompat(KEY_ENTRY_ATTACHMENT))
}
builder.setNegativeButton(android.R.string.cancel) { _, _ ->
dismiss()

View file

@ -44,6 +44,7 @@ import com.kunzisoft.keepass.otp.OtpElement.Companion.MIN_TOTP_PERIOD
import com.kunzisoft.keepass.otp.OtpTokenType
import com.kunzisoft.keepass.otp.OtpType
import com.kunzisoft.keepass.otp.TokenCalculator
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
import com.kunzisoft.keepass.utils.UriUtil.isContributingUser
import com.kunzisoft.keepass.utils.UriUtil.openUrl
import java.util.*
@ -126,14 +127,14 @@ class SetOTPDialogFragment : DatabaseDialogFragment() {
// Retrieve OTP model from instance state
if (savedInstanceState != null) {
if (savedInstanceState.containsKey(KEY_OTP)) {
savedInstanceState.getParcelable<OtpModel>(KEY_OTP)?.let { otpModel ->
savedInstanceState.getParcelableCompat<OtpModel>(KEY_OTP)?.let { otpModel ->
mOtpElement = OtpElement(otpModel)
}
}
} else {
arguments?.apply {
if (containsKey(KEY_OTP)) {
getParcelable<OtpModel?>(KEY_OTP)?.let { otpModel ->
getParcelableCompat<OtpModel>(KEY_OTP)?.let { otpModel ->
mOtpElement = OtpElement(otpModel)
}
}

View file

@ -42,6 +42,8 @@ import com.kunzisoft.keepass.model.AttachmentState
import com.kunzisoft.keepass.model.EntryAttachmentState
import com.kunzisoft.keepass.model.EntryInfo
import com.kunzisoft.keepass.model.StreamDirection
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableList
import com.kunzisoft.keepass.utils.ParcelableUtil.putParcelableList
import com.kunzisoft.keepass.view.TagsCompletionView
import com.kunzisoft.keepass.view.TemplateEditView
import com.kunzisoft.keepass.view.collapse
@ -128,7 +130,7 @@ class EntryEditFragment: DatabaseFragment() {
if (savedInstanceState != null) {
val attachments: List<Attachment> =
savedInstanceState.getParcelableArrayList(ATTACHMENTS_TAG) ?: listOf()
savedInstanceState.getParcelableList(ATTACHMENTS_TAG) ?: listOf()
setAttachments(attachments)
}
@ -383,7 +385,7 @@ class EntryEditFragment: DatabaseFragment() {
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putParcelableArrayList(ATTACHMENTS_TAG, ArrayList(getAttachments()))
outState.putParcelableList(ATTACHMENTS_TAG, getAttachments())
}
/* -------------

View file

@ -26,7 +26,9 @@ import com.kunzisoft.keepass.autofill.AutofillComponent
import com.kunzisoft.keepass.autofill.AutofillHelper
import com.kunzisoft.keepass.model.RegisterInfo
import com.kunzisoft.keepass.model.SearchInfo
import java.io.Serializable
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableExtraCompat
import com.kunzisoft.keepass.utils.getEnumExtra
import com.kunzisoft.keepass.utils.putEnumExtra
object EntrySelectionHelper {
@ -82,7 +84,7 @@ object EntrySelectionHelper {
}
fun retrieveSearchInfoFromIntent(intent: Intent): SearchInfo? {
return intent.getParcelableExtra(KEY_SEARCH_INFO)
return intent.getParcelableExtraCompat(KEY_SEARCH_INFO)
}
private fun addRegisterInfoInIntent(intent: Intent, registerInfo: RegisterInfo?) {
@ -92,7 +94,7 @@ object EntrySelectionHelper {
}
fun retrieveRegisterInfoFromIntent(intent: Intent): RegisterInfo? {
return intent.getParcelableExtra(KEY_REGISTER_INFO)
return intent.getParcelableExtraCompat(KEY_REGISTER_INFO)
}
fun removeInfoFromIntent(intent: Intent) {
@ -101,7 +103,7 @@ object EntrySelectionHelper {
}
fun addSpecialModeInIntent(intent: Intent, specialMode: SpecialMode) {
intent.putExtra(KEY_SPECIAL_MODE, specialMode as Serializable)
intent.putEnumExtra(KEY_SPECIAL_MODE, specialMode)
}
fun retrieveSpecialModeFromIntent(intent: Intent): SpecialMode {
@ -109,12 +111,11 @@ object EntrySelectionHelper {
if (AutofillHelper.retrieveAutofillComponent(intent) != null)
return SpecialMode.SELECTION
}
return intent.getSerializableExtra(KEY_SPECIAL_MODE) as SpecialMode?
?: SpecialMode.DEFAULT
return intent.getEnumExtra<SpecialMode>(KEY_SPECIAL_MODE) ?: SpecialMode.DEFAULT
}
private fun addTypeModeInIntent(intent: Intent, typeMode: TypeMode) {
intent.putExtra(KEY_TYPE_MODE, typeMode as Serializable)
intent.putEnumExtra(KEY_TYPE_MODE, typeMode)
}
fun retrieveTypeModeFromIntent(intent: Intent): TypeMode {
@ -122,7 +123,7 @@ object EntrySelectionHelper {
if (AutofillHelper.retrieveAutofillComponent(intent) != null)
return TypeMode.AUTOFILL
}
return intent.getSerializableExtra(KEY_TYPE_MODE) as TypeMode? ?: TypeMode.DEFAULT
return intent.getEnumExtra<TypeMode>(KEY_TYPE_MODE) ?: TypeMode.DEFAULT
}
fun removeModesFromIntent(intent: Intent) {
@ -175,7 +176,7 @@ object EntrySelectionHelper {
}
}
if (!autofillComponentInit) {
if (intent.getSerializableExtra(KEY_SPECIAL_MODE) != null) {
if (intent.getEnumExtra<SpecialMode>(KEY_SPECIAL_MODE) != null) {
when (retrieveTypeModeFromIntent(intent)) {
TypeMode.DEFAULT -> {
removeModesFromIntent(intent)

View file

@ -56,6 +56,7 @@ import com.kunzisoft.keepass.model.SearchInfo
import com.kunzisoft.keepass.settings.AutofillSettingsActivity
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.utils.LOCK_ACTION
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableExtraCompat
@RequiresApi(api = Build.VERSION_CODES.O)
@ -65,10 +66,10 @@ object AutofillHelper {
private const val EXTRA_INLINE_SUGGESTIONS_REQUEST = "com.kunzisoft.keepass.autofill.INLINE_SUGGESTIONS_REQUEST"
fun retrieveAutofillComponent(intent: Intent?): AutofillComponent? {
intent?.getParcelableExtra<AssistStructure?>(EXTRA_ASSIST_STRUCTURE)?.let { assistStructure ->
intent?.getParcelableExtraCompat<AssistStructure>(EXTRA_ASSIST_STRUCTURE)?.let { assistStructure ->
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
AutofillComponent(assistStructure,
intent.getParcelableExtra(EXTRA_INLINE_SUGGESTIONS_REQUEST))
intent.getParcelableExtraCompat(EXTRA_INLINE_SUGGESTIONS_REQUEST))
} else {
AutofillComponent(assistStructure, null)
}
@ -410,11 +411,11 @@ object AutofillHelper {
activity.setResult(Activity.RESULT_CANCELED)
} else {
var setResultOk = false
activity.intent?.getParcelableExtra<AssistStructure>(EXTRA_ASSIST_STRUCTURE)?.let { structure ->
activity.intent?.getParcelableExtraCompat<AssistStructure>(EXTRA_ASSIST_STRUCTURE)?.let { structure ->
StructureParser(structure).parse()?.let { result ->
// New Response
val response = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val compatInlineSuggestionsRequest = activity.intent?.getParcelableExtra<CompatInlineSuggestionsRequest?>(EXTRA_INLINE_SUGGESTIONS_REQUEST)
val compatInlineSuggestionsRequest = activity.intent?.getParcelableExtraCompat<CompatInlineSuggestionsRequest>(EXTRA_INLINE_SUGGESTIONS_REQUEST)
if (compatInlineSuggestionsRequest != null) {
Toast.makeText(activity.applicationContext, R.string.autofill_inline_suggestions_keyboard, Toast.LENGTH_SHORT).show()
}

View file

@ -26,6 +26,7 @@ import android.os.Parcelable
import android.service.autofill.FillRequest
import android.view.inputmethod.InlineSuggestionsRequest
import androidx.annotation.RequiresApi
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
/**
* Utility class only to prevent java.lang.NoClassDefFoundError for old Android version and new lib compilation
@ -52,8 +53,7 @@ class CompatInlineSuggestionsRequest : Parcelable {
constructor(parcel: Parcel) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
this.inlineSuggestionsRequest =
parcel.readParcelable(FillRequest::class.java.classLoader)
this.inlineSuggestionsRequest = parcel.readParcelableCompat()
}
else {
this.inlineSuggestionsRequest = null

View file

@ -24,6 +24,7 @@ import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.database.element.MasterCredential
import com.kunzisoft.keepass.hardware.HardwareKey
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import com.kunzisoft.keepass.utils.UriHelper.getUriInputStream
import com.kunzisoft.keepass.utils.readEnum
import com.kunzisoft.keepass.utils.writeEnum
@ -34,7 +35,7 @@ data class MainCredential(var password: String? = null,
constructor(parcel: Parcel) : this() {
password = parcel.readString()
keyFileUri = parcel.readParcelable(Uri::class.java.classLoader)
keyFileUri = parcel.readParcelableCompat()
hardwareKey = parcel.readEnum<HardwareKey>()
}

View file

@ -24,6 +24,7 @@ import android.net.Uri
import android.os.Parcel
import android.os.Parcelable
import android.text.format.Formatter
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import com.kunzisoft.keepass.viewmodels.FileDatabaseInfo
import java.text.DateFormat
import java.util.Date
@ -37,7 +38,7 @@ data class SnapFileDatabaseInfo(var fileUri: Uri?,
var size: Long?): Parcelable {
constructor(parcel: Parcel) : this(
parcel.readParcelable(Uri::class.java.classLoader),
parcel.readParcelableCompat(),
parcel.readByte() != 0.toByte(),
parcel.readValue(Long::class.java.classLoader) as? Long,
parcel.readValue(Long::class.java.classLoader) as? Long) {

View file

@ -36,6 +36,7 @@ import com.kunzisoft.keepass.model.AttachmentState
import com.kunzisoft.keepass.model.EntryAttachmentState
import com.kunzisoft.keepass.model.StreamDirection
import com.kunzisoft.keepass.tasks.BinaryDatabaseManager
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableExtraCompat
import com.kunzisoft.keepass.utils.UriUtil.getDocumentFile
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -131,7 +132,7 @@ class AttachmentFileNotificationService: LockNotificationService() {
private fun actionRequested(intent: Intent?) {
val downloadFileUri: Uri? = if (intent?.hasExtra(FILE_URI_KEY) == true) {
intent.getParcelableExtra(FILE_URI_KEY)
intent.getParcelableExtraCompat(FILE_URI_KEY)
} else null
when(intent?.action) {
@ -149,7 +150,7 @@ class AttachmentFileNotificationService: LockNotificationService() {
StreamDirection.DOWNLOAD)
}
ACTION_ATTACHMENT_REMOVE -> {
intent.getParcelableExtra<Attachment>(ATTACHMENT_KEY)?.let { entryAttachment ->
intent.getParcelableExtraCompat<Attachment>(ATTACHMENT_KEY)?.let { entryAttachment ->
attachmentNotificationList.firstOrNull { it.entryAttachmentState.attachment == entryAttachment }?.let { elementToRemove ->
attachmentNotificationList.remove(elementToRemove)
}
@ -325,7 +326,7 @@ class AttachmentFileNotificationService: LockNotificationService() {
if (fileUri != null
&& intent.hasExtra(ATTACHMENT_KEY)) {
try {
intent.getParcelableExtra<Attachment>(ATTACHMENT_KEY)?.let { entryAttachment ->
intent.getParcelableExtraCompat<Attachment>(ATTACHMENT_KEY)?.let { entryAttachment ->
val nextNotificationId = (attachmentNotificationList.maxByOrNull { it.notificationId }
?.notificationId ?: notificationId) + 1

View file

@ -31,6 +31,9 @@ import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.timeout.ClipboardHelper
import com.kunzisoft.keepass.timeout.TimeoutHelper.NEVER
import com.kunzisoft.keepass.utils.LOCK_ACTION
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableExtraCompat
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableList
import com.kunzisoft.keepass.utils.ParcelableUtil.putParcelableList
class ClipboardEntryNotificationService : LockNotificationService() {
@ -65,7 +68,7 @@ class ClipboardEntryNotificationService : LockNotificationService() {
super.onStartCommand(intent, flags, startId)
// Get entry info from intent
mEntryInfo = intent?.getParcelableExtra(EXTRA_ENTRY_INFO)
mEntryInfo = intent?.getParcelableExtraCompat(EXTRA_ENTRY_INFO)
when {
intent == null -> Log.w(TAG, "null intent")
@ -79,7 +82,7 @@ class ClipboardEntryNotificationService : LockNotificationService() {
}
else -> for (actionKey in ClipboardEntryNotificationField.allActionKeys) {
if (actionKey == intent.action) {
intent.getParcelableExtra<ClipboardEntryNotificationField>(
intent.getParcelableExtraCompat<ClipboardEntryNotificationField>(
ClipboardEntryNotificationField.getExtraKeyLinkToActionKey(actionKey))?.let {
fieldToCopy ->
val nextFields = constructListOfField(intent)
@ -93,10 +96,10 @@ class ClipboardEntryNotificationService : LockNotificationService() {
return START_NOT_STICKY
}
private fun constructListOfField(intent: Intent?): ArrayList<ClipboardEntryNotificationField> {
val fieldList = ArrayList<ClipboardEntryNotificationField>()
private fun constructListOfField(intent: Intent?): MutableList<ClipboardEntryNotificationField> {
val fieldList = mutableListOf<ClipboardEntryNotificationField>()
if (intent?.extras?.containsKey(EXTRA_CLIPBOARD_FIELDS) == true) {
intent.getParcelableArrayListExtra<ClipboardEntryNotificationField>(EXTRA_CLIPBOARD_FIELDS)?.let { retrieveFields ->
intent.getParcelableList<ClipboardEntryNotificationField>(EXTRA_CLIPBOARD_FIELDS)?.let { retrieveFields ->
fieldList.clear()
fieldList.addAll(retrieveFields)
}
@ -104,12 +107,12 @@ class ClipboardEntryNotificationService : LockNotificationService() {
return fieldList
}
private fun getCopyPendingIntent(fieldToCopy: ClipboardEntryNotificationField, fieldsToAdd: ArrayList<ClipboardEntryNotificationField>): PendingIntent {
private fun getCopyPendingIntent(fieldToCopy: ClipboardEntryNotificationField, fieldsToAdd: MutableList<ClipboardEntryNotificationField>): PendingIntent {
val copyIntent = Intent(this, ClipboardEntryNotificationService::class.java).apply {
action = fieldToCopy.actionKey
putExtra(EXTRA_ENTRY_INFO, mEntryInfo)
putExtra(fieldToCopy.extraKey, fieldToCopy)
putParcelableArrayListExtra(EXTRA_CLIPBOARD_FIELDS, fieldsToAdd)
putParcelableList(EXTRA_CLIPBOARD_FIELDS, fieldsToAdd)
}
return PendingIntent.getService(
this, 0, copyIntent,
@ -121,7 +124,7 @@ class ClipboardEntryNotificationService : LockNotificationService() {
)
}
private fun newNotification(title: String?, fieldsToAdd: ArrayList<ClipboardEntryNotificationField>) {
private fun newNotification(title: String?, fieldsToAdd: MutableList<ClipboardEntryNotificationField>) {
mTimerJob?.cancel()
val builder = buildNewNotification()
@ -136,7 +139,8 @@ class ClipboardEntryNotificationService : LockNotificationService() {
builder.setContentIntent(getCopyPendingIntent(field, fieldsToAdd))
// Add extra actions without 1st field
val fieldsWithoutFirstField = ArrayList(fieldsToAdd)
val fieldsWithoutFirstField = mutableListOf<ClipboardEntryNotificationField>()
fieldsWithoutFirstField.addAll(fieldsToAdd)
fieldsWithoutFirstField.remove(field)
// Add extra actions
for (fieldToAdd in fieldsWithoutFirstField) {
@ -147,7 +151,7 @@ class ClipboardEntryNotificationService : LockNotificationService() {
notificationManager?.notify(notificationId, builder.build())
}
private fun copyField(fieldToCopy: ClipboardEntryNotificationField, nextFields: ArrayList<ClipboardEntryNotificationField>) {
private fun copyField(fieldToCopy: ClipboardEntryNotificationField, nextFields: MutableList<ClipboardEntryNotificationField>) {
mTimerJob?.cancel()
try {
@ -259,7 +263,7 @@ class ClipboardEntryNotificationService : LockNotificationService() {
intent.action = ACTION_NEW_NOTIFICATION
intent.putExtra(EXTRA_ENTRY_INFO, entry)
// Construct notification fields
val notificationFields = ArrayList<ClipboardEntryNotificationField>()
val notificationFields = mutableListOf<ClipboardEntryNotificationField>()
// Add username if exists to notifications
if (containsUsernameToCopy)
notificationFields.add(
@ -304,7 +308,7 @@ class ClipboardEntryNotificationService : LockNotificationService() {
}
// Add notifications
startService = true
intent.putParcelableArrayListExtra(EXTRA_CLIPBOARD_FIELDS, notificationFields)
intent.putParcelableList(EXTRA_CLIPBOARD_FIELDS, notificationFields)
context.startService(intent)
}
}

View file

@ -57,6 +57,9 @@ import com.kunzisoft.keepass.timeout.TimeoutHelper
import com.kunzisoft.keepass.utils.DATABASE_START_TASK_ACTION
import com.kunzisoft.keepass.utils.DATABASE_STOP_TASK_ACTION
import com.kunzisoft.keepass.utils.LOCK_ACTION
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableExtraCompat
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableList
import com.kunzisoft.keepass.utils.ParcelableUtil.putParcelableList
import com.kunzisoft.keepass.utils.closeDatabase
import com.kunzisoft.keepass.viewmodels.FileDatabaseInfo
import kotlinx.coroutines.*
@ -702,9 +705,9 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
if (intent.hasExtra(DATABASE_URI_KEY)
&& intent.hasExtra(MAIN_CREDENTIAL_KEY)
) {
val databaseUri: Uri? = intent.getParcelableExtra(DATABASE_URI_KEY)
val databaseUri: Uri? = intent.getParcelableExtraCompat(DATABASE_URI_KEY)
val mainCredential: MainCredential =
intent.getParcelableExtra(MAIN_CREDENTIAL_KEY) ?: MainCredential()
intent.getParcelableExtraCompat(MAIN_CREDENTIAL_KEY) ?: MainCredential()
if (databaseUri == null) return null
return CreateDatabaseRunnable(this,
database,
@ -760,12 +763,12 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
&& intent.hasExtra(CIPHER_DATABASE_KEY)
&& intent.hasExtra(FIX_DUPLICATE_UUID_KEY)
) {
val databaseUri: Uri? = intent.getParcelableExtra(DATABASE_URI_KEY)
val databaseUri: Uri? = intent.getParcelableExtraCompat(DATABASE_URI_KEY)
val mainCredential: MainCredential =
intent.getParcelableExtra(MAIN_CREDENTIAL_KEY) ?: MainCredential()
intent.getParcelableExtraCompat(MAIN_CREDENTIAL_KEY) ?: MainCredential()
val readOnly: Boolean = intent.getBooleanExtra(READ_ONLY_KEY, true)
val cipherEncryptDatabase: CipherEncryptDatabase? =
intent.getParcelableExtra(CIPHER_DATABASE_KEY)
intent.getParcelableExtraCompat(CIPHER_DATABASE_KEY)
if (databaseUri == null) return null
return LoadDatabaseRunnable(
this,
@ -823,10 +826,10 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
var databaseToMergeUri: Uri? = null
var databaseToMergeMainCredential: MainCredential? = null
if (intent.hasExtra(DATABASE_URI_KEY)) {
databaseToMergeUri = intent.getParcelableExtra(DATABASE_URI_KEY)
databaseToMergeUri = intent.getParcelableExtraCompat(DATABASE_URI_KEY)
}
if (intent.hasExtra(MAIN_CREDENTIAL_KEY)) {
databaseToMergeMainCredential = intent.getParcelableExtra(MAIN_CREDENTIAL_KEY)
databaseToMergeMainCredential = intent.getParcelableExtraCompat(MAIN_CREDENTIAL_KEY)
}
return MergeDatabaseRunnable(
this,
@ -877,12 +880,12 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
return if (intent.hasExtra(DATABASE_URI_KEY)
&& intent.hasExtra(MAIN_CREDENTIAL_KEY)
) {
val databaseUri: Uri = intent.getParcelableExtra(DATABASE_URI_KEY) ?: return null
val databaseUri: Uri = intent.getParcelableExtraCompat(DATABASE_URI_KEY) ?: return null
SaveDatabaseRunnable(
this,
database,
saveDatabase = true,
intent.getParcelableExtra(MAIN_CREDENTIAL_KEY) ?: MainCredential(),
intent.getParcelableExtraCompat(MAIN_CREDENTIAL_KEY) ?: MainCredential(),
{ hardwareKey, seed ->
retrieveResponseFromChallenge(hardwareKey, seed)
},
@ -926,8 +929,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
&& intent.hasExtra(PARENT_ID_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
val parentId: NodeId<*>? = intent.getParcelableExtra(PARENT_ID_KEY)
val newGroup: Group? = intent.getParcelableExtra(GROUP_KEY)
val parentId: NodeId<*>? = intent.getParcelableExtraCompat(PARENT_ID_KEY)
val newGroup: Group? = intent.getParcelableExtraCompat(GROUP_KEY)
if (parentId == null || newGroup == null) return null
database.getGroupById(parentId)?.let { parent ->
AddGroupRunnable(this,
@ -953,8 +956,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
&& intent.hasExtra(GROUP_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
val groupId: NodeId<*>? = intent.getParcelableExtra(GROUP_ID_KEY)
val newGroup: Group? = intent.getParcelableExtra(GROUP_KEY)
val groupId: NodeId<*>? = intent.getParcelableExtraCompat(GROUP_ID_KEY)
val newGroup: Group? = intent.getParcelableExtraCompat(GROUP_KEY)
if (groupId == null || newGroup == null) return null
database.getGroupById(groupId)?.let { oldGroup ->
UpdateGroupRunnable(this,
@ -980,8 +983,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
&& intent.hasExtra(PARENT_ID_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
val parentId: NodeId<*>? = intent.getParcelableExtra(PARENT_ID_KEY)
val newEntry: Entry? = intent.getParcelableExtra(ENTRY_KEY)
val parentId: NodeId<*>? = intent.getParcelableExtraCompat(PARENT_ID_KEY)
val newEntry: Entry? = intent.getParcelableExtraCompat(ENTRY_KEY)
if (parentId == null || newEntry == null) return null
database.getGroupById(parentId)?.let { parent ->
AddEntryRunnable(this,
@ -1007,8 +1010,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
&& intent.hasExtra(ENTRY_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
val entryId: NodeId<UUID>? = intent.getParcelableExtra(ENTRY_ID_KEY)
val newEntry: Entry? = intent.getParcelableExtra(ENTRY_KEY)
val entryId: NodeId<UUID>? = intent.getParcelableExtraCompat(ENTRY_ID_KEY)
val newEntry: Entry? = intent.getParcelableExtraCompat(ENTRY_KEY)
if (entryId == null || newEntry == null) return null
database.getEntryById(entryId)?.let { oldEntry ->
UpdateEntryRunnable(this,
@ -1035,7 +1038,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
&& intent.hasExtra(PARENT_ID_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
val parentId: NodeId<*> = intent.getParcelableExtra(PARENT_ID_KEY) ?: return null
val parentId: NodeId<*> = intent.getParcelableExtraCompat(PARENT_ID_KEY) ?: return null
database.getGroupById(parentId)?.let { newParent ->
CopyNodesRunnable(this,
database,
@ -1061,7 +1064,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
&& intent.hasExtra(PARENT_ID_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
val parentId: NodeId<*> = intent.getParcelableExtra(PARENT_ID_KEY) ?: return null
val parentId: NodeId<*> = intent.getParcelableExtraCompat(PARENT_ID_KEY) ?: return null
database.getGroupById(parentId)?.let { newParent ->
MoveNodesRunnable(this,
database,
@ -1108,7 +1111,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
&& intent.hasExtra(ENTRY_HISTORY_POSITION_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
val entryId: NodeId<UUID> = intent.getParcelableExtra(ENTRY_ID_KEY) ?: return null
val entryId: NodeId<UUID> = intent.getParcelableExtraCompat(ENTRY_ID_KEY) ?: return null
database.getEntryById(entryId)?.let { mainEntry ->
RestoreEntryHistoryDatabaseRunnable(this,
database,
@ -1132,7 +1135,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
&& intent.hasExtra(ENTRY_HISTORY_POSITION_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
val entryId: NodeId<UUID> = intent.getParcelableExtra(ENTRY_ID_KEY) ?: return null
val entryId: NodeId<UUID> = intent.getParcelableExtraCompat(ENTRY_ID_KEY) ?: return null
database.getEntryById(entryId)?.let { mainEntry ->
DeleteEntryHistoryDatabaseRunnable(this,
database,
@ -1156,8 +1159,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
&& intent.hasExtra(NEW_ELEMENT_KEY)
&& intent.hasExtra(SAVE_DATABASE_KEY)
) {
val oldElement: CompressionAlgorithm? = intent.getParcelableExtra(OLD_ELEMENT_KEY)
val newElement: CompressionAlgorithm? = intent.getParcelableExtra(NEW_ELEMENT_KEY)
val oldElement: CompressionAlgorithm? = intent.getParcelableExtraCompat(OLD_ELEMENT_KEY)
val newElement: CompressionAlgorithm? = intent.getParcelableExtraCompat(NEW_ELEMENT_KEY)
if (oldElement == null || newElement == null) return null
return UpdateCompressionBinariesDatabaseRunnable(this,
database,
@ -1228,7 +1231,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
return if (intent.hasExtra(SAVE_DATABASE_KEY)) {
var databaseCopyUri: Uri? = null
if (intent.hasExtra(DATABASE_URI_KEY)) {
databaseCopyUri = intent.getParcelableExtra(DATABASE_URI_KEY)
databaseCopyUri = intent.getParcelableExtraCompat(DATABASE_URI_KEY)
}
SaveDatabaseRunnable(this,
database,
@ -1325,12 +1328,12 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
fun getListNodesFromBundle(database: ContextualDatabase, bundle: Bundle): List<Node> {
val nodesAction = ArrayList<Node>()
bundle.getParcelableArrayList<NodeId<*>>(GROUPS_ID_KEY)?.forEach {
bundle.getParcelableList<NodeId<*>>(GROUPS_ID_KEY)?.forEach {
database.getGroupById(it)?.let { groupRetrieve ->
nodesAction.add(groupRetrieve)
}
}
bundle.getParcelableArrayList<NodeId<UUID>>(ENTRIES_ID_KEY)?.forEach {
bundle.getParcelableList<NodeId<UUID>>(ENTRIES_ID_KEY)?.forEach {
database.getEntryById(it)?.let { entryRetrieve ->
nodesAction.add(entryRetrieve)
}
@ -1339,8 +1342,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
fun getBundleFromListNodes(nodes: List<Node>): Bundle {
val groupsId = ArrayList<NodeId<*>>()
val entriesId = ArrayList<NodeId<UUID>>()
val groupsId = mutableListOf<NodeId<*>>()
val entriesId = mutableListOf<NodeId<UUID>>()
nodes.forEach { nodeVersioned ->
when (nodeVersioned.type) {
Type.GROUP -> {
@ -1352,8 +1355,8 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
}
}
return Bundle().apply {
putParcelableArrayList(GROUPS_ID_KEY, groupsId)
putParcelableArrayList(ENTRIES_ID_KEY, entriesId)
putParcelableList(GROUPS_ID_KEY, groupsId)
putParcelableList(ENTRIES_ID_KEY, entriesId)
}
}
}

View file

@ -32,6 +32,7 @@ import com.kunzisoft.keepass.model.EntryInfo
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.timeout.TimeoutHelper
import com.kunzisoft.keepass.utils.LOCK_ACTION
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableExtraCompat
class KeyboardEntryNotificationService : LockNotificationService() {
@ -73,7 +74,7 @@ class KeyboardEntryNotificationService : LockNotificationService() {
else -> {
notificationManager?.cancel(notificationId)
if (intent.hasExtra(ENTRY_INFO_KEY)) {
intent.getParcelableExtra<EntryInfo>(ENTRY_INFO_KEY)?.let {
intent.getParcelableExtraCompat<EntryInfo>(ENTRY_INFO_KEY)?.let {
newNotification(it)
}
}

View file

@ -43,6 +43,8 @@ import com.kunzisoft.keepass.services.DatabaseTaskNotificationService
import com.kunzisoft.keepass.settings.preference.*
import com.kunzisoft.keepass.settings.preferencedialogfragment.*
import com.kunzisoft.keepass.tasks.ActionRunnable
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableCompat
import com.kunzisoft.keepass.utils.ParcelableUtil.getSerializableCompat
import com.kunzisoft.keepass.viewmodels.DatabaseViewModel
class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetrieval {
@ -433,8 +435,8 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev
dbCustomColorPref?.summary = defaultColorToShow
}
DatabaseTaskNotificationService.ACTION_DATABASE_UPDATE_COMPRESSION_TASK -> {
val oldCompression = data.getSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY) as CompressionAlgorithm
val newCompression = data.getSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY) as CompressionAlgorithm
val oldCompression = data.getSerializableCompat<CompressionAlgorithm>(DatabaseTaskNotificationService.OLD_ELEMENT_KEY)
val newCompression = data.getSerializableCompat<CompressionAlgorithm>(DatabaseTaskNotificationService.NEW_ELEMENT_KEY)
val algorithmToShow =
if (result.isSuccess) {
newCompression
@ -442,11 +444,11 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev
mDatabase?.compressionAlgorithm = oldCompression
oldCompression
}
dbDataCompressionPref?.summary = algorithmToShow.getLocalizedName(resources)
dbDataCompressionPref?.summary = algorithmToShow?.getLocalizedName(resources)
}
DatabaseTaskNotificationService.ACTION_DATABASE_UPDATE_RECYCLE_BIN_TASK -> {
val oldRecycleBin = data.getParcelable<Group?>(DatabaseTaskNotificationService.OLD_ELEMENT_KEY)
val newRecycleBin = data.getParcelable<Group?>(DatabaseTaskNotificationService.NEW_ELEMENT_KEY)
val oldRecycleBin = data.getParcelableCompat<Group>(DatabaseTaskNotificationService.OLD_ELEMENT_KEY)
val newRecycleBin = data.getParcelableCompat<Group>(DatabaseTaskNotificationService.NEW_ELEMENT_KEY)
val recycleBinToShow =
if (result.isSuccess) {
newRecycleBin
@ -457,8 +459,8 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev
refreshRecycleBinGroup(database)
}
DatabaseTaskNotificationService.ACTION_DATABASE_UPDATE_TEMPLATES_GROUP_TASK -> {
val oldTemplatesGroup = data.getParcelable<Group?>(DatabaseTaskNotificationService.OLD_ELEMENT_KEY)
val newTemplatesGroup = data.getParcelable<Group?>(DatabaseTaskNotificationService.NEW_ELEMENT_KEY)
val oldTemplatesGroup = data.getParcelableCompat<Group>(DatabaseTaskNotificationService.OLD_ELEMENT_KEY)
val newTemplatesGroup = data.getParcelableCompat<Group>(DatabaseTaskNotificationService.NEW_ELEMENT_KEY)
val templatesGroupToShow =
if (result.isSuccess) {
newTemplatesGroup
@ -499,8 +501,8 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev
--------
*/
DatabaseTaskNotificationService.ACTION_DATABASE_UPDATE_ENCRYPTION_TASK -> {
val oldEncryption = data.getSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY) as EncryptionAlgorithm
val newEncryption = data.getSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY) as EncryptionAlgorithm
val oldEncryption = data.getSerializableCompat<EncryptionAlgorithm>(DatabaseTaskNotificationService.OLD_ELEMENT_KEY)
val newEncryption = data.getSerializableCompat<EncryptionAlgorithm>(DatabaseTaskNotificationService.NEW_ELEMENT_KEY)
val algorithmToShow =
if (result.isSuccess) {
newEncryption
@ -511,8 +513,8 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev
mEncryptionAlgorithmPref?.summary = algorithmToShow.toString()
}
DatabaseTaskNotificationService.ACTION_DATABASE_UPDATE_KEY_DERIVATION_TASK -> {
val oldKeyDerivationEngine = data.getSerializable(DatabaseTaskNotificationService.OLD_ELEMENT_KEY) as KdfEngine
val newKeyDerivationEngine = data.getSerializable(DatabaseTaskNotificationService.NEW_ELEMENT_KEY) as KdfEngine
val oldKeyDerivationEngine = data.getSerializableCompat<KdfEngine>(DatabaseTaskNotificationService.OLD_ELEMENT_KEY)
val newKeyDerivationEngine = data.getSerializableCompat<KdfEngine>(DatabaseTaskNotificationService.NEW_ELEMENT_KEY)
val kdfEngineToShow =
if (result.isSuccess) {
newKeyDerivationEngine
@ -522,10 +524,10 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment(), DatabaseRetriev
}
mKeyDerivationPref?.summary = kdfEngineToShow.toString()
mRoundPref?.summary = kdfEngineToShow.defaultKeyRounds.toString()
mRoundPref?.summary = kdfEngineToShow?.defaultKeyRounds.toString()
// Disable memory and parallelism if not available
mMemoryPref?.summary = kdfEngineToShow.defaultMemoryUsage.toString()
mParallelismPref?.summary = kdfEngineToShow.defaultParallelism.toString()
mMemoryPref?.summary = kdfEngineToShow?.defaultMemoryUsage.toString()
mParallelismPref?.summary = kdfEngineToShow?.defaultParallelism.toString()
}
DatabaseTaskNotificationService.ACTION_DATABASE_UPDATE_ITERATIONS_TASK -> {
val oldIterations = data.getLong(DatabaseTaskNotificationService.OLD_ELEMENT_KEY)

View file

@ -28,6 +28,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.model.SearchInfo
import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.AutofillBlocklistAdapter
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableArrayCompat
import java.util.*
import kotlin.Comparator
import kotlin.collections.HashSet
@ -49,11 +50,9 @@ abstract class AutofillBlocklistPreferenceDialogFragmentCompat
super.onCreate(savedInstanceState)
// To get items for saved instance state
savedInstanceState?.getParcelableArray(ITEMS_KEY)?.let {
savedInstanceState?.getParcelableArrayCompat<SearchInfo>(ITEMS_KEY)?.let {
it.forEach { itemSaved ->
(itemSaved as SearchInfo?)?.let { item ->
persistedItems.add(item)
}
persistedItems.add(itemSaved)
}
} ?: run {
// Or from preference

View file

@ -32,6 +32,7 @@ import com.kunzisoft.keepass.BuildConfig
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.app.database.FileDatabaseHistoryAction
import com.kunzisoft.keepass.education.Education
import com.kunzisoft.keepass.utils.ParcelableUtil.getParcelableExtraCompat
import com.kunzisoft.keepass.utils.UriHelper.withContentScheme
import com.kunzisoft.keepass.utils.UriHelper.withFileScheme
import java.io.File
@ -183,7 +184,7 @@ object UriUtil {
}
}
} catch (e: Exception) {
return this.getParcelableExtra(key)
return this.getParcelableExtraCompat(key)
}
return null
}

View file

@ -12,6 +12,7 @@ import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.google.android.material.textfield.TextInputLayout
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import com.kunzisoft.keepass.utils.UriUtil.getDocumentFile
@ -92,7 +93,7 @@ class KeyFileSelectionView @JvmOverloads constructor(context: Context,
constructor(superState: Parcelable?) : super(superState) {}
private constructor(parcel: Parcel) : super(parcel) {
mUri = parcel.readParcelable(Uri::class.java.classLoader)
mUri = parcel.readParcelableCompat()
}
override fun writeToParcel(out: Parcel, flags: Int) {

View file

@ -26,6 +26,7 @@ import com.kunzisoft.keepass.model.EntryInfo
import com.kunzisoft.keepass.otp.OtpElement
import com.kunzisoft.keepass.otp.OtpEntryFields
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
abstract class TemplateAbstractView<
@ -710,10 +711,8 @@ abstract class TemplateAbstractView<
constructor(superState: Parcelable?) : super(superState)
private constructor(parcel: Parcel) : super(parcel) {
template = parcel.readParcelable(Template::class.java.classLoader)
?: template
entryInfo = parcel.readParcelable(EntryInfo::class.java.classLoader)
?: entryInfo
template = parcel.readParcelableCompat() ?: template
entryInfo = parcel.readParcelableCompat() ?: entryInfo
val dateTimeViewId = parcel.readInt()
if (dateTimeViewId != -1)
tempDateTimeViewId = dateTimeViewId

View file

@ -2,11 +2,11 @@ package com.kunzisoft.keepass.viewmodels
import android.os.Parcel
import android.os.Parcelable
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
class IconPickerViewModel: ViewModel() {
@ -69,7 +69,7 @@ class IconPickerViewModel: ViewModel() {
var errorConsumed: Boolean = false): Parcelable {
constructor(parcel: Parcel) : this(
parcel.readParcelable(IconImageCustom::class.java.classLoader),
parcel.readParcelableCompat(),
parcel.readByte() != 0.toByte(),
parcel.readInt(),
parcel.readByte() != 0.toByte())

View file

@ -23,6 +23,7 @@ import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.database.element.binary.BinaryByte
import com.kunzisoft.keepass.database.element.binary.BinaryData
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
data class Attachment(var name: String,
@ -30,7 +31,7 @@ data class Attachment(var name: String,
constructor(parcel: Parcel) : this(
parcel.readString() ?: "",
parcel.readParcelable(BinaryData::class.java.classLoader) ?: BinaryByte()
parcel.readParcelableCompat<BinaryData>() ?: BinaryByte()
)
override fun writeToParcel(parcel: Parcel, flags: Int) {

View file

@ -21,7 +21,8 @@ package com.kunzisoft.keepass.database.element
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.utils.ParcelableUtil
import com.kunzisoft.keepass.utils.ParcelableUtil.readStringParcelableMap
import com.kunzisoft.keepass.utils.ParcelableUtil.writeStringParcelableMap
import java.util.*
class CustomData : Parcelable {
@ -37,9 +38,7 @@ class CustomData : Parcelable {
constructor(parcel: Parcel) {
mCustomDataItems.clear()
mCustomDataItems.putAll(ParcelableUtil
.readStringParcelableMap(parcel, CustomDataItem::class.java)
)
mCustomDataItems.putAll(parcel.readStringParcelableMap())
}
fun get(key: String): CustomDataItem? {
@ -73,7 +72,7 @@ class CustomData : Parcelable {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
ParcelableUtil.writeStringParcelableMap(parcel, flags, mCustomDataItems)
parcel.writeStringParcelableMap(mCustomDataItems, flags)
}
override fun describeContents(): Int {

View file

@ -2,6 +2,7 @@ package com.kunzisoft.keepass.database.element
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
class CustomDataItem : Parcelable {
@ -12,7 +13,7 @@ class CustomDataItem : Parcelable {
constructor(parcel: Parcel) {
key = parcel.readString() ?: ""
value = parcel.readString() ?: ""
lastModificationTime = parcel.readParcelable(DateInstant::class.java.classLoader)
lastModificationTime = parcel.readParcelableCompat()
}
constructor(key: String, value: String, lastModificationTime: DateInstant? = null) {

View file

@ -21,6 +21,7 @@ package com.kunzisoft.keepass.database.element
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.utils.ParcelableUtil.readSerializableCompat
import com.kunzisoft.keepass.utils.readEnum
import com.kunzisoft.keepass.utils.writeEnum
import org.joda.time.Duration
@ -113,7 +114,7 @@ class DateInstant : Parcelable {
}
constructor(parcel: Parcel) {
jDate = parcel.readSerializable() as? Date? ?: jDate
jDate = parcel.readSerializableCompat() ?: jDate
mType = parcel.readEnum<Type>() ?: mType
}

View file

@ -23,6 +23,7 @@ import android.os.Parcel
import android.os.ParcelUuid
import android.os.Parcelable
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import java.util.*
class DeletedObject : Parcelable {
@ -38,8 +39,8 @@ class DeletedObject : Parcelable {
}
constructor(parcel: Parcel) {
uuid = parcel.readParcelable<ParcelUuid>(ParcelUuid::class.java.classLoader)?.uuid ?: DatabaseVersioned.UUID_ZERO
deletionTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: deletionTime
uuid = parcel.readParcelableCompat<ParcelUuid>()?.uuid ?: DatabaseVersioned.UUID_ZERO
deletionTime = parcel.readParcelableCompat() ?: deletionTime
}
override fun equals(other: Any?): Boolean {

View file

@ -36,6 +36,7 @@ import com.kunzisoft.keepass.database.element.node.Type
import com.kunzisoft.keepass.model.EntryInfo
import com.kunzisoft.keepass.otp.OtpElement
import com.kunzisoft.keepass.otp.OtpEntryFields
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import com.kunzisoft.keepass.utils.StringUtil.toFormattedColorInt
import com.kunzisoft.keepass.utils.StringUtil.toFormattedColorString
import java.util.UUID
@ -76,8 +77,8 @@ class Entry : Node, EntryVersionedInterface<Group> {
}
constructor(parcel: Parcel) {
entryKDB = parcel.readParcelable(EntryKDB::class.java.classLoader)
entryKDBX = parcel.readParcelable(EntryKDBX::class.java.classLoader)
entryKDB = parcel.readParcelableCompat()
entryKDBX = parcel.readParcelableCompat()
}
override fun describeContents(): Int {

View file

@ -22,6 +22,7 @@ package com.kunzisoft.keepass.database.element
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.database.element.security.ProtectedString
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
class Field : Parcelable {
@ -40,7 +41,7 @@ class Field : Parcelable {
constructor(parcel: Parcel) {
this.name = parcel.readString() ?: name
this.protectedValue = parcel.readParcelable(ProtectedString::class.java.classLoader) ?: protectedValue
this.protectedValue = parcel.readParcelableCompat() ?: protectedValue
}
override fun describeContents(): Int {

View file

@ -29,6 +29,7 @@ import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.database.element.node.*
import com.kunzisoft.keepass.model.EntryInfo
import com.kunzisoft.keepass.model.GroupInfo
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import java.util.*
import kotlin.collections.ArrayList
@ -75,8 +76,8 @@ class Group : Node, GroupVersionedInterface<Group, Entry> {
}
constructor(parcel: Parcel) {
groupKDB = parcel.readParcelable(GroupKDB::class.java.classLoader)
groupKDBX = parcel.readParcelable(GroupKDBX::class.java.classLoader)
groupKDB = parcel.readParcelableCompat()
groupKDBX = parcel.readParcelableCompat()
isVirtual = parcel.readByte().toInt() != 0
}

View file

@ -31,6 +31,7 @@ import com.kunzisoft.keepass.database.element.node.NodeId
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
import com.kunzisoft.keepass.database.element.node.NodeKDBInterface
import com.kunzisoft.keepass.database.element.node.Type
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import java.util.*
/**
@ -121,7 +122,7 @@ class EntryKDB : EntryVersioned<Int, UUID, GroupKDB, EntryKDB>, NodeKDBInterface
}
override fun readParentParcelable(parcel: Parcel): GroupKDB? {
return parcel.readParcelable(GroupKDB::class.java.classLoader)
return parcel.readParcelableCompat()
}
override fun writeParentParcelable(parent: GroupKDB?, parcel: Parcel, flags: Int) {

View file

@ -22,7 +22,11 @@ package com.kunzisoft.keepass.database.element.entry
import android.os.Parcel
import android.os.ParcelUuid
import android.os.Parcelable
import com.kunzisoft.keepass.database.element.*
import com.kunzisoft.keepass.database.element.Attachment
import com.kunzisoft.keepass.database.element.CustomData
import com.kunzisoft.keepass.database.element.DateInstant
import com.kunzisoft.keepass.database.element.Field
import com.kunzisoft.keepass.database.element.Tags
import com.kunzisoft.keepass.database.element.binary.AttachmentPool
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
@ -32,11 +36,14 @@ import com.kunzisoft.keepass.database.element.node.NodeIdUUID
import com.kunzisoft.keepass.database.element.node.NodeKDBXInterface
import com.kunzisoft.keepass.database.element.node.Type
import com.kunzisoft.keepass.database.element.security.ProtectedString
import com.kunzisoft.keepass.utils.ParcelableUtil
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import com.kunzisoft.keepass.utils.ParcelableUtil.readStringIntMap
import com.kunzisoft.keepass.utils.ParcelableUtil.readStringParcelableMap
import com.kunzisoft.keepass.utils.ParcelableUtil.writeStringIntMap
import com.kunzisoft.keepass.utils.ParcelableUtil.writeStringParcelableMap
import com.kunzisoft.keepass.utils.UnsignedLong
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.LinkedHashMap
import java.util.Date
import java.util.UUID
class EntryKDBX : EntryVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInterface {
@ -67,22 +74,22 @@ class EntryKDBX : EntryVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInte
constructor(parcel: Parcel) : super(parcel) {
usageCount = UnsignedLong(parcel.readLong())
locationChanged = parcel.readParcelable(DateInstant::class.java.classLoader) ?: locationChanged
customData = parcel.readParcelable(CustomData::class.java.classLoader) ?: CustomData()
fields = ParcelableUtil.readStringParcelableMap(parcel, ProtectedString::class.java)
binaries = ParcelableUtil.readStringIntMap(parcel)
locationChanged = parcel.readParcelableCompat() ?: locationChanged
customData = parcel.readParcelableCompat() ?: CustomData()
fields = parcel.readStringParcelableMap()
binaries = parcel.readStringIntMap()
foregroundColor = parcel.readString() ?: foregroundColor
backgroundColor = parcel.readString() ?: backgroundColor
overrideURL = parcel.readString() ?: overrideURL
tags = parcel.readParcelable(Tags::class.java.classLoader) ?: tags
previousParentGroup = parcel.readParcelable<ParcelUuid>(ParcelUuid::class.java.classLoader)?.uuid ?: DatabaseVersioned.UUID_ZERO
autoType = parcel.readParcelable(AutoType::class.java.classLoader) ?: autoType
tags = parcel.readParcelableCompat() ?: tags
previousParentGroup = parcel.readParcelableCompat<ParcelUuid>()?.uuid ?: DatabaseVersioned.UUID_ZERO
autoType = parcel.readParcelableCompat() ?: autoType
parcel.readTypedList(history, CREATOR)
additional = parcel.readString() ?: additional
}
override fun readParentParcelable(parcel: Parcel): GroupKDBX? {
return parcel.readParcelable(GroupKDBX::class.java.classLoader)
return parcel.readParcelableCompat()
}
override fun writeParentParcelable(parent: GroupKDBX?, parcel: Parcel, flags: Int) {
@ -94,8 +101,8 @@ class EntryKDBX : EntryVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInte
dest.writeLong(usageCount.toKotlinLong())
dest.writeParcelable(locationChanged, flags)
dest.writeParcelable(customData, flags)
ParcelableUtil.writeStringParcelableMap(dest, flags, fields)
ParcelableUtil.writeStringIntMap(dest, binaries)
dest.writeStringParcelableMap(fields, flags)
dest.writeStringIntMap(binaries)
dest.writeString(foregroundColor)
dest.writeString(backgroundColor)
dest.writeString(overrideURL)

View file

@ -27,6 +27,7 @@ import com.kunzisoft.keepass.database.element.node.NodeId
import com.kunzisoft.keepass.database.element.node.NodeIdInt
import com.kunzisoft.keepass.database.element.node.NodeKDBInterface
import com.kunzisoft.keepass.database.element.node.Type
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import java.util.*
class GroupKDB : GroupVersioned<Int, UUID, GroupKDB, EntryKDB>, NodeKDBInterface {
@ -41,7 +42,7 @@ class GroupKDB : GroupVersioned<Int, UUID, GroupKDB, EntryKDB>, NodeKDBInterface
}
override fun readParentParcelable(parcel: Parcel): GroupKDB? {
return parcel.readParcelable(GroupKDB::class.java.classLoader)
return parcel.readParcelableCompat()
}
override fun writeParentParcelable(parent: GroupKDB?, parcel: Parcel, flags: Int) {

View file

@ -31,6 +31,8 @@ import com.kunzisoft.keepass.database.element.node.NodeId
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
import com.kunzisoft.keepass.database.element.node.NodeKDBXInterface
import com.kunzisoft.keepass.database.element.node.Type
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import com.kunzisoft.keepass.utils.ParcelableUtil.readSerializableCompat
import com.kunzisoft.keepass.utils.UnsignedLong
import java.util.*
@ -65,8 +67,8 @@ class GroupKDBX : GroupVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInte
constructor(parcel: Parcel) : super(parcel) {
usageCount = UnsignedLong(parcel.readLong())
locationChanged = parcel.readParcelable(DateInstant::class.java.classLoader) ?: locationChanged
customData = parcel.readParcelable(CustomData::class.java.classLoader) ?: CustomData()
locationChanged = parcel.readParcelableCompat() ?: locationChanged
customData = parcel.readParcelableCompat() ?: CustomData()
notes = parcel.readString() ?: notes
isExpanded = parcel.readByte().toInt() != 0
val isSearchingEnabled = parcel.readInt()
@ -74,13 +76,13 @@ class GroupKDBX : GroupVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInte
val isAutoTypeEnabled = parcel.readInt()
enableAutoType = if (isAutoTypeEnabled == -1) null else isAutoTypeEnabled == 1
defaultAutoTypeSequence = parcel.readString() ?: defaultAutoTypeSequence
lastTopVisibleEntry = parcel.readSerializable() as UUID
tags = parcel.readParcelable(Tags::class.java.classLoader) ?: tags
previousParentGroup = parcel.readParcelable<ParcelUuid>(ParcelUuid::class.java.classLoader)?.uuid ?: DatabaseVersioned.UUID_ZERO
lastTopVisibleEntry = parcel.readSerializableCompat() ?: UUID.randomUUID()
tags = parcel.readParcelableCompat() ?: tags
previousParentGroup = parcel.readParcelableCompat<ParcelUuid>()?.uuid ?: DatabaseVersioned.UUID_ZERO
}
override fun readParentParcelable(parcel: Parcel): GroupKDBX? {
return parcel.readParcelable(GroupKDBX::class.java.classLoader)
return parcel.readParcelableCompat()
}
override fun writeParentParcelable(parent: GroupKDBX?, parcel: Parcel, flags: Int) {

View file

@ -21,6 +21,7 @@ package com.kunzisoft.keepass.database.element.icon
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
class IconImage() : IconImageDraw() {
@ -42,8 +43,8 @@ class IconImage() : IconImageDraw() {
}
constructor(parcel: Parcel) : this() {
standard = parcel.readParcelable(IconImageStandard::class.java.classLoader) ?: standard
custom = parcel.readParcelable(IconImageCustom::class.java.classLoader) ?: custom
standard = parcel.readParcelableCompat() ?: standard
custom = parcel.readParcelableCompat() ?: custom
}
override fun writeToParcel(parcel: Parcel, flags: Int) {

View file

@ -24,7 +24,8 @@ import android.os.ParcelUuid
import android.os.Parcelable
import com.kunzisoft.keepass.database.element.DateInstant
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
import java.util.*
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import java.util.UUID
class IconImageCustom : IconImageDraw {
@ -55,9 +56,9 @@ class IconImageCustom : IconImageDraw {
}
constructor(parcel: Parcel) {
uuid = parcel.readParcelable<ParcelUuid>(ParcelUuid::class.java.classLoader)?.uuid ?: DatabaseVersioned.UUID_ZERO
uuid = parcel.readParcelableCompat<ParcelUuid>()?.uuid ?: DatabaseVersioned.UUID_ZERO
name = parcel.readString() ?: name
lastModificationTime = parcel.readParcelable(DateInstant::class.java.classLoader)
lastModificationTime = parcel.readParcelableCompat()
}
override fun writeToParcel(dest: Parcel, flags: Int) {

View file

@ -22,6 +22,7 @@ package com.kunzisoft.keepass.database.element.node
import android.os.Parcel
import android.os.ParcelUuid
import android.os.Parcelable
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import com.kunzisoft.keepass.utils.UuidUtil
import java.util.*
@ -37,7 +38,7 @@ class NodeIdUUID : NodeId<UUID> {
}
constructor(parcel: Parcel) {
id = parcel.readParcelable<ParcelUuid>(ParcelUuid::class.java.classLoader)?.uuid ?: id
id = parcel.readParcelableCompat<ParcelUuid>()?.uuid ?: id
}
override fun writeToParcel(dest: Parcel, flags: Int) {

View file

@ -26,6 +26,7 @@ import com.kunzisoft.keepass.database.element.DateInstant
import com.kunzisoft.keepass.database.element.entry.EntryVersionedInterface
import com.kunzisoft.keepass.database.element.group.GroupVersionedInterface
import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
/**
* Abstract class who manage Groups and Entries
@ -43,13 +44,13 @@ abstract class NodeVersioned<IdType, Parent : GroupVersionedInterface<Parent, En
protected constructor()
protected constructor(parcel: Parcel) {
this.nodeId = parcel.readParcelable(NodeId::class.java.classLoader) ?: nodeId
this.nodeId = parcel.readParcelableCompat() ?: nodeId
this.parent = this.readParentParcelable(parcel)
this.icon = parcel.readParcelable(IconImage::class.java.classLoader) ?: icon
this.creationTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: creationTime
this.lastModificationTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: lastModificationTime
this.lastAccessTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: lastAccessTime
this.expiryTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: expiryTime
this.icon = parcel.readParcelableCompat() ?: icon
this.creationTime = parcel.readParcelableCompat() ?: creationTime
this.lastModificationTime = parcel.readParcelableCompat() ?: lastModificationTime
this.lastAccessTime = parcel.readParcelableCompat() ?: lastAccessTime
this.expiryTime = parcel.readParcelableCompat() ?: expiryTime
this.expires = parcel.readByte().toInt() != 0
}

View file

@ -23,6 +23,8 @@ import android.os.ParcelUuid
import android.os.Parcelable
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.utils.ParcelableUtil.readListCompat
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import java.util.*
import kotlin.collections.ArrayList
@ -83,12 +85,12 @@ class Template : Parcelable {
constructor(parcel: Parcel) {
version = parcel.readInt()
uuid = parcel.readParcelable<ParcelUuid>(ParcelUuid::class.java.classLoader)?.uuid ?: uuid
uuid = parcel.readParcelableCompat<ParcelUuid>()?.uuid ?: uuid
title = parcel.readString() ?: title
icon = parcel.readParcelable(IconImage::class.java.classLoader) ?: icon
icon = parcel.readParcelableCompat() ?: icon
backgroundColor = parcel.readInt()
foregroundColor = parcel.readInt()
parcel.readList(sections, TemplateSection::class.java.classLoader)
parcel.readListCompat(sections)
}
override fun writeToParcel(parcel: Parcel, flags: Int) {

View file

@ -20,7 +20,7 @@ package com.kunzisoft.keepass.database.element.template
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.utils.ParcelableUtil
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import com.kunzisoft.keepass.utils.readEnum
import com.kunzisoft.keepass.utils.writeEnum
@ -34,7 +34,7 @@ data class TemplateAttribute(var label: String,
parcel.readString() ?: "",
parcel.readEnum<TemplateAttributeType>() ?: TemplateAttributeType.TEXT,
parcel.readByte() != 0.toByte(),
parcel.readParcelable(TemplateAttributeOption::class.java.classLoader) ?: TemplateAttributeOption(),
parcel.readParcelableCompat() ?: TemplateAttributeOption(),
parcel.readEnum<TemplateAttributeAction>() ?: TemplateAttributeAction.NONE)
override fun writeToParcel(parcel: Parcel, flags: Int) {

View file

@ -21,18 +21,22 @@ package com.kunzisoft.keepass.database.element.template
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.database.element.DateInstant
import com.kunzisoft.keepass.utils.ParcelableUtil
import com.kunzisoft.keepass.utils.ParcelableUtil.readStringStringMap
import com.kunzisoft.keepass.utils.ParcelableUtil.writeStringStringMap
class TemplateAttributeOption() : Parcelable {
private val mOptions: MutableMap<String, String> = mutableMapOf()
constructor(parcel: Parcel) : this() {
ParcelableUtil.readStringParcelableMap(parcel)
mOptions.apply {
clear()
putAll(parcel.readStringStringMap())
}
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
ParcelableUtil.writeStringParcelableMap(parcel, LinkedHashMap(mOptions))
parcel.writeStringStringMap(mOptions)
}
override fun describeContents(): Int {

View file

@ -20,21 +20,22 @@ package com.kunzisoft.keepass.database.element.template
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.utils.ParcelableUtil.readListCompat
class TemplateSection: Parcelable {
var name: String = ""
var attributes: List<TemplateAttribute> = ArrayList()
var attributes: MutableList<TemplateAttribute> = mutableListOf()
private set
constructor(attributes: List<TemplateAttribute>, name: String = "") {
constructor(attributes: MutableList<TemplateAttribute>, name: String = "") {
this.name = name
this.attributes = attributes
}
constructor(parcel: Parcel) {
this.name = parcel.readString() ?: name
parcel.readList(this.attributes, TemplateAttribute::class.java.classLoader)
parcel.readListCompat(this.attributes)
}
override fun writeToParcel(parcel: Parcel, flags: Int) {

View file

@ -22,6 +22,7 @@ package com.kunzisoft.keepass.model
import android.net.Uri
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import com.kunzisoft.keepass.utils.readEnum
import com.kunzisoft.keepass.utils.writeEnum
@ -32,7 +33,7 @@ class CipherDecryptDatabase(): Parcelable {
var decryptedValue: ByteArray = byteArrayOf()
constructor(parcel: Parcel): this() {
databaseUri = parcel.readParcelable(Uri::class.java.classLoader)
databaseUri = parcel.readParcelableCompat()
credentialStorage = parcel.readEnum<CredentialStorage>() ?: credentialStorage
decryptedValue = ByteArray(parcel.readInt())
parcel.readByteArray(decryptedValue)

View file

@ -22,6 +22,7 @@ package com.kunzisoft.keepass.model
import android.net.Uri
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import com.kunzisoft.keepass.utils.readEnum
import com.kunzisoft.keepass.utils.writeEnum
@ -33,7 +34,7 @@ class CipherEncryptDatabase(): Parcelable {
var specParameters: ByteArray = byteArrayOf()
constructor(parcel: Parcel): this() {
databaseUri = parcel.readParcelable(Uri::class.java.classLoader)
databaseUri = parcel.readParcelableCompat()
credentialStorage = parcel.readEnum<CredentialStorage>() ?: credentialStorage
encryptedValue = ByteArray(parcel.readInt())
parcel.readByteArray(encryptedValue)

View file

@ -2,6 +2,7 @@ package com.kunzisoft.keepass.model
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.utils.ParcelableUtil.readSerializableCompat
import org.joda.time.DateTime
data class CreditCard(val cardholder: String?,
@ -12,7 +13,7 @@ data class CreditCard(val cardholder: String?,
constructor(parcel: Parcel) : this(
parcel.readString(),
parcel.readString(),
parcel.readSerializable() as DateTime?,
parcel.readSerializableCompat<DateTime>(),
parcel.readString()) {
}

View file

@ -23,6 +23,7 @@ import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.database.element.Attachment
import com.kunzisoft.keepass.database.element.binary.BinaryByte
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import com.kunzisoft.keepass.utils.readEnum
import com.kunzisoft.keepass.utils.writeEnum
@ -33,7 +34,7 @@ data class EntryAttachmentState(var attachment: Attachment,
var previewState: AttachmentState = AttachmentState.NULL) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readParcelable(Attachment::class.java.classLoader) ?: Attachment("", BinaryByte()),
parcel.readParcelableCompat() ?: Attachment("", BinaryByte()),
parcel.readEnum<StreamDirection>() ?: StreamDirection.DOWNLOAD,
parcel.readEnum<AttachmentState>() ?: AttachmentState.NULL,
parcel.readInt(),

View file

@ -29,6 +29,8 @@ import com.kunzisoft.keepass.database.element.template.TemplateField
import com.kunzisoft.keepass.otp.OtpElement
import com.kunzisoft.keepass.otp.OtpEntryFields
import com.kunzisoft.keepass.otp.OtpEntryFields.OTP_TOKEN_FIELD
import com.kunzisoft.keepass.utils.ParcelableUtil.readListCompat
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import java.util.*
class EntryInfo : NodeInfo {
@ -50,20 +52,20 @@ class EntryInfo : NodeInfo {
constructor() : super()
constructor(parcel: Parcel) : super(parcel) {
id = parcel.readParcelable<ParcelUuid>(ParcelUuid::class.java.classLoader)?.uuid ?: id
id = parcel.readParcelableCompat<ParcelUuid>()?.uuid ?: id
username = parcel.readString() ?: username
password = parcel.readString() ?: password
url = parcel.readString() ?: url
notes = parcel.readString() ?: notes
tags = parcel.readParcelable(Tags::class.java.classLoader) ?: tags
tags = parcel.readParcelableCompat() ?: tags
val readBgColor = parcel.readInt()
backgroundColor = if (readBgColor == -1) null else readBgColor
val readFgColor = parcel.readInt()
foregroundColor = if (readFgColor == -1) null else readFgColor
parcel.readList(customFields, Field::class.java.classLoader)
parcel.readList(attachments, Attachment::class.java.classLoader)
autoType = parcel.readParcelable(AutoType::class.java.classLoader) ?: autoType
otpModel = parcel.readParcelable(OtpModel::class.java.classLoader) ?: otpModel
parcel.readListCompat(customFields)
parcel.readListCompat(attachments)
autoType = parcel.readParcelableCompat() ?: autoType
otpModel = parcel.readParcelableCompat() ?: otpModel
isTemplate = parcel.readByte().toInt() != 0
}

View file

@ -3,6 +3,7 @@ package com.kunzisoft.keepass.model
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.database.element.Field
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
class FocusedEditField : Parcelable {
@ -13,7 +14,7 @@ class FocusedEditField : Parcelable {
constructor()
constructor(parcel: Parcel) {
this.field = parcel.readParcelable(Field::class.java.classLoader)
this.field = parcel.readParcelableCompat()
this.cursorSelectionStart = parcel.readInt()
this.cursorSelectionEnd = parcel.readInt()
}

View file

@ -6,6 +6,7 @@ import android.os.Parcelable
import com.kunzisoft.keepass.database.element.Tags
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
import com.kunzisoft.keepass.database.element.icon.IconImageStandard.Companion.FOLDER_ID
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
import java.util.*
class GroupInfo : NodeInfo {
@ -24,14 +25,14 @@ class GroupInfo : NodeInfo {
constructor(): super()
constructor(parcel: Parcel): super(parcel) {
id = parcel.readParcelable<ParcelUuid>(ParcelUuid::class.java.classLoader)?.uuid ?: id
id = parcel.readParcelableCompat<ParcelUuid>()?.uuid ?: id
notes = parcel.readString()
val isSearchingEnabled = parcel.readInt()
searchable = if (isSearchingEnabled == -1) null else isSearchingEnabled == 1
val isAutoTypeEnabled = parcel.readInt()
enableAutoType = if (isAutoTypeEnabled == -1) null else isAutoTypeEnabled == 1
defaultAutoTypeSequence = parcel.readString() ?: defaultAutoTypeSequence
tags = parcel.readParcelable(Tags::class.java.classLoader) ?: tags
tags = parcel.readParcelableCompat() ?: tags
}
override fun writeToParcel(parcel: Parcel, flags: Int) {

View file

@ -5,8 +5,7 @@ import android.os.Parcelable
import com.kunzisoft.keepass.database.element.CustomData
import com.kunzisoft.keepass.database.element.DateInstant
import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.utils.UuidUtil
import java.util.*
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
open class NodeInfo() : Parcelable {
@ -20,12 +19,12 @@ open class NodeInfo() : Parcelable {
constructor(parcel: Parcel) : this() {
title = parcel.readString() ?: title
icon = parcel.readParcelable(IconImage::class.java.classLoader) ?: icon
creationTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: creationTime
lastModificationTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: lastModificationTime
icon = parcel.readParcelableCompat() ?: icon
creationTime = parcel.readParcelableCompat() ?: creationTime
lastModificationTime = parcel.readParcelableCompat() ?: lastModificationTime
expires = parcel.readInt() != 0
expiryTime = parcel.readParcelable(DateInstant::class.java.classLoader) ?: expiryTime
customData = parcel.readParcelable(CustomData::class.java.classLoader) ?: customData
expiryTime = parcel.readParcelableCompat() ?: expiryTime
customData = parcel.readParcelableCompat() ?: customData
}
override fun writeToParcel(parcel: Parcel, flags: Int) {

View file

@ -2,6 +2,7 @@ package com.kunzisoft.keepass.model
import android.os.Parcel
import android.os.Parcelable
import com.kunzisoft.keepass.utils.ParcelableUtil.readParcelableCompat
data class RegisterInfo(val searchInfo: SearchInfo,
val username: String?,
@ -9,10 +10,10 @@ data class RegisterInfo(val searchInfo: SearchInfo,
val creditCard: CreditCard?): Parcelable {
constructor(parcel: Parcel) : this(
parcel.readParcelable(SearchInfo::class.java.classLoader) ?: SearchInfo(),
parcel.readParcelableCompat() ?: SearchInfo(),
parcel.readString() ?: "",
parcel.readString() ?: "",
parcel.readParcelable(CreditCard::class.java.classLoader)) {
parcel.readParcelableCompat()) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {

View file

@ -19,34 +19,111 @@
*/
package com.kunzisoft.keepass.utils
import android.content.Intent
import android.os.Build.VERSION.SDK_INT
import android.os.Bundle
import android.os.Parcel
import android.os.Parcelable
import java.io.Serializable
import java.util.*
import kotlin.collections.LinkedHashMap
object ParcelableUtil {
inline fun <reified T : Parcelable> Intent.getParcelableExtraCompat(key: String?): T? = when {
key == null -> null
SDK_INT >= 33 -> getParcelableExtra(key, T::class.java)
else -> @Suppress("DEPRECATION") getParcelableExtra(key) as? T
}
inline fun <reified T : Serializable> Intent.getSerializableExtraCompat(key: String?): T? = when {
key == null -> null
SDK_INT >= 33 -> getSerializableExtra(key, T::class.java)
else -> @Suppress("DEPRECATION") getSerializableExtra(key) as? T
}
inline fun <reified T : Parcelable> Bundle.getParcelableCompat(key: String?): T? = when {
key == null -> null
SDK_INT >= 33 -> getParcelable(key, T::class.java)
else -> @Suppress("DEPRECATION") getParcelable(key) as? T
}
inline fun <reified T : Serializable> Bundle.getSerializableCompat(key: String?): T? = when {
SDK_INT >= 33 -> getSerializable(key, T::class.java)
else -> @Suppress("DEPRECATION") getSerializable(key) as? T
}
inline fun <reified T : Parcelable> Bundle.getParcelableArrayCompat(key: String?): Array<out T>? {
return when {
SDK_INT >= 33 -> getParcelableArray(key, T::class.java)
else -> @Suppress("DEPRECATION", "UNCHECKED_CAST") (getParcelableArray(key) as? Array<T>)
}
}
inline fun <reified E : Parcelable> Intent.putParcelableList(key: String?, list: MutableList<E>) {
putExtra(key, list.toTypedArray())
}
inline fun <reified E : Parcelable> Intent.getParcelableList(key: String?): MutableList<E>? = when {
SDK_INT >= 33 -> getParcelableArrayExtra(key, E::class.java)?.toMutableList()
else -> @Suppress("DEPRECATION", "UNCHECKED_CAST") (getParcelableArrayExtra(key) as? Array<E>)?.toMutableList()
}
inline fun <reified E : Parcelable> Bundle.putParcelableList(key: String?, list: List<E>) {
putParcelableArray(key, list.toTypedArray())
}
inline fun <reified E : Parcelable> Bundle.getParcelableList(key: String?): MutableList<E>? = when {
SDK_INT >= 33 -> getParcelableArray(key, E::class.java)?.toMutableList()
else -> @Suppress("DEPRECATION", "UNCHECKED_CAST") (getParcelableArray(key) as? Array<E>)?.toMutableList()
}
inline fun <reified T : Parcelable> Parcel.readParcelableCompat(): T? = when {
SDK_INT >= 33 -> readParcelable(T::class.java.classLoader, T::class.java)
else -> @Suppress("DEPRECATION") readParcelable(T::class.java.classLoader) as? T
}
fun <T> Parcel.readParcelableCompat(clazz: Class<T>): T? = when {
SDK_INT >= 33 -> readParcelable(clazz.classLoader, clazz)
else -> @Suppress("DEPRECATION") readParcelable(clazz.classLoader) as? T
}
inline fun <reified T : Serializable> Parcel.readSerializableCompat(): T? = when {
SDK_INT >= 33 -> readSerializable(T::class.java.classLoader, T::class.java)
else -> @Suppress("DEPRECATION") readSerializable() as? T
}
inline fun <reified T> Parcel.readListCompat(outVal: MutableList<T>) {
when {
SDK_INT >= 33 -> readList(outVal, T::class.java.classLoader, T::class.java)
else -> @Suppress("DEPRECATION") readList(outVal, T::class.java.classLoader)
}
}
// For writing to a Parcel
fun <K : Parcelable, V : Parcelable> writeParcelableMap(
parcel: Parcel, flags: Int, map: Map<K, V>) {
parcel.writeInt(map.size)
fun <K : Parcelable, V : Parcelable> Parcel.writeParcelableMap(map: Map<K, V>, flags: Int) {
writeInt(map.size)
for ((key, value) in map) {
parcel.writeParcelable(key, flags)
parcel.writeParcelable(value, flags)
writeParcelable(key, flags)
writeParcelable(value, flags)
}
}
// For reading from a Parcel
fun <K : Parcelable, V : Parcelable> readParcelableMap(
parcel: Parcel, kClass: Class<K>, vClass: Class<V>): Map<K, V> {
val size = parcel.readInt()
inline fun <reified K : Parcelable, reified V : Parcelable> Parcel.readParcelableMap(): Map<K, V> {
val size = readInt()
val map = HashMap<K, V>(size)
for (i in 0 until size) {
val key: K? = try {
parcel.readParcelable(kClass.classLoader)
when {
SDK_INT >= 33 -> readParcelable(K::class.java.classLoader, K::class.java)
else -> @Suppress("DEPRECATION") readParcelable(K::class.java.classLoader)
}
} catch (e: Exception) { null }
val value: V? = try {
parcel.readParcelable(vClass.classLoader)
when {
SDK_INT >= 33 -> readParcelable(V::class.java.classLoader, V::class.java)
else -> @Suppress("DEPRECATION") readParcelable(V::class.java.classLoader)
}
} catch (e: Exception) { null }
if (key != null && value != null)
map[key] = value
@ -55,33 +132,25 @@ object ParcelableUtil {
}
// For writing map with string key to a Parcel
fun <V : Parcelable> writeStringParcelableMap(
parcel: Parcel, flags: Int, map: HashMap<String, V>) {
parcel.writeInt(map.size)
fun <V : Parcelable> Parcel.writeStringParcelableMap(map: HashMap<String, V>, flags: Int) {
writeInt(map.size)
for ((key, value) in map) {
parcel.writeString(key)
parcel.writeParcelable(value, flags)
}
}
// For writing map with string key and Int value to a Parcel
fun writeStringIntMap(parcel: Parcel, map: LinkedHashMap<String, Int>) {
parcel.writeInt(map.size)
for ((key, value) in map) {
parcel.writeString(key)
parcel.writeInt(value)
writeString(key)
writeParcelable(value, flags)
}
}
// For reading map with string key from a Parcel
fun <V : Parcelable> readStringParcelableMap(
parcel: Parcel, vClass: Class<V>): LinkedHashMap<String, V> {
val size = parcel.readInt()
inline fun <reified V : Parcelable> Parcel.readStringParcelableMap(): LinkedHashMap<String, V> {
val size = readInt()
val map = LinkedHashMap<String, V>(size)
for (i in 0 until size) {
val key: String? = parcel.readString()
val key: String? = readString()
val value: V? = try {
parcel.readParcelable(vClass.classLoader)
when {
SDK_INT >= 33 -> readParcelable(V::class.java.classLoader, V::class.java)
else -> @Suppress("DEPRECATION") readParcelable(V::class.java.classLoader)
}
} catch (e: Exception) { null }
if (key != null && value != null)
map[key] = value
@ -89,14 +158,23 @@ object ParcelableUtil {
return map
}
// For writing map with string key and Int value to a Parcel
fun Parcel.writeStringIntMap(map: LinkedHashMap<String, Int>) {
writeInt(map.size)
for ((key, value) in map) {
writeString(key)
writeInt(value)
}
}
// For reading map with string key and Int value from a Parcel
fun readStringIntMap(parcel: Parcel): LinkedHashMap<String, Int> {
val size = parcel.readInt()
fun Parcel.readStringIntMap(): LinkedHashMap<String, Int> {
val size = readInt()
val map = LinkedHashMap<String, Int>(size)
for (i in 0 until size) {
val key: String? = parcel.readString()
val value: Int? = parcel.readInt()
if (key != null && value != null)
val key: String? = readString()
val value: Int = readInt()
if (key != null)
map[key] = value
}
return map
@ -104,21 +182,20 @@ object ParcelableUtil {
// For writing map with string key and string value to a Parcel
fun writeStringParcelableMap(dest: Parcel, map: LinkedHashMap<String, String>) {
dest.writeInt(map.size)
fun Parcel.writeStringStringMap(map: MutableMap<String, String>) {
writeInt(map.size)
for ((key, value) in map) {
dest.writeString(key)
dest.writeString(value)
writeString(key)
writeString(value)
}
}
// For reading map with string key and string value from a Parcel
fun readStringParcelableMap(parcel: Parcel): LinkedHashMap<String, String> {
val size = parcel.readInt()
fun Parcel.readStringStringMap(): LinkedHashMap<String, String> {
val size = readInt()
val map = LinkedHashMap<String, String>(size)
for (i in 0 until size) {
val key: String? = parcel.readString()
val value: String? = parcel.readString()
val key: String? = readString()
val value: String? = readString()
if (key != null && value != null)
map[key] = value
}
@ -146,6 +223,12 @@ fun Parcel.writeByteArrayCompat(data: ByteArray?) {
}
}
inline fun <reified T : Enum<T>> Intent.getEnumExtra(key: String?) =
getStringExtra(key)?.let { enumValueOf<T>(it) }
fun <T : Enum<T>> Intent.putEnumExtra(key: String?, value: T?) =
putExtra(key, value?.name)
inline fun <reified T : Enum<T>> Parcel.readEnum() =
readString()?.let { enumValueOf<T>(it) }