Merge "Catch NPE and add more logging for a crash in Tile" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
781ebfb059
@@ -174,7 +174,7 @@ public class Tile implements Parcelable {
|
||||
packageManager.getResourcesForApplication(mActivityPackage);
|
||||
title = res.getString(mMetaData.getInt(META_DATA_PREFERENCE_TITLE));
|
||||
} catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) {
|
||||
Log.d(TAG, "Couldn't find info", e);
|
||||
Log.w(TAG, "Couldn't find info", e);
|
||||
}
|
||||
} else {
|
||||
title = mMetaData.getString(META_DATA_PREFERENCE_TITLE);
|
||||
@@ -183,25 +183,15 @@ public class Tile implements Parcelable {
|
||||
// Set the preference title to the activity's label if no
|
||||
// meta-data is found
|
||||
if (title == null) {
|
||||
title = getActivityInfo(context).loadLabel(packageManager);
|
||||
final ActivityInfo activityInfo = getActivityInfo(context);
|
||||
if (activityInfo == null) {
|
||||
return null;
|
||||
}
|
||||
title = activityInfo.loadLabel(packageManager);
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw metadata for summary, this is used for comparing 2 summary text without
|
||||
* loading the real string.
|
||||
*/
|
||||
public String getSummaryReference() {
|
||||
if (mSummaryOverride != null) {
|
||||
return mSummaryOverride.toString();
|
||||
}
|
||||
if (mMetaData != null && mMetaData.containsKey(META_DATA_PREFERENCE_SUMMARY)) {
|
||||
return mMetaData.get(META_DATA_PREFERENCE_SUMMARY).toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the summary. This can happen when injected tile wants to provide dynamic summary.
|
||||
*/
|
||||
@@ -302,7 +292,7 @@ public class Tile implements Parcelable {
|
||||
if (iconResId != 0) {
|
||||
final Icon icon = Icon.createWithResource(activityInfo.packageName, iconResId);
|
||||
if (isIconTintable(context)) {
|
||||
final TypedArray a = context.obtainStyledAttributes(new int[] {
|
||||
final TypedArray a = context.obtainStyledAttributes(new int[]{
|
||||
android.R.attr.colorControlNormal});
|
||||
final int tintColor = a.getColor(0, 0);
|
||||
a.recycle();
|
||||
@@ -357,6 +347,9 @@ public class Tile implements Parcelable {
|
||||
if (infoList != null && !infoList.isEmpty()) {
|
||||
mActivityInfo = infoList.get(0).activityInfo;
|
||||
mMetaData = mActivityInfo.metaData;
|
||||
} else {
|
||||
Log.e(TAG, "Cannot find package info for "
|
||||
+ intent.getComponent().flattenToString());
|
||||
}
|
||||
}
|
||||
return mActivityInfo;
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
import org.robolectric.shadows.ShadowPackageManager;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class TileTest {
|
||||
@@ -164,4 +165,17 @@ public class TileTest {
|
||||
|
||||
assertThat(tile.mLastUpdateTime).isNotEqualTo(staleTimeStamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTitle_noActivity_returnNull() {
|
||||
final ResolveInfo info = new ResolveInfo();
|
||||
info.activityInfo = mActivityInfo;
|
||||
final ShadowPackageManager spm = Shadow.extract(mContext.getPackageManager());
|
||||
spm.removePackage(mActivityInfo.packageName);
|
||||
|
||||
final Tile tile = new Tile(mActivityInfo, "category");
|
||||
ReflectionHelpers.setField(tile, "mActivityInfo", null);
|
||||
|
||||
assertThat(tile.getTitle(RuntimeEnvironment.application)).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user