TIF: Accept any character for custom label.

Bug: 16874696
Change-Id: Idc42853ea7f4b12a2eda1f45319bc31ee1a8c6b7
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 52f1dd9..3917c8c 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -4737,17 +4737,16 @@
 
         /**
          * 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 <TV input id, custom name>
-         * 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 3f5697f..106e1dc 100644
--- a/media/java/android/media/tv/TvInputInfo.java
+++ b/media/java/android/media/tv/TvInputInfo.java
@@ -46,7 +46,6 @@
 
 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 static Set<String> getHiddenTvInputIds(Context context, int userId) {
             String hiddenIdsString = Settings.Secure.getStringForUser(
                     context.getContentResolver(), Settings.Secure.TV_INPUT_HIDDEN_INPUTS, userId);
+            Set<String> set = new HashSet<String>();
             if (TextUtils.isEmpty(hiddenIdsString)) {
-                return new HashSet<String>();
+                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 @@
             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 @@
                 } 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 @@
                 } 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 @@
             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);
-            }
         }
     }
 }