From 6b4695625132192a78cc3d3a8efa751130f2603d Mon Sep 17 00:00:00 2001 From: Brad Lassey Date: Mon, 28 Feb 2011 11:32:05 -0500 Subject: [PATCH] bug 635814 - add shellName and shellVersion to nsSystemInfo r=dougt a=2.0+ --- widget/src/android/AndroidBridge.cpp | 17 +++++++++++++++++ widget/src/android/AndroidBridge.h | 2 ++ xpcom/base/nsSystemInfo.cpp | 16 +++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/widget/src/android/AndroidBridge.cpp b/widget/src/android/AndroidBridge.cpp index b3b5f23aa4d..193966e2520 100644 --- a/widget/src/android/AndroidBridge.cpp +++ b/widget/src/android/AndroidBridge.cpp @@ -642,6 +642,23 @@ AndroidBridge::CallEglCreateWindowSurface(void *dpy, void *config, AndroidGeckoS return (void*) realSurface; } +bool +AndroidBridge::GetStaticIntField(const char *className, const char *fieldName, PRInt32* aInt) +{ + AutoLocalJNIFrame jniFrame(3); + jclass cls = mJNIEnv->FindClass(className); + if (!cls) + return false; + + jfieldID field = mJNIEnv->GetStaticFieldID(cls, fieldName, "I"); + if (!field) + return false; + + *aInt = static_cast(mJNIEnv->GetStaticIntField(cls, field)); + + return true; +} + bool AndroidBridge::GetStaticStringField(const char *className, const char *fieldName, nsAString &result) { diff --git a/widget/src/android/AndroidBridge.h b/widget/src/android/AndroidBridge.h index c5bd4c8ed42..2e7d9e3245f 100644 --- a/widget/src/android/AndroidBridge.h +++ b/widget/src/android/AndroidBridge.h @@ -217,6 +217,8 @@ public: bool GetStaticStringField(const char *classID, const char *field, nsAString &result); + bool GetStaticIntField(const char *className, const char *fieldName, PRInt32* aInt); + void SetKeepScreenOn(bool on); protected: diff --git a/xpcom/base/nsSystemInfo.cpp b/xpcom/base/nsSystemInfo.cpp index 0279a225b96..1afab5f5ed2 100644 --- a/xpcom/base/nsSystemInfo.cpp +++ b/xpcom/base/nsSystemInfo.cpp @@ -149,8 +149,22 @@ nsSystemInfo::Init() SetPropertyAsAString(NS_LITERAL_STRING("device"), str); if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "MANUFACTURER", str)) SetPropertyAsAString(NS_LITERAL_STRING("manufacturer"), str); - if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "HARDWARE", str)) + PRInt32 version; + if (!mozilla::AndroidBridge::Bridge()->GetStaticIntField("android/os/Build$VERSION", "SDK_INT", &version)) + version = 0; + if (version >= 8 && mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "HARDWARE", str)) SetPropertyAsAString(NS_LITERAL_STRING("hardware"), str); + SetPropertyAsAString(NS_LITERAL_STRING("shellName"), NS_LITERAL_STRING("Android")); + if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "CODENAME", str)) { + if (version) { + str.Append(NS_LITERAL_STRING(" (")); + str.AppendInt(version); + str.Append(NS_LITERAL_STRING(")")); + } + SetPropertyAsAString(NS_LITERAL_STRING("shellVersion"), str); + } + + } #endif return NS_OK;