am 0488dc97: Add MDM app name under "Work" in Accounts section of Settings.

* commit '0488dc97686051d6cac744edb8a9d9c7ec477009':
  Add MDM app name under "Work" in Accounts section of Settings.
diff --git a/res/layout/work_profile_category.xml b/res/layout/work_profile_category.xml
new file mode 100644
index 0000000..8ca99f1
--- /dev/null
+++ b/res/layout/work_profile_category.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+
+<!-- Layout used for "Work" preference group in Accounts. -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:layout_marginBottom="16dip"
+    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+    android:paddingTop="16dip"
+    android:orientation="vertical">
+    <TextView
+        android:id="@android:id/title"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textAppearance="@android:style/TextAppearance.Material.Body2"
+        android:textColor="?android:attr/colorAccent" />
+    <TextView
+        android:id="@android:id/summary"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textAppearance="?android:attr/textAppearanceListItemSecondary"
+        android:textColor="?android:attr/textColorSecondary"
+        android:ellipsize="end"
+        android:singleLine="true" />
+</LinearLayout>
\ No newline at end of file
diff --git a/src/com/android/settings/accounts/AccountSettings.java b/src/com/android/settings/accounts/AccountSettings.java
index 1bf83f3..ffada53 100644
--- a/src/com/android/settings/accounts/AccountSettings.java
+++ b/src/com/android/settings/accounts/AccountSettings.java
@@ -29,6 +29,8 @@
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
 import android.content.pm.UserInfo;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
@@ -269,8 +271,14 @@
         profileData.userInfo = userInfo;
         if (addCategory) {
             profileData.preferenceGroup = new PreferenceCategory(context);
-            profileData.preferenceGroup.setTitle(userInfo.isManagedProfile()
-                    ? R.string.category_work : R.string.category_personal);
+            if (userInfo.isManagedProfile()) {
+                profileData.preferenceGroup.setLayoutResource(R.layout.work_profile_category);
+                profileData.preferenceGroup.setTitle(R.string.category_work);
+                profileData.preferenceGroup.setSummary(getWorkGroupSummary(context, userInfo));
+                profileData.removeWorkProfilePreference = newRemoveWorkProfilePreference(context);
+            } else {
+                profileData.preferenceGroup.setTitle(R.string.category_personal);
+            }
             parent.addPreference(profileData.preferenceGroup);
         } else {
             profileData.preferenceGroup = parent;
@@ -282,9 +290,6 @@
                 profileData.addAccountPreference = newAddAccountPreference(context);
             }
         }
-        if (userInfo.isManagedProfile()) {
-            profileData.removeWorkProfilePreference = newRemoveWorkProfilePreference(context);
-        }
         mProfiles.put(userInfo.id, profileData);
     }
 
@@ -306,6 +311,16 @@
         return preference;
     }
 
+    private String getWorkGroupSummary(Context context, UserInfo userInfo) {
+        PackageManager packageManager = context.getPackageManager();
+        ApplicationInfo adminApplicationInfo = Utils.getAdminApplicationInfo(context, userInfo.id);
+        if (adminApplicationInfo == null) {
+            return null;
+        }
+        CharSequence appLabel = packageManager.getApplicationLabel(adminApplicationInfo);
+        return getString(R.string.managing_admin, appLabel);
+    }
+
     private void cleanUpPreferences() {
         PreferenceScreen preferenceScreen = getPreferenceScreen();
         if (preferenceScreen != null) {