|
|
@@ -0,0 +1,89 @@
|
|
|
+package org.las2mile.okio.utils;
|
|
|
+
|
|
|
+
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import android.content.Context;
|
|
|
+import android.util.Log;
|
|
|
+import java.lang.reflect.Method;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Looper;
|
|
|
+import android.os.ResultReceiver;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import org.las2mile.scrcpy.wrappers.ServiceManager;
|
|
|
+import org.las2mile.scrcpy.wrappers.WifiManager;
|
|
|
+
|
|
|
+public class SystemUtils{
|
|
|
+ //@param filePath su 文件的路径,比如/system/bin/su 或者/system/xbin/su
|
|
|
+ public static boolean isCanExecute(String filePath) {
|
|
|
+ java.lang.Process process = null;
|
|
|
+ try {
|
|
|
+ process = Runtime.getRuntime().exec("ls -l " + filePath);
|
|
|
+ BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
|
+ String str = in.readLine();
|
|
|
+ if (str != null && str.length() >= 4) {
|
|
|
+ char flag = str.charAt(3);
|
|
|
+ if (flag == 's' || flag == 'x') {
|
|
|
+ Runtime.getRuntime().exec("su ");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (process != null) {
|
|
|
+ process.destroy();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void getAppContext() {
|
|
|
+ ServiceManager serviceManager = new ServiceManager();
|
|
|
+ // serviceManager.getWifiManager().hasKNKJapp();
|
|
|
+ Log.d("OKIOscr","getAppContextv serviceManager.getWifiManager() ");;
|
|
|
+ new Thread(){
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ super.run();
|
|
|
+ Looper.prepare();
|
|
|
+ ResultReceiver resultReceiver = new ResultReceiver(new Handler(Looper.myLooper()));
|
|
|
+ Class activityThreadClass = null;
|
|
|
+ Context context = null;
|
|
|
+ try {
|
|
|
+
|
|
|
+
|
|
|
+ activityThreadClass = Class.forName("android.app.ActivityThread");
|
|
|
+ Method currentActivityThread = activityThreadClass.getDeclaredMethod("currentActivityThread");
|
|
|
+ currentActivityThread.setAccessible(true);
|
|
|
+ Object activityThread = currentActivityThread.invoke(null);
|
|
|
+ Log.d("OKIOscr","getAppContext activityThread "+activityThread);
|
|
|
+ context = (Context) activityThreadClass.getMethod("getSystemContext").invoke(activityThread);
|
|
|
+ Context getApplication = (Context)activityThreadClass.getMethod("getApplication").invoke(activityThread);
|
|
|
+ Log.d("OKIOscr",getApplication+" getAppContext getSystemContext "+context);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ Log.d("OKIOscr","getAppContext "+e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ Looper.loop();
|
|
|
+ }
|
|
|
+ }.start();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Object getCurrentActivityThread() {
|
|
|
+ try {
|
|
|
+ Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");
|
|
|
+ Field currentActivityThreadField = activityThreadClass.getDeclaredField("sCurrentActivityThread");
|
|
|
+ currentActivityThreadField.setAccessible(true);
|
|
|
+ Object currentActivityThread = currentActivityThreadField.get(null);
|
|
|
+ Log.d("OKIOscr","getAppContext currentActivityThread "+currentActivityThread);
|
|
|
+ return currentActivityThread;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|