常用工具类,文件和内存的大小获取,shell脚本的执行
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ package android.cts.util; import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.app.Instrumentation;
import android.content.Context;
import android.os.ParcelFileDescriptor;
import android.os.StatFs; import java.io.FileInputStream;
import java.io.IOException; public class SystemUtil {
public static long getFreeDiskSize(Context context) {
StatFs statFs = new StatFs(context.getFilesDir().getAbsolutePath());
return (long)statFs.getAvailableBlocks() * statFs.getBlockSize();
} public static long getFreeMemory(Context context) {
MemoryInfo info = new MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(info);
return info.availMem;
} public static long getTotalMemory(Context context) {
MemoryInfo info = new MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(info);
return info.totalMem; // TODO totalMem N/A in ICS.
} /**
* Executes a shell command using shell user identity, and return the standard output in string
* <p>Note: calling this function requires API level 21 or above
* @param instrumentation {@link Instrumentation} instance, obtained from a test running in
* instrumentation framework
* @param cmd the command to run
* @return the standard output of the command
* @throws Exception
*/
public static String runShellCommand(Instrumentation instrumentation, String cmd)
throws IOException {
ParcelFileDescriptor pfd = instrumentation.getUiAutomation().executeShellCommand(cmd);
byte[] buf = new byte[512];
int bytesRead;
FileInputStream fis = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
StringBuffer stdout = new StringBuffer();
while ((bytesRead = fis.read(buf)) != -1) {
stdout.append(new String(buf, 0, bytesRead));
}
fis.close();
return stdout.toString();
} }
常用工具类,文件和内存的大小获取,shell脚本的执行的更多相关文章
- [C#] 常用工具类——文件操作类
/// <para> FilesUpload:工具方法:ASP.NET上传文件的方法</para> /// <para> FileExists:返回文件是否存在&l ...
- c#常用工具类:文件和二进制转换
//================二进制相关转换类============== #region 将文件转换为二进制数组 /// <summary> /// 将文件转换为二进制数组 /// ...
- Android 常用工具类之SPUtil,可以修改默认sp文件的路径
参考: 1. 利用Java反射机制改变SharedPreferences存储路径 Singleton1900 2. Android快速开发系列 10个常用工具类 Hongyang import ...
- vue项目工具文件utils.js javascript常用工具类,javascript常用工具类,util.js
vue项目工具文件utils.js :https://blog.csdn.net/Ajaxguan/article/details/79924249 javascript常用工具类,util.js : ...
- commons-lang3-3.2.jar中的常用工具类的使用
这个包中的很多工具类可以简化我们的操作,在这里简单的研究其中的几个工具类的使用. 1.StringUtils工具类 可以判断是否是空串,是否为null,默认值设置等操作: /** * StringUt ...
- PHP常用工具类
<?php namespace isslib\Util; use think\Config; /** * 常用工具类 * User: xaxiong * Date: 2016/12/19 * T ...
- 简单了解Spring中常用工具类_java - JAVA
文章来源:嗨学网 敏而好学论坛www.piaodoo.com 欢迎大家相互学习 文件资源操作 Spring 定义了一个 org.springframework.core.io.Resource 接口, ...
- js常用工具类.
一些js的工具类 复制代码 /** * Created by sevennight on 15-1-31. * js常用工具类 */ /** * 方法作用:[格式化时间] * 使用方法 * 示例: * ...
- 封装一个简单好用的打印Log的工具类And快速开发系列 10个常用工具类
快速开发系列 10个常用工具类 http://blog.csdn.net/lmj623565791/article/details/38965311 ------------------------- ...
随机推荐
- C++程序设计实践指导1.15找出回文数改写要求实现
改写要求1:用单链表实现 #include <cstdlib> #include <iostream> using namespace std; struct LinkNode ...
- javascript在不同的浏览器处理事件
实现javascript事件处理兼容问题,例子如下,可以实现大部分浏览器处理事件的问题 var btn = document.getElementById("btn"); if(b ...
- unzip解压中文文件名乱码
由于中文的Windows使用的是GBK编码,而Linux默认使用UTF-8编码的,如果在Windows打包带中文文件的zip包,则这个zip包在Linux下面使用默认的归档管理器打开这个zip包的时候 ...
- hdu Buy the Ticket
import java.math.BigInteger; import java.util.*; public class Main { public static void main(String ...
- SqlServer IF Exists([database]|[table]|[prop]) / Column([Operation])
*************************** --判断数据库是否存在 IF EXISTS (SELECT * FROM MASTER..sysdatabases WHERE NAME = ' ...
- Linux命令之xargs的分析及隐患
写一个main.c: #include <stdio.h> int main(){ printf("foo"); printf("bar"); re ...
- java数组复制的方式和效率比较
java中,数组的复制有以下三种方式: 1. 调用System.arraycopy(Arrays.copyOfRange可以当作第四种,但是底层调用的是System.arraycopy,所以,认为是同 ...
- Windows下安装使用curl命令
1 进入http://curl.haxx.se/download/?C=M;O=D网站 2 根据自己的操作系统位数和是否需要SSL下载相应的版本.这里下载curl-7.33.0-win64-ssl-s ...
- live555学习之RTSP连接建立以及请求消息处理过程
1,RTSP连接的建立过程 RTSPServer类用于构建一个RTSP服务器,该类同时在其内部定义了一个RTSPClientSession类,用于处理单独的客户会话. 首先创建RTSP服务 ...
- Linux Ubuntu download
下载地址:http://www.ubuntu.com/download/ Ubuntu桌面用户版 符合用户个性的版本