diff options
author | Guang Zhu <guangzhu@google.com> | 2012-09-04 13:49:46 -0700 |
---|---|---|
committer | Guang Zhu <guangzhu@google.com> | 2012-09-04 13:51:24 -0700 |
commit | 818b58c3cc3d9f99d65bc9e4e7ff5b80021079ec (patch) | |
tree | d0c142e7996c22f0fe450562ccde368e94ae2014 | |
parent | 46899d1b5d606e9349a40079b60034e3cf6eaafb (diff) | |
download | extras-818b58c3cc3d9f99d65bc9e4e7ff5b80021079ec.tar.gz |
Guard against NPE in SendBug
Add some null checks in case that SendBug is invoked while system
server is in fact not running, e.g. during a runtime restart. So
that we don't hit NPE in SendBug, looking suspiciously like the
cause rather than a consequence of the real issue.
Bug: 7097125
Change-Id: I82676ab936fe19a781c32f949e6e429eb4045d63
-rw-r--r-- | bugmailer/src/com/android/commands/sendbug/SendBug.java | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/bugmailer/src/com/android/commands/sendbug/SendBug.java b/bugmailer/src/com/android/commands/sendbug/SendBug.java index 9b693a06..398bdc22 100644 --- a/bugmailer/src/com/android/commands/sendbug/SendBug.java +++ b/bugmailer/src/com/android/commands/sendbug/SendBug.java @@ -68,9 +68,13 @@ public class SendBug { intent = getSendMailIntent(bugreportUri, screenshotUri); } if (intent != null) { - final IActivityManager mAm = ActivityManagerNative.getDefault(); + final IActivityManager am = ActivityManagerNative.getDefault(); + if (am == null) { + Log.e(LOG_TAG, "Cannot get ActivityManager, is the system running?"); + return; + } try { - mAm.startActivity(null, intent, intent.getType(), null, null, 0, 0, + am.startActivity(null, intent, intent.getType(), null, null, 0, 0, null, null, null); } catch (RemoteException e) { // ignore @@ -84,26 +88,27 @@ public class SendBug { private Intent tryBugReporter(Uri bugreportUri) { final Intent intent = new Intent(SEND_BUG_INTENT_ACTION); intent.setData(bugreportUri); - final IPackageManager mPm = IPackageManager.Stub.asInterface( + final IPackageManager pm = IPackageManager.Stub.asInterface( ServiceManager.getService("package")); - if (mPm != null) { - final List<ResolveInfo> results; - try { - results = mPm.queryIntentActivities(intent, null, 0, 0); - } catch (RemoteException e) { - return null; - } - if (results != null && results.size() > 0) { - final ResolveInfo info = results.get(0); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.setClassName(info.activityInfo.applicationInfo.packageName, - info.activityInfo.name); - return intent; - } else { - return null; - } + if (pm == null) { + Log.e(LOG_TAG, "Cannot get PackageManager, is the system running?"); + return null; + } + final List<ResolveInfo> results; + try { + results = pm.queryIntentActivities(intent, null, 0, 0); + } catch (RemoteException e) { + return null; + } + if (results != null && results.size() > 0) { + final ResolveInfo info = results.get(0); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.setClassName(info.activityInfo.applicationInfo.packageName, + info.activityInfo.name); + return intent; + } else { + return null; } - return null; } private Intent getSendMailIntent(Uri bugreportUri, Uri screenshotUri) { @@ -135,6 +140,10 @@ public class SendBug { private Account findSendToAccount() { final IAccountManager accountManager = IAccountManager.Stub.asInterface(ServiceManager .getService(Context.ACCOUNT_SERVICE)); + if (accountManager == null) { + Log.e(LOG_TAG, "Cannot get AccountManager, is the system running?"); + return null; + } Account[] accounts = null; Account foundAccount = null; String preferredDomain = SystemProperties.get("sendbug.preferred.domain"); @@ -167,5 +176,4 @@ public class SendBug { } return foundAccount; } - } |