Bug 811763 - Ensure crash reporter is invoked with the right android user serial number in Android 4.2 and above. r=blassey, snorp

This commit is contained in:
Kartikaya Gupta 2012-11-15 14:56:22 -08:00
parent 183031c4dd
commit 2007d09f19
2 changed files with 56 additions and 8 deletions

View File

@ -448,6 +448,32 @@ public class GeckoAppShell
f = context.getCacheDir();
GeckoAppShell.putenv("CACHE_DIRECTORY=" + f.getPath());
/* We really want to use this code, but it requires bumping up the SDK to 17 so for now
we will use reflection. See https://bugzilla.mozilla.org/show_bug.cgi?id=811763#c11
if (Build.VERSION.SDK_INT >= 17) {
android.os.UserManager um = (android.os.UserManager)context.getSystemService(Context.USER_SERVICE);
if (um != null) {
GeckoAppShell.putenv("MOZ_ANDROID_USER_SERIAL_NUMBER=" + um.getSerialNumberForUser(android.os.Process.myUserHandle()));
} else {
Log.d(LOGTAG, "Unable to obtain user manager service on a device with SDK version " + Build.VERSION.SDK_INT);
}
}
*/
try {
Object userManager = context.getSystemService("user");
if (userManager != null) {
// if userManager is non-null that means we're running on 4.2+ and so the rest of this
// should just work
Object userHandle = android.os.Process.class.getMethod("myUserHandle", (Class[])null).invoke(null);
Object userSerial = userManager.getClass().getMethod("getSerialNumberForUser", userHandle.getClass()).invoke(userManager, userHandle);
GeckoAppShell.putenv("MOZ_ANDROID_USER_SERIAL_NUMBER=" + userSerial.toString());
}
} catch (Exception e) {
// Guard against any unexpected failures
Log.d(LOGTAG, "Unable to set the user serial number", e);
}
putLocaleEnv();
}

View File

@ -182,6 +182,13 @@ static bool lastRunCrashID_checked = false;
// The minidump ID contained in the marker file.
static nsString* lastRunCrashID = nullptr;
#if defined(MOZ_WIDGET_ANDROID)
// on Android 4.2 and above there is a user serial number associated
// with the current process that gets lost when we fork so we need to
// explicitly pass it to am
static char* androidUserSerial = nullptr;
#endif
// these are just here for readability
static const char kCrashTimeParameter[] = "CrashTime=";
static const int kCrashTimeParameterLen = sizeof(kCrashTimeParameter)-1;
@ -695,20 +702,31 @@ bool MinidumpCallback(
crashReporterPath, minidumpPath, (char*)0);
#else
// Invoke the reportCrash activity using am
(void) execlp("/system/bin/am",
"/system/bin/am",
"start",
"-a", "org.mozilla.gecko.reportCrash",
"-n", crashReporterPath,
"--es", "minidumpPath", minidumpPath,
(char*)0);
if (androidUserSerial) {
(void) execlp("/system/bin/am",
"/system/bin/am",
"start",
"--user", androidUserSerial,
"-a", "org.mozilla.gecko.reportCrash",
"-n", crashReporterPath,
"--es", "minidumpPath", minidumpPath,
(char*)0);
} else {
(void) execlp("/system/bin/am",
"/system/bin/am",
"start",
"-a", "org.mozilla.gecko.reportCrash",
"-n", crashReporterPath,
"--es", "minidumpPath", minidumpPath,
(char*)0);
}
#endif
_exit(1);
}
#endif // XP_MACOSX
#endif // XP_UNIX
return returnValue;
return returnValue;
}
#ifdef XP_WIN
@ -916,6 +934,10 @@ nsresult SetExceptionHandler(nsIFile* aXREDirectory,
}
#endif // XP_WIN32
#ifdef MOZ_WIDGET_ANDROID
androidUserSerial = getenv("MOZ_ANDROID_USER_SERIAL_NUMBER");
#endif
// now set the exception handler
#ifdef XP_LINUX
MinidumpDescriptor descriptor(tempPath.get());