From be16357f40406d32de6d9a1632910bcdfacc0d21 Mon Sep 17 00:00:00 2001 From: Kenny Guy Date: Thu, 25 Sep 2014 15:40:51 +0100 Subject: [PATCH] Ignore badly formed ComponentNames when loading device_owner.xml In the past we wrote out badly formed ComponentNames with no class part. Loading these results in a null pointer exception blocking boot. Bug: 17652534 Change-Id: Iec592343425a23c7ada5f73cf30b8646d31eae81 --- .../server/devicepolicy/DeviceOwner.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java b/services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java index 5938819e34d53..9fd0e0960d894 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java @@ -229,11 +229,20 @@ public class DeviceOwner { String profileOwnerComponentStr = parser.getAttributeValue(null, ATTR_COMPONENT_NAME); int userId = Integer.parseInt(parser.getAttributeValue(null, ATTR_USERID)); - OwnerInfo profileOwnerInfo; + OwnerInfo profileOwnerInfo = null; if (profileOwnerComponentStr != null) { - profileOwnerInfo = new OwnerInfo(profileOwnerName, - ComponentName.unflattenFromString(profileOwnerComponentStr)); - } else { + ComponentName admin = ComponentName.unflattenFromString( + profileOwnerComponentStr); + if (admin != null) { + profileOwnerInfo = new OwnerInfo(profileOwnerName, admin); + } else { + // This shouldn't happen but switch from package name -> component name + // might have written bad device owner files. b/17652534 + Slog.e(TAG, "Error parsing device-owner file. Bad component name " + + profileOwnerComponentStr); + } + } + if (profileOwnerInfo == null) { profileOwnerInfo = new OwnerInfo(profileOwnerName, profileOwnerPackageName); } mProfileOwners.put(userId, profileOwnerInfo);