手机优化

手机优化


支持空文件夹/日志文件/临时文件/缩略图/应用残留/大apk文件


  1. 缩略图:
    1. version code 小于8的:

{ "/Camera/.thumbnails", "/DCIM/camera/.thumbnails", "/DCIM/.thumbnails",

"/.thumbnails/" }

    1. version code 大于等于8的:

{ "/Camera/.thumbnails", "/camera/.thumbnails/", "/.thumbnails/"}

参见com.baidu.appsearch.youhua.utils. TrashThumbnails

  1. 内存缓存

PackageManager.class.getMethod("getPackageSizeInfo",

                    new Class[] { String.class, IPackageStatsObserver.class} );

PackageManager.class.getMethod("freeStorageAndNotify", new Class[] {

                    long.class, IPackageDataObserver.class });

  1. 关闭空进程
    1. 读取"/proc/meminfo"中的MemTotal的值a。
    2. ActivityManager.killBackgroundProcesses(String packageName)。
    3. 计算killBackgroundProcesses()前后MemTotal的差值。
  2. 应用残留
    1. 在assets文件夹中放filepath.db,把它复制到数据库目录(context.getDatabasePath(TrashDBHelper.SQLITE_NAME))。
    2. filepath.db中数据为参见应用在SD卡中建立的文件夹名和文件名。
  3. 空文件夹
  4. root后关闭进程:

Runtime.getRuntime().exec(new String[] { su, "-c", "service call activity 79 s16 com.baidu.appsearch" }).

  1. 不常用应用
  2. 山寨应用
    1. 得到把本地应用签名。
    2. 把应用签名转换成md5。
    3. 把md5转换成signMd5。
    4. 把signMd5传到服务器。
    5. 服务器比对signMD5,判断山寨应用信息,并反馈给手机端。
  3. 验证本apk是否为正版,防止apk被反编译后修改代码然后签名、运行。

同八。

  1. 静默安装(需root)
    1. pm install –r
    2. pm.getClass().getDeclaredMethod("installPackage", Uri.class, IPackageInstallObserver.class, int.class, String.class);
  2. 验证手机是否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();

                        }

                    }

                }

  1. CPU统计
    1. 名字:/proc/cpuinfo
    2. 最大频率:/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
    3. 最小频率:/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq
    4. 当前频率:/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
  2. 内存统计

读取"/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: 表示当系统剩余内存低于好多时就看成低内存运行


  1. 流量统计
    1. 手机全部流量:/proc/net/dev
      1. 总接受流量TrafficStats.getTotalRxBytes()
      2. 总发送流量TrafficStats.getTotalTxBytes()
      3. 不包含WIFI的手机GPRS接收量TrafficStats.getMobileRxBytes()
      4. 不包含Wifi的手机GPRS发送量TrafficStats.getMobileTxBytes()
    2. 某一个进程的流量:/proc/uid_stat/***
      1. 某一个进程的总接收量TrafficStats.getUidRxBytes(Uid));
      2. 某一个进程的总发送量TrafficStats.getUidTxBytes(Uid));
  2. 电量

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));

  1. 其他
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值