Merge "Follow up to I15baa5b1d19324521070d641ae6a227d782a4e9e"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index bc2076a..f32966d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5303,6 +5303,10 @@
     <string name="user_enable_calling_and_sms_confirm_title">Turn on phone calls &amp; SMS?</string>
     <!-- Message for confirmation of turning on calls and SMS [CHAR LIMIT=none] -->
     <string name="user_enable_calling_and_sms_confirm_message">Call and SMS history will be shared with this user.</string>
+    <!-- Title for the emergency info preference [CHAR LIMIT=40] -->
+    <string name="emergency_info_title">Emergency information</string>
+    <!-- Description of the emergency info preference [CHAR LIMIT=80] -->
+    <string name="emergency_info_subtitle">Accessible through lock screen in the emergency dialer</string>
 
     <!-- Application Restrictions screen title [CHAR LIMIT=45] -->
     <string name="application_restrictions">Allow apps and content</string>
diff --git a/res/xml/app_notification_settings.xml b/res/xml/app_notification_settings.xml
index d48cf93..ccf242c 100644
--- a/res/xml/app_notification_settings.xml
+++ b/res/xml/app_notification_settings.xml
@@ -18,12 +18,6 @@
         android:title="@string/app_notifications_title"
         android:key="app_notification_settings">
 
-     <!-- App notification preferences -->
-    <Preference
-            android:key="app_settings"
-            android:title="@string/app_notification_preferences"
-            android:order="1" />
-
     <!-- Apps without topics -->
     <!-- Importance -->
     <Preference
diff --git a/res/xml/user_settings.xml b/res/xml/user_settings.xml
index 4fefc10..5944b3e 100644
--- a/res/xml/user_settings.xml
+++ b/res/xml/user_settings.xml
@@ -35,5 +35,9 @@
                 android:key="add_users_when_locked"
                 android:title="@string/user_add_on_lockscreen_menu"
                 android:summary="@string/user_add_on_lockscreen_menu_summary" />
+        <Preference
+            android:key="emergency_info"
+            android:title="@string/emergency_info_title"
+            android:summary="@string/emergency_info_subtitle"/>
     </PreferenceCategory>
 </PreferenceScreen>
diff --git a/src/com/android/settings/AppHeader.java b/src/com/android/settings/AppHeader.java
index 0351ed5..2b3e6c4 100644
--- a/src/com/android/settings/AppHeader.java
+++ b/src/com/android/settings/AppHeader.java
@@ -39,27 +39,38 @@
 
     public static void createAppHeader(SettingsPreferenceFragment fragment, Drawable icon,
             CharSequence label, String pkgName, int uid) {
-        createAppHeader(fragment, icon, label, pkgName, uid, 0);
+        createAppHeader(fragment, icon, label, pkgName, uid, 0, null);
+    }
+
+    public static void createAppHeader(SettingsPreferenceFragment fragment, Drawable icon,
+            CharSequence label, String pkgName, int uid, Intent externalSettings) {
+        createAppHeader(fragment, icon, label, pkgName, uid, 0, externalSettings);
     }
 
     public static void createAppHeader(Activity activity, Drawable icon, CharSequence label,
             String pkgName, int uid, ViewGroup pinnedHeader) {
         final View bar = activity.getLayoutInflater().inflate(R.layout.app_header,
                 pinnedHeader, false);
-        setupHeaderView(activity, icon, label, pkgName, uid, false, 0, bar);
+        setupHeaderView(activity, icon, label, pkgName, uid, false, 0, bar, null);
         pinnedHeader.addView(bar);
     }
 
     public static void createAppHeader(SettingsPreferenceFragment fragment, Drawable icon,
             CharSequence label, String pkgName, int uid, int tintColorRes) {
+        createAppHeader(fragment, icon, label, pkgName, uid, tintColorRes, null);
+    }
+
+    public static void createAppHeader(SettingsPreferenceFragment fragment, Drawable icon,
+            CharSequence label, String pkgName, int uid, int tintColorRes,
+            Intent externalSettings) {
         View bar = fragment.setPinnedHeaderView(R.layout.app_header);
         setupHeaderView(fragment.getActivity(), icon, label, pkgName, uid, includeAppInfo(fragment),
-                tintColorRes, bar);
+                tintColorRes, bar, externalSettings);
     }
 
     public static View setupHeaderView(final Activity activity, Drawable icon, CharSequence label,
             final String pkgName, final int uid, final boolean includeAppInfo, int tintColorRes,
-            View bar) {
+            View bar, final Intent externalSettings) {
         final ImageView appIcon = (ImageView) bar.findViewById(R.id.app_icon);
         appIcon.setImageDrawable(icon);
         if (tintColorRes != 0) {
@@ -83,6 +94,16 @@
                     }
                 }
             });
+            if (externalSettings != null) {
+                final View appSettings = bar.findViewById(R.id.app_settings);
+                appSettings.setVisibility(View.VISIBLE);
+                appSettings.setOnClickListener(new OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        activity.startActivity(externalSettings);
+                    }
+                });
+            }
         }
         return bar;
     }
