Merge "Improvements to user settings" into lmp-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index fac2d34..b9f87d1 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -93,6 +93,13 @@
             </intent-filter>
         </activity>
 
+        <receiver android:name="LauncherIconToggler">
+            <intent-filter>
+                <action android:name="android.intent.action.BOOT_COMPLETED"/>
+                <action android:name="android.intent.action.PRE_BOOT_COMPLETED"/>
+            </intent-filter>
+        </receiver>
+
         <activity android:name=".SubSettings"
                 android:taskAffinity="com.android.settings"
                 android:parentActivityName="Settings">
diff --git a/res/layout/crypt_keeper_password_entry.xml b/res/layout/crypt_keeper_password_entry.xml
index ecbfefd..6e99527 100644
--- a/res/layout/crypt_keeper_password_entry.xml
+++ b/res/layout/crypt_keeper_password_entry.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
 **
-** Copyright 2011, The Android Open Source Project
+** Copyright 2014, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License")
 ** you may not use this file except in compliance with the License.
@@ -20,29 +20,36 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="vertical"
->
+    android:orientation="vertical">
+
     <include layout="@layout/crypt_keeper_status" />
 
     <LinearLayout
-        android:layout_height="wrap_content"
+        android:layout_height="0dp"
         android:layout_width="match_parent"
-        android:layout_marginStart="8dip"
-        android:layout_marginEnd="8dip"
-        android:orientation="horizontal"
-    >
-        <include layout="@layout/crypt_keeper_password_field" />
+        android:layout_weight="1"
+        android:layout_marginStart="@dimen/crypt_keeper_edit_text_margin"
+        android:layout_marginEnd="@dimen/crypt_keeper_edit_text_margin"
+        android:orientation="vertical"
+        android:gravity="center_vertical">
+
+        <LinearLayout
+            android:background="@color/crypt_keeper_password_background"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal">
+            <include layout="@layout/crypt_keeper_password_field" />
+        </LinearLayout>
+
     </LinearLayout>
+
     <!-- Emergency call button.
          Text is set by CryptKeeper.updateEmergencyCallButtonState() -->
     <Button android:id="@+id/emergencyCallButton"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_gravity="center"
-        android:layout_marginTop="16dip"
-        style="?android:attr/borderlessButtonStyle"
-        android:textSize="14sp"
-        android:drawablePadding="6dip"
-        />
+        android:layout_gravity="center_horizontal"
+        android:layout_marginTop="@dimen/crypt_keeper_emergency_call_space_above"
+        style="?android:attr/borderlessButtonStyle" />
 
 </LinearLayout>
diff --git a/res/layout/crypt_keeper_password_field.xml b/res/layout/crypt_keeper_password_field.xml
index 9a2a24d..2d98b25 100644
--- a/res/layout/crypt_keeper_password_field.xml
+++ b/res/layout/crypt_keeper_password_field.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
 **
-** Copyright 2011, The Android Open Source Project
+** Copyright 2014, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License")
 ** you may not use this file except in compliance with the License.
@@ -20,16 +20,13 @@
 <!-- Contents of the password entry field for CryptKeeper. Comes with an IME
      switcher, if necessary. Assumed to be in a horizontal LinearLayout. -->
 <merge xmlns:android="http://schemas.android.com/apk/res/android">
+
     <EditText android:id="@+id/passwordEntry"
         android:layout_height="wrap_content"
         android:layout_width="0dip"
         android:layout_weight="1"
-        android:singleLine="true"
         android:inputType="textPassword"
-        android:imeOptions="flagForceAscii|actionDone"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        android:gravity="center_horizontal"
-     />
+        style="@style/TextAppearance.CryptKeeper_PasswordEntry" />
 
    <ImageView android:id="@+id/switch_ime_button"
        android:layout_width="wrap_content"
@@ -37,9 +34,9 @@
        android:src="@drawable/ic_lockscreen_ime"
        android:clickable="true"
        android:contentDescription="@string/crypt_keeper_switch_input_method"
-       android:padding="8dip"
+       android:padding="@dimen/crypt_keeper_edit_text_ime_padding"
        android:layout_gravity="center"
        android:background="?android:attr/selectableItemBackground"
