Merge "Remove setApplicationsHidden" into lmp-dev
diff --git a/api/current.txt b/api/current.txt
index a9ee558..fc5a3a0 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -5433,6 +5433,8 @@
     method public int getPasswordMinimumSymbols(android.content.ComponentName);
     method public int getPasswordMinimumUpperCase(android.content.ComponentName);
     method public int getPasswordQuality(android.content.ComponentName);
+    method public java.util.List<java.lang.String> getPermittedAccessibilityServices(android.content.ComponentName);
+    method public java.util.List<java.lang.String> getPermittedInputMethods(android.content.ComponentName);
     method public boolean getScreenCaptureDisabled(android.content.ComponentName);
     method public boolean getStorageEncryption(android.content.ComponentName);
     method public int getStorageEncryptionStatus();
@@ -5474,6 +5476,8 @@
     method public void setPasswordMinimumSymbols(android.content.ComponentName, int);
     method public void setPasswordMinimumUpperCase(android.content.ComponentName, int);
     method public void setPasswordQuality(android.content.ComponentName, int);
+    method public boolean setPermittedAccessibilityServices(android.content.ComponentName, java.util.List<java.lang.String>);
+    method public boolean setPermittedInputMethods(android.content.ComponentName, java.util.List<java.lang.String>);
     method public void setProfileEnabled(android.content.ComponentName);
     method public void setProfileName(android.content.ComponentName, java.lang.String);
     method public void setRecommendedGlobalProxy(android.content.ComponentName, android.net.ProxyInfo);
@@ -31509,7 +31513,7 @@
     field public static final java.lang.String CASE_GENITIVE = "android.genitive";
     field public static final java.lang.String CASE_INSTRUMENTAL = "android.instrumental";
     field public static final java.lang.String CASE_LOCATIVE = "android.locative";
