Merge "AAPT: Fix printing of resource configurations" into mnc-dev
diff --git a/core/java/android/text/Hyphenator.java b/core/java/android/text/Hyphenator.java
index 1ee3827..10a994a 100644
--- a/core/java/android/text/Hyphenator.java
+++ b/core/java/android/text/Hyphenator.java
@@ -45,6 +45,8 @@
     @GuardedBy("sLock")
     final static HashMap<Locale, Hyphenator> sMap = new HashMap<Locale, Hyphenator>();
 
+    final static Hyphenator sEmptyHyphenator = new Hyphenator(StaticLayout.nLoadHyphenator(""));
+
     final private long mNativePtr;
 
     private Hyphenator(long nativePtr) {
@@ -53,19 +55,19 @@
 
     public static long get(@Nullable Locale locale) {
         synchronized (sLock) {
-            if (sMap.containsKey(locale)) {
-                Hyphenator result = sMap.get(locale);
-                return (result == null) ? 0 : result.mNativePtr;
+            Hyphenator result = sMap.get(locale);
+            if (result != null) {
+                return result.mNativePtr;
             }
 
             // TODO: Convert this a proper locale-fallback system
 
             // Fall back to language-only, if available
             Locale languageOnlyLocale = new Locale(locale.getLanguage());
-            if (sMap.containsKey(languageOnlyLocale)) {
-                Hyphenator result = sMap.get(languageOnlyLocale);
+            result = sMap.get(languageOnlyLocale);
+            if (result != null) {
                 sMap.put(locale, result);
-                return (result == null) ? 0 : result.mNativePtr;
+                return result.mNativePtr;
             }
 
             // Fall back to script-only, if available
@@ -75,16 +77,16 @@
                         .setLanguage("und")
                         .setScript(script)
                         .build();
-                if (sMap.containsKey(scriptOnlyLocale)) {
-                    Hyphenator result = sMap.get(scriptOnlyLocale);
+                result = sMap.get(scriptOnlyLocale);
+                if (result != null) {
                     sMap.put(locale, result);
-                    return (result == null) ? 0 : result.mNativePtr;
+                    return result.mNativePtr;
                 }
             }
 
-            sMap.put(locale, null); // To remember we found nothing.
+            sMap.put(locale, sEmptyHyphenator);  // To remember we found nothing.
         }
-        return 0;
+        return sEmptyHyphenator.mNativePtr;
     }
 
     private static Hyphenator loadHyphenator(String languageTag) {
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 9b1db57..c22c0ef 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -555,11 +555,6 @@
                 mPendingContentInsets.set(mAttachInfo.mContentInsets);
                 mPendingStableInsets.set(mAttachInfo.mStableInsets);
                 mPendingVisibleInsets.set(0, 0, 0, 0);
-                try {
-                    relayoutWindow(attrs, getHostVisibility(), false);
-                } catch (RemoteException e) {
-                    if (DEBUG_LAYOUT) Log.e(TAG, "failed to relayoutWindow", e);
-                }
                 if (DEBUG_LAYOUT) Log.v(TAG, "Added window " + mWindow);
                 if (res < WindowManagerGlobal.ADD_OKAY) {
                     mAttachInfo.mRootView = null;
diff --git a/services/core/java/com/android/server/MountService.java b/services/core/java/com/android/server/MountService.java
index ed136e9..857394f 100644
--- a/services/core/java/com/android/server/MountService.java
+++ b/services/core/java/com/android/server/MountService.java
@@ -146,8 +146,6 @@
 class MountService extends IMountService.Stub
         implements INativeDaemonConnectorCallbacks, Watchdog.Monitor {
 
-    // TODO: finish enforcing UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA
-
     // Static direct instance pointer for the tightly-coupled idle service to use
     static MountService sSelf = null;
 
@@ -631,6 +629,10 @@
                 }
                 case H_VOLUME_MOUNT: {
                     final VolumeInfo vol = (VolumeInfo) msg.obj;
+                    if (isMountDisallowed(vol)) {
+                        Slog.i(TAG, "Ignoring mount " + vol.getId() + " due to policy");
+                        break;
+                    }
                     try {
                         mConnector.execute("volume", "mount", vol.id, vol.mountFlags,
                                 vol.mountUserId);
@@ -1305,10 +1307,16 @@
         mContext.enforceCallingOrSelfPermission(perm, perm);
     }
 
-    private void enforceUserRestriction(String restriction) {
-        UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
-        if (um.hasUserRestriction(restriction, Binder.getCallingUserHandle())) {
-            throw new SecurityException("User has restriction " + restriction);
+    /**
+     * Decide if volume is mountable per device policies.
+     */
+    private boolean isMountDisallowed(VolumeInfo vol) {
+        if (vol.type == VolumeInfo.TYPE_PUBLIC || vol.type == VolumeInfo.TYPE_PRIVATE) {
+            final UserManager userManager = mContext.getSystemService(UserManager.class);
+            return userManager.hasUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA,
+                    Binder.getCallingUserHandle());
+        } else {
+            return false;
         }
     }
 
@@ -1586,8 +1594,8 @@
         waitForReady();
 
         final VolumeInfo vol = findVolumeByIdOrThrow(volId);
-        if (vol.type == VolumeInfo.TYPE_PUBLIC || vol.type == VolumeInfo.TYPE_PRIVATE) {
-            enforceUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA);
+        if (isMountDisallowed(vol)) {
+            throw new SecurityException("Mounting " + volId + " restricted by policy");
         }
         try {
             mConnector.execute("volume", "mount", vol.id, vol.mountFlags, vol.mountUserId);
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index 23cb767..6707562 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -529,6 +529,7 @@
 
     @Override
     public void setUserRestriction(String key, boolean value, int userId) {
+        checkManageUsersPermission("setUserRestriction");
         synchronized (mPackagesLock) {
             if (!SYSTEM_CONTROLLED_RESTRICTIONS.contains(key)) {
                 Bundle restrictions = getUserRestrictions(userId);