RootCommand 调用Process 类型转换异常

 

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

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

    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) {
            }
        }
    }  

一.类型转换异常

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类

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

 二.举个栗子

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 @ 2020-10-22 18:12  CrushGirl  阅读(440)  评论(0编辑  收藏  举报