-    field public static final java.lang.String CASE_NOMINATIVE = "android.nomative";
+    field public static final java.lang.String CASE_NOMINATIVE = "android.nominative";
     field public static final java.lang.String CASE_VOCATIVE = "android.vocative";
     field public static final java.lang.String GENDER_FEMALE = "android.female";
     field public static final java.lang.String GENDER_MALE = "android.male";
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 78b9529..4dbe82f 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -2643,6 +2643,161 @@
     }
 
     /**
+     * Called by a profile or device owner to set the permitted accessibility services. When
+     * set by a device owner or profile owner the restriction applies to all profiles of the
+     * user the device owner or profile owner is an admin for.
+     * 
+     * By default the user can use any accessiblity service. When zero or more packages have
+     * been added, accessiblity services that are not in the list and not part of the system
+     * can not be enabled by the user. 
+     *
+     * <p> Calling with a null value for the list disables the restriction so that all services
+     * can be used, calling with an empty list only allows the builtin system's services.
+     *
+     * <p> System accesibility services are always available to the user the list can't modify
+     * this.
+     *
+     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
+     * @param packageNames List of accessibility service package names.
+     *
+     * @return true if setting the restriction succeeded. It fail if there is
+     * one or more non-system accessibility services enabled, that are not in the list.
+     */
+    public boolean setPermittedAccessibilityServices(ComponentName admin,
+            List<String> packageNames) {
+        if (mService != null) {
+            try {
+                return mService.setPermittedAccessibilityServices(admin, packageNames);
+            } catch (RemoteException e) {
+                Log.w(TAG, "Failed talking with device policy service", e);
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Returns the list of permitted accessibility services set by this device or profile owner.
+     *
+     * <p>An empty list means no accessibility services except system services are allowed.
+     * Null means all accessibility services are allowed.
+     *
+     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
+     * @return List of accessiblity service package names.
+     */
+    public List<String> getPermittedAccessibilityServices(ComponentName admin) {
+        if (mService != null) {
+            try {
+                return mService.getPermittedAccessibilityServices(admin);
+            } catch (RemoteException e) {
+                Log.w(TAG, "Failed talking with device policy service", e);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the list of accessibility services permitted by the device or profiles
+     * owners of this user.
+     *
+     * <p>Null means all accessibility services are allowed, if a non-null list is returned
+     * it will contain the intersection of the permitted lists for any device or profile
+     * owners that apply to this user. It will also include any system accessibility services.
+     *
+     * @param userId which user to check for.
+     * @return List of accessiblity service package names.
+     * @hide
+     */
+     @SystemApi
+     public List<String> getPermittedAccessibilityServices(int userId) {
+        if (mService != null) {
+            try {
+                return mService.getPermittedAccessibilityServicesForUser(userId);
+            } catch (RemoteException e) {
+                Log.w(TAG, "Failed talking with device policy service", e);
+            }
+        }
+        return null;
+     }
+
+    /**
+     * Called by a profile or device owner to set the permitted input methods services. When
+     * set by a device owner or profile owner the restriction applies to all profiles of the
+     * user the device owner or profile owner is an admin for.
+     *
+     * By default the user can use any input method. When zero or more packages have
+     * been added, input method that are not in the list and not part of the system
+     * can not be enabled by the user.
+     *
+     * This method will fail if it is called for a admin that is not for the foreground user
+     * or a profile of the foreground user.
+     *
+     * <p> Calling with a null value for the list disables the restriction so that all input methods
+     * can be used, calling with an empty list disables all but the system's own input methods.
+     *
+     * <p> System input methods are always available to the user this method can't modify this.
+     *
+     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
+     * @param packageNames List of input method package names.
+     * @return true if setting the restriction succeeded. It will fail if there is
+     *     one or more input method enabled, that are not in the list or user if the foreground
+     *     user.
+     */
+    public boolean setPermittedInputMethods(ComponentName admin, List<String> packageNames) {
+        if (mService != null) {
+            try {
+                return mService.setPermittedInputMethods(admin, packageNames);
+            } catch (RemoteException e) {
+                Log.w(TAG, "Failed talking with device policy service", e);
+            }
+        }
+        return false;
+    }
+
+
+    /**
+     * Returns the list of permitted input methods set by this device or profile owner.
+     *
+     * <p>An empty list means no input methods except system input methods are allowed.
+     * Null means all input methods are allowed.
+     *
+     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
+     * @return List of input method package names.
+     */
+    public List<String> getPermittedInputMethods(ComponentName admin) {
+        if (mService != null) {
+            try {
+                return mService.getPermittedInputMethods(admin);
+            } catch (RemoteException e) {
+                Log.w(TAG, "Failed talking with device policy service", e);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the list of input methods permitted by the device or profiles
+     * owners of the current user.
+     *
+     * <p>Null means all input methods are allowed, if a non-null list is returned
+     * it will contain the intersection of the permitted lists for any device or profile
+     * owners that apply to this user. It will also include any system input methods.
+     *
+     * @return List of input method package names.
+     * @hide
+     */
+    @SystemApi
+    public List<String> getPermittedInputMethodsForCurrentUser() {
+        if (mService != null) {
+            try {
+                return mService.getPermittedInputMethodsForCurrentUser();
+            } catch (RemoteException e) {
+                Log.w(TAG, "Failed talking with device policy service", e);
+            }
+        }
+        return null;
+    }
+
+    /**
      * Called by a device owner to create a user with the specified name. The UserHandle returned
      * by this method should not be persisted as user handles are recycled as users are removed and
      * created. If you need to persist an identifier for this user, use
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index 107be60..54be438 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -24,6 +24,7 @@
 import android.os.Bundle;
 import android.os.RemoteCallback;
 import android.os.UserHandle;
+import java.util.List;
 
 /**
  * Internal IPC interface to the device policy service.
@@ -137,6 +138,14 @@
     void addCrossProfileIntentFilter(in ComponentName admin, in IntentFilter filter, int flags);
     void clearCrossProfileIntentFilters(in ComponentName admin);
 
+    boolean setPermittedAccessibilityServices(in ComponentName admin,in List packageList);
+    List getPermittedAccessibilityServices(in ComponentName admin);
+    List getPermittedAccessibilityServicesForUser(int userId);
+
+    boolean setPermittedInputMethods(in ComponentName admin,in List packageList);
+    List getPermittedInputMethods(in ComponentName admin);
+    List getPermittedInputMethodsForCurrentUser();
+
     boolean setApplicationHidden(in ComponentName admin, in String packageName, boolean hidden);
     boolean isApplicationHidden(in ComponentName admin, in String packageName);
 
diff --git a/core/java/android/text/style/TtsSpan.java b/core/java/android/text/style/TtsSpan.java
index cb447fd..342a183 100644
--- a/core/java/android/text/style/TtsSpan.java
+++ b/core/java/android/text/style/TtsSpan.java
@@ -26,10 +26,14 @@
 
 /**
  * A span that supplies additional meta-data for the associated text intended
- * for text-to-speech engines.  If the text is being processed by a
+ * for text-to-speech engines. If the text is being processed by a
  * text-to-speech engine, the engine may use the data in this span in addition
  * to or instead of its associated text.
  *
+ * Each instance of a TtsSpan has a type, for example {@link #TYPE_DATE}
+ * or {@link #TYPE_MEASURE}. And a list of arguments, provided as
+ * key-value pairs in a bundle.
+ *
  * The inner classes are there for convenience and provide builders for each
  * TtsSpan type.
  */
@@ -39,7 +43,7 @@
 
     /**
      * This span type can be used to add morphosyntactic features to the text it
-     * spans over, or synthesize a something else than the spanned text.  Use
+     * spans over, or synthesize a something else than the spanned text. Use
      * the argument {@link #ARG_TEXT} to set a different text.
      * Accepts the arguments {@link #ARG_GENDER},
      * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
@@ -48,7 +52,7 @@
     public static final String TYPE_TEXT = "android.type.text";
 
     /**
-     * The text associated with this span is a cardinal.  Must include the
+     * The text associated with this span is a cardinal. Must include the
      * number to be synthesized with {@link #ARG_NUMBER}.
      * Also accepts the arguments {@link #ARG_GENDER},
      * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
@@ -108,12 +112,12 @@
     public static final String TYPE_TIME = "android.type.time";
 
     /**
-     * The text associated with this span is a date. All arguments are optional,
-     * but at least one has to be provided: {@link #ARG_WEEKDAY},
-     * {@link #ARG_DAY}, {@link #ARG_MONTH} and {@link #ARG_YEAR}.
-     * Also accepts the arguments {@link #ARG_GENDER},
-     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
-     * {@link #ARG_CASE}.
+     * The text associated with this span is a date. At least one of the
+     * arguments {@link #ARG_MONTH} and {@link #ARG_YEAR} has to be provided.
+     * The argument {@link #ARG_DAY} is optional if {@link #ARG_MONTH} is set.
+     * The argument {@link #ARG_WEEKDAY} is optional if {@link #ARG_DAY} is set.
+     * Also accepts the arguments {@link #ARG_GENDER}, {@link #ARG_ANIMACY},
+     * {@link #ARG_MULTIPLICITY} and {@link #ARG_CASE}.
      */
     public static final String TYPE_DATE = "android.type.date";
 
@@ -121,13 +125,11 @@
      * The text associated with this span is a telephone number. The argument
      * {@link #ARG_NUMBER_PARTS} is required. {@link #ARG_COUNTRY_CODE} and
      * {@link #ARG_EXTENSION} are optional.
-     * Also accepts the arguments {@link #ARG_GENDER},
-     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
-     * {@link #ARG_CASE}.
+     * Also accepts the arguments {@link #ARG_GENDER}, {@link #ARG_ANIMACY},
+     * {@link #ARG_MULTIPLICITY} and {@link #ARG_CASE}.
      */
     public static final String TYPE_TELEPHONE = "android.type.telephone";
 
-
     /**
      * The text associated with this span is a URI (can be used for URLs and
      * email addresses). The full schema for URLs, which email addresses can
@@ -138,9 +140,8 @@
      * {@link #ARG_PROTOCOL}, {@link #ARG_USERNAME}, {@link #ARG_PASSWORD},
      * {@link #ARG_DOMAIN}, {@link #ARG_PORT}, {@link #ARG_PATH},
      * {@link #ARG_QUERY_STRING} and {@link #ARG_FRAGMENT_ID}.
-     * Also accepts the arguments {@link #ARG_GENDER},
-     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
-     * {@link #ARG_CASE}.
+     * Also accepts the arguments {@link #ARG_GENDER}, {@link #ARG_ANIMACY},
+     * {@link #ARG_MULTIPLICITY} and {@link #ARG_CASE}.
      */
     public static final String TYPE_ELECTRONIC = "android.type.electronic";
 
@@ -149,18 +150,16 @@
      * with the same arguments as {@link #TYPE_DECIMAL}.
      * {@link #ARG_CURRENCY} is used to set the currency. {@link #ARG_QUANTITY}
      * is optional.
-     * Also accepts the arguments {@link #ARG_GENDER},
-     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
-     * {@link #ARG_CASE}.
+     * Also accepts the arguments {@link #ARG_GENDER}, {@link #ARG_ANIMACY},
+     * {@link #ARG_MULTIPLICITY} and {@link #ARG_CASE}.
      */
     public static final String TYPE_MONEY = "android.type.money";
 
     /**
      * The text associated with this span is a series of digits that have to be
-     * read sequentially. {@link #ARG_DIGITS} is required.
-     * Also accepts the arguments {@link #ARG_GENDER},
-     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
-     * {@link #ARG_CASE}.
+     * read sequentially. The digits can be set with {@link #ARG_DIGITS}.
+     * Also accepts the arguments {@link #ARG_GENDER}, {@link #ARG_ANIMACY},
+     * {@link #ARG_MULTIPLICITY} and {@link #ARG_CASE}.
      */
     public static final String TYPE_DIGITS = "android.type.digits";
 
@@ -169,13 +168,12 @@
      * be read verbatim. The engine will attempt to ready out any character like
      * punctuation but excluding whitespace. {@link #ARG_VERBATIM} is required.
      * Also accepts the arguments {@link #ARG_GENDER},
-     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and
-     * {@link #ARG_CASE}.
+     * {@link #ARG_ANIMACY}, {@link #ARG_MULTIPLICITY} and {@link #ARG_CASE}.
      */
     public static final String TYPE_VERBATIM = "android.type.verbatim";
 
     /**
-     * String argument supplying gender information.  Can be any of
+     * String argument supplying gender information. Can be any of
      * {@link #GENDER_NEUTRAL}, {@link #GENDER_MALE} and
      * {@link #GENDER_FEMALE}.
      */
@@ -186,7 +184,7 @@
     public static final String GENDER_FEMALE = "android.female";
 
     /**
-     * String argument supplying animacy information.  Can be
+     * String argument supplying animacy information. Can be
      * {@link #ANIMACY_ANIMATE} or
      * {@link #ANIMACY_INANIMATE}
      */
@@ -196,9 +194,8 @@
     public static final String ANIMACY_INANIMATE = "android.inanimate";
 
     /**
-     * String argument supplying multiplicity information.  Can be any of
-     * {@link #MULTIPLICITY_SINGLE},
-     * {@link #MULTIPLICITY_DUAL} and
+     * String argument supplying multiplicity information. Can be any of
+     * {@link #MULTIPLICITY_SINGLE}, {@link #MULTIPLICITY_DUAL} and
      * {@link #MULTIPLICITY_PLURAL}
      */
     public static final String ARG_MULTIPLICITY = "android.arg.multiplicity";
@@ -208,16 +205,14 @@
     public static final String MULTIPLICITY_PLURAL = "android.plural";
 
     /**
-     * String argument supplying case information.  Can be any of
-     * {@link #CASE_NOMINATIVE}, {@link #CASE_ACCUSATIVE},
-     * {@link #CASE_DATIVE}, {@link #CASE_ABLATIVE},
-     * {@link #CASE_GENITIVE}, {@link #CASE_VOCATIVE},
-     * {@link #CASE_LOCATIVE} and
-     * {@link #CASE_INSTRUMENTAL}
+     * String argument supplying case information. Can be any of
+     * {@link #CASE_NOMINATIVE}, {@link #CASE_ACCUSATIVE}, {@link #CASE_DATIVE},
+     * {@link #CASE_ABLATIVE}, {@link #CASE_GENITIVE}, {@link #CASE_VOCATIVE},
+     * {@link #CASE_LOCATIVE} and {@link #CASE_INSTRUMENTAL}
      */
     public static final String ARG_CASE = "android.arg.case";
 
-    public static final String CASE_NOMINATIVE = "android.nomative";
+    public static final String CASE_NOMINATIVE = "android.nominative";
     public static final String CASE_ACCUSATIVE = "android.accusative";
     public static final String CASE_DATIVE = "android.dative";
     public static final String CASE_ABLATIVE = "android.ablative";
@@ -227,14 +222,14 @@
     public static final String CASE_INSTRUMENTAL = "android.instrumental";
 
     /**
-     * String supplying the text to be synthesized.  The synthesizer is free
+     * String supplying the text to be synthesized. The synthesizer is free
      * to decide how to interpret the text.
      * Can be used with {@link #TYPE_TEXT}.
      */
     public static final String ARG_TEXT = "android.arg.text";
 
     /**
-     * Argument used to specify a whole number.  The value can be a string of
+     * Argument used to specify a whole number. The value can be a string of
      * digits of any size optionally prefixed with a - or +.
      * Can be used with {@link #TYPE_CARDINAL} and {@link #TYPE_ORDINAL}.
      */
@@ -293,7 +288,7 @@
      * specified in English singular form. Prefixes may be used. Engines will do
      * their best to pronounce them correctly in the language used. Engines are
      * expected to at least support the most common ones like "meter", "second",
-     * "degree celcius" and "degree fahrenheit" with some common prefixes like
+     * "degree celsius" and "degree fahrenheit" with some common prefixes like
      * "milli" and "kilo".
      * Can be used with {@link #TYPE_MEASURE}.
      */
@@ -589,8 +584,8 @@
 
         /**
          * Sets the gender information for this instance.
-         * @param gender Can any of {@link TtsSpan#GENDER_NEUTRAL},
-         *     {@link TtsSpan#GENDER_MALE} and {@link TtsSpan#GENDER_FEMALE}.
+         * @param gender Can any of {@link #GENDER_NEUTRAL},
+         *     {@link #GENDER_MALE} and {@link #GENDER_FEMALE}.
          * @return This instance.
          */
         public C setGender(String gender) {
@@ -599,8 +594,8 @@
 
         /**
          * Sets the animacy information for this instance.
-         * @param animacy Can be any of {@link TtsSpan#ANIMACY_ANIMATE} and
-         *     {@link TtsSpan#ANIMACY_INANIMATE}.
+         * @param animacy Can be any of {@link #ANIMACY_ANIMATE} and
+         *     {@link #ANIMACY_INANIMATE}.
          * @return This instance.
          */
         public C setAnimacy(String animacy) {
@@ -610,9 +605,8 @@
         /**
          * Sets the multiplicity information for this instance.
          * @param multiplicity Can be any of
-         *     {@link TtsSpan#MULTIPLICITY_SINGLE},
-         *     {@link TtsSpan#MULTIPLICITY_DUAL} and
-         *     {@link TtsSpan#MULTIPLICITY_PLURAL}.
+         *     {@link #MULTIPLICITY_SINGLE}, {@link #MULTIPLICITY_DUAL} and
+         *     {@link #MULTIPLICITY_PLURAL}.
          * @return This instance.
          */
         public C setMultiplicity(String multiplicity) {
@@ -621,11 +615,11 @@
 
         /**
          * Sets the grammatical case information for this instance.
-         * @param grammaticalCase Can be any of {@link TtsSpan#CASE_NOMINATIVE},
-         *     {@link TtsSpan#CASE_ACCUSATIVE}, {@link TtsSpan#CASE_DATIVE},
-         *     {@link TtsSpan#CASE_ABLATIVE}, {@link TtsSpan#CASE_GENITIVE},
-         *     {@link TtsSpan#CASE_VOCATIVE}, {@link TtsSpan#CASE_LOCATIVE} and
-         *     {@link TtsSpan#CASE_INSTRUMENTAL}.
+         * @param grammaticalCase Can be any of {@link #CASE_NOMINATIVE},
+         *     {@link #CASE_ACCUSATIVE}, {@link #CASE_DATIVE},
+         *     {@link #CASE_ABLATIVE}, {@link #CASE_GENITIVE},
+         *     {@link #CASE_VOCATIVE}, {@link #CASE_LOCATIVE} and
+         *     {@link #CASE_INSTRUMENTAL}.
          * @return This instance.
          */
         public C setCase(String grammaticalCase) {
@@ -634,20 +628,20 @@
     }
 
     /**
-     * A builder for TtsSpans of type {@link TtsSpan #TYPE_TEXT}.
+     * A builder for TtsSpans of type {@link #TYPE_TEXT}.
      */
     public static class TextBuilder extends SemioticClassBuilder<TextBuilder> {
 
         /**
-         * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_TEXT}.
+         * Creates a builder for a TtsSpan of type {@link #TYPE_TEXT}.
          */
         public TextBuilder() {
             super(TtsSpan.TYPE_TEXT);
         }
 
         /**
-         * Creates a TtsSpan of type {@link TtsSpan#TYPE_TEXT} and sets the
-         * {@link TtsSpan#ARG_TEXT} argument.
+         * Creates a TtsSpan of type {@link #TYPE_TEXT} and sets the
+         * {@link #ARG_TEXT} argument.
          * @param text The text to be synthesized.
          * @see #setText(String)
          */
@@ -657,8 +651,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_TEXT} argument, the text to be
-         * synthesized.
+         * Sets the {@link #ARG_TEXT} argument, the text to be synthesized.
          * @param text The string that will be synthesized.
          * @return This instance.
          */
@@ -668,22 +661,21 @@
     }
 
     /**
-     * A builder for TtsSpans of type {@link TtsSpan #TYPE_CARDINAL}.
+     * A builder for TtsSpans of type {@link #TYPE_CARDINAL}.
      */
     public static class CardinalBuilder
             extends SemioticClassBuilder<CardinalBuilder> {
 
         /**
-         * Creates a builder for a TtsSpan of type
-         * {@link TtsSpan#TYPE_CARDINAL}.
+         * Creates a builder for a TtsSpan of type {@link #TYPE_CARDINAL}.
          */
         public CardinalBuilder() {
             super(TtsSpan.TYPE_CARDINAL);
         }
 
         /**
-         * Creates a TtsSpan of type {@link TtsSpan#TYPE_CARDINAL} and sets the
-         * {@link TtsSpan#ARG_NUMBER} argument.
+         * Creates a TtsSpan of type {@link #TYPE_CARDINAL} and sets the
+         * {@link #ARG_NUMBER} argument.
          * @param number The number to synthesize.
          * @see #setNumber(long)
          */
@@ -693,8 +685,8 @@
         }
 
         /**
-         * Creates a TtsSpan of type {@link TtsSpan#TYPE_CARDINAL} and sets the
-         * {@link TtsSpan#ARG_NUMBER} argument.
+         * Creates a TtsSpan of type {@link #TYPE_CARDINAL} and sets the
+         * {@link #ARG_NUMBER} argument.
          * @param number The number to synthesize.
          * @see #setNumber(String)
          */
@@ -705,7 +697,7 @@
 
         /**
          * Convenience method that converts the number to a String and set it to
-         * the value for {@link TtsSpan#ARG_NUMBER}.
+         * the value for {@link #ARG_NUMBER}.
          * @param number The number that will be synthesized.
          * @return This instance.
          */
@@ -714,7 +706,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_NUMBER} argument.
+         * Sets the {@link #ARG_NUMBER} argument.
          * @param number A non-empty string of digits with an optional
          *     leading + or -.
          * @return This instance.
@@ -725,21 +717,21 @@
     }
 
     /**
-     * A builder for TtsSpans of type {@link TtsSpan#TYPE_ORDINAL}.
+     * A builder for TtsSpans of type {@link #TYPE_ORDINAL}.
      */
     public static class OrdinalBuilder
             extends SemioticClassBuilder<OrdinalBuilder> {
 
         /**
-         * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_ORDINAL}.
+         * Creates a builder for a TtsSpan of type {@link #TYPE_ORDINAL}.
          */
         public OrdinalBuilder() {
             super(TtsSpan.TYPE_ORDINAL);
         }
 
         /**
-         * Creates a TtsSpan of type {@link TtsSpan#TYPE_ORDINAL} and sets the
-         * {@link TtsSpan#ARG_NUMBER} argument.
+         * Creates a TtsSpan of type {@link #TYPE_ORDINAL} and sets the
+         * {@link #ARG_NUMBER} argument.
          * @param number The ordinal number to synthesize.
          * @see #setNumber(long)
          */
@@ -749,8 +741,8 @@
         }
 
         /**
-         * Creates a TtsSpan of type {@link TtsSpan#TYPE_ORDINAL} and sets the
-         * {@link TtsSpan#ARG_NUMBER} argument.
+         * Creates a TtsSpan of type {@link #TYPE_ORDINAL} and sets the
+         * {@link #ARG_NUMBER} argument.
          * @param number The number to synthesize.
          * @see #setNumber(String)
          */
@@ -761,7 +753,7 @@
 
         /**
          * Convenience method that converts the number to a String and sets it
-         * to the value for {@link TtsSpan#ARG_NUMBER}.
+         * to the value for {@link #ARG_NUMBER}.
          * @param number The ordinal number that will be synthesized.
          * @return This instance.
          */
@@ -770,7 +762,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_NUMBER} argument.
+         * Sets the {@link #ARG_NUMBER} argument.
          * @param number A non-empty string of digits with an optional
          *     leading + or -.
          * @return This instance.
@@ -781,22 +773,21 @@
     }
 
     /**
-     * A builder for TtsSpans of type {@link TtsSpan#TYPE_DECIMAL}.
+     * A builder for TtsSpans of type {@link #TYPE_DECIMAL}.
      */
     public static class DecimalBuilder
             extends SemioticClassBuilder<DecimalBuilder> {
 
         /**
-         * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_DECIMAL}.
+         * Creates a builder for a TtsSpan of type {@link #TYPE_DECIMAL}.
          */
         public DecimalBuilder() {
             super(TtsSpan.TYPE_DECIMAL);
         }
 
         /**
-         * Creates a TtsSpan of type {@link TtsSpan#TYPE_DECIMAL} and sets the
-         * {@link TtsSpan#ARG_INTEGER_PART} and
-         * {@link TtsSpan#ARG_FRACTIONAL_PART} arguments.
+         * Creates a TtsSpan of type {@link #TYPE_DECIMAL} and sets the
+         * {@link #ARG_INTEGER_PART} and {@link #ARG_FRACTIONAL_PART} arguments.
          * @see {@link #setArgumentsFromDouble(double, int, int)
          */
         public DecimalBuilder(double number,
@@ -809,9 +800,8 @@
         }
 
         /**
-         * Creates a TtsSpan of type {@link TtsSpan#TYPE_DECIMAL} and sets the
-         * {@link TtsSpan#ARG_INTEGER_PART} and
-         * {@link TtsSpan#ARG_FRACTIONAL_PART} arguments.
+         * Creates a TtsSpan of type {@link #TYPE_DECIMAL} and sets the
+         * {@link #ARG_INTEGER_PART} and {@link #ARG_FRACTIONAL_PART} arguments.
          */
         public DecimalBuilder(String integerPart, String fractionalPart) {
             this();
@@ -821,8 +811,8 @@
 
         /**
          * Convenience method takes a double and a maximum number of fractional
-         * digits, it sets the {@link TtsSpan#ARG_INTEGER_PART} and
-         * {@link TtsSpan#ARG_FRACTIONAL_PART} arguments.
+         * digits, it sets the {@link #ARG_INTEGER_PART} and
+         * {@link #ARG_FRACTIONAL_PART} arguments.
          * @param number The number to be synthesized.
          * @param minimumFractionDigits The minimum number of fraction digits
          *     that are pronounced.
@@ -856,7 +846,7 @@
 
         /**
          * Convenience method that converts the number to a String and sets it
-         * to the value for {@link TtsSpan#ARG_INTEGER_PART}.
+         * to the value for {@link #ARG_INTEGER_PART}.
          * @param integerPart The integer part of the decimal.
          * @return This instance.
          */
@@ -865,7 +855,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_INTEGER_PART} argument.
+         * Sets the {@link #ARG_INTEGER_PART} argument.
          * @param integerPart A non-empty string of digits with an optional
          *     leading + or -.
          * @return This instance.
@@ -875,7 +865,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_FRACTIONAL_PART} argument.
+         * Sets the {@link #ARG_FRACTIONAL_PART} argument.
          * @param fractionalPart A non-empty string of digits.
          * @return This instance.
          */
@@ -886,23 +876,22 @@
     }
 
     /**
-     * A builder for TtsSpans of type {@link TtsSpan#TYPE_FRACTION}.
+     * A builder for TtsSpans of type {@link #TYPE_FRACTION}.
      */
     public static class FractionBuilder
             extends SemioticClassBuilder<FractionBuilder> {
 
         /**
-         * Creates a builder for a TtsSpan of type
-         * {@link TtsSpan#TYPE_FRACTION}.
+         * Creates a builder for a TtsSpan of type {@link #TYPE_FRACTION}.
          */
         public FractionBuilder() {
             super(TtsSpan.TYPE_FRACTION);
         }
 
         /**
-         * Creates a TtsSpan of type {@link TtsSpan#TYPE_FRACTION} and sets the
-         * {@link TtsSpan#ARG_INTEGER_PART}, {@link TtsSpan#ARG_NUMERATOR}, and
-         * {@link TtsSpan#ARG_DENOMINATOR} arguments.
+         * Creates a TtsSpan of type {@link #TYPE_FRACTION} and sets the
+         * {@link #ARG_INTEGER_PART}, {@link #ARG_NUMERATOR}, and
+         * {@link #ARG_DENOMINATOR} arguments.
          */
         public FractionBuilder(long integerPart,
                                long numerator,
@@ -913,10 +902,9 @@
             setDenominator(denominator);
         }
 
-
         /**
          * Convenience method that converts the integer to a String and sets the
-         * argument {@link TtsSpan#ARG_NUMBER}.
+         * argument {@link #ARG_NUMBER}.
          * @param integerPart The integer part.
          * @return This instance.
          */
@@ -925,7 +913,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_INTEGER_PART} argument.
+         * Sets the {@link #ARG_INTEGER_PART} argument.
          * @param integerPart A non-empty string of digits with an optional
          *     leading + or -.
          * @return This instance.
@@ -936,7 +924,7 @@
 
         /**
          * Convenience method that converts the numerator to a String and sets
-         * the argument {@link TtsSpan#ARG_NUMERATOR}.
+         * the argument {@link #ARG_NUMERATOR}.
          * @param numerator The numerator.
          * @return This instance.
          */
@@ -945,7 +933,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_NUMERATOR} argument.
+         * Sets the {@link #ARG_NUMERATOR} argument.
          * @param numerator A non-empty string of digits with an optional
          *     leading + or -.
          * @return This instance.
@@ -956,7 +944,7 @@
 
         /**
          * Convenience method that converts the denominator to a String and sets
-         * the argument {@link TtsSpan#ARG_DENOMINATOR}.
+         * the argument {@link #ARG_DENOMINATOR}.
          * @param denominator The denominator.
          * @return This instance.
          */
@@ -965,7 +953,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_DENOMINATOR} argument.
+         * Sets the {@link #ARG_DENOMINATOR} argument.
          * @param denominator A non-empty string of digits with an optional
          *     leading + or -.
          * @return This instance.
@@ -976,13 +964,13 @@
     }
 
     /**
-     * A builder for TtsSpans of type {@link TtsSpan #TYPE_MEASURE}.
+     * A builder for TtsSpans of type {@link #TYPE_MEASURE}.
      */
     public static class MeasureBuilder
             extends SemioticClassBuilder<MeasureBuilder> {
 
         /**
-         * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_MEASURE}.
+         * Creates a builder for a TtsSpan of type {@link #TYPE_MEASURE}.
          */
         public MeasureBuilder() {
             super(TtsSpan.TYPE_MEASURE);
@@ -990,7 +978,7 @@
 
         /**
          * Convenience method that converts the number to a String and set it to
-         * the value for {@link TtsSpan#ARG_NUMBER}.
+         * the value for {@link #ARG_NUMBER}.
          * @param number The amount of the measure.
          * @return This instance.
          */
@@ -999,7 +987,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_NUMBER} argument.
+         * Sets the {@link #ARG_NUMBER} argument.
          * @param number A non-empty string of digits with an optional
          *     leading + or -.
          * @return This instance.
@@ -1010,7 +998,7 @@
 
         /**
          * Convenience method that converts the integer part to a String and set
-         * it to the value for {@link TtsSpan#ARG_INTEGER_PART}.
+         * it to the value for {@link #ARG_INTEGER_PART}.
          * @param integerPart The integer part of a decimal or fraction.
          * @return This instance.
          */
@@ -1019,7 +1007,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_INTEGER_PART} argument.
+         * Sets the {@link #ARG_INTEGER_PART} argument.
          * @param integerPart The integer part of a decimal or fraction; a
          * non-empty string of digits with an optional
          *     leading + or -.
@@ -1030,10 +1018,9 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_FRACTIONAL_PART} argument.
+         * Sets the {@link #ARG_FRACTIONAL_PART} argument.
          * @param fractionalPart The fractional part of a decimal; a non-empty
-         * string of digits with an optional
-         *     leading + or -.
+         *     string of digits with an optional leading + or -.
          * @return This instance.
          */
         public MeasureBuilder setFractionalPart(String fractionalPart) {
@@ -1043,7 +1030,7 @@
 
         /**
          * Convenience method that converts the numerator to a String and set it
-         * to the value for {@link TtsSpan#ARG_NUMERATOR}.
+         * to the value for {@link #ARG_NUMERATOR}.
          * @param numerator The numerator of a fraction.
          * @return This instance.
          */
@@ -1052,7 +1039,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_NUMERATOR} argument.
+         * Sets the {@link #ARG_NUMERATOR} argument.
          * @param numerator The numerator of a fraction; a non-empty string of
          *     digits with an optional leading + or -.
          * @return This instance.
@@ -1063,7 +1050,7 @@
 
         /**
          * Convenience method that converts the denominator to a String and set
-         * it to the value for {@link TtsSpan#ARG_DENOMINATOR}.
+         * it to the value for {@link #ARG_DENOMINATOR}.
          * @param denominator The denominator of a fraction.
          * @return This instance.
          */
@@ -1072,7 +1059,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_DENOMINATOR} argument.
+         * Sets the {@link #ARG_DENOMINATOR} argument.
          * @param denominator The denominator of a fraction; a non-empty string
          *     of digits with an optional leading + or -.
          * @return This instance.
@@ -1082,7 +1069,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_UNIT} argument.
+         * Sets the {@link #ARG_UNIT} argument.
          * @param unit The unit of the measure.
          * @return This instance.
          * @see {@link TtsSpan.ARG_UNIT}
@@ -1093,22 +1080,21 @@
     }
 
     /**
-     * A builder for TtsSpans of type {@link TtsSpan #TYPE_TIME}.
+     * A builder for TtsSpans of type {@link #TYPE_TIME}.
      */
     public static class TimeBuilder
             extends SemioticClassBuilder<TimeBuilder> {
 
         /**
-         * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_TIME}.
+         * Creates a builder for a TtsSpan of type {@link #TYPE_TIME}.
          */
         public TimeBuilder() {
             super(TtsSpan.TYPE_TIME);
         }
 
         /**
-         * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_TIME} and
-         * sets the {@link TtsSpan#ARG_HOURS} and {@link TtsSpan#ARG_MINUTES}
-         * arguments.
+         * Creates a builder for a TtsSpan of type {@link #TYPE_TIME} and
+         * sets the {@link #ARG_HOURS} and {@link #ARG_MINUTES} arguments.
          */
         public TimeBuilder(int hours, int minutes) {
             this();
@@ -1117,22 +1103,21 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_HOURS} argument.
-         * @param hours The value to be set for hours. See
-         * {@link TtsSpan#ARG_HOURS}.
+         * Sets the {@link #ARG_HOURS} argument.
+         * @param hours The value to be set for hours. See {@link #ARG_HOURS}.
          * @return This instance.
-         * @see {@link TtsSpan#ARG_HOURS}
+         * @see {@link #ARG_HOURS}
          */
         public TimeBuilder setHours(int hours) {
             return setIntArgument(TtsSpan.ARG_HOURS, hours);
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_MINUTES} argument.
+         * Sets the {@link #ARG_MINUTES} argument.
          * @param minutes The value to be set for minutes. See
-         * {@link TtsSpan#ARG_MINUTES}.
+         *     {@link #ARG_MINUTES}.
          * @return This instance.
-         * @see {@link TtsSpan#ARG_MINUTES}
+         * @see {@link #ARG_MINUTES}
          */
         public TimeBuilder setMinutes(int minutes) {
             return setIntArgument(TtsSpan.ARG_MINUTES, minutes);
@@ -1140,24 +1125,23 @@
     }
 
     /**
-     * A builder for TtsSpans of type {@link TtsSpan #TYPE_DATE}.
+     * A builder for TtsSpans of type {@link #TYPE_DATE}.
      */
     public static class DateBuilder
             extends SemioticClassBuilder<DateBuilder> {
 
         /**
-         * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_DATE}.
+         * Creates a builder for a TtsSpan of type {@link #TYPE_DATE}.
          */
         public DateBuilder() {
             super(TtsSpan.TYPE_DATE);
         }
 
         /**
-         * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_TIME} and
-         * possibly sets the {@link TtsSpan#ARG_WEEKDAY},
-         * {@link TtsSpan#ARG_DAY}, {@link TtsSpan#ARG_MONTH} and
-         * {@link TtsSpan#ARG_YEAR} arguments. Pass null to any argument to
-         * leave it unset.
+         * Creates a builder for a TtsSpan of type {@link #TYPE_TIME} and
+         * possibly sets the {@link #ARG_WEEKDAY}, {@link #ARG_DAY},
+         * {@link #ARG_MONTH} and {@link #ARG_YEAR} arguments. Pass null to any
+         * argument to leave it unset.
          */
         public DateBuilder(Integer weekday,
                            Integer day,
@@ -1179,44 +1163,41 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_WEEKDAY} argument.
+         * Sets the {@link #ARG_WEEKDAY} argument.
          * @param weekday The value to be set for weekday. See
-         * {@link TtsSpan#ARG_WEEKDAY}.
+         *     {@link #ARG_WEEKDAY}.
          * @return This instance.
-         * @see {@link TtsSpan#ARG_WEEKDAY}
+         * @see {@link #ARG_WEEKDAY}
          */
         public DateBuilder setWeekday(int weekday) {
             return setIntArgument(TtsSpan.ARG_WEEKDAY, weekday);
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_DAY} argument.
-         * @param day The value to be set for day. See
-         * {@link TtsSpan#ARG_DAY}.
+         * Sets the {@link #ARG_DAY} argument.
+         * @param day The value to be set for day. See {@link #ARG_DAY}.
          * @return This instance.
-         * @see {@link TtsSpan#ARG_DAY}
+         * @see {@link #ARG_DAY}
          */
         public DateBuilder setDay(int day) {
             return setIntArgument(TtsSpan.ARG_DAY, day);
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_MONTH} argument.
-         * @param month The value to be set for month. See
-         * {@link TtsSpan#ARG_MONTH}.
+         * Sets the {@link #ARG_MONTH} argument.
+         * @param month The value to be set for month. See {@link #ARG_MONTH}.
          * @return This instance.
-         * @see {@link TtsSpan#ARG_MONTH}
+         * @see {@link #ARG_MONTH}
          */
         public DateBuilder setMonth(int month) {
             return setIntArgument(TtsSpan.ARG_MONTH, month);
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_YEAR} argument.
-         * @param year The value to be set for year. See
-         * {@link TtsSpan#ARG_YEAR}.
+         * Sets the {@link #ARG_YEAR} argument.
+         * @param year The value to be set for year. See {@link #ARG_YEAR}.
          * @return This instance.
-         * @see {@link TtsSpan#ARG_YEAR}
+         * @see {@link #ARG_YEAR}
          */
         public DateBuilder setYear(int year) {
             return setIntArgument(TtsSpan.ARG_YEAR, year);
@@ -1224,13 +1205,13 @@
     }
 
     /**
-     * A builder for TtsSpans of type {@link TtsSpan #TYPE_MONEY}.
+     * A builder for TtsSpans of type {@link #TYPE_MONEY}.
      */
     public static class MoneyBuilder
             extends SemioticClassBuilder<MoneyBuilder> {
 
         /**
-         * Creates a TtsSpan of type {@link TtsSpan#TYPE_MONEY}.
+         * Creates a TtsSpan of type {@link #TYPE_MONEY}.
          */
         public MoneyBuilder() {
             super(TtsSpan.TYPE_MONEY);
@@ -1238,7 +1219,7 @@
 
         /**
          * Convenience method that converts the number to a String and set it to
-         * the value for {@link TtsSpan#ARG_INTEGER_PART}.
+         * the value for {@link #ARG_INTEGER_PART}.
          * @param integerPart The integer part of the amount.
          * @return This instance.
          */
@@ -1247,7 +1228,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_INTEGER_PART} argument.
+         * Sets the {@link #ARG_INTEGER_PART} argument.
          * @param integerPart A non-empty string of digits with an optional
          *     leading + or -.
          * @return This instance.
@@ -1257,7 +1238,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_FRACTIONAL_PART} argument.
+         * Sets the {@link #ARG_FRACTIONAL_PART} argument.
          * @param fractionalPart Can be a string of digits of any size.
          * @return This instance.
          */
@@ -1266,7 +1247,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_CURRENCY} argument.
+         * Sets the {@link #ARG_CURRENCY} argument.
          * @param currency Should be a ISO4217 currency code, e.g. "USD".
          * @return This instance.
          */
@@ -1275,7 +1256,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_QUANTITY} argument.
+         * Sets the {@link #ARG_QUANTITY} argument.
          * @param quantity
          * @return This instance.
          */
@@ -1285,21 +1266,21 @@
     }
 
     /**
-     * A builder for TtsSpans of type {@link TtsSpan #TYPE_TELEPHONE}.
+     * A builder for TtsSpans of type {@link #TYPE_TELEPHONE}.
      */
     public static class TelephoneBuilder
             extends SemioticClassBuilder<TelephoneBuilder> {
 
         /**
-         * Creates a TtsSpan of type {@link TtsSpan#TYPE_TELEPHONE}.
+         * Creates a TtsSpan of type {@link #TYPE_TELEPHONE}.
          */
         public TelephoneBuilder() {
             super(TtsSpan.TYPE_TELEPHONE);
         }
 
         /**
-         * Creates a TtsSpan of type {@link TtsSpan#TYPE_TELEPHONE} and sets the
-         * {@link TtsSpan#ARG_NUMBER_PARTS} argument.
+         * Creates a TtsSpan of type {@link #TYPE_TELEPHONE} and sets the
+         * {@link #ARG_NUMBER_PARTS} argument.
          */
         public TelephoneBuilder(String numberParts) {
             this();
@@ -1307,7 +1288,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_COUNTRY_CODE} argument.
+         * Sets the {@link #ARG_COUNTRY_CODE} argument.
          * @param countryCode The country code can be a series of digits
          * optionally prefixed with a "+".
          * @return This instance.
@@ -1317,7 +1298,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_NUMBER_PARTS} argument.
+         * Sets the {@link #ARG_NUMBER_PARTS} argument.
          * @param numberParts The main telephone number. Can be a series of
          *     digits and letters separated by spaces, "/", "-" or ".".
          * @return This instance.
@@ -1327,7 +1308,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_EXTENSION} argument.
+         * Sets the {@link #ARG_EXTENSION} argument.
          * @param extension The extension can be a series of digits.
          * @return This instance.
          */
@@ -1337,20 +1318,20 @@
     }
 
     /**
-     * A builder for TtsSpans of type {@link TtsSpan #TYPE_ELECTRONIC}.
+     * A builder for TtsSpans of type {@link #TYPE_ELECTRONIC}.
      */
     public static class ElectronicBuilder
             extends SemioticClassBuilder<ElectronicBuilder> {
 
         /**
-         * Creates a TtsSpan of type {@link TtsSpan#TYPE_ELECTRONIC}.
+         * Creates a TtsSpan of type {@link #TYPE_ELECTRONIC}.
          */
         public ElectronicBuilder() {
             super(TtsSpan.TYPE_ELECTRONIC);
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_USERNAME} and {@link TtsSpan#ARG_DOMAIN}
+         * Sets the {@link #ARG_USERNAME} and {@link #ARG_DOMAIN}
          *     arguments, representing an email address.
          * @param username The part before the @ in the email address.
          * @param domain The part after the @ in the email address.
@@ -1362,7 +1343,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_PROTOCOL} argument.
+         * Sets the {@link #ARG_PROTOCOL} argument.
          * @param protocol The protocol of the URI. Examples are "http" and
          *     "ftp".
          * @return This instance.
@@ -1372,7 +1353,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_USERNAME} argument.
+         * Sets the {@link #ARG_USERNAME} argument.
          * @return This instance.
          */
         public ElectronicBuilder setUsername(String username) {
@@ -1380,7 +1361,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_PASSWORD} argument.
+         * Sets the {@link #ARG_PASSWORD} argument.
          * @return This instance.
          */
         public ElectronicBuilder setPassword(String password) {
@@ -1388,7 +1369,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_DOMAIN} argument.
+         * Sets the {@link #ARG_DOMAIN} argument.
          * @param domain The domain, for example "source.android.com".
          * @return This instance.
          */
@@ -1397,7 +1378,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_PORT} argument.
+         * Sets the {@link #ARG_PORT} argument.
          * @return This instance.
          */
         public ElectronicBuilder setPort(int port) {
@@ -1405,7 +1386,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_PATH} argument.
+         * Sets the {@link #ARG_PATH} argument.
          * @param path For example "source/index.html".
          * @return This instance.
          */
@@ -1414,7 +1395,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_QUERY_STRING} argument.
+         * Sets the {@link #ARG_QUERY_STRING} argument.
          * @param queryString For example "arg=value&argtwo=value".
          * @return This instance.
          */
@@ -1423,7 +1404,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_FRAGMENT_ID} argument.
+         * Sets the {@link #ARG_FRAGMENT_ID} argument.
          * @return This instance.
          */
         public ElectronicBuilder setFragmentId(String fragmentId) {
@@ -1432,22 +1413,21 @@
     }
 
     /**
-     * A builder for TtsSpans of type {@link TtsSpan #TYPE_DIGITS}.
+     * A builder for TtsSpans of type {@link #TYPE_DIGITS}.
      */
     public static class DigitsBuilder
             extends SemioticClassBuilder<DigitsBuilder> {
 
         /**
-         * Creates a builder for a TtsSpan of type
-         * {@link TtsSpan#TYPE_VERBATIM}.
+         * Creates a builder for a TtsSpan of type {@link #TYPE_DIGITS}.
          */
         public DigitsBuilder() {
             super(TtsSpan.TYPE_DIGITS);
         }
 
         /**
-         * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_DIGITS}
-         * and sets the {@link TtsSpan#ARG_DIGITS} argument.
+         * Creates a builder for a TtsSpan of type {@link #TYPE_DIGITS}
+         * and sets the {@link #ARG_DIGITS} argument.
          */
         public DigitsBuilder(String digits) {
             this();
@@ -1455,7 +1435,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_DIGITS} argument.
+         * Sets the {@link #ARG_DIGITS} argument.
          * @param digits A string of digits.
          * @return This instance.
          */
@@ -1465,22 +1445,21 @@
     }
 
     /**
-     * A builder for TtsSpans of type {@link TtsSpan #TYPE_VERBATIM}.
+     * A builder for TtsSpans of type {@link #TYPE_VERBATIM}.
      */
     public static class VerbatimBuilder
             extends SemioticClassBuilder<VerbatimBuilder> {
 
         /**
-         * Creates a builder for a TtsSpan of type
-         * {@link TtsSpan#TYPE_VERBATIM}.
+         * Creates a builder for a TtsSpan of type {@link #TYPE_VERBATIM}.
          */
         public VerbatimBuilder() {
             super(TtsSpan.TYPE_VERBATIM);
         }
 
         /**
-         * Creates a builder for a TtsSpan of type {@link TtsSpan#TYPE_VERBATIM}
-         * and sets the {@link TtsSpan#ARG_VERBATIM} argument.
+         * Creates a builder for a TtsSpan of type {@link #TYPE_VERBATIM}
+         * and sets the {@link #ARG_VERBATIM} argument.
          */
         public VerbatimBuilder(String verbatim) {
             this();
@@ -1488,7 +1467,7 @@
         }
 
         /**
-         * Sets the {@link TtsSpan#ARG_VERBATIM} argument.
+         * Sets the {@link #ARG_VERBATIM} argument.
          * @param verbatim A string of characters that will be read verbatim,
          *     except whitespace.
          * @return This instance.
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 9d71859..b198329 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -3958,9 +3958,9 @@
     <string name="permission_request_notification_with_subtitle">Permission requested\nfor account <xliff:g id="account" example="foo@gmail.com">%s</xliff:g>.</string>
 
     <!-- Message to show when an intent automatically switches users into the personal profile. -->
-    <string name="forward_intent_to_owner">You\'re using this app in your personal space</string>
+    <string name="forward_intent_to_owner">You\'re using this app in your personal profile</string>
     <!-- Message to show when an intent automatically switches users into a work profile. -->
-    <string name="forward_intent_to_work">You\'re using this app in your work space</string>
+    <string name="forward_intent_to_work">You\'re using this app in your work profile</string>
 
     <!-- Label to show for a service that is running because it is an input method. -->
     <string name="input_method_binding_label">Input method</string>
@@ -4859,15 +4859,12 @@
     <!-- Exting lock-to-app indication. -->
     <string name="lock_to_app_exit">Screen unpinned</string>
 
-    <!-- Lock-to-app checkbox for lock on exit -->
-    <string name="lock_to_app_use_screen_lock">Ask for %1$s before unpinning</string>
-
     <!-- Lock-to-app unlock pin string -->
-    <string name="lock_to_app_unlock_pin">PIN</string>
+    <string name="lock_to_app_unlock_pin">Ask for PIN before unpinning</string>
     <!-- Lock-to-app unlock pattern string -->
-    <string name="lock_to_app_unlock_pattern">unlock pattern</string>
+    <string name="lock_to_app_unlock_pattern">Ask for unlock pattern before unpinning</string>
     <!-- Lock-to-app unlock password string -->
-    <string name="lock_to_app_unlock_password">password</string>
+    <string name="lock_to_app_unlock_password">Ask for password before unpinning</string>
 
     <!-- [CHAR_LIMIT=NONE] Battery saver: Feature description -->
     <string name="battery_saver_description">To help improve battery life, battery saver reduces your device’s performance and limits vibration and most background data. Email, messaging, and other apps that rely on syncing may not update unless you open them.\n\nBattery saver turns off automatically when your device is charging</string>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 1f862fd..9b3c05e 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -622,7 +622,6 @@
   <java-symbol type="id" name="lock_to_app_checkbox" />
   <java-symbol type="string" name="lock_to_app_start" />
   <java-symbol type="string" name="lock_to_app_exit" />
-  <java-symbol type="string" name="lock_to_app_use_screen_lock" />
   <java-symbol type="string" name="lock_to_app_unlock_pin" />
   <java-symbol type="string" name="lock_to_app_unlock_pattern" />
   <java-symbol type="string" name="lock_to_app_unlock_password" />
diff --git a/media/java/android/media/tv/TvView.java b/media/java/android/media/tv/TvView.java
index f348b9b..7110db9 100644
--- a/media/java/android/media/tv/TvView.java
+++ b/media/java/android/media/tv/TvView.java
@@ -38,6 +38,7 @@
 import android.view.ViewGroup;
 import android.view.ViewRootImpl;
 
+import java.lang.ref.WeakReference;
 import java.util.List;
 
 /**
@@ -69,8 +70,10 @@
     private static final int CAPTION_ENABLED = 1;
     private static final int CAPTION_DISABLED = 2;
 
+    private static final WeakReference<TvView> NULL_TV_VIEW = new WeakReference(null);
+
     private static final Object sMainTvViewLock = new Object();
-    private static TvView sMainTvView;
+    private static WeakReference<TvView> sMainTvView = NULL_TV_VIEW;
 
     private final Handler mHandler = new Handler();
     private Session mSession;
@@ -186,16 +189,16 @@
      * (including the tuner, composite, S-Video, etc.), the internal device (= TV itself) becomes
      * the active source.
      * </p><p>
-     * First tuned {@link TvView} becomes main automatically, and keeps to be main until {@link
-     * #setMain} is called for other {@link TvView}. Note that main {@link TvView} won't be reset
-     * even when current main {@link TvView} is removed from view hierarchy.
+     * First tuned {@link TvView} becomes main automatically, and keeps to be main until either
+     * {@link #reset} is called for the main {@link TvView} or {@link #setMain} is called for other
+     * {@link TvView}.
      * </p>
      * @hide
      */
     @SystemApi
     public void setMain() {
         synchronized (sMainTvViewLock) {
-            sMainTvView = this;
+            sMainTvView = new WeakReference(this);
             if (hasWindowFocus() && mSession != null) {
                 mSession.setMain();
             }
@@ -288,8 +291,8 @@
             throw new IllegalArgumentException("inputId cannot be null or an empty string");
         }
         synchronized (sMainTvViewLock) {
-            if (sMainTvView == null) {
-                sMainTvView = this;
+            if (sMainTvView.get() == null) {
+                sMainTvView = new WeakReference(this);
             }
         }
         if (mSessionCallback != null && mSessionCallback.mInputId.equals(inputId)) {
@@ -320,6 +323,11 @@
      */
     public void reset() {
         if (DEBUG) Log.d(TAG, "reset()");
+        synchronized (sMainTvViewLock) {
+            if (this == sMainTvView.get()) {
+                sMainTvView = NULL_TV_VIEW;
+            }
+        }
         if (mSession != null) {
             release();
             resetSurfaceView();
@@ -530,7 +538,7 @@
         // Other app may have shown its own main TvView.
         // Set main again to regain main session.
         synchronized (sMainTvViewLock) {
-            if (hasFocus && this == sMainTvView && mSession != null) {
+            if (hasFocus && this == sMainTvView.get() && mSession != null) {
                 mSession.setMain();
             }
         }
@@ -828,7 +836,7 @@
             mSession = session;
             if (session != null) {
                 synchronized (sMainTvViewLock) {
-                    if (hasWindowFocus() && TvView.this == sMainTvView) {
+                    if (hasWindowFocus() && TvView.this == sMainTvView.get()) {
                         mSession.setMain();
                     }
                 }
diff --git a/packages/SystemUI/res/drawable/ic_qs_vpn.xml b/packages/SystemUI/res/drawable/ic_qs_vpn.xml
index e9141ef..e7ef02a 100644
--- a/packages/SystemUI/res/drawable/ic_qs_vpn.xml
+++ b/packages/SystemUI/res/drawable/ic_qs_vpn.xml
@@ -18,8 +18,7 @@
         android:height="12.0dp"
         android:viewportWidth="24.0"
         android:viewportHeight="24.0">
-
     <path
         android:fillColor="#4DFFFFFF"
-        android:pathData="M22.000000,4.000000L22.000000,3.500000C22.000000,2.100000 20.900000,1.000000 19.500000,1.000000C18.100000,1.000000 17.000000,2.100000 17.000000,3.500000L17.000000,4.000000c-0.600000,0.000000 -1.000000,0.400000 -1.000000,1.000000l0.000000,4.000000c0.000000,0.600000 0.400000,1.000000 1.000000,1.000000l5.000000,0.000000c0.600000,0.000000 1.000000,-0.400000 1.000000,-1.000000L23.000000,5.000000C23.000000,4.400000 22.600000,4.000000 22.000000,4.000000zM21.200001,4.000000l-3.400000,0.000000L17.800001,3.500000c0.000000,-0.900000 0.800000,-1.700000 1.700000,-1.700000c0.900000,0.000000 1.700000,0.800000 1.700000,1.700000L21.200003,4.000000zM18.900000,12.000000c0.000000,0.300000 0.100000,0.700000 0.100000,1.000000c0.000000,2.100000 -0.800000,4.000000 -2.100000,5.400000c-0.300000,-0.800000 -1.000000,-1.400000 -1.900000,-1.400000l-1.000000,0.000000l0.000000,-3.000000c0.000000,-0.600000 -0.400000,-1.000000 -1.000000,-1.000000L7.000000,13.000000l0.000000,-2.000000l2.000000,0.000000c0.600000,0.000000 1.000000,-0.400000 1.000000,-1.000000L10.000000,8.000000l2.000000,0.000000c1.100000,0.000000 2.000000,-0.900000 2.000000,-2.000000L14.000000,3.500000C13.100000,3.200000 12.000000,3.000000 11.000000,3.000000C5.500000,3.000000 1.000000,7.500000 1.000000,13.000000c0.000000,5.500000 4.500000,10.000000 10.000000,10.000000c5.500000,0.000000 10.000000,-4.500000 10.000000,-10.000000c0.000000,-0.300000 0.000000,-0.700000 -0.100000,-1.000000L18.900000,12.000000zM10.000000,20.900000c-3.900000,-0.500000 -7.000000,-3.900000 -7.000000,-7.900000c0.000000,-0.600000 0.100000,-1.200000 0.200000,-1.800000L8.000000,16.000000l0.000000,1.000000c0.000000,1.100000 0.900000,2.000000 2.000000,2.000000L10.000000,20.900000z"/>
+        android:pathData="M12.700000,10.000000c-0.800000,-2.300000 -3.000000,-4.000000 -5.700000,-4.000000c-3.300000,0.000000 -6.000000,2.700000 -6.000000,6.000000s2.700000,6.000000 6.000000,6.000000c2.600000,0.000000 4.800000,-1.700000 5.700000,-4.000000L17.000000,14.000000l0.000000,4.000000l4.000000,0.000000l0.000000,-4.000000l2.000000,0.000000l0.000000,-4.000000L12.700000,10.000000zM7.000000,14.000000c-1.100000,0.000000 -2.000000,-0.900000 -2.000000,-2.000000c0.000000,-1.100000 0.900000,-2.000000 2.000000,-2.000000s2.000000,0.900000 2.000000,2.000000C9.000000,13.100000 8.100000,14.000000 7.000000,14.000000z"/>
 </vector>
diff --git a/packages/SystemUI/res/layout/super_status_bar.xml b/packages/SystemUI/res/layout/super_status_bar.xml
index 365a7d2..09e541f 100644
--- a/packages/SystemUI/res/layout/super_status_bar.xml
+++ b/packages/SystemUI/res/layout/super_status_bar.xml
@@ -38,7 +38,9 @@
                 android:layout_height="match_parent"
                 android:elevation="2dp"
                 android:background="@drawable/brightness_mirror_background">
-            <include layout="@layout/quick_settings_brightness_dialog" />
+            <include layout="@layout/quick_settings_brightness_dialog"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content" />
         </FrameLayout>
     </FrameLayout>
 
diff --git a/services/core/java/com/android/server/am/LockTaskNotify.java b/services/core/java/com/android/server/am/LockTaskNotify.java
index cf65243..5768ddb 100644
--- a/services/core/java/com/android/server/am/LockTaskNotify.java
+++ b/services/core/java/com/android/server/am/LockTaskNotify.java
@@ -34,6 +34,7 @@
     private final Context mContext;
     private final H mHandler;
     private AccessibilityManager mAccessibilityManager;
+    private Toast mLastToast;
 
     public LockTaskNotify(Context context) {
         mContext = context;
@@ -52,7 +53,11 @@
         if (!isLocked && mAccessibilityManager.isEnabled()) {
             text = mContext.getString(R.string.lock_to_app_toast_accessible);
         }
-        Toast.makeText(mContext, text, Toast.LENGTH_LONG).show();
+        if (mLastToast != null) {
+            mLastToast.cancel();
+        }
+        mLastToast = Toast.makeText(mContext, text, Toast.LENGTH_LONG);
+        mLastToast.show();
     }
 
     public void show(boolean starting) {
diff --git a/services/core/java/com/android/server/am/LockToAppRequestDialog.java b/services/core/java/com/android/server/am/LockToAppRequestDialog.java
index 12dcf7e..5abf699 100644
--- a/services/core/java/com/android/server/am/LockToAppRequestDialog.java
+++ b/services/core/java/com/android/server/am/LockToAppRequestDialog.java
@@ -102,8 +102,7 @@
         if (unlockStringId != 0) {
             String unlockString = mContext.getString(unlockStringId);
             mCheckbox = (CheckBox) mDialog.findViewById(R.id.lock_to_app_checkbox);
-            mCheckbox.setText(mContext.getString(R.string.lock_to_app_use_screen_lock,
-                    unlockString));
+            mCheckbox.setText(unlockString);
 
             // Remember state.
             try {
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index b47a5e4..47df30b 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -18,6 +18,7 @@
 
 import static android.Manifest.permission.MANAGE_CA_CERTIFICATES;
 
+import android.accessibilityservice.AccessibilityServiceInfo;
 import android.app.Activity;
 import android.app.ActivityManagerNative;
 import android.app.AlarmManager;
@@ -39,14 +40,15 @@
 import android.content.IntentFilter;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.IPackageManager;
+import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.ResolveInfo;
 import android.content.pm.UserInfo;
 import android.media.AudioManager;
 import android.media.IAudioService;
 import android.net.ConnectivityManager;
 import android.net.Uri;
-import android.content.pm.PackageManager.NameNotFoundException;
 import android.database.ContentObserver;
 import android.hardware.usb.UsbManager;
 import android.net.ProxyInfo;
@@ -77,6 +79,10 @@
 import android.util.Slog;
 import android.util.SparseArray;
 import android.util.Xml;
+import android.view.accessibility.AccessibilityManager;
+import android.view.accessibility.IAccessibilityManager;
+import android.view.inputmethod.InputMethodInfo;
+import android.view.inputmethod.InputMethodManager;
 import android.view.IWindowManager;
 
 import com.android.internal.R;
@@ -282,6 +288,8 @@
         private static final String TAG_DISABLE_SCREEN_CAPTURE = "disable-screen-capture";
         private static final String TAG_DISABLE_ACCOUNT_MANAGEMENT = "disable-account-management";
         private static final String TAG_ACCOUNT_TYPE = "account-type";
+        private static final String TAG_PERMITTED_ACCESSIBILITY_SERVICES
+                = "permitted-accessiblity-services";
         private static final String TAG_ENCRYPTION_REQUESTED = "encryption-requested";
         private static final String TAG_MANAGE_TRUST_AGENT_FEATURES = "manage-trust-agent-features";
         private static final String TAG_TRUST_AGENT_FEATURE = "feature";
@@ -291,6 +299,7 @@
         private static final String TAG_GLOBAL_PROXY_EXCLUSION_LIST = "global-proxy-exclusion-list";
         private static final String TAG_GLOBAL_PROXY_SPEC = "global-proxy-spec";
         private static final String TAG_SPECIFIES_GLOBAL_PROXY = "specifies-global-proxy";
+        private static final String TAG_PERMITTED_IMES = "permitted-imes";
         private static final String TAG_MAX_FAILED_PASSWORD_WIPE = "max-failed-password-wipe";
         private static final String TAG_MAX_TIME_TO_UNLOCK = "max-time-to-unlock";
         private static final String TAG_MIN_PASSWORD_NONLETTER = "min-password-nonletter";
@@ -307,6 +316,7 @@
         private static final String TAG_CROSS_PROFILE_WIDGET_PROVIDERS =
                 "cross-profile-widget-providers";
         private static final String TAG_PROVIDER = "provider";
+        private static final String TAG_PACKAGE_LIST_ITEM  = "item";
 
         final DeviceAdminInfo info;
 
@@ -358,6 +368,16 @@
 
         Set<String> accountTypesWithManagementDisabled = new HashSet<String>();
 
+        // The list of permitted accessibility services package namesas set by a profile
+        // or device owner. Null means all accessibility services are allowed, empty means
+        // none except system services are allowed.
+        List<String> permittedAccessiblityServices;
+
+        // The list of permitted input methods package names as set by a profile or device owner.
+        // Null means all input methods are allowed, empty means none except system imes are
+        // allowed.
+        List<String> permittedInputMethods;
+
         // TODO: review implementation decisions with frameworks team
         boolean specifiesGlobalProxy = false;
         String globalProxySpec = null;
@@ -521,6 +541,25 @@
                 }
                 out.endTag(null, TAG_CROSS_PROFILE_WIDGET_PROVIDERS);
             }
+            writePackageListToXml(out, TAG_PERMITTED_ACCESSIBILITY_SERVICES,
+                    permittedAccessiblityServices);
+            writePackageListToXml(out, TAG_PERMITTED_IMES, permittedInputMethods);
+        }
+
+        void writePackageListToXml(XmlSerializer out, String outerTag,
+                List<String> packageList)
+                throws IllegalArgumentException, IllegalStateException, IOException {
+            if (packageList == null) {
+                return;
+            }
+
+            out.startTag(null, outerTag);
+            for (String packageName : packageList) {
+                out.startTag(null, TAG_PACKAGE_LIST_ITEM);
+                out.attribute(null, ATTR_VALUE, packageName);
+                out.endTag(null, TAG_PACKAGE_LIST_ITEM);
+            }
+            out.endTag(null, outerTag);
         }
 
         void readFromXml(XmlPullParser parser)
@@ -604,6 +643,10 @@
                     trustAgentFeatures = getAllTrustAgentFeatures(parser, tag);
                 } else if (TAG_CROSS_PROFILE_WIDGET_PROVIDERS.equals(tag)) {
                     crossProfileWidgetProviders = getCrossProfileWidgetProviders(parser, tag);
+                } else if (TAG_PERMITTED_ACCESSIBILITY_SERVICES.equals(tag)) {
+                    permittedAccessiblityServices = readPackageList(parser, tag);
+                } else if (TAG_PERMITTED_IMES.equals(tag)) {
+                    permittedInputMethods = readPackageList(parser, tag);
                 } else {
                     Slog.w(LOG_TAG, "Unknown admin tag: " + tag);
                 }
@@ -611,6 +654,31 @@
             }
         }
 
+        private List<String> readPackageList(XmlPullParser parser,
+                String tag) throws XmlPullParserException, IOException {
+            List<String> result = new ArrayList<String>();
+            int outerDepth = parser.getDepth();
+            int outerType;
+            while ((outerType=parser.next()) != XmlPullParser.END_DOCUMENT
+                    && (outerType != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+                if (outerType == XmlPullParser.END_TAG || outerType == XmlPullParser.TEXT) {
+                    continue;
+                }
+                String outerTag = parser.getName();
+                if (TAG_PACKAGE_LIST_ITEM.equals(outerTag)) {
+                    String packageName = parser.getAttributeValue(null, ATTR_VALUE);
+                    if (packageName != null) {
+                        result.add(packageName);
+                    } else {
+                        Slog.w(LOG_TAG, "Package name missing under " + outerTag);
+                    }
+                } else {
+                    Slog.w(LOG_TAG, "Unknown tag under " + tag +  ": " + outerTag);
+                }
+            }
+            return result;
+        }
+
         private Set<String> readDisableAccountInfo(XmlPullParser parser, String tag)
                 throws XmlPullParserException, IOException {
             int outerDepthDAM = parser.getDepth();
@@ -754,6 +822,14 @@
                     pw.println(disabledKeyguardFeatures);
             pw.print(prefix); pw.print("crossProfileWidgetProviders=");
                     pw.println(crossProfileWidgetProviders);
+            if (!(permittedAccessiblityServices == null)) {
+                pw.print(prefix); pw.print("permittedAccessibilityServices=");
+                        pw.println(permittedAccessiblityServices.toString());
+            }
+            if (!(permittedInputMethods == null)) {
+                pw.print(prefix); pw.print("permittedInputMethods=");
+                        pw.println(permittedInputMethods.toString());
+            }
         }
     }
 
@@ -3971,6 +4047,343 @@
         }
     }
 
+    /**
+     * @return true if all packages in enabledPackages are either in the list
+     * permittedList or are a system app.
+     */
+    private boolean checkPackagesInPermittedListOrSystem(List<String> enabledPackages,
+            List<String> permittedList) {
+        int userIdToCheck = UserHandle.getCallingUserId();
+        long id = Binder.clearCallingIdentity();
+        try {
+            // If we have an enabled packages list for a managed profile the packages
+            // we should check are installed for the parent user.
+            UserInfo user = mUserManager.getUserInfo(userIdToCheck);
+            if (user.isManagedProfile()) {
+                userIdToCheck = user.profileGroupId;
+            }
+
+            IPackageManager pm = AppGlobals.getPackageManager();
+            for (String enabledPackage : enabledPackages) {
+                boolean systemService = false;
+                try {
+                    ApplicationInfo applicationInfo = pm.getApplicationInfo(enabledPackage,
+                            PackageManager.GET_UNINSTALLED_PACKAGES, userIdToCheck);
+                    systemService = (applicationInfo.flags
+                            & ApplicationInfo.FLAG_SYSTEM) != 0;
+                } catch (RemoteException e) {
+                    Log.i(LOG_TAG, "Can't talk to package managed", e);
+                }
+                if (!systemService && !permittedList.contains(enabledPackage)) {
+                    return false;
+                }
+            }
+        } finally {
+            restoreCallingIdentity(id);
+        }
+        return true;
+    }
+
+    private AccessibilityManager getAccessibilityManagerForUser(int userId) {
+        // Not using AccessibilityManager.getInstance because that guesses
+        // at the user you require based on callingUid and caches for a given
+        // process.
+        IBinder iBinder = ServiceManager.getService(Context.ACCESSIBILITY_SERVICE);
+        IAccessibilityManager service = iBinder == null
+                ? null : IAccessibilityManager.Stub.asInterface(iBinder);
+        return new AccessibilityManager(mContext, service, userId);
+    }
+
+    @Override
+    public boolean setPermittedAccessibilityServices(ComponentName who, List packageList) {
+        if (!mHasFeature) {
+            return false;
+        }
+        if (who == null) {
+            throw new NullPointerException("ComponentName is null");
+        }
+
+        if (packageList != null) {
+            int userId = UserHandle.getCallingUserId();
+            List<AccessibilityServiceInfo> enabledServices = null;
+            long id = Binder.clearCallingIdentity();
+            try {
+                UserInfo user = mUserManager.getUserInfo(userId);
+                if (user.isManagedProfile()) {
+                    userId = user.profileGroupId;
+                }
+                AccessibilityManager accessibilityManager = getAccessibilityManagerForUser(userId);
+                enabledServices = accessibilityManager.getEnabledAccessibilityServiceList(
+                        AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
+            } finally {
+                restoreCallingIdentity(id);
+            }
+
+            if (enabledServices != null) {
+                List<String> enabledPackages = new ArrayList<String>();
+                for (AccessibilityServiceInfo service : enabledServices) {
+                    enabledPackages.add(service.getResolveInfo().serviceInfo.packageName);
+                }
+                if (!checkPackagesInPermittedListOrSystem(enabledPackages, packageList)) {
+                    Slog.e(LOG_TAG, "Cannot set permitted accessibility services, "
+                            + "because it contains already enabled accesibility services.");
+                    return false;
+                }
+            }
+        }
+
+        synchronized (this) {
+            ActiveAdmin admin = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
+            admin.permittedAccessiblityServices = packageList;
+            saveSettingsLocked(UserHandle.getCallingUserId());
+        }
+        return true;
+    }
+
+    @Override
+    public List getPermittedAccessibilityServices(ComponentName who) {
+        if (!mHasFeature) {
+            return null;
+        }
+
+        if (who == null) {
+            throw new NullPointerException("ComponentName is null");
+        }
+
+        synchronized (this) {
+            ActiveAdmin admin = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
+            return admin.permittedAccessiblityServices;
+        }
+    }
+
+    @Override
+    public List getPermittedAccessibilityServicesForUser(int userId) {
+        if (!mHasFeature) {
+            return null;
+        }
+        synchronized (this) {
+            List<String> result = null;
+            // If we have multiple profiles we return the intersection of the
+            // permitted lists. This can happen in cases where we have a device
+            // and profile owner.
+            List<UserInfo> profiles = mUserManager.getProfiles(userId);
+            final int PROFILES_SIZE = profiles.size();
+            for (int i = 0; i < PROFILES_SIZE; ++i) {
+                // Just loop though all admins, only device or profiles
+                // owners can have permitted lists set.
+                DevicePolicyData policy = getUserData(profiles.get(i).id);
+                final int N = policy.mAdminList.size();
+                for (int j = 0; j < N; j++) {
+                    ActiveAdmin admin = policy.mAdminList.get(j);
+                    List<String> fromAdmin = admin.permittedAccessiblityServices;
+                    if (fromAdmin != null) {
+                        if (result == null) {
+                            result = new ArrayList<String>(fromAdmin);
+                        } else {
+                            result.retainAll(fromAdmin);
+                        }
+                    }
+                }
+            }
+
+            // If we have a permitted list add all system accessibility services.
+            if (result != null) {
+                long id = Binder.clearCallingIdentity();
+                try {
+                    UserInfo user = mUserManager.getUserInfo(userId);
+                    if (user.isManagedProfile()) {
+                        userId = user.profileGroupId;
+                    }
+                    AccessibilityManager accessibilityManager =
+                            getAccessibilityManagerForUser(userId);
+                    List<AccessibilityServiceInfo> installedServices =
+                            accessibilityManager.getInstalledAccessibilityServiceList();
+
+                    IPackageManager pm = AppGlobals.getPackageManager();
+                    if (installedServices != null) {
+                        for (AccessibilityServiceInfo service : installedServices) {
+                            String packageName = service.getResolveInfo().serviceInfo.packageName;
+                            try {
+                                ApplicationInfo applicationInfo = pm.getApplicationInfo(packageName,
+                                        PackageManager.GET_UNINSTALLED_PACKAGES, userId);
+                                if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+                                    result.add(packageName);
+                                }
+                            } catch (RemoteException e) {
+                                Log.i(LOG_TAG, "Accessibility service in missing package", e);
+                            }
+                        }
+                    }
+                } finally {
+                    restoreCallingIdentity(id);
+                }
+            }
+
+            return result;
+        }
+    }
+
+    private boolean checkCallerIsCurrentUserOrProfile() {
+        int callingUserId = UserHandle.getCallingUserId();
+        long token = Binder.clearCallingIdentity();
+        try {
+            UserInfo currentUser;
+            UserInfo callingUser = mUserManager.getUserInfo(callingUserId);
+            try {
+                currentUser = ActivityManagerNative.getDefault().getCurrentUser();
+            } catch (RemoteException e) {
+                Slog.e(LOG_TAG, "Failed to talk to activity managed.", e);
+                return false;
+            }
+
+            if (callingUser.isManagedProfile() && callingUser.profileGroupId != currentUser.id) {
+                Slog.e(LOG_TAG, "Cannot set permitted input methods for managed profile "
+                        + "of a user that isn't the foreground user.");
+                return false;
+            }
+            if (!callingUser.isManagedProfile() && callingUserId != currentUser.id ) {
+                Slog.e(LOG_TAG, "Cannot set permitted input methods "
+                        + "of a user that isn't the foreground user.");
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+        return true;
+    }
+
+    @Override
+    public boolean setPermittedInputMethods(ComponentName who, List packageList) {
+        if (!mHasFeature) {
+            return false;
+        }
+        if (who == null) {
+            throw new NullPointerException("ComponentName is null");
+        }
+
+        // TODO When InputMethodManager supports per user calls remove
+        //      this restriction.
+        if (!checkCallerIsCurrentUserOrProfile()) {
+            return false;
+        }
+
+        if (packageList != null) {
+            // InputMethodManager fetches input methods for current user.
+            // So this can only be set when calling user is the current user
+            // or parent is current user in case of managed profiles.
+            InputMethodManager inputMethodManager = (InputMethodManager) mContext
+                    .getSystemService(Context.INPUT_METHOD_SERVICE);
+            List<InputMethodInfo> enabledImes = inputMethodManager.getEnabledInputMethodList();
+
+            if (enabledImes != null) {
+                List<String> enabledPackages = new ArrayList<String>();
+                for (InputMethodInfo ime : enabledImes) {
+                    enabledPackages.add(ime.getPackageName());
+                }
+                if (!checkPackagesInPermittedListOrSystem(enabledPackages, packageList)) {
+                    Slog.e(LOG_TAG, "Cannot set permitted input methods, "
+                            + "because it contains already enabled input method.");
+                    return false;
+                }
+            }
+        }
+
+        synchronized (this) {
+            ActiveAdmin admin = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
+            admin.permittedInputMethods = packageList;
+            saveSettingsLocked(UserHandle.getCallingUserId());
+        }
+        return true;
+    }
+
+    @Override
+    public List getPermittedInputMethods(ComponentName who) {
+        if (!mHasFeature) {
+            return null;
+        }
+
+        if (who == null) {
+            throw new NullPointerException("ComponentName is null");
+        }
+
+        synchronized (this) {
+            ActiveAdmin admin = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
+            return admin.permittedInputMethods;
+        }
+    }
+
+    @Override
+    public List getPermittedInputMethodsForCurrentUser() {
+        UserInfo currentUser;
+        try {
+            currentUser = ActivityManagerNative.getDefault().getCurrentUser();
+        } catch (RemoteException e) {
+            Slog.e(LOG_TAG, "Failed to make remote calls to get current user", e);
+            // Activity managed is dead, just allow all IMEs
+            return null;
+        }
+
+        int userId = currentUser.id;
+        synchronized (this) {
+            List<String> result = null;
+            // If we have multiple profiles we return the intersection of the
+            // permitted lists. This can happen in cases where we have a device
+            // and profile owner.
+            List<UserInfo> profiles = mUserManager.getProfiles(userId);
+            final int PROFILES_SIZE = profiles.size();
+            for (int i = 0; i < PROFILES_SIZE; ++i) {
+                // Just loop though all admins, only device or profiles
+                // owners can have permitted lists set.
+                DevicePolicyData policy = getUserData(profiles.get(i).id);
+                final int N = policy.mAdminList.size();
+                for (int j = 0; j < N; j++) {
+                    ActiveAdmin admin = policy.mAdminList.get(j);
+                    List<String> fromAdmin = admin.permittedInputMethods;
+                    if (fromAdmin != null) {
+                        if (result == null) {
+                            result = new ArrayList<String>(fromAdmin);
+                        } else {
+                            result.retainAll(fromAdmin);
+                        }
+                    }
+                }
+            }
+
+            // If we have a permitted list add all system input methods.
+            if (result != null) {
+                InputMethodManager inputMethodManager = (InputMethodManager) mContext
+                        .getSystemService(Context.INPUT_METHOD_SERVICE);
+                List<InputMethodInfo> imes = inputMethodManager.getInputMethodList();
+                long id = Binder.clearCallingIdentity();
+                try {
+                    IPackageManager pm = AppGlobals.getPackageManager();
+                    if (imes != null) {
+                        for (InputMethodInfo ime : imes) {
+                            String packageName = ime.getPackageName();
+                            try {
+                                ApplicationInfo applicationInfo = pm.getApplicationInfo(
+                                        packageName, PackageManager.GET_UNINSTALLED_PACKAGES,
+                                        userId);
+                                if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+                                    result.add(packageName);
+                                }
+                            } catch (RemoteException e) {
+                                Log.i(LOG_TAG, "Input method for missing package", e);
+                            }
+                        }
+                    }
+                } finally {
+                    restoreCallingIdentity(id);
+                }
+            }
+            return result;
+        }
+    }
+
     @Override
     public UserHandle createUser(ComponentName who, String name) {
         synchronized (this) {