Merge "Notification settings updates"
diff --git a/src/com/android/settings/applications/RecentAppsPreferenceController.java b/src/com/android/settings/applications/RecentAppsPreferenceController.java
index 20c5581..3859081 100644
--- a/src/com/android/settings/applications/RecentAppsPreferenceController.java
+++ b/src/com/android/settings/applications/RecentAppsPreferenceController.java
@@ -325,7 +325,7 @@
             // Not visible on launcher -> likely not a user visible app, skip if non-instant.
             final ApplicationsState.AppEntry appEntry =
                     mApplicationsState.getEntry(pkgName, mUserId);
-            if (!AppUtils.isInstant(appEntry.info)) {
+            if (appEntry == null || appEntry.info == null || !AppUtils.isInstant(appEntry.info)) {
                 Log.d(TAG, "Not a user visible or instant app, skipping " + pkgName);
                 return false;
             }
diff --git a/src/com/android/settings/location/LocationEnabler.java b/src/com/android/settings/location/LocationEnabler.java
index 28ee213..30ecf2e 100644
--- a/src/com/android/settings/location/LocationEnabler.java
+++ b/src/com/android/settings/location/LocationEnabler.java
@@ -123,7 +123,8 @@
             }
             return;
         }
-        updateLocationEnabled(mContext, enabled, UserHandle.myUserId());
+        updateLocationEnabled(mContext, enabled, UserHandle.myUserId(),
+                Settings.Secure.LOCATION_CHANGER_SYSTEM_SETTINGS);
         refreshLocationMode();
     }
 
@@ -142,7 +143,8 @@
             return;
         }
 
-        updateLocationMode(mContext, currentMode, mode, ActivityManager.getCurrentUser());
+        updateLocationMode(mContext, currentMode, mode, ActivityManager.getCurrentUser(),
+                Settings.Secure.LOCATION_CHANGER_SYSTEM_SETTINGS);
         refreshLocationMode();
     }
 
diff --git a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java
index ef34a9b..dbffc55 100644
--- a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java
+++ b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java
@@ -283,7 +283,7 @@
             // Not visible on launcher -> likely not a user visible app, skip if non-instant.
             final ApplicationsState.AppEntry appEntry =
                     mApplicationsState.getEntry(pkgName, mUserId);
-            if (!AppUtils.isInstant(appEntry.info)) {
+            if (appEntry == null || appEntry.info == null || !AppUtils.isInstant(appEntry.info)) {
                 Log.d(TAG, "Not a user visible or instant app, skipping " + pkgName);
                 return false;
             }
diff --git a/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java
index bd57211..ed97fe7 100644
--- a/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java
@@ -248,6 +248,33 @@
     }
 
     @Test
+    public void display_showRecentsWithNullAppEntryOrInfo() {
+        final List<UsageStats> stats = new ArrayList<>();
+        final UsageStats stat1 = new UsageStats();
+        final UsageStats stat2 = new UsageStats();
+        stat1.mLastTimeUsed = System.currentTimeMillis();
+        stat1.mPackageName = "pkg.class";
+        stats.add(stat1);
+
+        stat2.mLastTimeUsed = System.currentTimeMillis();
+        stat2.mPackageName = "pkg.class2";
+        stats.add(stat2);
+
+        // app1 has AppEntry with null info, app2 has null AppEntry.
+        mAppEntry.info = null;
+        when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
+                .thenReturn(mAppEntry);
+        when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId()))
+                .thenReturn(null);
+
+        when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
+                .thenReturn(stats);
+
+        // We should not crash here.
+        mController.displayPreference(mScreen);
+    }
+
+    @Test
     public void display_hasRecentButNoneDisplayable_showAppInfo() {
         final List<UsageStats> stats = new ArrayList<>();
         final UsageStats stat1 = new UsageStats();
diff --git a/tests/robotests/src/com/android/settings/location/LocationEnablerTest.java b/tests/robotests/src/com/android/settings/location/LocationEnablerTest.java
index 8cc92cd..1bae729 100644
--- a/tests/robotests/src/com/android/settings/location/LocationEnablerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationEnablerTest.java
@@ -179,7 +179,7 @@
     }
 
     @Test
-    public void setLocationMode_notRestricted_shouldBroadcastUpdate() {
+    public void setLocationMode_notRestricted_shouldBroadcastUpdateAndSetChanger() {
         when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
         Settings.Secure.putInt(mContext.getContentResolver(),
                 Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_BATTERY_SAVING);
@@ -189,6 +189,9 @@
                 argThat(actionMatches(LocationManager.MODE_CHANGING_ACTION)),
                 eq(UserHandle.of(ActivityManager.getCurrentUser())),
                 eq(WRITE_SECURE_SETTINGS));
+        assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
+                Settings.Secure.LOCATION_CHANGER, Settings.Secure.LOCATION_CHANGER_UNKNOWN))
+                .isEqualTo(Settings.Secure.LOCATION_CHANGER_SYSTEM_SETTINGS);
     }
 
     @Test
@@ -202,7 +205,7 @@
     }
 
     @Test
-    public void setLocationEnabled_notRestricted_shouldBroadcastUpdate() {
+    public void setLocationEnabled_notRestricted_shouldBroadcastUpdateAndSetChanger() {
         when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
         Settings.Secure.putInt(mContext.getContentResolver(),
             Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
@@ -212,6 +215,9 @@
             argThat(actionMatches(LocationManager.MODE_CHANGING_ACTION)),
             eq(UserHandle.of(ActivityManager.getCurrentUser())),
             eq(WRITE_SECURE_SETTINGS));
+        assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
+                Settings.Secure.LOCATION_CHANGER, Settings.Secure.LOCATION_CHANGER_UNKNOWN))
+                .isEqualTo(Settings.Secure.LOCATION_CHANGER_SYSTEM_SETTINGS);
     }
 
     @Test