From f0e530e4eb1d4af7df76fa8d8e75e6783d6e7c29 Mon Sep 17 00:00:00 2001 From: Jaewan Kim Date: Fri, 22 Aug 2014 00:43:31 +0900 Subject: [PATCH] TIF: Accept any character for custom label. Bug: 16874696 Change-Id: Idc42853ea7f4b12a2eda1f45319bc31ee1a8c6b7 --- core/java/android/provider/Settings.java | 9 ++++--- media/java/android/media/tv/TvInputInfo.java | 25 ++++++++------------ 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 52f1dd979275f..3917c8ca050a9 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -4737,17 +4737,16 @@ public final class Settings { /** * List of TV inputs that are currently hidden. This is a string - * containing the IDs of all hidden TV inputs. Each ID is separated by ':'. - * + * containing the IDs of all hidden TV inputs. Each ID is encoded by + * {@link android.net.Uri#encode(String)} and separated by ':'. * @hide */ public static final String TV_INPUT_HIDDEN_INPUTS = "tv_input_hidden_inputs"; /** * List of custom TV input labels. This is a string containing - * pairs. Each pair is separated by ':' and TV input id and custom name are separated by - * ','. - * + * pairs. TV input id and custom name are encoded by {@link android.net.Uri#encode(String)} + * and separated by ','. Each pair is separated by ':'. * @hide */ public static final String TV_INPUT_CUSTOM_LABELS = "tv_input_custom_labels"; diff --git a/media/java/android/media/tv/TvInputInfo.java b/media/java/android/media/tv/TvInputInfo.java index 3f5697f6c701e..106e1dcf54588 100644 --- a/media/java/android/media/tv/TvInputInfo.java +++ b/media/java/android/media/tv/TvInputInfo.java @@ -46,7 +46,6 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.io.InputStream; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -616,11 +615,15 @@ public final class TvInputInfo implements Parcelable { public static Set getHiddenTvInputIds(Context context, int userId) { String hiddenIdsString = Settings.Secure.getStringForUser( context.getContentResolver(), Settings.Secure.TV_INPUT_HIDDEN_INPUTS, userId); + Set set = new HashSet(); if (TextUtils.isEmpty(hiddenIdsString)) { - return new HashSet(); + return set; } String[] ids = hiddenIdsString.split(TV_INPUT_SEPARATOR); - return new HashSet<>(Arrays.asList(ids)); + for (String id : ids) { + set.add(Uri.decode(id)); + } + return set; } /** @@ -641,7 +644,7 @@ public final class TvInputInfo implements Parcelable { String[] pairs = labelsString.split(TV_INPUT_SEPARATOR); for (String pairString : pairs) { String[] pair = pairString.split(CUSTOM_NAME_SEPARATOR); - map.put(pair[0], pair[1]); + map.put(Uri.decode(pair[0]), Uri.decode(pair[1])); } return map; } @@ -667,7 +670,7 @@ public final class TvInputInfo implements Parcelable { } else { builder.append(TV_INPUT_SEPARATOR); } - builder.append(inputId); + builder.append(Uri.encode(inputId)); } Settings.Secure.putStringForUser(context.getContentResolver(), Settings.Secure.TV_INPUT_HIDDEN_INPUTS, builder.toString(), userId); @@ -695,9 +698,9 @@ public final class TvInputInfo implements Parcelable { } else { builder.append(TV_INPUT_SEPARATOR); } - builder.append(entry.getKey()); + builder.append(Uri.encode(entry.getKey())); builder.append(CUSTOM_NAME_SEPARATOR); - builder.append(entry.getValue()); + builder.append(Uri.encode(entry.getValue())); } Settings.Secure.putStringForUser(context.getContentResolver(), Settings.Secure.TV_INPUT_CUSTOM_LABELS, builder.toString(), userId); @@ -707,14 +710,6 @@ public final class TvInputInfo implements Parcelable { if (TextUtils.isEmpty(value)) { throw new IllegalArgumentException(value + " should not empty "); } - if (value.contains(TV_INPUT_SEPARATOR)) { - throw new IllegalArgumentException(value + " should not include " - + TV_INPUT_SEPARATOR); - } - if (value.contains(CUSTOM_NAME_SEPARATOR)) { - throw new IllegalArgumentException(value + " should not include " - + CUSTOM_NAME_SEPARATOR); - } } } }