1 /* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2005
20 * the Initial Developer. All Rights Reserved.
23 * Seth Spitzer <sspitzer@mozilla.org> (original author)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsSystemInfo.h"
44 #ifdef MOZ_WIDGET_GTK2
49 #include "AndroidBridge.h"
52 nsSystemInfo::nsSystemInfo()
56 nsSystemInfo::~nsSystemInfo()
63 nsresult rv
= nsHashPropertyBag::Init();
64 NS_ENSURE_SUCCESS(rv
, rv
);
70 { PR_SI_SYSNAME
, "name" },
71 { PR_SI_HOSTNAME
, "host" },
72 { PR_SI_ARCHITECTURE
, "arch" },
73 { PR_SI_RELEASE
, "version" }
76 for (PRUint32 i
= 0; i
< (sizeof(items
) / sizeof(items
[0])); i
++) {
77 char buf
[SYS_INFO_BUFFER_LENGTH
];
78 if (PR_GetSystemInfo(items
[i
].cmd
, buf
, sizeof(buf
)) == PR_SUCCESS
) {
79 rv
= SetPropertyAsACString(NS_ConvertASCIItoUTF16(items
[i
].name
),
80 nsDependentCString(buf
));
81 NS_ENSURE_SUCCESS(rv
, rv
);
84 NS_WARNING("PR_GetSystemInfo failed");
88 // Additional informations not available through PR_GetSystemInfo.
89 SetInt32Property(NS_LITERAL_STRING("pagesize"), PR_GetPageSize());
90 SetInt32Property(NS_LITERAL_STRING("pageshift"), PR_GetPageShift());
91 SetInt32Property(NS_LITERAL_STRING("memmapalign"), PR_GetMemMapAlignment());
92 SetInt32Property(NS_LITERAL_STRING("cpucount"), PR_GetNumberOfProcessors());
93 SetUint64Property(NS_LITERAL_STRING("memsize"), PR_GetPhysicalMemorySize());
95 #ifdef MOZ_WIDGET_GTK2
96 // This must be done here because NSPR can only separate OS's when compiled, not libraries.
97 char* gtkver
= PR_smprintf("GTK %u.%u.%u", gtk_major_version
, gtk_minor_version
, gtk_micro_version
);
99 rv
= SetPropertyAsACString(NS_LITERAL_STRING("secondaryLibrary"),
100 nsDependentCString(gtkver
));
101 PR_smprintf_free(gtkver
);
102 NS_ENSURE_SUCCESS(rv
, rv
);
107 #ifdef MOZ_PLATFORM_MAEMO
108 char * line
= nsnull
;
111 FILE *fp
= fopen ("/proc/component_version", "r");
113 while ((read
= getline(&line
, &len
, fp
)) != -1) {
115 if (strstr(line
, "RX-51")) {
116 SetPropertyAsACString(NS_LITERAL_STRING("device"), NS_LITERAL_CSTRING("Nokia N900"));
117 SetPropertyAsACString(NS_LITERAL_STRING("manufacturer"), NS_LITERAL_CSTRING("Nokia"));
118 SetPropertyAsACString(NS_LITERAL_STRING("hardware"), NS_LITERAL_CSTRING("RX-51"));
120 } else if (strstr(line
, "RX-44") ||
121 strstr(line
, "RX-48") ||
122 strstr(line
, "RX-32") ) {
123 /* not as accurate as we can be, but these devices are deprecated */
124 SetPropertyAsACString(NS_LITERAL_STRING("device"), NS_LITERAL_CSTRING("Nokia N8xx"));
125 SetPropertyAsACString(NS_LITERAL_STRING("manufacturer"), NS_LITERAL_CSTRING("Nokia"));
126 SetPropertyAsACString(NS_LITERAL_STRING("hardware"), NS_LITERAL_CSTRING("N8xx"));
138 if (mozilla::AndroidBridge::Bridge()) {
140 if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "MODEL", str
))
141 SetPropertyAsAString(NS_LITERAL_STRING("device"), str
);
142 if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "MANUFACTURER", str
))
143 SetPropertyAsAString(NS_LITERAL_STRING("manufacturer"), str
);
144 if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "HARDWARE", str
))
145 SetPropertyAsAString(NS_LITERAL_STRING("hardware"), str
);
152 nsSystemInfo::SetInt32Property(const nsAString
&aPropertyName
,
153 const PRInt32 aValue
)
155 NS_WARN_IF_FALSE(aValue
> 0, "Unable to read system value");
160 SetPropertyAsInt32(aPropertyName
, aValue
);
161 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv
), "Unable to set property");
166 nsSystemInfo::SetUint64Property(const nsAString
&aPropertyName
,
167 const PRUint64 aValue
)
169 NS_WARN_IF_FALSE(aValue
> 0, "Unable to read system value");
174 SetPropertyAsUint64(aPropertyName
, aValue
);
175 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv
), "Unable to set property");