List of usage examples for android.app ActivityManager getMemoryInfo
public void getMemoryInfo(MemoryInfo outInfo)
From source file:org.xwalk.runtime.extension.api.device_capabilities.DeviceCapabilitiesMemory.java
private void readMemoryInfo() { MemoryInfo mem_info = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); activityManager.getMemoryInfo(mem_info); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mCapacity = mem_info.totalMem;/*from w w w.j av a 2 s . c om*/ } else { mCapacity = getTotalMemFromFile(); } mAvailableCapacity = mem_info.availMem; }
From source file:rus.cpuinfo.AndroidDepedentModel.DevInfo.java
@NonNull private ActivityManager.MemoryInfo getMemoryInfo() { ActivityManager activityManager = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(mi); return mi;/*w w w. ja v a 2 s .com*/ }
From source file:com.fallahpoor.infocenter.fragments.RamFragment.java
private String getFreeRam() { MemoryInfo memoryInfo;//from ww w . j a va2 s. c o m ActivityManager activityManager; long lngFreeRam; String freeRam; activityManager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); if (activityManager != null) { memoryInfo = new MemoryInfo(); activityManager.getMemoryInfo(memoryInfo); lngFreeRam = memoryInfo.availMem; freeRam = Utils.getFormattedSize(lngFreeRam); } else { freeRam = getString(R.string.unknown); } return freeRam; }
From source file:com.wso2.mobile.mdm.api.PhoneState.java
/** *Returns the available amount of memory in the device *//*from w w w. j a v a2 s . c om*/ public String getAvailableMemory() { ActivityManager activityManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE); MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(memoryInfo); Log.v("Available Memory", memoryInfo.availMem + ""); String availMemory = memoryInfo.availMem + ""; return availMemory; }
From source file:org.wso2.emm.agent.api.RuntimeInfo.java
public List<Device.Property> getRAMInfo() throws AndroidAgentException { List<Device.Property> properties = new ArrayList<>(); Device.Property property;/* w ww. j a v a 2s . c o m*/ ActivityManager actManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); actManager.getMemoryInfo(memInfo); long totalMemory = memInfo.totalMem; long availableMemory = memInfo.availMem; long threshold = memInfo.threshold; boolean lowMemory = memInfo.lowMemory; // The available memory on the system. property = new Device.Property(); property.setName(Constants.Device.TOTAL_MEMORY); property.setValue(String.valueOf(totalMemory)); properties.add(property); // The total memory accessible by the kernel. property = new Device.Property(); property.setName(Constants.Device.AVAILABLE_MEMORY); property.setValue(String.valueOf(availableMemory)); properties.add(property); // The threshold of availMem at which we consider memory to be low and start // killing background services and other non-extraneous processes. property = new Device.Property(); property.setName(Constants.Device.THRESHOLD); property.setValue(String.valueOf(threshold)); properties.add(property); // Set to true if the system considers itself to currently be in a low memory situation. property = new Device.Property(); property.setName(Constants.Device.LOW_MEMORY); property.setValue(String.valueOf(lowMemory)); properties.add(property); return properties; }
From source file:fr.inria.ucn.collectors.SysStateCollector.java
/** * /* w w w. j a va 2 s. c om*/ * @param c * @param ts * @param change */ @SuppressLint("NewApi") public void run(Context c, long ts, boolean change) { try { JSONObject data = new JSONObject(); data.put("on_screen_state_change", change); // this collection run was triggered by screen state change data.put("hostname", Helpers.getSystemProperty("net.hostname", "unknown hostname")); data.put("current_timezone", Time.getCurrentTimezone()); // general memory state ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo mi = new MemoryInfo(); am.getMemoryInfo(mi); JSONObject mem = new JSONObject(); mem.put("available", mi.availMem); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { mem.put("total", mi.totalMem); } mem.put("is_low", mi.lowMemory); data.put("memory", mem); // screen state PowerManager pm = (PowerManager) c.getSystemService(Context.POWER_SERVICE); data.put("screen_on", pm.isScreenOn()); // battery state IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent battery = c.registerReceiver(null, ifilter); int level = battery.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = battery.getIntExtra(BatteryManager.EXTRA_SCALE, -1); float pct = (float) (100.0 * level) / scale; int status = battery.getIntExtra(BatteryManager.EXTRA_STATUS, -1); boolean isCharging = (status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL); int chargePlug = battery.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB; boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC; JSONObject batt = new JSONObject(); batt.put("level", level); batt.put("scale", scale); batt.put("pct", pct); batt.put("is_charging", isCharging); batt.put("usb_charge", usbCharge); batt.put("ac_charge", acCharge); data.put("battery", batt); // some proc stats data.put("cpu", getCpuStat()); data.put("loadavg", getLoadStat()); data.put("uptime", getUptimeStat()); // audio state data.put("audio", getAudioState(c)); // done Helpers.sendResultObj(c, "system_state", ts, data); } catch (JSONException jex) { Log.w(Constants.LOGTAG, "failed to create json object", jex); } }
From source file:be.k0suke.tistats.TiStatsModule.java
@Kroll.method public String stats() { Log.d(LCAT, "stats called"); TiApplication tiApp = TiApplication.getInstance(); ActivityManager activityManager = (ActivityManager) tiApp.getSystemService(Activity.ACTIVITY_SERVICE); JSONObject json = new JSONObject(); try {//from w ww. j a v a 2 s . c o m JSONObject memoryInfoJson = new JSONObject(); ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(memoryInfo); memoryInfoJson.put("availMem", (int) (memoryInfo.availMem)); JSONObject processMemoryInfoJson = new JSONObject(); int[] pids = new int[1]; pids[0] = android.os.Process.myPid(); android.os.Debug.MemoryInfo[] processMemoryInfo = activityManager.getProcessMemoryInfo(pids); processMemoryInfoJson.put("totalPrivateDirty", processMemoryInfo[0].getTotalPrivateDirty()); processMemoryInfoJson.put("totalSharedDirty", processMemoryInfo[0].getTotalSharedDirty()); processMemoryInfoJson.put("totalPss", processMemoryInfo[0].getTotalPss()); json.put("memoryInfo", memoryInfoJson); json.put("processMemoryInfo", processMemoryInfoJson); } catch (JSONException e) { } return json.toString(); }
From source file:com.doomy.padlock.InfoFragment.java
/** * Gets random access memory size.// w w w . j av a2 s .c o m * * @return The RAM size. */ public String getRAMSize() { ActivityManager mActivityManager = (ActivityManager) getActivity() .getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo mMemoryInfo = new ActivityManager.MemoryInfo(); mActivityManager.getMemoryInfo(mMemoryInfo); long mTotalMemory = mMemoryInfo.totalMem; return Formatter.formatFileSize(getActivity(), mTotalMemory); }
From source file:com.error.hunter.ListenService.java
private void generateBugReport(ActivityManager.ProcessErrorStateInfo entry) { String condition;/* w ww.j a va 2 s . c o m*/ badProcess = entry.processName; String build = Build.DISPLAY; String fingerprint = Build.FINGERPRINT; String serial = Build.SERIAL; String product = Build.PRODUCT; String model = Build.MODEL; File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); @SuppressWarnings("deprecation") long blockSize = stat.getBlockSize(); @SuppressWarnings("deprecation") long availableBlocks = stat.getAvailableBlocks(); String memory = Formatter.formatFileSize(this, availableBlocks * blockSize).toString(); MemoryInfo mi = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); long availableMegs = mi.availMem / 1048576L; strBuf.append("Problem detected in: ").append(badProcess); if (entry.tag != null) { strBuf.append(" (").append(entry.tag).append(")"); } strBuf.append("\nDevice product: " + product); strBuf.append("\nDevice model: " + model); strBuf.append("\nDevice build: " + build); strBuf.append("\nDevice fingerprint: " + fingerprint); strBuf.append("\nDevice SN: " + serial); strBuf.append("\nDevice available RAM (MB): " + availableMegs); strBuf.append("\nDevice free phisical memory: " + memory + "\n"); strBuf.append(getNetworkInfo()); strBuf.append("\n"); ActivityManager actvityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> procInfos = actvityManager.getRunningServices(1000); Iterator<RunningServiceInfo> taskIter = procInfos.iterator(); RunningServiceInfo info; while (taskIter.hasNext()) { info = taskIter.next(); if (info.process.equals(badProcess)) { strBuf.append("\nService " + info.service + " crash count: " + info.crashCount + " active since: " + info.activeSince + " process: " + info.process); } } strBuf.append("\n"); //android.os.Debug.MemoryInfo[] miPid = activityManager.getProcessMemoryInfo(new int[]{entry.pid}); //String memoryProc = miPid[0].toString(); //strBuf.append("\nRAM used by process (Process: " + entry.processName + " PID: " + entry.pid +"): " + memoryProc + "MB\n"); switch (entry.condition) { case ActivityManager.ProcessErrorStateInfo.CRASHED: condition = "CRASHED"; getDeviceProcessInfo(badProcess, entry.stackTrace); writeLogsToFile(condition, badProcess); break; case ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING: condition = "ANR"; getDeviceProcessInfo(badProcess, ""); writeLogsToFile(condition, badProcess); break; default: condition = "<unknown>"; getDeviceProcessInfo(badProcess, entry.stackTrace); writeLogsToFile(condition, badProcess); break; } }
From source file:com.landenlabs.all_devtool.ConsoleFragment.java
private void snapConsole() { try {//from www . ja v a 2 s . c om MemoryInfo mi = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) getActivity() .getSystemService(Context.ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); consoleState.lastFreeze = new Date(); consoleState.usingMemory = Debug.getNativeHeapSize(); consoleState.freeMemory = mi.availMem; if (Build.VERSION.SDK_INT >= 16) { consoleState.totalMemory = mi.totalMem; } consoleState.netRxBytes = TrafficStats.getTotalRxBytes(); consoleState.netRxPacks = TrafficStats.getTotalRxPackets(); consoleState.netTxBytes = TrafficStats.getTotalTxBytes(); consoleState.netTxPacks = TrafficStats.getTotalRxPackets(); ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); consoleState.processCnt = actMgr.getRunningAppProcesses().size(); consoleState.batteryLevel = calculateBatteryLevel(getActivity()); } catch (Exception ex) { } }