手机优化
支持空文件夹/日志文件/临时文件/缩略图/应用残留/大apk文件
- 缩略图:
- version code 小于8的:
{ "/Camera/.thumbnails", "/DCIM/camera/.thumbnails", "/DCIM/.thumbnails",
"/.thumbnails/" }
- version code 大于等于8的:
{ "/Camera/.thumbnails", "/camera/.thumbnails/", "/.thumbnails/"}
参见com.baidu.appsearch.youhua.utils. TrashThumbnails
- 内存缓存
PackageManager.class.getMethod("getPackageSizeInfo",
new Class[] { String.class, IPackageStatsObserver.class} );
PackageManager.class.getMethod("freeStorageAndNotify", new Class[] {
long.class, IPackageDataObserver.class });
- 关闭空进程
- 读取"/proc/meminfo"中的MemTotal的值a。
- ActivityManager.killBackgroundProcesses(String packageName)。
- 计算killBackgroundProcesses()前后MemTotal的差值。
- 应用残留
- 在assets文件夹中放filepath.db,把它复制到数据库目录(context.getDatabasePath(TrashDBHelper.SQLITE_NAME))。
- filepath.db中数据为参见应用在SD卡中建立的文件夹名和文件名。
- 空文件夹
- root后关闭进程:
Runtime.getRuntime().exec(new String[] { su, "-c", "service call activity 79 s16 com.baidu.appsearch" }).
- 不常用应用
- 山寨应用
- 得到把本地应用签名。
- 把应用签名转换成md5。
- 把md5转换成signMd5。
- 把signMd5传到服务器。
- 服务器比对signMD5,判断山寨应用信息,并反馈给手机端。
- 验证本apk是否为正版,防止apk被反编译后修改代码然后签名、运行。
同八。
- 静默安装(需root)
- pm install –r
- pm.getClass().getDeclaredMethod("installPackage", Uri.class, IPackageInstallObserver.class, int.class, String.class);
- 验证手机是否root
java.lang.Process process = null;
boolean isRootGained = false;
try {
process = Runtime.getRuntime().exec("su");
OutputStream os = process.getOutputStream();
InputStream is = process.getInputStream();
if (os != null && is != null) {
DataOutputStream dos = new DataOutputStream(process.getOutputStream());
DataInputStream dis = new DataInputStream(process.getInputStream());
dos.writeBytes("id\n");
dos.flush();
String result = dis.readLine();
boolean needExit = false;
if (result == null) {
needExit = true;
isRootGained = false;
} else if (result.toLowerCase().contains("uid=0")) {
isRootGained = true;
needExit = true;
} else {
isRootGained = false;
needExit = true;
}
if (needExit) {
dos.writeBytes("exit\n");
os.flush();
}
dis.close();
dos.close();
}
} catch (IOException e) {
if (DEBUG) {
e.printStackTrace();
}
isRootGained = false;
} finally {
if (is4Uninstall) {
sendRequestRootResult4Uninstall(context, packageName, isRootGained);
} else {
sendRequestRootResult(context, handler, appkey, isRootGained);
}
if (process != null) {
// process运行时马上调用destroy是杀不掉进程的,因为此时进程还在锁定中
try {
Thread.sleep(3000);// SUPPRESS CHECKSTYLE
process.destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
}
- CPU统计
- 名字:/proc/cpuinfo
- 最大频率:/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
- 最小频率:/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq
- 当前频率:/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
- 内存统计
读取"/proc/meminfo"中的MemTotal等的值。
final ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(info);
MemoryInfo.availMem: 表示系统剩余内存
MemoryInfo .lowMemory: boolean值,表示系统是否处于低内存运行
MemoryInfo .hreshold: 表示当系统剩余内存低于好多时就看成低内存运行
- 流量统计
- 手机全部流量:/proc/net/dev
- 总接受流量TrafficStats.getTotalRxBytes()
- 总发送流量TrafficStats.getTotalTxBytes()
- 不包含WIFI的手机GPRS接收量TrafficStats.getMobileRxBytes()
- 不包含Wifi的手机GPRS发送量TrafficStats.getMobileTxBytes()
- 某一个进程的流量:/proc/uid_stat/***
- 某一个进程的总接收量TrafficStats.getUidRxBytes(Uid));
- 某一个进程的总发送量TrafficStats.getUidTxBytes(Uid));
- 手机全部流量:/proc/net/dev
- 电量
private BroadcastReceiver batteryReceiver=new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
int level = intent.getIntExtra("level", 0);
// level加%就是当前电量
}
};
registerReceiver(batteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
- 其他