以Shell用户身份运行Android应用程序 [英] Run Android application as Shell User

查看:691
本文介绍了以Shell用户身份运行Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要启动一个本机二进制文件,该二进制文件打开并从某些/sys/kernel files中读取.如果我通过使用adb shell(从/data/local/tmp手动启动)进行连接来启动本机二进制文件,则一切正常.

In my application, I need to start a native binary that opens and read from some /sys/kernel files. If I launch the native binary by connecting using adb shell (launching manually from /data/local/tmp), then everything works fine.

我希望应用程序以编程方式做两件事,

I would like the App to programmatically do two things,

  1. 将二进制文件复制到/data/local/tmp/.同样,由于普通的android应用程序没有足够的权限,因此无法正常工作.

  1. Copy the binary to /data/local/tmp/. Again this wont work as the normal android app doesnt have enough privileges.

以外壳程序用户身份启动二进制文件,因此我可以拥有必要的特权.我试过使用android:sharedUserId="android.uid.shell,但这似乎不起作用.

Start the binary as a shell user so I can have the necessary privileges. I have tried using android:sharedUserId="android.uid.shell , but that doesnt seem to work.

请注意,我不需要root即可打开/sys文件.
我所需要的只是成为shell用户.
任何想法都将不胜感激.

Please note that I don't need root to open the /sys files.
All I need is to be shell user.
Any thoughts will be greatly appreciated.

谢谢

推荐答案

shell UID保留用于开发和测试.使用具有shell特权的应用程序正在绕过Google的安全模型.因此,如果不植根,您将无法在安全的商用设备上进行操作.

The shell UID is reserved for development and testing. Running an app with shell privileges is circumventing Google's security model. So you will not be able do it on a secured commercial device without rooting it.

可能的临时解决方案(重新启动之间是非持久性的),解决方法是:

A possible temporary (non-persistent between reboots) workaround would be:

  1. 使用adb shell启动作为Shell UID运行的后台服务进程

  1. Use adb shell to start a background service process, running as shell UID

在您的应用程序中,使用IPC要求服务为您执行特殊任务

In your application, using IPC to ask the service to perform special task for you

这篇关于以Shell用户身份运行Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