Bug 1264076 - Allow customized device string for user agent on Fennec; r=mcmanus
authorMichael Kaply <mozilla@kaply.com>
Wed, 13 Apr 2016 20:46:13 -0500
changeset 330961 f6fe48816b24556b76f34e7e3ec9713a439bb191
parent 330960 f3ff455f8a397e85691cb5c8aa3f7f88ac5317f3
child 330962 52ebea10c080da799bc43150e261e043ba824f5b
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1264076
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1264076 - Allow customized device string for user agent on Fennec; r=mcmanus
mobile/android/confvars.sh
netwerk/protocol/http/nsHttpHandler.cpp
--- a/mobile/android/confvars.sh
+++ b/mobile/android/confvars.sh
@@ -79,17 +79,17 @@ MOZ_ANDROID_SEARCH_ACTIVITY=1
 
 # Enable the Mozilla Location Service stumbler.
 MOZ_ANDROID_MLS_STUMBLER=1
 
 # Enable adding to the system downloads list.
 MOZ_ANDROID_DOWNLOADS_INTEGRATION=1
 
 # Build and package the install bouncer APK by default.
-MOZ_ANDROID_PACKAGE_INSTALL_BOUNCER=1
+#MOZ_ANDROID_PACKAGE_INSTALL_BOUNCER=1
 
 # Use the low-memory GC tuning.
 export JS_GC_SMALL_CHUNK_SIZE=1
 
 # Enable GCM registration on Nightly builds only.
 if test "$NIGHTLY_BUILD"; then
   MOZ_ANDROID_GCM=1
 fi
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -124,24 +124,34 @@ NewURI(const nsACString &aSpec,
 
     url.forget(aURI);
     return NS_OK;
 }
 
 #ifdef ANDROID
 static nsCString
 GetDeviceModelId() {
+    // Assumed to be running on the main thread
+    // We need the device property in either case
+    nsAutoCString deviceModelId;
     nsCOMPtr<nsIPropertyBag2> infoService = do_GetService("@mozilla.org/system-info;1");
     MOZ_ASSERT(infoService, "Could not find a system info service");
     nsAutoString androidDevice;
     nsresult rv = infoService->GetPropertyAsAString(NS_LITERAL_STRING("device"), androidDevice);
     if (NS_SUCCEEDED(rv)) {
-        return NS_LossyConvertUTF16toASCII(androidDevice);
+        deviceModelId = NS_LossyConvertUTF16toASCII(androidDevice);
     }
-    return EmptyCString();
+    nsAutoCString deviceString;
+    rv = Preferences::GetCString(UA_PREF("device_string"), &deviceString);
+    if (NS_SUCCEEDED(rv)) {
+        deviceString.Trim(" ", true, true);
+        deviceString.ReplaceSubstring(NS_LITERAL_CSTRING("%DEVICEID%"), deviceModelId);
+        return deviceString;
+    }
+    return deviceModelId;
 }
 #endif
 
 //-----------------------------------------------------------------------------
 // nsHttpHandler <public>
 //-----------------------------------------------------------------------------
 
 nsHttpHandler *gHttpHandler = nullptr;