Newer
Older
KillProcess / app / src / main / java / me / bell / killprocess / MainActivity.java
package me.bell.killprocess;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import me.bell.killprocess.db.entity.AppData;
import me.bell.killprocess.db.util.AppDataDaoUtil;

public class MainActivity extends AppCompatActivity {
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = MainActivity.this;

        findViewById(R.id.start).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                runClean(context);
            }
        });

        findViewById(R.id.show).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, AppListActivity.class);
                startActivity(intent);
            }
        });

//        RootUtil.KillProcess("su -c dumpsys activity |  grep mFocusedActivity");
//


    }


    public static void runClean(final Context context) {

        mHandler.sendEmptyMessage(0);

        AppDataDaoUtil dao = new AppDataDaoUtil(context);
        List<AppData> data = dao.queryAppByChecked(1);
        int pre = data.size() / 10;

        List<AppData> d0 = new ArrayList<>();
        List<AppData> d1 = new ArrayList<>();
        List<AppData> d2 = new ArrayList<>();
        List<AppData> d3 = new ArrayList<>();
        List<AppData> d4 = new ArrayList<>();
        List<AppData> d5 = new ArrayList<>();
        List<AppData> d6 = new ArrayList<>();
        List<AppData> d7 = new ArrayList<>();
        List<AppData> d8 = new ArrayList<>();
        List<AppData> d9 = new ArrayList<>();
        List<AppData> d10 = new ArrayList<>();

        for (int i = 0; i < data.size(); i++) {
            AppData a = data.get(i);
            if (i < pre) {
                d0.add(a);
            } else if (i < pre * 2) {
                d1.add(a);
            } else if (i < pre * 3) {
                d2.add(a);
            } else if (i < pre * 4) {
                d3.add(a);
            } else if (i < pre * 5) {
                d4.add(a);
            } else if (i < pre * 6) {
                d5.add(a);
            } else if (i < pre * 7) {
                d6.add(a);
            } else if (i < pre * 8) {
                d7.add(a);
            } else if (i < pre * 9) {
                d8.add(a);
            } else if (i < pre * 10) {
                d9.add(a);
            } else {
                d10.add(a);
            }
        }


        new Thread(new ThreadTest(d0, mHandler)).start();
        new Thread(new ThreadTest(d1, mHandler)).start();
        new Thread(new ThreadTest(d2, mHandler)).start();
        new Thread(new ThreadTest(d3, mHandler)).start();
        new Thread(new ThreadTest(d4, mHandler)).start();
        new Thread(new ThreadTest(d5, mHandler)).start();
        new Thread(new ThreadTest(d6, mHandler)).start();
        new Thread(new ThreadTest(d7, mHandler)).start();
        new Thread(new ThreadTest(d8, mHandler)).start();
        new Thread(new ThreadTest(d9, mHandler)).start();
        new Thread(new ThreadTest(d10, mHandler)).start();



    }
    static int count = 0;
    static MHandler mHandler = new MHandler();
    public static class MHandler  extends Handler {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 0:
                    Toast.makeText(App.getContext(), "开始", Toast.LENGTH_LONG).show();
                    break;

                case 1:
                    count++;
                    if (count==11){
                        Log.e("runnable", "333333");
                        Toast.makeText(App.getContext(), "完成", Toast.LENGTH_LONG).show();

                        //清理tim的进程
                        RootUtil.KillProcess("su -c am force-stop com.tencent.tim");
                        RootUtil.KillProcess("su -c am force-stop com.tencent.tim:Daemon");
                        RootUtil.KillProcess("su -c am force-stop com.tencent.tim:MSF");
                        //系统设置
                        RootUtil.KillProcess("su -c am force-stop com.android.settings");
                        //google套件
                        RootUtil.KillProcess("su -c am force-stop com.android.vending");
                        RootUtil.KillProcess("su -c am force-stop com.google.android.gms");
                        RootUtil.KillProcess("su -c am force-stop com.google.android.gms.persistent");
                        RootUtil.KillProcess("su -c am force-stop com.google.process.gapps");
                        RootUtil.KillProcess("su -c am force-stop com.google.android.gms.feedback");
                        RootUtil.KillProcess("su -c am force-stop com.google.android.apps.messaging");

                        //程序本身
                        RootUtil.KillProcess("su -c am force-stop me.bell.killprocess");

                    }
                    break;
            }
        }
    }
}