我一直在以设备所有者的身份制作软件包,但未成功。我已经将我的设备植根于相同的位置。我正在使用此命令。
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>
我想以编程方式使用命令或任何其他建议的方式使我的植根设备所有者成为我的应用程序包的所有者。
答案 0 :(得分: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
注意:重新启动设备之前,请确保已安装要成为设备所有者的应用程序。如果您不这样做,您将获得无限期的启动动画。
答案 1 :(得分: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)
{
}
}