Avoid NPE when screen title is null
The screen title of Settings pages could be empty, e.g., Mobile network detail page. It will cause NPE when Settings generates the slice object, and then results in the Settings Search showing empty view for slice search result. It’s a bad user experience, we need to add the null check to avoid it. Bug: 157986273 Test: robotests Change-Id: I8bf6a081c6b3e97ccb173424ff4a310ae863ae2f
This commit is contained in:
@@ -220,9 +220,11 @@ public class SliceBuilderUtils {
|
|||||||
|
|
||||||
public static Intent getContentIntent(Context context, SliceData sliceData) {
|
public static Intent getContentIntent(Context context, SliceData sliceData) {
|
||||||
final Uri contentUri = new Uri.Builder().appendPath(sliceData.getKey()).build();
|
final Uri contentUri = new Uri.Builder().appendPath(sliceData.getKey()).build();
|
||||||
|
final String screenTitle = TextUtils.isEmpty(sliceData.getScreenTitle()) ? null
|
||||||
|
: sliceData.getScreenTitle().toString();
|
||||||
final Intent intent = buildSearchResultPageIntent(context,
|
final Intent intent = buildSearchResultPageIntent(context,
|
||||||
sliceData.getFragmentClassName(), sliceData.getKey(),
|
sliceData.getFragmentClassName(), sliceData.getKey(),
|
||||||
sliceData.getScreenTitle().toString(), 0 /* TODO */);
|
screenTitle, 0 /* TODO */);
|
||||||
intent.setClassName(context.getPackageName(), SubSettings.class.getName());
|
intent.setClassName(context.getPackageName(), SubSettings.class.getName());
|
||||||
intent.setData(contentUri);
|
intent.setData(contentUri);
|
||||||
return intent;
|
return intent;
|
||||||
@@ -399,7 +401,8 @@ public class SliceBuilderUtils {
|
|||||||
|
|
||||||
keywords.add(data.getTitle());
|
keywords.add(data.getTitle());
|
||||||
|
|
||||||
if (!TextUtils.equals(data.getTitle(), data.getScreenTitle())) {
|
if (!TextUtils.isEmpty(data.getScreenTitle())
|
||||||
|
&& !TextUtils.equals(data.getTitle(), data.getScreenTitle())) {
|
||||||
keywords.add(data.getScreenTitle().toString());
|
keywords.add(data.getScreenTitle().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user