-       android:visibility="gone"
-   />
+       android:visibility="gone" />
+
 </merge>
diff --git a/res/layout/crypt_keeper_pattern_entry.xml b/res/layout/crypt_keeper_pattern_entry.xml
index 2538809..80e318f 100644
--- a/res/layout/crypt_keeper_pattern_entry.xml
+++ b/res/layout/crypt_keeper_pattern_entry.xml
@@ -20,18 +20,26 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="vertical"
->
+    android:orientation="vertical">
+
     <include layout="@layout/crypt_keeper_status" />
 
     <LinearLayout
-        android:layout_height="wrap_content"
+        android:layout_height="0dp"
         android:layout_width="match_parent"
-        android:layout_marginStart="8dip"
-        android:layout_marginEnd="8dip"
-        android:orientation="horizontal"
-    >
-        <include layout="@layout/crypt_keeper_pattern_field" />
+        android:layout_weight="1"
+        android:orientation="vertical"
+        android:gravity="center_vertical">
+
+        <LinearLayout
+            android:layout_height="wrap_content"
+            android:layout_width="match_parent"
+            android:layout_marginStart="@dimen/crypt_keeper_edit_text_margin"
+            android:layout_marginEnd="@dimen/crypt_keeper_edit_text_margin"
+            android:orientation="horizontal" >
+            <include layout="@layout/crypt_keeper_pattern_field" />
+        </LinearLayout>
+
     </LinearLayout>
 
     <!-- Emergency call button.
@@ -40,9 +48,7 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center"
-        android:layout_marginTop="16dip"
-        style="?android:attr/borderlessButtonStyle"
-        android:drawablePadding="6dip"
-    />
+        android:layout_marginTop="@dimen/crypt_keeper_emergency_call_space_above"
+        style="?android:attr/borderlessButtonStyle" />
 
 </LinearLayout>
diff --git a/res/layout/crypt_keeper_pattern_field.xml b/res/layout/crypt_keeper_pattern_field.xml
index a24d9aa..cf6a29f 100644
--- a/res/layout/crypt_keeper_pattern_field.xml
+++ b/res/layout/crypt_keeper_pattern_field.xml
@@ -20,11 +20,11 @@
 <!-- Contents of the password entry field for CryptKeeper. Comes with an IME
      switcher, if necessary. Assumed to be in a horizontal LinearLayout. -->
 <merge xmlns:android="http://schemas.android.com/apk/res/android">
+
    <com.android.internal.widget.LockPatternView android:id="@+id/lockPattern"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
-       android:background="@color/lock_pattern_background"
-   />
+       android:background="@color/lock_pattern_background" />
 
    <ImageView android:id="@+id/switch_ime_button"
        android:layout_width="wrap_content"
@@ -32,9 +32,9 @@
        android:src="@drawable/ic_lockscreen_ime"
        android:clickable="true"
        android:contentDescription="@string/crypt_keeper_switch_input_method"
-       android:padding="8dip"
+       android:padding="@dimen/crypt_keeper_edit_text_ime_padding"
        android:layout_gravity="center"
        android:background="?android:attr/selectableItemBackground"
-       android:visibility="gone"
-   />
+       android:visibility="gone" />
+
 </merge>
diff --git a/res/layout/crypt_keeper_pin_entry.xml b/res/layout/crypt_keeper_pin_entry.xml
index 0f1f1e7..0bcbec5 100644
--- a/res/layout/crypt_keeper_pin_entry.xml
+++ b/res/layout/crypt_keeper_pin_entry.xml
@@ -20,29 +20,36 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="vertical"
->
+    android:orientation="vertical">
+
     <include layout="@layout/crypt_keeper_status" />
 
     <LinearLayout
-        android:layout_height="wrap_content"
+        android:layout_height="0dp"
         android:layout_width="match_parent"
