diff options
| author | 2024-03-03 12:10:02 -0500 | |
|---|---|---|
| committer | 2024-03-03 13:03:00 -0500 | |
| commit | 39553a1b848ee573acb306e3297688df096f404f (patch) | |
| tree | b9232a20818c0863003e38d512a8cc67ad15ab84 /java/src | |
| parent | 2b9f86f50bc8b3ee83ffc0be1aed5c87fdd16d72 (diff) | |
Fix CreationExtras.addDefaultArgs when args absent
addDefaultArgs grabs the existing Bundle from CreationExtras
and adds in the additional values. If default args aren't
present (whenever the initial intent did not have extras),
the updated bundle was never returned within the original
instance since it was relying on modifying the Bundle
in-place.
This corrects the issue by explicitly returning a new instance
containing the updated `DEFAULT_ARGS` Bundle.
Test: atest com.android.intentresolver.v2.ext.CreationExtrasExtTest
Change-Id: I5a7c61baaaeefa2878b4041d809c348bf5ac70c0
Diffstat (limited to 'java/src')
| -rw-r--r-- | java/src/com/android/intentresolver/v2/ext/CreationExtrasExt.kt | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/java/src/com/android/intentresolver/v2/ext/CreationExtrasExt.kt b/java/src/com/android/intentresolver/v2/ext/CreationExtrasExt.kt index ebd613f1..6c36e6aa 100644 --- a/java/src/com/android/intentresolver/v2/ext/CreationExtrasExt.kt +++ b/java/src/com/android/intentresolver/v2/ext/CreationExtrasExt.kt @@ -18,14 +18,17 @@ package com.android.intentresolver.v2.ext import android.os.Bundle import android.os.Parcelable +import androidx.core.os.bundleOf import androidx.lifecycle.DEFAULT_ARGS_KEY import androidx.lifecycle.viewmodel.CreationExtras +import androidx.lifecycle.viewmodel.MutableCreationExtras -/** Adds one or more key-value pairs to the default Args bundle in this extras instance. */ +/** + * Returns a new instance with additional [values] added to the existing default args Bundle (if + * present), otherwise adds a new entry with a copy of this bundle. + */ fun CreationExtras.addDefaultArgs(vararg values: Pair<String, Parcelable>): CreationExtras { val defaultArgs: Bundle = get(DEFAULT_ARGS_KEY) ?: Bundle() - for ((key, value) in values) { - defaultArgs.putParcelable(key, value) - } - return this + defaultArgs.putAll(bundleOf(*values)) + return MutableCreationExtras(this).apply { set(DEFAULT_ARGS_KEY, defaultArgs) } } |