Prevent crash when flattening ComponentKey to string with invalid user.

Bug: 22658306
Change-Id: I213d44e0bb22ac0617d46c80ab8cfec8f750a2cc
This commit is contained in:
Winson Chung committed 2015-07-30 12:05:41 -07:00
1 parent fd69e0b527
commit 70d5a07c5d
1 file changed
+5 -2
@@ -64,8 +64,11 @@ public class ComponentKey {
* Encodes a component key as a string of the form [flattenedComponentString#userId].
*/
public String flattenToString(Context context) {
return componentName.flattenToString() + "#" +
UserManagerCompat.getInstance(context).getSerialNumberForUser(user);
String flattened = componentName.flattenToString();
if (user != null) {
flattened += "#" + UserManagerCompat.getInstance(context).getSerialNumberForUser(user);
}
return flattened;
}
@Override