1

我一直在努力以设备所有者的身份制作软件包,但没有发现任何成功。我已经为我的设备植根了。我正在使用这个命令。

                val exe = ShellExecuter()
                var command = "dpm set-device-owner $packageName/ .MyDeviceAdminReceiver"
                val outp = exe.Executer(command)

ShellExecuter 片段

public String Executer(String command) {
                    StringBuffer output = new StringBuffer();
                    Process p;
                    try {
                        p = Runtime.getRuntime().exec(command);
                        p.waitFor();
                        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
                        String line = "";
                        while ((line = reader.readLine())!= null) {
                            output.append(line + "\n");
                        }
                    } catch (Exception e) {`enter code here`
                        e.printStackTrace();
                    }
                    String response = output.toString();
                    return response;
                } 

MyDeviceAdminReceiver 片段

class MyDeviceAdminReceiver : DeviceAdminReceiver() {
    companion object {
        fun getComponentName(context: Context): ComponentName {
            return ComponentName(context.applicationContext, MyDeviceAdminReceiver::class.java)
        }

        private val TAG = MyDeviceAdminReceiver::class.java.simpleName
    }

    override fun onLockTaskModeEntering(context: Context?, intent: Intent?, pkg: String?) {
        super.onLockTaskModeEntering(context, intent, pkg)
        Log.d(TAG, "onLockTaskModeEntering")
    }

    override fun onLockTaskModeExiting(context: Context?, intent: Intent?) {
        super.onLockTaskModeExiting(context, intent)
        Log.d(TAG, "onLockTaskModeExiting")
    }
}

device_admin_reciever 片段

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<device-admin>
    <uses-policies>
        <limit-password />
        <watch-login />
        <reset-password />
        <force-lock />
        <wipe-data />
        <expire-password />
        <encrypted-storage />
        <disable-camera />
    </uses-policies>
</device-admin>

如果有人可以建议,我想以编程方式使用命令或任何其他方式使我的应用程序包的根设备所有者。

4

2 回答 2

0

创建 xml 文件并将您的代码复制到正确的位置 /data/system/device_owner.xml 并执行此代码以设置适当的权限。并调用重启命令

final String[] run_cmd = new String[]{"chown","system:system","/data/system/device_owner.xml"};
String reboot = "/system/bin/reboot";

execute(null,run_cmd);
execute(null,reboot);


 public void execute(Map<String, String> environvenmentVars, String[] cmd) {

            try {

                Process process = Runtime.getRuntime().exec(cmd);
                BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));

                StringBuffer output = new StringBuffer();

                char[] buffer = new char[4096];
                int read;

                while ((read = reader.read(buffer)) > 0) {
                    output.append(buffer, 0, read);
                }

                reader.close();

                process.waitFor();    
                BufferedReader reader2 = new BufferedReader(new InputStreamReader(process.getErrorStream()));    
                StringBuffer output2 = new StringBuffer();

                char[] buffer2 = new char[4096];
                int read2;

                while ((read2 = reader2.read(buffer2)) > 0) {
                    output2.append(buffer2, 0, read2);
                }

                reader.close();
                process.waitFor();
                }

            catch (Exception e)
            {

            }

        }
于 2019-01-01T06:52:15.883 回答
0

如果您是设备的 root,则可以按照此方法成为设备所有者。

首先,创建一个包含以下内容的文件 device_owner.xml:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<device-owner package="your.owner.app.package.id" name="Your app name" />

现在执行以下步骤

adb push device_owner.xml /sdcard/

adb shell

su

cp /sdcard/device_owner.xml /data/system/

cd /data/system/

chown system:system device_owner.xml

reboot

注意:在重新启动设备之前,请确保您已安装应用程序,您正在尝试将其设为设备所有者。如果您不这样做,您将获得无限时间的启动动画。

检查这个问题 如何使我的应用程序成为设备所有者?

于 2018-12-27T17:33:09.490 回答