-        android:layout_marginStart="8dip"
-        android:layout_marginEnd="8dip"
-        android:orientation="horizontal"
-    >
-        <include layout="@layout/crypt_keeper_pin_field" />
+        android:layout_weight="1"
+        android:layout_marginStart="@dimen/crypt_keeper_edit_text_margin"
+        android:layout_marginEnd="@dimen/crypt_keeper_edit_text_margin"
+        android:orientation="vertical"
+        android:gravity="center_vertical">
+
+        <LinearLayout
+            android:background="@color/crypt_keeper_password_background"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal">
+            <include layout="@layout/crypt_keeper_pin_field" />
+        </LinearLayout>
+
     </LinearLayout>
 
     <!-- Emergency call button.
-         Text and icon are set by CryptKeeper.updateEmergencyCallButtonState() -->
+         Text is set by CryptKeeper.updateEmergencyCallButtonState() -->
     <Button android:id="@+id/emergencyCallButton"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_gravity="center"
-        android:layout_marginTop="16dip"
-        style="?android:attr/borderlessButtonStyle"
-        android:drawablePadding="6dip"
-    />
+        android:layout_gravity="center_horizontal"
+        android:layout_marginTop="@dimen/crypt_keeper_emergency_call_space_above"
+        style="?android:attr/borderlessButtonStyle" />
 
 </LinearLayout>
diff --git a/res/layout/crypt_keeper_pin_field.xml b/res/layout/crypt_keeper_pin_field.xml
index dd9d233..2fc1e81 100644
--- a/res/layout/crypt_keeper_pin_field.xml
+++ b/res/layout/crypt_keeper_pin_field.xml
@@ -20,16 +20,13 @@
 <!-- Contents of the password entry field for CryptKeeper. Comes with an IME
      switcher, if necessary. Assumed to be in a horizontal LinearLayout. -->
 <merge xmlns:android="http://schemas.android.com/apk/res/android">
+
     <EditText android:id="@+id/passwordEntry"
         android:layout_height="wrap_content"
         android:layout_width="0dip"
         android:layout_weight="1"
-        android:singleLine="true"
         android:inputType="numberPassword"
-        android:imeOptions="flagForceAscii|actionDone"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        android:gravity="center_horizontal"
-     />
+        style="@style/TextAppearance.CryptKeeper_PasswordEntry" />
 
    <ImageView android:id="@+id/switch_ime_button"
        android:layout_width="wrap_content"
@@ -37,9 +34,9 @@
        android:src="@drawable/ic_lockscreen_ime"
        android:clickable="true"
        android:contentDescription="@string/crypt_keeper_switch_input_method"
-       android:padding="8dip"
+       android:padding="@dimen/crypt_keeper_edit_text_ime_padding"
        android:layout_gravity="center"
        android:background="?android:attr/selectableItemBackground"
-       android:visibility="gone"
-   />
+       android:visibility="gone" />
+
 </merge>
diff --git a/res/layout/crypt_keeper_status.xml b/res/layout/crypt_keeper_status.xml
index 9015613..72f7aec 100644
--- a/res/layout/crypt_keeper_status.xml
+++ b/res/layout/crypt_keeper_status.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
 **
-** Copyright 2011, The Android Open Source Project
+** Copyright 2014, The Android Open Source Project
 **
 ** Licensed under the Apache License, Version 2.0 (the "License")
 ** you may not use this file except in compliance with the License.
@@ -23,8 +23,8 @@
     android:orientation="vertical"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:layout_gravity="center_horizontal"
->
+    android:layout_gravity="center_horizontal">
+
     <TextView
         android:id="@+id/status"
         android:layout_width="wrap_content"
@@ -33,11 +33,10 @@
         android:layout_marginStart="8dip"
         android:layout_marginEnd="8dip"
         android:textSize="18sp"
-        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:textAppearance="?android:attr/textAppearanceLarge"
         android:text="@string/enter_password"
-        android:drawableLeft="@*android:drawable/ic_lock_idle_lock"
-        android:layout_gravity="center_horizontal"
-        />
+        android:layout_gravity="center_horizontal" />
+
     <TextView
         android:id="@+id/owner_info"
         android:layout_width="match_parent"
@@ -49,6 +48,6 @@
         android:ellipsize="marquee"
         android:marqueeRepeatLimit ="marquee_forever"
         android:textSize="16sp"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        />
+        android:textAppearance="?android:attr/textAppearanceMedium" />
+
 </LinearLayout>
