Merge "Prevent crashes on null intent in Slice Builder" into pi-dev am: 69fce6df71
am: 46dd838e8d
Change-Id: I2048cd12599e9d2ad115f2e6b1a6371feb2e72ae
diff --git a/src/com/android/settings/slices/SliceBuilderUtils.java b/src/com/android/settings/slices/SliceBuilderUtils.java
index 3ac0069..c6f6db4 100644
--- a/src/com/android/settings/slices/SliceBuilderUtils.java
+++ b/src/com/android/settings/slices/SliceBuilderUtils.java
@@ -30,13 +30,16 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
+import android.provider.Settings;
import android.provider.SettingsSlicesContract;
import android.text.TextUtils;
+import android.util.Log;
import android.util.Pair;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
+import com.android.settings.SettingsActivity;
import com.android.settings.SubSettings;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.SliderPreferenceController;
@@ -75,6 +78,7 @@
* {@param sliceData} is an inline controller.
*/
public static Slice buildSlice(Context context, SliceData sliceData) {
+ Log.d(TAG, "Creating slice for: " + sliceData.getPreferenceController());
final BasePreferenceController controller = getPreferenceController(context, sliceData);
final Pair<Integer, Object> sliceNamePair =
Pair.create(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_NAME, sliceData.getKey());
@@ -177,8 +181,7 @@
* @return {@link PendingIntent} to the Settings home page.
*/
public static PendingIntent getSettingsIntent(Context context) {
- final PackageManager manager = context.getPackageManager();
- final Intent intent = manager.getLaunchIntentForPackage(context.getPackageName());
+ final Intent intent = new Intent(Settings.ACTION_SETTINGS);
return PendingIntent.getActivity(context, 0 /* requestCode */, intent, 0 /* flags */);
}
diff --git a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
index 20bb5a0..a74e2ba 100644
--- a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
@@ -24,6 +24,7 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
+import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -405,6 +406,16 @@
assertThat(intentData).isEqualTo(expectedUri);
}
+ @Test
+ public void getSettingsIntent_createsIntentToSettings() {
+ final Intent intent = new Intent(Settings.ACTION_SETTINGS);
+ final PendingIntent expectedIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
+
+ final PendingIntent settingsIntent = SliceBuilderUtils.getSettingsIntent(mContext);
+
+ assertThat(expectedIntent).isEqualTo(settingsIntent);
+ }
+
private SliceData getDummyData() {
return getDummyData(TOGGLE_CONTROLLER, SUMMARY, SliceData.SliceType.SWITCH);
}