2006-07-06 06:32:03 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-01-27 09:40:17 +00:00
|
|
|
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2006-07-06 06:32:03 +00:00
|
|
|
#include "nsSystemInfo.h"
|
|
|
|
#include "prsystem.h"
|
2013-09-19 18:29:31 +00:00
|
|
|
#include "prio.h"
|
2013-09-19 18:27:35 +00:00
|
|
|
#include "prprf.h"
|
2011-10-06 15:35:46 +00:00
|
|
|
#include "mozilla/SSE.h"
|
|
|
|
#include "mozilla/arm.h"
|
2008-03-14 15:42:34 +00:00
|
|
|
|
2013-02-12 01:49:33 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <windows.h>
|
2013-11-01 22:54:25 +00:00
|
|
|
#include <winioctl.h>
|
|
|
|
#include "base/scoped_handle_win.h"
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
2013-12-02 17:41:44 +00:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2013-11-01 22:54:25 +00:00
|
|
|
#include "nsDirectoryServiceUtils.h"
|
2013-02-12 01:49:33 +00:00
|
|
|
#endif
|
|
|
|
|
2012-06-16 06:05:00 +00:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2008-03-14 15:42:34 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#endif
|
2000-01-27 09:40:17 +00:00
|
|
|
|
2011-11-11 00:17:46 +00:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2010-09-11 13:20:20 +00:00
|
|
|
#include "AndroidBridge.h"
|
2013-11-12 18:41:01 +00:00
|
|
|
using namespace mozilla::widget::android;
|
2012-03-26 01:52:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include <sys/system_properties.h>
|
|
|
|
#endif
|
2011-12-05 18:41:11 +00:00
|
|
|
|
2012-03-26 01:52:03 +00:00
|
|
|
#ifdef ANDROID
|
2011-12-05 18:41:11 +00:00
|
|
|
extern "C" {
|
2011-12-22 01:13:31 +00:00
|
|
|
NS_EXPORT int android_sdk_version;
|
2011-12-05 18:41:11 +00:00
|
|
|
}
|
2010-09-11 13:20:20 +00:00
|
|
|
#endif
|
|
|
|
|
2013-11-01 22:54:25 +00:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
namespace {
|
2013-12-02 17:41:44 +00:00
|
|
|
nsresult GetHDDInfo(const char* aSpecialDirName, nsAutoCString& aModel,
|
|
|
|
nsAutoCString& aRevision)
|
2013-11-01 22:54:25 +00:00
|
|
|
{
|
|
|
|
aModel.Truncate();
|
|
|
|
aRevision.Truncate();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> profDir;
|
2013-12-02 17:41:44 +00:00
|
|
|
nsresult rv = NS_GetSpecialDirectory(aSpecialDirName,
|
2013-11-01 22:54:25 +00:00
|
|
|
getter_AddRefs(profDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsAutoString profDirPath;
|
|
|
|
rv = profDir->GetPath(profDirPath);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
wchar_t volumeMountPoint[MAX_PATH] = {L'\\', L'\\', L'.', L'\\'};
|
|
|
|
const size_t PREFIX_LEN = 4;
|
|
|
|
if (!::GetVolumePathNameW(profDirPath.get(), volumeMountPoint + PREFIX_LEN,
|
|
|
|
mozilla::ArrayLength(volumeMountPoint) -
|
|
|
|
PREFIX_LEN)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
size_t volumeMountPointLen = wcslen(volumeMountPoint);
|
|
|
|
// Since we would like to open a drive and not a directory, we need to
|
|
|
|
// remove any trailing backslash. A drive handle is valid for
|
|
|
|
// DeviceIoControl calls, a directory handle is not.
|
|
|
|
if (volumeMountPoint[volumeMountPointLen - 1] == L'\\') {
|
|
|
|
volumeMountPoint[volumeMountPointLen - 1] = L'\0';
|
|
|
|
}
|
|
|
|
ScopedHandle handle(::CreateFileW(volumeMountPoint, 0,
|
2013-11-11 19:17:14 +00:00
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
nullptr, OPEN_EXISTING, 0, nullptr));
|
2013-11-01 22:54:25 +00:00
|
|
|
if (!handle.IsValid()) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
STORAGE_PROPERTY_QUERY queryParameters = {StorageDeviceProperty,
|
|
|
|
PropertyStandardQuery};
|
|
|
|
STORAGE_DEVICE_DESCRIPTOR outputHeader = {sizeof(STORAGE_DEVICE_DESCRIPTOR)};
|
|
|
|
DWORD bytesRead = 0;
|
|
|
|
if (!::DeviceIoControl(handle, IOCTL_STORAGE_QUERY_PROPERTY,
|
|
|
|
&queryParameters, sizeof(queryParameters),
|
|
|
|
&outputHeader, sizeof(outputHeader), &bytesRead,
|
|
|
|
nullptr)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
PSTORAGE_DEVICE_DESCRIPTOR deviceOutput =
|
|
|
|
(PSTORAGE_DEVICE_DESCRIPTOR)malloc(outputHeader.Size);
|
|
|
|
if (!::DeviceIoControl(handle, IOCTL_STORAGE_QUERY_PROPERTY,
|
|
|
|
&queryParameters, sizeof(queryParameters),
|
|
|
|
deviceOutput, outputHeader.Size, &bytesRead,
|
|
|
|
nullptr)) {
|
|
|
|
free(deviceOutput);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
// Some HDDs are including product ID info in the vendor field. Since PNP
|
|
|
|
// IDs include vendor info and product ID concatenated together, we'll do
|
|
|
|
// that here and interpret the result as a unique ID for the HDD model.
|
|
|
|
if (deviceOutput->VendorIdOffset) {
|
|
|
|
aModel = reinterpret_cast<char*>(deviceOutput) +
|
|
|
|
deviceOutput->VendorIdOffset;
|
|
|
|
}
|
|
|
|
if (deviceOutput->ProductIdOffset) {
|
|
|
|
aModel += reinterpret_cast<char*>(deviceOutput) +
|
|
|
|
deviceOutput->ProductIdOffset;
|
|
|
|
}
|
|
|
|
aModel.CompressWhitespace();
|
|
|
|
if (deviceOutput->ProductRevisionOffset) {
|
|
|
|
aRevision = reinterpret_cast<char*>(deviceOutput) +
|
|
|
|
deviceOutput->ProductRevisionOffset;
|
|
|
|
aRevision.CompressWhitespace();
|
|
|
|
}
|
|
|
|
free(deviceOutput);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
#endif // defined(XP_WIN)
|
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2006-07-06 06:32:03 +00:00
|
|
|
nsSystemInfo::nsSystemInfo()
|
|
|
|
{
|
|
|
|
}
|
2000-01-27 09:40:17 +00:00
|
|
|
|
2006-07-06 06:32:03 +00:00
|
|
|
nsSystemInfo::~nsSystemInfo()
|
2000-01-27 09:40:17 +00:00
|
|
|
{
|
2006-07-06 06:32:03 +00:00
|
|
|
}
|
2000-01-27 09:40:17 +00:00
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
// CPU-specific information.
|
|
|
|
static const struct PropItems {
|
|
|
|
const char *name;
|
|
|
|
bool (*propfun)(void);
|
|
|
|
} cpuPropItems[] = {
|
|
|
|
// x86-specific bits.
|
|
|
|
{ "hasMMX", mozilla::supports_mmx },
|
|
|
|
{ "hasSSE", mozilla::supports_sse },
|
|
|
|
{ "hasSSE2", mozilla::supports_sse2 },
|
|
|
|
{ "hasSSE3", mozilla::supports_sse3 },
|
|
|
|
{ "hasSSSE3", mozilla::supports_ssse3 },
|
|
|
|
{ "hasSSE4A", mozilla::supports_sse4a },
|
|
|
|
{ "hasSSE4_1", mozilla::supports_sse4_1 },
|
|
|
|
{ "hasSSE4_2", mozilla::supports_sse4_2 },
|
|
|
|
// ARM-specific bits.
|
|
|
|
{ "hasEDSP", mozilla::supports_edsp },
|
|
|
|
{ "hasARMv6", mozilla::supports_armv6 },
|
2012-08-21 11:20:46 +00:00
|
|
|
{ "hasARMv7", mozilla::supports_armv7 },
|
2011-10-11 05:50:08 +00:00
|
|
|
{ "hasNEON", mozilla::supports_neon }
|
|
|
|
};
|
|
|
|
|
2006-07-06 06:32:03 +00:00
|
|
|
nsresult
|
|
|
|
nsSystemInfo::Init()
|
|
|
|
{
|
2013-09-02 08:41:57 +00:00
|
|
|
nsresult rv;
|
2000-01-27 09:40:17 +00:00
|
|
|
|
2006-07-06 06:32:03 +00:00
|
|
|
static const struct {
|
|
|
|
PRSysInfo cmd;
|
|
|
|
const char *name;
|
|
|
|
} items[] = {
|
|
|
|
{ PR_SI_SYSNAME, "name" },
|
|
|
|
{ PR_SI_HOSTNAME, "host" },
|
|
|
|
{ PR_SI_ARCHITECTURE, "arch" },
|
|
|
|
{ PR_SI_RELEASE, "version" }
|
|
|
|
};
|
2000-01-27 09:40:17 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < (sizeof(items) / sizeof(items[0])); i++) {
|
2006-07-06 06:32:03 +00:00
|
|
|
char buf[SYS_INFO_BUFFER_LENGTH];
|
|
|
|
if (PR_GetSystemInfo(items[i].cmd, buf, sizeof(buf)) == PR_SUCCESS) {
|
|
|
|
rv = SetPropertyAsACString(NS_ConvertASCIItoUTF16(items[i].name),
|
|
|
|
nsDependentCString(buf));
|
2013-11-19 21:27:37 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv)))
|
|
|
|
return rv;
|
2006-07-06 06:32:03 +00:00
|
|
|
}
|
2009-11-04 14:41:37 +00:00
|
|
|
else {
|
2006-07-06 06:32:03 +00:00
|
|
|
NS_WARNING("PR_GetSystemInfo failed");
|
2009-11-04 14:41:37 +00:00
|
|
|
}
|
2006-07-06 06:32:03 +00:00
|
|
|
}
|
2008-03-14 15:42:34 +00:00
|
|
|
|
2013-12-10 18:42:16 +00:00
|
|
|
#if defined(XP_WIN) && defined(MOZ_METRO)
|
|
|
|
// Create "hasWindowsTouchInterface" property.
|
|
|
|
nsAutoString version;
|
|
|
|
rv = GetPropertyAsAString(NS_LITERAL_STRING("version"), version);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-01-08 17:22:24 +00:00
|
|
|
double versionDouble = version.ToDouble(&rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-12-10 18:42:16 +00:00
|
|
|
|
|
|
|
rv = SetPropertyAsBool(NS_ConvertASCIItoUTF16("hasWindowsTouchInterface"),
|
|
|
|
versionDouble >= 6.2);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
#else
|
|
|
|
rv = SetPropertyAsBool(NS_ConvertASCIItoUTF16("hasWindowsTouchInterface"), false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
#endif
|
|
|
|
|
2009-11-04 14:41:37 +00:00
|
|
|
// Additional informations not available through PR_GetSystemInfo.
|
|
|
|
SetInt32Property(NS_LITERAL_STRING("pagesize"), PR_GetPageSize());
|
|
|
|
SetInt32Property(NS_LITERAL_STRING("pageshift"), PR_GetPageShift());
|
|
|
|
SetInt32Property(NS_LITERAL_STRING("memmapalign"), PR_GetMemMapAlignment());
|
|
|
|
SetInt32Property(NS_LITERAL_STRING("cpucount"), PR_GetNumberOfProcessors());
|
|
|
|
SetUint64Property(NS_LITERAL_STRING("memsize"), PR_GetPhysicalMemorySize());
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(cpuPropItems); i++) {
|
2011-10-06 15:35:46 +00:00
|
|
|
rv = SetPropertyAsBool(NS_ConvertASCIItoUTF16(cpuPropItems[i].name),
|
|
|
|
cpuPropItems[i].propfun());
|
2013-11-19 21:27:37 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv)))
|
|
|
|
return rv;
|
2011-10-06 15:35:46 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 01:49:33 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
BOOL isWow64;
|
|
|
|
BOOL gotWow64Value = IsWow64Process(GetCurrentProcess(), &isWow64);
|
|
|
|
NS_WARN_IF_FALSE(gotWow64Value, "IsWow64Process failed");
|
|
|
|
if (gotWow64Value) {
|
|
|
|
rv = SetPropertyAsBool(NS_LITERAL_STRING("isWow64"), !!isWow64);
|
2013-11-19 21:27:37 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv)))
|
|
|
|
return rv;
|
2013-02-12 01:49:33 +00:00
|
|
|
}
|
2013-11-01 22:54:25 +00:00
|
|
|
nsAutoCString hddModel, hddRevision;
|
2013-12-02 17:41:44 +00:00
|
|
|
if (NS_SUCCEEDED(GetHDDInfo(NS_APP_USER_PROFILE_50_DIR, hddModel,
|
|
|
|
hddRevision))) {
|
2013-11-01 22:54:25 +00:00
|
|
|
rv = SetPropertyAsACString(NS_LITERAL_STRING("profileHDDModel"), hddModel);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = SetPropertyAsACString(NS_LITERAL_STRING("profileHDDRevision"),
|
|
|
|
hddRevision);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2013-12-02 17:41:44 +00:00
|
|
|
if (NS_SUCCEEDED(GetHDDInfo(NS_GRE_DIR, hddModel, hddRevision))) {
|
|
|
|
rv = SetPropertyAsACString(NS_LITERAL_STRING("binHDDModel"), hddModel);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = SetPropertyAsACString(NS_LITERAL_STRING("binHDDRevision"),
|
|
|
|
hddRevision);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(GetHDDInfo(NS_WIN_WINDOWS_DIR, hddModel, hddRevision))) {
|
|
|
|
rv = SetPropertyAsACString(NS_LITERAL_STRING("winHDDModel"), hddModel);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = SetPropertyAsACString(NS_LITERAL_STRING("winHDDRevision"),
|
|
|
|
hddRevision);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2013-02-12 01:49:33 +00:00
|
|
|
#endif
|
|
|
|
|
2013-06-10 12:36:26 +00:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2008-03-14 15:42:34 +00:00
|
|
|
// This must be done here because NSPR can only separate OS's when compiled, not libraries.
|
|
|
|
char* gtkver = PR_smprintf("GTK %u.%u.%u", gtk_major_version, gtk_minor_version, gtk_micro_version);
|
|
|
|
if (gtkver) {
|
2010-11-17 20:52:59 +00:00
|
|
|
rv = SetPropertyAsACString(NS_LITERAL_STRING("secondaryLibrary"),
|
2008-03-14 15:42:34 +00:00
|
|
|
nsDependentCString(gtkver));
|
|
|
|
PR_smprintf_free(gtkver);
|
2013-11-19 21:27:37 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv)))
|
|
|
|
return rv;
|
2008-03-14 15:42:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
2009-10-25 06:09:46 +00:00
|
|
|
|
2011-11-11 00:17:46 +00:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2010-09-11 13:20:20 +00:00
|
|
|
if (mozilla::AndroidBridge::Bridge()) {
|
|
|
|
nsAutoString str;
|
|
|
|
if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "MODEL", str))
|
|
|
|
SetPropertyAsAString(NS_LITERAL_STRING("device"), str);
|
2010-11-17 20:52:59 +00:00
|
|
|
if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "MANUFACTURER", str))
|
|
|
|
SetPropertyAsAString(NS_LITERAL_STRING("manufacturer"), str);
|
2012-11-30 02:38:09 +00:00
|
|
|
if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build$VERSION", "RELEASE", str))
|
|
|
|
SetPropertyAsAString(NS_LITERAL_STRING("release_version"), str);
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t version;
|
2011-02-28 16:32:05 +00:00
|
|
|
if (!mozilla::AndroidBridge::Bridge()->GetStaticIntField("android/os/Build$VERSION", "SDK_INT", &version))
|
|
|
|
version = 0;
|
2011-12-05 18:41:11 +00:00
|
|
|
android_sdk_version = version;
|
2011-02-28 16:32:05 +00:00
|
|
|
if (version >= 8 && mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "HARDWARE", str))
|
2010-11-17 20:52:59 +00:00
|
|
|
SetPropertyAsAString(NS_LITERAL_STRING("hardware"), str);
|
2013-11-12 18:41:01 +00:00
|
|
|
bool isTablet = GeckoAppShell::IsTablet();
|
2012-02-01 04:04:23 +00:00
|
|
|
SetPropertyAsBool(NS_LITERAL_STRING("tablet"), isTablet);
|
2012-10-10 15:10:39 +00:00
|
|
|
// NSPR "version" is the kernel version. For Android we want the Android version.
|
|
|
|
// Rename SDK version to version and put the kernel version into kernel_version.
|
|
|
|
rv = GetPropertyAsAString(NS_LITERAL_STRING("version"), str);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
SetPropertyAsAString(NS_LITERAL_STRING("kernel_version"), str);
|
|
|
|
}
|
|
|
|
SetPropertyAsInt32(NS_LITERAL_STRING("version"), android_sdk_version);
|
2010-09-11 13:20:20 +00:00
|
|
|
}
|
|
|
|
#endif
|
2012-03-26 01:52:03 +00:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2013-09-23 13:03:16 +00:00
|
|
|
char sdk[PROP_VALUE_MAX], characteristics[PROP_VALUE_MAX];
|
2012-03-26 01:52:03 +00:00
|
|
|
if (__system_property_get("ro.build.version.sdk", sdk))
|
|
|
|
android_sdk_version = atoi(sdk);
|
2013-09-23 13:03:16 +00:00
|
|
|
if (__system_property_get("ro.build.characteristics", characteristics)) {
|
|
|
|
if (!strcmp(characteristics, "tablet"))
|
|
|
|
SetPropertyAsBool(NS_LITERAL_STRING("tablet"), true);
|
|
|
|
}
|
2012-03-26 01:52:03 +00:00
|
|
|
#endif
|
|
|
|
|
2006-07-06 06:32:03 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-01-27 09:40:17 +00:00
|
|
|
|
2009-11-04 14:41:37 +00:00
|
|
|
void
|
|
|
|
nsSystemInfo::SetInt32Property(const nsAString &aPropertyName,
|
2012-08-22 15:56:38 +00:00
|
|
|
const int32_t aValue)
|
2009-11-04 14:41:37 +00:00
|
|
|
{
|
|
|
|
NS_WARN_IF_FALSE(aValue > 0, "Unable to read system value");
|
|
|
|
if (aValue > 0) {
|
2010-07-11 13:00:19 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv =
|
|
|
|
#endif
|
|
|
|
SetPropertyAsInt32(aPropertyName, aValue);
|
2009-11-04 14:41:37 +00:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Unable to set property");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSystemInfo::SetUint64Property(const nsAString &aPropertyName,
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint64_t aValue)
|
2009-11-04 14:41:37 +00:00
|
|
|
{
|
|
|
|
NS_WARN_IF_FALSE(aValue > 0, "Unable to read system value");
|
|
|
|
if (aValue > 0) {
|
2010-07-11 13:00:19 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv =
|
|
|
|
#endif
|
|
|
|
SetPropertyAsUint64(aPropertyName, aValue);
|
2009-11-04 14:41:37 +00:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Unable to set property");
|
|
|
|
}
|
|
|
|
}
|