diff --git a/res/layout/preference_list_fragment.xml b/res/layout/preference_list_fragment.xml
index 297e33b..a97415e 100644
--- a/res/layout/preference_list_fragment.xml
+++ b/res/layout/preference_list_fragment.xml
@@ -29,8 +29,8 @@
               android:layout_width="match_parent"
               android:layout_height="0px"
               android:layout_weight="1"
-              android:paddingStart="@dimen/dashboard_padding_start"
-              android:paddingEnd="@dimen/dashboard_padding_end"
+              android:paddingStart="@dimen/settings_side_margin"
+              android:paddingEnd="@dimen/settings_side_margin"
               android:paddingTop="@dimen/dashboard_padding_top"
               android:paddingBottom="@dimen/dashboard_padding_bottom"
               android:scrollbarStyle="@*android:integer/preference_fragment_scrollbarStyle"
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index a00fbb4..3911378 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -641,10 +641,12 @@
         <item>alarm volume</item>
         <item>notification volume</item>
         <item>bluetooth volume</item>
-        <item>mute/unmute microphone</item>
         <item>keep awake</item>
         <item>monitor location</item>
         <item>monitor high power location</item>
+        <item>get usage stats</item>
+        <item>mute/unmute microphone</item>
+        <item>project media</item>
     </string-array>
 
     <!-- User display names for app ops codes -->
@@ -689,10 +691,12 @@
         <item>Alarm volume</item>
         <item>Notification volume</item>
         <item>Bluetooth volume</item>
-        <item>Mute/unmute microphone</item>
         <item>Keep awake</item>
         <item>Location</item>
         <item>Location</item>
+        <item>Get usage stats</item>
+        <item>Mute/unmute microphone</item>
+        <item>Project media</item>
     </string-array>
 
     <!-- Titles for the list of long press timeout options. -->
diff --git a/res/values/colors.xml b/res/values/colors.xml
index ee9c4c4..5b0092e 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -34,6 +34,7 @@
     <color name="crypt_keeper_clock_background">#ff9a9a9a</color>
     <color name="crypt_keeper_clock_foreground">#ff666666</color>
     <color name="crypt_keeper_clock_am_pm">#ff9a9a9a</color>
+    <color name="crypt_keeper_password_background">#70606060</color>
 
     <color name="divider_color">#20ffffff</color>
     <color name="title_color">@android:color/holo_blue_light</color>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index ae654e4..29d311f 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -171,4 +171,13 @@
     <dimen name="wifi_assistant_padding">25dp</dimen>
     <dimen name="wifi_assistant_text_padding">16dp</dimen>
 
+    <!-- CryptKeeper edit text margin -->
+    <dimen name="crypt_keeper_edit_text_margin">16dip</dimen>
+
+    <!-- CryptKeeper emergency call button dimensions -->
+    <dimen name="crypt_keeper_emergency_call_space_above">16dip</dimen>
+
+    <!-- CryptKeeper edit text ime icon padding -->
+    <dimen name="crypt_keeper_edit_text_ime_padding">8dip</dimen>
+
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d938772..96ccc59 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1296,8 +1296,6 @@
 
     <!-- Wifi Assistant title string.  [CHAR LIMIT=20] -->
     <string name="wifi_assistant_intro_setup">Introducing\nWi\u2011Fi Assistant</string>
-    <!-- Wifi Assistant title string.  [CHAR LIMIT=40] -->
-    <string name="wifi_assistant_title">Wi\u2011Fi Assistant</string>
     <!-- Wifi Assistant No, thanks string.  Text to say no to wifi assistant. [CHAR LIMIT=20] -->
     <string name="wifi_assistant_no_thanks">NO, THANKS</string>
     <!-- Wifi Assistant setup string.  Text to say yes to wifi assistant and begin setup. [CHAR LIMIT=20] -->
@@ -4848,7 +4846,7 @@
     <!-- Data Usage Foreground label.  [CHAR LIMIT=40] -->
     <string name="data_usage_forground_label">Foreground:</string>
     <!-- Data Usage Background label.  [CHAR LIMIT=40] -->