diff --git a/src/com/android/settings/datausage/AppDataUsage.java b/src/com/android/settings/datausage/AppDataUsage.java
index a65f007..6a7b6b2 100644
--- a/src/com/android/settings/datausage/AppDataUsage.java
+++ b/src/com/android/settings/datausage/AppDataUsage.java
@@ -282,7 +282,7 @@
         } catch (PackageManager.NameNotFoundException e) {
         }
         AppHeader.setupHeaderView(getActivity(), mIcon, mLabel,
-                pkg, uid, AppHeader.includeAppInfo(this), 0, header);
+                pkg, uid, AppHeader.includeAppInfo(this), 0, header, null);
     }
 
     @Override
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index 626e5a4..ccb1216 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -51,7 +51,6 @@
     private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
 
     private static final String KEY_BLOCK = "block";
-    private static final String KEY_APP_SETTINGS = "app_settings";
     private static final String KEY_CATEGORIES = "categories";
 
     private static final Intent APP_NOTIFICATION_PREFS_CATEGORY_INTENT
@@ -66,7 +65,8 @@
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
         if (mAppRow == null) return;
-        AppHeader.createAppHeader(this, mAppRow.icon, mAppRow.label, mAppRow.pkg, mAppRow.uid);
+        AppHeader.createAppHeader(this, mAppRow.icon, mAppRow.label, mAppRow.pkg, mAppRow.uid,
+                mAppRow.settingsIntent);
     }
 
     @Override
@@ -127,19 +127,6 @@
                 mCategories.addPreference(topicPreference);
             }
         }
-
-        if (mAppRow.settingsIntent != null) {
-            findPreference(KEY_APP_SETTINGS).setOnPreferenceClickListener(
-                    new OnPreferenceClickListener() {
-                @Override
-                public boolean onPreferenceClick(Preference preference) {
-                    mContext.startActivity(mAppRow.settingsIntent);
-                    return true;
-                }
-            });
-        } else {
-            removePreference(KEY_APP_SETTINGS);
-        }
     }
 
     @Override
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index 1837a2c..c9cdeb8 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -27,6 +27,7 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.SharedPreferences;
+import android.content.pm.ResolveInfo;
 import android.content.pm.UserInfo;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
@@ -42,6 +43,7 @@
 import android.support.v14.preference.SwitchPreference;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.Preference.OnPreferenceClickListener;
+import android.support.v7.preference.PreferenceCategory;
 import android.support.v7.preference.PreferenceGroup;
 import android.support.v7.preference.PreferenceScreen;
 import android.util.Log;
@@ -101,6 +103,10 @@
     private static final String KEY_USER_LIST = "user_list";
     private static final String KEY_USER_ME = "user_me";
     private static final String KEY_ADD_USER = "user_add";
+    private static final String KEY_EMERGENCY_INFO = "emergency_info";
+    private static final String KEY_LOCK_SCREEN_SETTINGS = "lock_screen_settings";
+
+    private static final String ACTION_EDIT_EMERGENCY_INFO = "android.settings.EDIT_EMERGENGY_INFO";
 
     private static final int MENU_REMOVE_USER = Menu.FIRST;
 
@@ -134,6 +140,7 @@
     private DimmableIconPreference mAddUser;
     private PreferenceGroup mLockScreenSettings;
     private RestrictedSwitchPreference mAddUserWhenLocked;
+    private Preference mEmergencyInfoPreference;
     private int mRemovingUserId = -1;
     private int mAddedUserId = 0;
     private boolean mAddingUser;
@@ -229,6 +236,15 @@
         }
         mLockScreenSettings = (PreferenceGroup) findPreference("lock_screen_settings");
         mAddUserWhenLocked = (RestrictedSwitchPreference) findPreference("add_users_when_locked");
+        mEmergencyInfoPreference = findPreference(KEY_EMERGENCY_INFO);
+        if(emergencyInfoActivityPresent()) {
+            mEmergencyInfoPreference.setOnPreferenceClickListener(this);
+        } else {
+            // Remove this view if the emergency info package is not found.
+            PreferenceCategory lockScreenSettingsCategory =
+                    (PreferenceCategory) findPreference(KEY_LOCK_SCREEN_SETTINGS);
+            lockScreenSettingsCategory.removePreference(mEmergencyInfoPreference);
+        }
         loadProfile();
         setHasOptionsMenu(true);
         IntentFilter filter = new IntentFilter(Intent.ACTION_USER_REMOVED);
@@ -598,6 +614,15 @@
         }
     }
 
+    private boolean emergencyInfoActivityPresent() {
+        Intent intent = new Intent(ACTION_EDIT_EMERGENCY_INFO).setPackage("com.android.emergency");
+        List<ResolveInfo> infos = getContext().getPackageManager().queryIntentActivities(intent, 0);
+        if (infos == null || infos.isEmpty()) {
+            return false;
+        }
+        return true;
+    }
+
     private void removeUserNow() {
         if (mRemovingUserId == UserHandle.myUserId()) {
             removeThisUser();
@@ -917,6 +942,9 @@
             } else {
                 onAddUserClicked(USER_TYPE_USER);
             }
+        } else if (pref == mEmergencyInfoPreference) {
+            Intent intent = new Intent(ACTION_EDIT_EMERGENCY_INFO);
+            startActivity(intent);
         }
         return false;
     }