Bug 1453691 part 2 - Use the device's actual model and build id in the fabricated Chrome UA string.
MozReview-Commit-ID: 1pvnNDJivMh
--- a/mobile/android/extensions/gws-and-facebook-chrome-spoof/bootstrap.js
+++ b/mobile/android/extensions/gws-and-facebook-chrome-spoof/bootstrap.js
@@ -18,18 +18,21 @@ const OverrideNotice = "The user agent s
const defaultUA = Cc["@mozilla.org/network/protocol;1?name=http"].
getService(Ci.nsIHttpProtocolHandler).userAgent;
const RunningFirefoxVersion = (defaultUA.match(/Firefox\/([0-9.]+)/) || ["", "58.0"])[1];
const RunningAndroidVersion = defaultUA.match(/Android\/[0-9.]+/) || "Android 6.0";
const ChromeMajorVersionToMimic = `${parseInt(RunningFirefoxVersion) + 4}.0.0.0`;
-const ChromePhoneUA = `Mozilla/5.0 (Linux; ${RunningAndroidVersion}; Nexus 5 Build/MRA58N) FxQuantum/${RunningFirefoxVersion} AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${ChromeMajorVersionToMimic} Mobile Safari/537.36`;
-const ChromeTabletUA = `Mozilla/5.0 (Linux; ${RunningAndroidVersion}; Nexus 7 Build/JSS15Q) FxQuantum/${RunningFirefoxVersion} AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${ChromeMajorVersionToMimic} Safari/537.36`;
+const DeviceModel = Services.sysinfo.getProperty("model");
+const DeviceBuildId = Services.sysinfo.getProperty("buildid");
+
+const ChromePhoneUA = `Mozilla/5.0 (Linux; ${RunningAndroidVersion}; ${DeviceModel} Build/${DeviceBuildId}) FxQuantum/${RunningFirefoxVersion} AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${ChromeMajorVersionToMimic} Mobile Safari/537.36`;
+const ChromeTabletUA = `Mozilla/5.0 (Linux; ${RunningAndroidVersion}; ${DeviceModel} Build/${DeviceBuildId}) FxQuantum/${RunningFirefoxVersion} AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${ChromeMajorVersionToMimic} Safari/537.36`;
const IsPhone = defaultUA.includes("Mobile");
const TargetUA = IsPhone ? ChromePhoneUA : ChromeTabletUA;
this.install = () => {};
this.uninstall = () => {};
this.shutdown = () => {};
--- a/xpcom/base/nsSystemInfo.cpp
+++ b/xpcom/base/nsSystemInfo.cpp
@@ -53,16 +53,18 @@
#endif
#ifdef MOZ_WIDGET_ANDROID
#include "AndroidBridge.h"
#include "mozilla/dom/ContentChild.h"
#endif
#ifdef ANDROID
+#include <dlfcn.h>
+#include <sys/system_properties.h>
extern "C" {
NS_EXPORT int android_sdk_version;
}
#endif
#ifdef XP_MACOSX
#include <sys/sysctl.h>
#endif
@@ -979,19 +981,62 @@ nsSystemInfo::GetAndroidSystemInfo(Andro
if (!mozilla::AndroidBridge::Bridge()->GetStaticIntField(
"android/os/Build$VERSION", "SDK_INT", &sdk_version)) {
sdk_version = 0;
}
aInfo->sdk_version() = sdk_version;
aInfo->isTablet() = java::GeckoAppShell::IsTablet();
}
+#if defined(ANDROID)
+#if (__ANDROID_API__ >= ANDROID_VERSION_LOLLIPOP)
+typedef int (system_property_get)(const char*, char*);
+
+static int
+wrap_system_property_get(const char* aName, char* aValue)
+{
+ void* libc = dlopen("libc.so", RTLD_LAZY);
+ if (!libc) {
+ LOG("Failed to open libc.so");
+ return -1;
+ }
+ system_property_get* func = (system_property_get*)
+ dlsym(libc, "__system_property_get");
+ int ret = -1;
+ if (func) {
+ ret = func(aName, aValue);
+ }
+ dlclose(libc);
+ return ret;
+}
+#endif
+
+static int
+android_system_property_get(const char* aName, char* aValue)
+{
+#if (__ANDROID_API__ >= ANDROID_VERSION_LOLLIPOP)
+ return wrap_system_property_get(aName, aValue);
+#else
+ return __system_property_get(aName, aValue);
+#endif
+}
+#endif
+
void
nsSystemInfo::SetupAndroidInfo(const AndroidSystemInfo& aInfo)
{
+ char buf[PROP_VALUE_MAX];
+ memset(buf, 0, PROP_VALUE_MAX);
+
+ Unused << android_system_property_get("ro.product.model", buf);
+ Unused << SetPropertyAsACString(NS_LITERAL_STRING("model"), nsDependentCString(buf));
+
+ Unused << android_system_property_get("ro.build.id", buf);
+ Unused << SetPropertyAsACString(NS_LITERAL_STRING("buildid"), nsDependentCString(buf));
+
if (!aInfo.device().IsEmpty()) {
SetPropertyAsAString(NS_LITERAL_STRING("device"), aInfo.device());
}
if (!aInfo.manufacturer().IsEmpty()) {
SetPropertyAsAString(NS_LITERAL_STRING("manufacturer"), aInfo.manufacturer());
}
if (!aInfo.release_version().IsEmpty()) {
SetPropertyAsAString(NS_LITERAL_STRING("release_version"), aInfo.release_version());