-    <string name="data_usage_forground_label">Background:</string>
+    <string name="data_usage_background_label">Background:</string>
     <!-- Button title for launching application-specific data usage settings. [CHAR LIMIT=32] -->
     <string name="data_usage_app_settings">View app settings</string>
     <!-- Checkbox label that restricts background data usage of a specific application. [CHAR LIMIT=32] -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 32a205d..1923ce6 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -82,6 +82,15 @@
         <item name="android:textColor">?android:attr/textColorPrimary</item>
     </style>
 
+    <style name="TextAppearance.CryptKeeper_PasswordEntry" parent="android:TextAppearance.Material">
+        <item name="android:textSize">36sp</item>
+        <item name="android:gravity">center_horizontal</item>
+        <item name="android:background">@null</item>
+        <item name="android:textCursorDrawable">@null</item>
+        <item name="android:singleLine">true</item>
+        <item name="android:imeOptions">flagForceAscii|actionDone</item>
+    </style>
+
     <style name="TallTitleBarTheme" parent="android:Theme.NoTitleBar">
         <item name="android:windowContentOverlay">@null</item>
     </style>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 44b83b1..54b5d41 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -150,6 +150,10 @@
     </style>
 
     <style name="Theme.CryptKeeper" parent="@android:style/Theme.Material.NoActionBar">
+        <item name="android:windowTranslucentStatus">false</item>
+        <item name="android:windowTranslucentNavigation">false</item>
+        <item name="android:windowDrawsSystemBarBackgrounds">false</item>
+
         <!-- LockPatternView colors -->
         <item name="@*android:regularColor">@color/unlock_pattern_view_regular_color</item>
         <item name="@*android:successColor">@color/unlock_pattern_view_success_color</item>
diff --git a/src/com/android/settings/LauncherIconToggler.java b/src/com/android/settings/LauncherIconToggler.java
new file mode 100644
index 0000000..5016918
--- /dev/null
+++ b/src/com/android/settings/LauncherIconToggler.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings;
+
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.UserManager;
+
+/**
+ * Listens to {@link Intent.ACTION_BOOT_COMPLETED} and {@link Intent.ACTION_PRE_BOOT_COMPLETED} and
+ * disables the launcher icon of the Settings app for a managed profile.
+ */
+public class LauncherIconToggler extends BroadcastReceiver {
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)
+                || intent.getAction().equals(Intent.ACTION_PRE_BOOT_COMPLETED)) {
+            final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
+            if (Utils.isManagedProfile(um)) {
+                ComponentName launcherActivity = new ComponentName(context, Settings.class);
+                final PackageManager pm  = context.getPackageManager();
+                pm.setComponentEnabledSetting(launcherActivity,
+                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+                        PackageManager.DONT_KILL_APP);
+            }
+        }
+    }
+}
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index f035d7b..d3f0466 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -510,7 +510,8 @@
         mToggleLargeTextPreference.setChecked(mCurConfig.fontScale == LARGE_FONT_SCALE);
 
         mToggleHighTextContrastPreference.setChecked(
-                AccessibilityManager.getInstance(getActivity()).isHighTextContrastEnabled());
+                Settings.Secure.getInt(getContentResolver(),
+                        Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, 0) == 1);
 
         // Power button ends calls.
         if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_POWER)
diff --git a/src/com/android/settings/accounts/AddAccountSettings.java b/src/com/android/settings/accounts/AddAccountSettings.java
index 0af0260..4e97c05 100644
--- a/src/com/android/settings/accounts/AddAccountSettings.java
+++ b/src/com/android/settings/accounts/AddAccountSettings.java
@@ -98,7 +98,7 @@
                             Utils.hasMultipleUsers(AddAccountSettings.this));
                     addAccountOptions.putParcelable(EXTRA_USER, mUserHandle);
                     intent.putExtras(addAccountOptions);
