From bf8b57af351ae9272b7490b373ca57b2a96e643a Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Wed, 11 Jun 2014 17:16:03 -0400 Subject: Fix "pm list permissions" crash if resource string missing The "pm list permissions" command lists detailed information about each permission on the system, including its label and description, both of which can be stored as translatable resource strings in APK files. However, it is possible that the resource identifiers for these strings point to non-existent resources. When this happens, the loadText() method throws Resources.NotFoundException, causing the "pm" command to abort prematurely, simply printing "Killed" to stdout and a stack trace to logcat. This commit fixes the crash by explicitly catching the Resources.NotFoundException exception in loadText() and returning null if it is thrown. The loadText() method already has the potential to return null so none of its callers need be modified. This fixes the crash and simply shows "label:null" and/or "description:null" in the output if the string resource is missing. Change-Id: I92273399e1dac6029163750d004940ee1da67428 --- cmds/pm/src/com/android/commands/pm/Pm.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'cmds/pm') diff --git a/cmds/pm/src/com/android/commands/pm/Pm.java b/cmds/pm/src/com/android/commands/pm/Pm.java index 75b0a82..c10c959 100644 --- a/cmds/pm/src/com/android/commands/pm/Pm.java +++ b/cmds/pm/src/com/android/commands/pm/Pm.java @@ -504,7 +504,10 @@ public final class Pm { if (res != 0) { Resources r = getResources(pii); if (r != null) { - return r.getString(res); + try { + return r.getString(res); + } catch (Resources.NotFoundException e) { + } } } return null; -- cgit v1.1