From ab0ca69ff3b331f1aee286594b0ead46c9786c5a Mon Sep 17 00:00:00 2001
From: hjw <hjw@ma.nodka.com>
Date: Thu, 28 Nov 2024 11:35:29 +0000
Subject: [PATCH] 开放接口(HDMI分辨率设置、应用保活、系统截图、静默安装、静默卸载、蓝牙开关、WIFI开关、以太网开关、系统重启/关机)

---
 app/src/main/java/com/jwipc/nodka_reboot_under/utils/Utils.java |   61 ++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/app/src/main/java/com/jwipc/nodka_reboot_under/utils/Utils.java b/app/src/main/java/com/jwipc/nodka_reboot_under/utils/Utils.java
index 210c117..4f07730 100644
--- a/app/src/main/java/com/jwipc/nodka_reboot_under/utils/Utils.java
+++ b/app/src/main/java/com/jwipc/nodka_reboot_under/utils/Utils.java
@@ -1,6 +1,7 @@
 package com.jwipc.nodka_reboot_under.utils;
 
 import java.io.BufferedReader;
+import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -688,6 +689,66 @@
 		
 		return re;
 	}
+
+	public String getRootCmdSilent(String cmd) {
+		DataOutputStream dos = null;
+		DataInputStream dis = null;
+		Process process = null;
+		try {
+			process = Runtime.getRuntime().exec("su");
+			dos = new DataOutputStream(process.getOutputStream());
+			dis = new DataInputStream(process.getInputStream());
+			dos.write(cmd.getBytes());
+			dos.flush();
+			dos.close();
+			process.waitFor();
+			return getStrFromDataInPutStream(dis);
+		} catch (Exception e) {
+			e.printStackTrace();
+			return null;
+		} finally {
+			if (dos != null) {
+				try {
+					dos.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+			if (dis != null) {
+				try {
+					dis.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+			if (process != null) {
+				process.destroy();
+			}
+		}
+	}
+
+	private String getStrFromDataInPutStream(DataInputStream dos) {
+		if (null == dos) {
+			return "";
+		}
+		int BUFFER_SIZE = 512;
+		byte[] buffer = new byte[BUFFER_SIZE];
+		StringBuilder result = new StringBuilder();
+		try {
+			while (true) {
+				int read = dos.read(buffer);
+				if (read > 0) {
+					result.append(new String(buffer, 0, read));
+				}
+				if (read < BUFFER_SIZE) {
+					break;
+				}
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return result.toString();
+	}
 	
 	public boolean isSpiritVersion() {
 		return Build.VERSION.SDK_INT <= 25;

--
Gitblit v1.6.2