android:app_process两种用法

来源:互联网 发布:arp ip 对应mac地址 编辑:程序博客网 时间:2024/06/10 02:09

(1)app_process是用来干嘛的?
app_process可以在Android启动独立的Java进程(Main应用程序)

(2)在什么情况下,可以启动Java进程呢?
a. 利用adb shell启动的Java进程,这种情况下Java进程拥有shell级别的权限,所以Java程序对应的PID和Shell的PID一样。
b.利用app启动的Java进程,这种情况下Java进程跟当前app的权限一样,没有Shell权限。

(3)可以做哪些事情?
通过电脑shell启动一个shell的Java程序,就可以长驻手机了,可以做远程录屏、远程控制等特殊功能。

(4)在adb下,如何启动?

d:cd D:\work_sdk\android\platform-toolsadb push  D:\test\Main.dex       /sdcard/@echo offecho export CLASSPATH=/sdcard/Main.dex  >>  temp.txtecho exec app_process /sdcard  cn.mimashuo.puppet.Main  >>     temp.txtadb shell   <    temp.txtdel   "temp.txt"pause

(5)在Android下,如何启动?

    private int testAppProcess() {        int status = 0;        synchronized (HomeActivity.class) {            Process process = null;            DataOutputStream os = null;            MsgInputThread msgInput = null;            ErrorInputThread errorInput = null;            try {                process = Runtime.getRuntime().exec("su");// 切换到root帐号                os = new DataOutputStream(process.getOutputStream());                os.writeBytes(" export CLASSPATH=/sdcard/Main.dex   \n");                os.writeBytes(" exec app_process /sdcard  cn.mimashuo.puppet.Main   \n");                os.writeBytes(" exit \n");                os.flush();                // 启动两个线程,一个线程负责读标准输出流,另一个负责读标准错误流=>解决waitFor()阻塞的问题                msgInput = new MsgInputThread(process.getInputStream(), new MsgInputThread.Listen() {                    @Override                    public void test() {                    }                });                msgInput.start();                errorInput = new ErrorInputThread(process.getErrorStream());                errorInput.start();                // waitFor返回的退出值的过程。按照惯例,0表示正常终止。waitFor会一直等待                status = process.waitFor();// 什么意思呢?具体看http://my.oschina.net/sub/blog/134436                if (status != 0) {                    LogUtil.d("root日志:" + msgInput.getMsg());                }            } catch (Exception e) {                LogUtil.e("出错:" + e.getMessage());                status = -2;                return status;            } finally {                try {                    if (os != null) {                        os.close();                    }                } catch (Exception e) {                }                try {                    if (process != null) {                        process.destroy();                    }                } catch (Exception e) {                }                try {                    if (msgInput != null) {                        msgInput.setOver(true);                    }                } catch (Exception e) {                }                try {                    if (errorInput != null) {                        errorInput.setOver(true);                    }                } catch (Exception e) {                }            }        } // end synchronized        return status;    }

(6)关于Java进程启动后的Pid, Uid与权限等问题,可参考:

http://blog.csdn.net/u010651541/article/details/53163542

原创粉丝点击