示例#1
0
 /**
  * CPU信息
  *
  * @return
  */
 private String fetch_cpu_info() {
   String result = null;
   CMDExecute cmdexe = new CMDExecute();
   try {
     String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
     result = cmdexe.run(args, "/system/bin/");
     result = result.substring(0, result.lastIndexOf("\n"));
   } catch (IOException ex) {
     ex.printStackTrace();
   }
   return "CPU信息:" + result;
 }
示例#2
0
 private String fetchVersionCore() {
   String result = null;
   CMDExecute cmdexe = new CMDExecute();
   try {
     String[] args = {"/system/bin/cat", "/proc/version"};
     result = cmdexe.run(args, "system/bin/");
     result = result.substring(0, result.indexOf("\n"));
   } catch (IOException ex) {
     ex.printStackTrace();
   }
   return "Linux内核:" + result;
 }
示例#3
0
 /**
  * mac地址,无线
  *
  * @return
  */
 public static String fetch_mac_wlan() {
   String result = null;
   CMDExecute cmdexe = new CMDExecute();
   try {
     String[] args = {"/system/bin/cat", "/sys/class/net/wlan0/address"};
     result = cmdexe.run(args, "system/bin/");
     result = result.substring(0, result.indexOf("\n"));
     // 防止获取不到返回乱码
     if (result.length() > 28) {
       result = result.substring(0, 28);
     }
   } catch (IOException ex) {
     ex.printStackTrace();
   }
   return result;
 }
示例#4
0
  private List<Map<String, Object>> getData() {
    List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

    String linuxVer = cmd.executeCat("/proc/version");
    int pos = linuxVer.indexOf(" (");
    if (pos >= 0) {
      linuxVer = linuxVer.substring(0, pos);
    }
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("title", "Linux version");
    map.put("info", linuxVer);
    // map.put("no", 1);
    list.add(map);

    String cpuInfo = cmd.executeCat("/proc/cpuinfo");
    pos = cpuInfo.indexOf(": ");
    int pos2 = cpuInfo.indexOf("\n");
    cpuInfo = cpuInfo.substring(pos + 2, pos2);
    map = new HashMap<String, Object>();
    map.put("title", "Cpu info");
    map.put("info", cpuInfo);
    // map.put("no", 2);
    list.add(map);

    ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
    activityManager.getMemoryInfo(memInfo);
    String memStr = cmd.executeCat("/proc/meminfo");
    Pattern pattern = Pattern.compile("(\\d+)");
    Matcher match = pattern.matcher(memStr);
    if (match.find()) {
      int allMem = Integer.parseInt(match.group(1));
      memStr = "" + allMem / 1024;
    }
    map = new HashMap<String, Object>();
    map.put("title", "Memory");
    map.put(
        "info", "Total: " + memStr + " MB  Available: " + memInfo.availMem / 1024 / 1024 + " MB");
    // map.put("no", 3);
    list.add(map);

    String netInfo = getIp();
    if (netInfo == null) {
      netInfo = cmd.execute(new String[] {"/system/bin/netcfg"});
      if (netInfo.length() > 0) {
        netInfo = netInfo.substring(0, netInfo.length() - 1);
      }
    }
    map = new HashMap<String, Object>();
    map.put("title", "Network");
    map.put("info", netInfo);
    // map.put("no", 4);
    list.add(map);

    map = new HashMap<String, Object>();
    map.put("title", "Screen");
    map.put("info", getDisplayMetrics());
    // map.put("no", 5);
    list.add(map);

    cpuInfo = cmd.executeCat("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq");
    //		Log.v("Hardware Activity", "cpu freq=" + cpuInfo);
    long cpuFreq = -1;
    try {
      cpuInfo = cpuInfo.substring(0, cpuInfo.length() - 1);
      cpuFreq = Long.valueOf(cpuInfo);
    } catch (Exception e) {
    }
    map = new HashMap<String, Object>();
    map.put("title", "CPU Freq");
    map.put("info", cpuFreq > 0 ? (cpuFreq / 1000 + " MHz") : "unknow");
    // map.put("no", 6);
    list.add(map);

    map = new HashMap<String, Object>();
    map.put("title", "Battery");
    map.put("info", mLastBattery);
    // map.put("no", 7);
    list.add(map);

    long[] romInfo = getRomMemroy();
    map = new HashMap<String, Object>();
    map.put("title", "Rom info");
    map.put("info", "All: " + formatSize(romInfo[0]) + "  Available: " + formatSize(romInfo[1]));
    // map.put("no", 8);
    list.add(map);

    long[] cardInfo = getSDCardMemory();
    map = new HashMap<String, Object>();
    map.put("title", "SDCard info");
    map.put("info", "All: " + formatSize(cardInfo[0]) + "  Available: " + formatSize(cardInfo[1]));
    // map.put("no", 9);
    list.add(map);

    map = new HashMap<String, Object>();
    map.put("title", "Mac Address");
    map.put("info", getMacAddress());
    // map.put("no", 10);
    list.add(map);

    map = new HashMap<String, Object>();
    map.put("title", "Startup ElapsedTime");
    map.put("info", getStartupElapsedTimes());
    // map.put("no", 11);
    list.add(map);

    Runtime runtime = Runtime.getRuntime();
    int maxMemory = ((int) runtime.maxMemory()) / 1024 / 1024;
    // 应用程序已获得内存
    long totalMemory = ((int) runtime.totalMemory()) / 1024 / 1024;
    // 应用程序已获得内存中未使用内存
    long freeMemory = ((int) runtime.freeMemory()) / 1024 / 1024;

    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    int heapMemory = am.getMemoryClass();
    int largeHeapMemory = am.getLargeMemoryClass();
    //        /system/build.prop  dalvik.vm.heapstartsize dalvik.vm.heapgrowthlimit
    // dalvik.vm.heapsize=512m
    map = new HashMap<String, Object>();
    map.put("title", "App Memory");
    map.put(
        "info",
        String.format(
            Locale.getDefault(),
            "maxMemory=%dM, totalMemory=%dM, freeMemory=%dM, heapMemory=%dM, largeHeapMemory=%dM(可能还是heap, 待验证)",
            maxMemory,
            totalMemory,
            freeMemory,
            heapMemory,
            largeHeapMemory));
    // map.put("no", 12);
    list.add(map);

    return list;
  }