-                    startActivityForResult(intent, ADD_ACCOUNT_REQUEST);
+                    startActivityForResultAsUser(intent, ADD_ACCOUNT_REQUEST, mUserHandle);
                 } else {
                     setResult(RESULT_OK);
                     if (mPendingIntent != null) {
@@ -199,22 +199,15 @@
         mPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(), 0);
         addAccountOptions.putParcelable(KEY_CALLER_IDENTITY, mPendingIntent);
         addAccountOptions.putBoolean(EXTRA_HAS_MULTIPLE_USERS, Utils.hasMultipleUsers(this));
-        // TODO: We need an API to add an account to a different user. See: http://b/15466880
-        int userId = mUserHandle.getIdentifier();
-        int callingUserId = UserHandle.getCallingUserId();
-        if (userId != callingUserId) {
-            Log.w(TAG, "Cannot add an account for user " + userId + " from " + callingUserId + ".");
-            finish();
-            return;
-        }
-        AccountManager.get(this).addAccount(
+        AccountManager.get(this).addAccountAsUser(
                 accountType,
                 null, /* authTokenType */
                 null, /* requiredFeatures */
                 addAccountOptions,
                 null,
                 mCallback,
-                null /* handler */);
+                null /* handler */,
+                mUserHandle);
         mAddAccountCalled  = true;
     }
 }
diff --git a/src/com/android/settings/applications/AppOpsState.java b/src/com/android/settings/applications/AppOpsState.java
index 4ef5ef2..75a8372 100644
--- a/src/com/android/settings/applications/AppOpsState.java
+++ b/src/com/android/settings/applications/AppOpsState.java
@@ -103,14 +103,14 @@
                     AppOpsManager.OP_WIFI_SCAN,
                     AppOpsManager.OP_NEIGHBORING_CELLS,
                     AppOpsManager.OP_MONITOR_LOCATION,
