android:app_process两种用法

(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-tools
adb push  D:\test\Main.dex       /sdcard/
@echo off
echo export CLASSPATH=/sdcard/Main.dex  >>  temp.txt
echo exec app_process /sdcard  cn.mimashuo.puppet.Main  >>     temp.txt
adb shell   <    temp.txt
del   "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

  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值