Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Bug 811763 - Ensure crash reporter is invoked with the right android …
Browse files Browse the repository at this point in the history
…user serial number in Android 4.2 and above. r=blassey, snorp a=akeybl
  • Loading branch information
staktrace committed Nov 15, 2012
1 parent 09aadd6 commit 6a1af87
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
26 changes: 26 additions & 0 deletions mobile/android/base/GeckoAppShell.java
Expand Up @@ -453,6 +453,32 @@ public static void setupGeckoEnvironment(Context context) {
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();
}

Expand Down
38 changes: 30 additions & 8 deletions toolkit/crashreporter/nsExceptionHandler.cpp
Expand Up @@ -178,6 +178,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;
Expand Down Expand Up @@ -676,20 +683,31 @@ bool MinidumpCallback(const XP_CHAR* dump_path,
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
Expand Down Expand Up @@ -897,6 +915,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
gExceptionHandler = new google_breakpad::
ExceptionHandler(tempPath.get(),
Expand Down

0 comments on commit 6a1af87

Please sign in to comment.