LCOV - code coverage report
Current view: directory - xpcom/base - nsSystemInfo.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 41 40 97.6 %
Date: 2012-06-02 Functions: 6 6 100.0 %

       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
       4                 :  *
       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/
       9                 :  *
      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
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * mozilla.org
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2005
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Seth Spitzer <sspitzer@mozilla.org> (original author)
      24                 :  *
      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.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #include "mozilla/Util.h"
      40                 : 
      41                 : #include "nsSystemInfo.h"
      42                 : #include "prsystem.h"
      43                 : #include "nsString.h"
      44                 : #include "prprf.h"
      45                 : #include "mozilla/SSE.h"
      46                 : #include "mozilla/arm.h"
      47                 : 
      48                 : #ifdef MOZ_WIDGET_GTK2
      49                 : #include <gtk/gtk.h>
      50                 : #endif
      51                 : 
      52                 : #ifdef MOZ_WIDGET_ANDROID
      53                 : #include "AndroidBridge.h"
      54                 : 
      55                 : extern "C" {
      56                 : NS_EXPORT int android_sdk_version;
      57                 : }
      58                 : #endif
      59                 : 
      60                 : using namespace mozilla;
      61                 : 
      62             230 : nsSystemInfo::nsSystemInfo()
      63                 : {
      64             230 : }
      65                 : 
      66             460 : nsSystemInfo::~nsSystemInfo()
      67                 : {
      68             920 : }
      69                 : 
      70                 : // CPU-specific information.
      71                 : static const struct PropItems {
      72                 :     const char *name;
      73                 :     bool (*propfun)(void);
      74                 : } cpuPropItems[] = {
      75                 :     // x86-specific bits.
      76                 :     { "hasMMX", mozilla::supports_mmx },
      77                 :     { "hasSSE", mozilla::supports_sse },
      78                 :     { "hasSSE2", mozilla::supports_sse2 },
      79                 :     { "hasSSE3", mozilla::supports_sse3 },
      80                 :     { "hasSSSE3", mozilla::supports_ssse3 },
      81                 :     { "hasSSE4A", mozilla::supports_sse4a },
      82                 :     { "hasSSE4_1", mozilla::supports_sse4_1 },
      83                 :     { "hasSSE4_2", mozilla::supports_sse4_2 },
      84                 :     // ARM-specific bits.
      85                 :     { "hasEDSP", mozilla::supports_edsp },
      86                 :     { "hasARMv6", mozilla::supports_armv6 },
      87                 :     { "hasNEON", mozilla::supports_neon }
      88                 : };
      89                 : 
      90                 : nsresult
      91             230 : nsSystemInfo::Init()
      92                 : {
      93             230 :     nsresult rv = nsHashPropertyBag::Init();
      94             230 :     NS_ENSURE_SUCCESS(rv, rv);
      95                 : 
      96                 :     static const struct {
      97                 :       PRSysInfo cmd;
      98                 :       const char *name;
      99                 :     } items[] = {
     100                 :       { PR_SI_SYSNAME, "name" },
     101                 :       { PR_SI_HOSTNAME, "host" },
     102                 :       { PR_SI_ARCHITECTURE, "arch" },
     103                 :       { PR_SI_RELEASE, "version" }
     104                 :     };
     105                 : 
     106            1150 :     for (PRUint32 i = 0; i < (sizeof(items) / sizeof(items[0])); i++) {
     107                 :       char buf[SYS_INFO_BUFFER_LENGTH];
     108             920 :       if (PR_GetSystemInfo(items[i].cmd, buf, sizeof(buf)) == PR_SUCCESS) {
     109             920 :         rv = SetPropertyAsACString(NS_ConvertASCIItoUTF16(items[i].name),
     110            1840 :                                    nsDependentCString(buf));
     111             920 :         NS_ENSURE_SUCCESS(rv, rv);
     112                 :       }
     113                 :       else {
     114               0 :         NS_WARNING("PR_GetSystemInfo failed");
     115                 :       }
     116                 :     }
     117                 : 
     118                 :     // Additional informations not available through PR_GetSystemInfo.
     119             230 :     SetInt32Property(NS_LITERAL_STRING("pagesize"), PR_GetPageSize());
     120             230 :     SetInt32Property(NS_LITERAL_STRING("pageshift"), PR_GetPageShift());
     121             230 :     SetInt32Property(NS_LITERAL_STRING("memmapalign"), PR_GetMemMapAlignment());
     122             230 :     SetInt32Property(NS_LITERAL_STRING("cpucount"), PR_GetNumberOfProcessors());
     123             230 :     SetUint64Property(NS_LITERAL_STRING("memsize"), PR_GetPhysicalMemorySize());
     124                 : 
     125            2760 :     for (PRUint32 i = 0; i < ArrayLength(cpuPropItems); i++) {
     126            2530 :         rv = SetPropertyAsBool(NS_ConvertASCIItoUTF16(cpuPropItems[i].name),
     127            2530 :                                cpuPropItems[i].propfun());
     128            2530 :         NS_ENSURE_SUCCESS(rv, rv);
     129                 :     }
     130                 : 
     131                 : #ifdef MOZ_WIDGET_GTK2
     132                 :     // This must be done here because NSPR can only separate OS's when compiled, not libraries.
     133             230 :     char* gtkver = PR_smprintf("GTK %u.%u.%u", gtk_major_version, gtk_minor_version, gtk_micro_version);
     134             230 :     if (gtkver) {
     135             230 :       rv = SetPropertyAsACString(NS_LITERAL_STRING("secondaryLibrary"),
     136             460 :                                  nsDependentCString(gtkver));
     137             230 :       PR_smprintf_free(gtkver);
     138             230 :       NS_ENSURE_SUCCESS(rv, rv);
     139                 :     }
     140                 : #endif
     141                 : 
     142                 : 
     143                 : #ifdef MOZ_PLATFORM_MAEMO
     144                 :     char *  line = nsnull;
     145                 :     size_t  len = 0;
     146                 :     ssize_t read;
     147                 : #if MOZ_PLATFORM_MAEMO > 5
     148                 :     FILE *fp = popen("/usr/bin/sysinfoclient --get /component/product", "r");
     149                 : #else
     150                 :     FILE *fp = fopen("/proc/component_version", "r");
     151                 : #endif
     152                 :     if (fp) {
     153                 :       while ((read = getline(&line, &len, fp)) != -1) {
     154                 :         if (line) {
     155                 :           if (strstr(line, "RX-51")) {
     156                 :             SetPropertyAsACString(NS_LITERAL_STRING("device"), NS_LITERAL_CSTRING("Nokia N900"));
     157                 :             SetPropertyAsACString(NS_LITERAL_STRING("manufacturer"), NS_LITERAL_CSTRING("Nokia"));
     158                 :             SetPropertyAsACString(NS_LITERAL_STRING("hardware"), NS_LITERAL_CSTRING("RX-51"));
     159                 :             break;
     160                 :           } else if (strstr(line, "RX-44") ||
     161                 :                      strstr(line, "RX-48") ||
     162                 :                      strstr(line, "RX-32") ) {
     163                 :             /* not as accurate as we can be, but these devices are deprecated */
     164                 :             SetPropertyAsACString(NS_LITERAL_STRING("device"), NS_LITERAL_CSTRING("Nokia N8xx"));
     165                 :             SetPropertyAsACString(NS_LITERAL_STRING("manufacturer"), NS_LITERAL_CSTRING("Nokia"));
     166                 :             SetPropertyAsACString(NS_LITERAL_STRING("hardware"), NS_LITERAL_CSTRING("N8xx"));
     167                 :             break;
     168                 :           }
     169                 :         }
     170                 :       }
     171                 :       if (line)
     172                 :         free(line);
     173                 : #if MOZ_PLATFORM_MAEMO > 5
     174                 :       pclose(fp);
     175                 : #else
     176                 :       fclose(fp);
     177                 : #endif
     178                 :     }
     179                 : #endif
     180                 : 
     181                 : #ifdef MOZ_WIDGET_ANDROID
     182                 :     if (mozilla::AndroidBridge::Bridge()) {
     183                 :         nsAutoString str;
     184                 :         if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "MODEL", str))
     185                 :             SetPropertyAsAString(NS_LITERAL_STRING("device"), str);
     186                 :         if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "MANUFACTURER", str))
     187                 :             SetPropertyAsAString(NS_LITERAL_STRING("manufacturer"), str);
     188                 :         PRInt32 version;
     189                 :         if (!mozilla::AndroidBridge::Bridge()->GetStaticIntField("android/os/Build$VERSION", "SDK_INT", &version))
     190                 :             version = 0;
     191                 :         android_sdk_version = version;
     192                 :         if (version >= 8 && mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "HARDWARE", str))
     193                 :             SetPropertyAsAString(NS_LITERAL_STRING("hardware"), str);
     194                 :         SetPropertyAsAString(NS_LITERAL_STRING("shellName"), NS_LITERAL_STRING("Android"));
     195                 :         if (mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build$VERSION", "CODENAME", str)) {
     196                 :             if (version) {
     197                 :                 str.Append(NS_LITERAL_STRING(" ("));
     198                 :                 str.AppendInt(version);
     199                 :                 str.Append(NS_LITERAL_STRING(")"));
     200                 :             }
     201                 :             SetPropertyAsAString(NS_LITERAL_STRING("shellVersion"), str);
     202                 :         }
     203                 :         bool isTablet = mozilla::AndroidBridge::Bridge()->IsTablet();
     204                 :         SetPropertyAsBool(NS_LITERAL_STRING("tablet"), isTablet);
     205                 :     }
     206                 : #endif
     207             230 :     return NS_OK;
     208                 : }
     209                 : 
     210                 : void
     211             920 : nsSystemInfo::SetInt32Property(const nsAString &aPropertyName,
     212                 :                                const PRInt32 aValue)
     213                 : {
     214             920 :   NS_WARN_IF_FALSE(aValue > 0, "Unable to read system value");
     215             920 :   if (aValue > 0) {
     216                 : #ifdef DEBUG
     217                 :     nsresult rv =
     218                 : #endif
     219             920 :       SetPropertyAsInt32(aPropertyName, aValue);
     220             920 :     NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Unable to set property");
     221                 :   }
     222             920 : }
     223                 : 
     224                 : void
     225             230 : nsSystemInfo::SetUint64Property(const nsAString &aPropertyName,
     226                 :                                 const PRUint64 aValue)
     227                 : {
     228             230 :   NS_WARN_IF_FALSE(aValue > 0, "Unable to read system value");
     229             230 :   if (aValue > 0) {
     230                 : #ifdef DEBUG
     231                 :     nsresult rv =
     232                 : #endif
     233             230 :       SetPropertyAsUint64(aPropertyName, aValue);
     234             230 :     NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Unable to set property");
     235                 :   }
     236             230 : }

Generated by: LCOV version 1.7