mobile/android/base/SysInfo.java.in

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 #filter substitution
     2 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
     3  * This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 package org.mozilla.gecko;
     9 import org.mozilla.gecko.util.HardwareUtils;
    11 import android.os.StrictMode;
    12 import android.util.Log;
    14 import java.io.File;
    15 import java.io.FileFilter;
    17 import java.util.regex.Pattern;
    19 /**
    20  * A collection of system info values, broadly mirroring a subset of
    21  * nsSystemInfo. See also the constants in AppConstants, which reflect
    22  * much of nsIXULAppInfo.
    23  */
    24 public final class SysInfo {
    25     private static final String LOG_TAG = "GeckoSysInfo";
    27     // We don't mind an instant of possible duplicate work, we only wish to
    28     // avoid inconsistency, so we don't bother with synchronization for
    29     // these.
    30     private static volatile int cpuCount = -1;
    32       /**
    33        * Get the number of cores on the device.
    34        *
    35        * We can't use a nice tidy API call, because they're all wrong:
    36        *
    37        * <http://stackoverflow.com/questions/7962155/how-can-you-detect-a-dual-core-
    38        * cpu-on-an-android-device-from-code>
    39        *
    40        * This method is based on that code.
    41        *
    42        * @return the number of CPU cores, or 1 if the number could not be
    43        *         determined.
    44        */
    45     public static int getCPUCount() {
    46         if (cpuCount > 0) {
    47             return cpuCount;
    48         }
    50         if (android.os.Build.VERSION.SDK_INT < 9) {
    51             return readCPUCount();
    52         }
    54         // Avoid a strict mode warning... but only on devices that have StrictMode.
    55         StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
    56         try {
    57             return readCPUCount();
    58         } finally {
    59             StrictMode.setThreadPolicy(savedPolicy);
    60         }
    61     }
    63     private static int readCPUCount() {
    64         class CpuFilter implements FileFilter {
    65             @Override
    66             public boolean accept(File pathname) {
    67                 return Pattern.matches("cpu[0-9]+", pathname.getName());
    68             }
    69         }
    70         try {
    71             final File dir = new File("/sys/devices/system/cpu/");
    72             return cpuCount = dir.listFiles(new CpuFilter()).length;
    73         } catch (Exception e) {
    74             Log.w(LOG_TAG, "Assuming 1 CPU; got exception.", e);
    75             return cpuCount = 1;
    76         }
    77     }
    79     /**
    80      * Wraps HardwareUtils so callers don't need to know about it.
    81      */
    82     public static int getMemSize() {
    83         return HardwareUtils.getMemSize();
    84     }
    86     /**
    87      * @return the SDK version supported by this device, such as '16'.
    88      */
    89     public static int getVersion() {
    90         return android.os.Build.VERSION.SDK_INT;
    91     }
    93     /**
    94      * @return the release version string, such as "4.1.2".
    95      */
    96     public static String getReleaseVersion() {
    97         return android.os.Build.VERSION.RELEASE;
    98     }
   100     /**
   101      * @return the kernel version string, such as "3.4.10-geb45596".
   102      */
   103     public static String getKernelVersion() {
   104         return System.getProperty("os.version", "");
   105     }
   107     /**
   108      * @return the device manufacturer, such as "HTC".
   109      */
   110     public static String getManufacturer() {
   111         return android.os.Build.MANUFACTURER;
   112     }
   114     /**
   115      * @return the device name, such as "HTC One".
   116      */
   117     public static String getDevice() {
   118         // No, not android.os.Build.DEVICE.
   119         return android.os.Build.MODEL;
   120     }
   122     /**
   123      * @return the Android "hardware" identifier, such as "m7".
   124      */
   125     public static String getHardware() {
   126         return android.os.Build.HARDWARE;
   127     }
   129     /**
   130      * @return the system OS name. Hardcoded to "Android".
   131      */
   132     public static String getName() {
   133         // We deliberately differ from PR_SI_SYSNAME, which is "Linux".
   134         return "Android";
   135     }
   137     /**
   138      * @return the architecture string, excluding ABI.
   139      */
   140     public static String getArch() {
   141         return "@CPU_ARCH@";   // "arm"
   142     }
   144     /**
   145      * @return the Android architecture string, including ABI.
   146      */
   147     public static String getArchABI() {
   148         // Android likes to include the ABI, too ("armeabiv7"), so we
   149         // differ to add value.
   150         return android.os.Build.CPU_ABI;
   151     }
   153     /**
   154      * @return the default system locale, such as "en-US"
   155      */
   156     public static String getLocale() {
   157         return java.util.Locale.getDefault().toString().replace('_', '-');
   158     }
   159 }

mercurial