Skip to content

Commit f5ecca3

Browse files
authored
android: StringArrayListMDMSetting should check for String[] (#527)
getFromBundle should check for both String[] and ArrayList<String> Fixes tailscale/corp#23557 Signed-off-by: kari-ts <[email protected]>
1 parent 8eabe8d commit f5ecca3

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

android/src/main/java/com/tailscale/ipn/mdm/MDMSettingsDefinitions.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,26 @@ class StringMDMSetting(key: String, localizedTitle: String) :
4646

4747
class StringArrayListMDMSetting(key: String, localizedTitle: String) :
4848
MDMSetting<List<String>?>(null, key, localizedTitle) {
49-
override fun getFromBundle(bundle: Bundle) = bundle.getStringArrayList(key)
50-
override fun getFromPrefs(prefs: SharedPreferences) =
51-
prefs.getStringSet(key, HashSet<String>())?.toList()
49+
override fun getFromBundle(bundle: Bundle): List<String>? {
50+
// Try to retrieve the value as a String[] first
51+
val stringArray = bundle.getStringArray(key)
52+
if (stringArray != null) {
53+
return stringArray.toList()
54+
}
55+
56+
// Optionally, handle other types if necessary
57+
val stringArrayList = bundle.getStringArrayList(key)
58+
if (stringArrayList != null) {
59+
return stringArrayList
60+
}
61+
62+
// If neither String[] nor ArrayList<String> is found, return null
63+
return null
64+
}
65+
66+
override fun getFromPrefs(prefs: SharedPreferences): List<String>? {
67+
return prefs.getStringSet(key, HashSet<String>())?.toList()
68+
}
5269
}
5370

5471
class AlwaysNeverUserDecidesMDMSetting(key: String, localizedTitle: String) :

0 commit comments

Comments
 (0)