Skip to content

Commit fe0a5ee

Browse files
committed
SettingsLib: Fix possible NPEs
getText() can return null, resulting in a NPE when trying to call toString(). Add a null check to prevent this. Additionally add a null check for packageInfo, as this can also be null. Change-Id: Ia76326522872f4de4702ef56640b2f7b357c2bb7 Reference: BugDumps 20161104-10 L#135
1 parent 6d2ff1d commit fe0a5ee

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

packages/SettingsLib/src/com/android/settingslib/net/UidDetailProvider.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,16 @@ private UidDetail buildUidDetail(int uid) {
166166
final ApplicationInfo appInfo = ipm.getApplicationInfo(packageName,
167167
0 /* no flags */, userId);
168168

169-
if (appInfo != null) {
169+
if (appInfo != null && packageInfo != null) {
170170
detail.detailLabels[i] = appInfo.loadLabel(pm).toString();
171171
detail.detailContentDescriptions[i] = um.getBadgedLabelForUser(
172172
detail.detailLabels[i], userHandle);
173173
if (packageInfo.sharedUserLabel != 0) {
174-
detail.label = pm.getText(packageName, packageInfo.sharedUserLabel,
175-
packageInfo.applicationInfo).toString();
174+
CharSequence label = pm.getText(packageName,
175+
packageInfo.sharedUserLabel, packageInfo.applicationInfo);
176+
if (label != null) {
177+
detail.label = label.toString();
178+
}
176179
detail.icon = um.getBadgedIconForUser(appInfo.loadIcon(pm), userHandle);
177180
}
178181
}

0 commit comments

Comments
 (0)