RootCommand 调用Process 类型转换异常

 

RootCommnd  /system/bin/sh    /system/xbin/su

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.io.DataInputStream;
import java.io.DataOutputStream;
 
    public void RootCommand(String cmd) {
        Process process = null;
        DataOutputStream os = null;
        DataInputStream is = null;
        try {
            process = Runtime.getRuntime().exec("su");
            os = new DataOutputStream(process.getOutputStream());
            os.writeBytes(cmd + "\n");
            os.writeBytes("exit\n");
            os.flush();
            int aa = process.waitFor();
            is = new DataInputStream(process.getInputStream());
            byte[] buffer = new byte[is.available()];
            is.read(buffer);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (os != null) {
                    os.close();
                }
                if (is != null) {
                    is.close();
                }
                process.destroy();
            } catch (Exception e) {
            }
        }
    }

Android11  RootCommand

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public static void RootCommand(String cmd) {
    Process process = null;
    DataOutputStream os = null;
 
    try {
        process = Runtime.getRuntime().exec("/system/xbin/su");
        os = new DataOutputStream(process.getOutputStream());
        os.writeBytes(cmd + "\n");
        os.writeBytes("exit\n");
        os.flush();
 
        process.waitFor();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (os != null) {
                os.close();
            }
            process.destroy();
        } catch (Exception e) {
        }
    }
}  

一.类型转换异常

1
2
3
4
5
ERROR: /home/will/ZK-Rxxx_Android7.1/ZK_RXXX_RK3288_ANDROID7.1/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java:6341: Type mismatch: cannot convert from java.lang.Process to android.os.Process
ERROR: /home/will/ZK-Rxxx_Android7.1/ZK_RXXX_RK3288_ANDROID7.1/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java:6342: The method getOutputStream() is undefined for the type Process
ERROR: /home/will/ZK-Rxxx_Android7.1/ZK_RXXX_RK3288_ANDROID7.1/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java:6347: The method waitFor() is undefined for the type Process
ERROR: /home/will/ZK-Rxxx_Android7.1/ZK_RXXX_RK3288_ANDROID7.1/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java:6348: The method getInputStream() is undefined for the type Process
ERROR: /home/will/ZK-Rxxx_Android7.1/ZK_RXXX_RK3288_ANDROID7.1/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java:6363: The method destroy() is undefined for the type Process

  问题:同时调用的java.lang和android.os两个包下的Process类

1
2
java.lang.Process process = null;
android.os.Process process = null;  

 二.举个栗子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
diff --git a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
index ce46afc0..9d1f06f 100755
--- a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -16,6 +16,9 @@
  
 package com.android.server.policy;
  
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+
 import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
 import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
 import static android.app.ActivityManager.StackId.HOME_STACK_ID;
@@ -153,6 +156,7 @@ import com.android.server.policy.keyguard.KeyguardServiceDelegate;
 import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
 import com.android.server.statusbar.StatusBarManagerInternal;
 import com.android.server.vr.VrManagerInternal;
+import com.android.xhapimanager.XHApiManager;
  
 import java.io.File;
 import java.io.FileReader;
@@ -174,7 +178,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
     static final String TAG = "WindowManager";
     static final boolean DEBUG = false;
     static final boolean localLOGV = false;
-    static final boolean DEBUG_INPUT = false;
+    static final boolean DEBUG_INPUT = true;
     static final boolean DEBUG_KEYGUARD = false;
     static final boolean DEBUG_LAYOUT = false;
     static final boolean DEBUG_STARTING_WINDOW = false;
@@ -3543,8 +3547,18 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                            mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
             }
             return -1;
+        }else if(keyCode == 142){
+           XHApiManager apimanager = new XHApiManager();
+           //Log.d("gatsby","input keyCode AAAAAAAAAAAAAAAAA "+keyCode);
+                   if(!down){
+                       RootCommand("echo 1 > /sys/class/xh_custom/xh_custom_gpio/device/backlight_en");
+                       //Log.d("gatsby","BBBBBBBBBBBBBBBBBB  up");
+                   }else{           
+                       RootCommand("echo 0 > /sys/class/xh_custom/xh_custom_gpio/device/backlight_en");
+                       //Log.d("gatsby","CCCCCCCCCCCCCCCCCCCCC  down");                       
+                   }
+                  return -1;
         }
-
         // Toggle Caps Lock on META-ALT.
         boolean actionTriggered = false;
         if (KeyEvent.isModifierKey(keyCode)) {
@@ -5944,7 +5958,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                                                 mKeyguardDelegate.isShowing()));
  
         if (DEBUG_INPUT) {
-            Log.d(TAG, "interceptKeyTq keycode=" + keyCode
+            Log.d(TAG, "interceptKeyTq Gatsby keycode=" + keyCode
                     + " interactive=" + interactive + " keyguardActive=" + keyguardActive
                     + " policyFlags=" + Integer.toHexString(policyFlags));
         }
@@ -6319,6 +6333,39 @@ public class PhoneWindowManager implements WindowManagerPolicy {
         }
     }
  
+       private void RootCommand(String cmd) {          
+       java.lang.Process process = null;//这里引用 Java
+       DataOutputStream os = null;
+       DataInputStream is = null;
+       try {
+           process = Runtime.getRuntime().exec("su");
+           os = new DataOutputStream(process.getOutputStream());
+           os.writeBytes(cmd + "\n");
+           os.writeBytes("exit\n");
+           os.flush();
+
+           int aa = process.waitFor();
+           is = new DataInputStream(process.getInputStream());
+
+           byte[] buffer = new byte[is.available()];
+           is.read(buffer);
+
+       } catch (Exception e) {
+           e.printStackTrace();
+       } finally {
+           try {
+               if (os != null) {
+                   os.close();
+               }
+               if (is != null) {
+                   is.close();
+               }
+               process.destroy();
+           } catch (Exception e) {
+           }
+       }
+   }
+  
     /**
      * Returns true if the key can have global actions attached to it.
      * We reserve all power management keys for the system since they require

  

  

posted @   CrushGirl  阅读(454)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示