-                    AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION},
+                    AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION },
             new boolean[] { true,
                     true,
                     false,
                     false,
                     false,
                     false,
-                    false}
+                    false }
             );
 
     public static final OpsTemplate PERSONAL_TEMPLATE = new OpsTemplate(
@@ -189,13 +189,15 @@
                     AppOpsManager.OP_CALL_PHONE,
                     AppOpsManager.OP_WRITE_SETTINGS,
                     AppOpsManager.OP_SYSTEM_ALERT_WINDOW,
-                    AppOpsManager.OP_WAKE_LOCK },
+                    AppOpsManager.OP_WAKE_LOCK,
+                    AppOpsManager.OP_PROJECT_MEDIA },
             new boolean[] { false,
                     true,
                     true,
                     true,
                     true,
-                    true,  }
+                    true,
+                    false, }
             );
 
     public static final OpsTemplate[] ALL_TEMPLATES = new OpsTemplate[] {
diff --git a/src/com/android/settings/location/RecentLocationApps.java b/src/com/android/settings/location/RecentLocationApps.java
index 164f4e7..8e1ec05 100644
--- a/src/com/android/settings/location/RecentLocationApps.java
+++ b/src/com/android/settings/location/RecentLocationApps.java
@@ -16,15 +16,18 @@
 
 package com.android.settings.location;
 
-import android.app.ActivityManager;
+import android.app.AppGlobals;
 import android.app.AppOpsManager;
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
+import android.content.pm.IPackageManager;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.os.Process;
+import android.os.RemoteException;
 import android.os.UserHandle;
+import android.os.UserManager;
 import android.preference.Preference;
 import android.util.Log;
 
@@ -89,33 +92,37 @@
     }
 
     /**
-     * Fills a list of applications which queried location recently within
-     * specified time.
+     * Fills a list of applications which queried location recently within specified time.
      */
     public List<Preference> getAppList() {
         // Retrieve a location usage list from AppOps
         AppOpsManager aoManager =
                 (AppOpsManager) mActivity.getSystemService(Context.APP_OPS_SERVICE);
-        List<AppOpsManager.PackageOps> appOps = aoManager.getPackagesForOps(
-                new int[] {
-                    AppOpsManager.OP_MONITOR_LOCATION,
-                    AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION,
-                });
+        List<AppOpsManager.PackageOps> appOps = aoManager.getPackagesForOps(new int[] {
+                AppOpsManager.OP_MONITOR_LOCATION, AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION, });
 
         // Process the AppOps list and generate a preference list.
         ArrayList<Preference> prefs = new ArrayList<Preference>();
-        long now = System.currentTimeMillis();
-        for (AppOpsManager.PackageOps ops : appOps) {
+        final long now = System.currentTimeMillis();
+        final UserManager um = (UserManager) mActivity.getSystemService(Context.USER_SERVICE);
+        final List<UserHandle> profiles = um.getUserProfiles();
+
+        final int appOpsN = appOps.size();
+        for (int i = 0; i < appOpsN; ++i) {
+            AppOpsManager.PackageOps ops = appOps.get(i);
             // Don't show the Android System in the list - it's not actionable for the user.
-            // Also don't show apps belonging to background users.
+            // Also don't show apps belonging to background users except managed users.
+            String packageName = ops.getPackageName();
             int uid = ops.getUid();
-            boolean isAndroidOs = (uid == Process.SYSTEM_UID)
-                    && ANDROID_SYSTEM_PACKAGE_NAME.equals(ops.getPackageName());
-            if (!isAndroidOs && ActivityManager.getCurrentUser() == UserHandle.getUserId(uid)) {
-                Preference pref = getPreferenceFromOps(now, ops);
-                if (pref != null) {
-                    prefs.add(pref);
-                }
+            int userId = UserHandle.getUserId(uid);
+            boolean isAndroidOs =
+                    (uid == Process.SYSTEM_UID) && ANDROID_SYSTEM_PACKAGE_NAME.equals(packageName);
+            if (isAndroidOs || !profiles.contains(new UserHandle(userId))) {
+                continue;
+            }
+            Preference preference = getPreferenceFromOps(um, now, ops);
+            if (preference != null) {
+                prefs.add(preference);
             }
         }
 
@@ -130,7 +137,8 @@
      * When the PackageOps is fresh enough, this method returns a Preference pointing to the App
      * Info page for that package.
      */
-    private Preference getPreferenceFromOps(long now, AppOpsManager.PackageOps ops) {
+    private Preference getPreferenceFromOps(final UserManager um, long now,
+            AppOpsManager.PackageOps ops) {
         String packageName = ops.getPackageName();
         List<AppOpsManager.OpEntry> entries = ops.getOps();
         boolean highBattery = false;
@@ -161,30 +169,24 @@
 
         // The package is fresh enough, continue.
 
-        Preference pref = null;
+        int uid = ops.getUid();
+        int userId = UserHandle.getUserId(uid);
+
+        Preference preference = null;
         try {
-          ApplicationInfo appInfo = mPackageManager.getApplicationInfo(
-              packageName, PackageManager.GET_META_DATA);
-          // Multiple users can install the same package. Each user gets a different Uid for
-          // the same package.
-          //
-          // Here we retrieve the Uid with package name, that will be the Uid for that package
-          // associated with the current active user. If the Uid differs from the Uid in ops,
-          // that means this entry belongs to another inactive user and we should ignore that.
-          if (appInfo.uid == ops.getUid()) {
-            pref = createRecentLocationEntry(
-                mPackageManager.getApplicationIcon(appInfo),
-                mPackageManager.getApplicationLabel(appInfo),
-                highBattery,
-                new PackageEntryClickedListener(packageName));
-          } else if (Log.isLoggable(TAG, Log.VERBOSE)) {
-            Log.v(TAG, "package " + packageName + " with Uid " + ops.getUid() +
-                " belongs to another inactive account, ignored.");
-          }
-        } catch (PackageManager.NameNotFoundException e) {
-          Log.wtf(TAG, "Package not found: " + packageName, e);
+            IPackageManager ipm = AppGlobals.getPackageManager();
+            ApplicationInfo appInfo =
+                    ipm.getApplicationInfo(packageName, PackageManager.GET_META_DATA, userId);
+
+            Drawable icon = um.getBadgedDrawableForUser(
+                    mPackageManager.getApplicationIcon(appInfo), new UserHandle(userId));
+            preference = createRecentLocationEntry(icon,
+                    mPackageManager.getApplicationLabel(appInfo), highBattery,
+                    new PackageEntryClickedListener(packageName));
+        } catch (RemoteException e) {
+            Log.w(TAG, "Error while retrieving application info", e);
         }
 
-        return pref;
+        return preference;
     }
 }