RK android6.0 实现假关机真开机效果
- 需求描述
- 解决方法
郑重声明:本人原创博文,都是实战,均经过实际项目验证出货的
转载请标明出处:攻城狮2015
Platform: Rockchip
CPU:rk3368
OS:Android 7.1.2
Kernel: 3.10
需求描述
由于硬件设计,使用错误的pmu,导致每次关机,机器会自动开机,现在需要实现假关机,假关机后再按一次power键,自动重启机器,等效于关机再开机
解决方法
实现假关机,再开机就是重启机器。关机的时候,关闭HDMI,再开机的时候执行reboot命令
+++ b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -130,6 +130,12 @@ import com.android.server.LocalServices;
import com.android.server.policy.keyguard.KeyguardServiceDelegate;
import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
@@ -168,6 +174,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
static final boolean SHOW_STARTING_ANIMATIONS = true;
static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
+ public static int xfwu_power_rebootHdmi=0;
+
// Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
// No longer recommended for desk docks; still useful in car docks.
static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
@@ -5262,15 +5270,29 @@ public class PhoneWindowManager implements WindowManagerPolicy {
break;
}
- case KeyEvent.KEYCODE_POWER: {
+ case KeyEvent.KEYCODE_POWER: {
result &= ~ACTION_PASS_TO_USER;
isWakeKey = false; // wake-up will be handled separately
if (down) {
- interceptPowerKeyDown(event, interactive);
+ //interceptPowerKeyDown(event, interactive);
+
+ if(xfwu_power_rebootHdmi==0){
+ xfwu_power_rebootHdmi=1;
+ StringCmd("echo 0 > /sys/class/display/HDMI/enable");
+ Log.d(TAG,"shutdown hdmi and shutdown irled");
+ //StringCmd("echo 0 > /sys/class/leds/red/brightness");
+ interceptPowerKeyDown(event, interactive);
+ }else{
+ xfwu_power_rebootHdmi=0;
+ //StringCmd("echo 255 > /sys/class/leds/red/brightness");
+ StringCmd("reboot");
+ }
+
} else {
interceptPowerKeyUp(event, interactive, canceled);
}
- break;
+ break;
+
}
case KeyEvent.KEYCODE_SLEEP: {
@@ -5368,6 +5390,46 @@ public class PhoneWindowManager implements WindowManagerPolicy {
return result;
}
+ public void StringCmd(final String path){
+ new Thread(new Runnable(){
+ @Override
+ public void run(){
+ DataOutputStream out = null;
+ BufferedReader errorStream = null;
+ try{
+ java.lang.Process process = Runtime.getRuntime().exec("su");
+ out = new DataOutputStream(process.getOutputStream());
+ String command = path + "\n";
+ out.write(command.getBytes(Charset.forName("UTF-8")));
+ out.flush();
+ out.writeBytes("exit\n");
+ out.flush();
+ process.waitFor();
+ errorStream = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+ String msg = "";
+ String line;
+ while((line = errorStream.readLine())!=null){
+ msg+=line;
+ }
+ //slog.e("XFWU","StringCmd:"+msg);
+ }catch(Exception e){
+ //slog.e("XFWU",e.getMessage(),e);
+ }finally{
+ try{
+ if(out!=null){
+ out.close();
+ }
+ if(errorStream!=null){
+ errorStream.close();
+ }
+ }catch(IOException e){
+ //slog.e("XFWU",e.getMessage(),e);
+ }
+ }
+ }
+ }).start();
+ }
+
/**
* Returns true if the key can have global actions attached to it.
以上方法,等效于执行了adb命令
郑重声明:本人原创博文,都是实战,均经过实际项目验证出货的
转载请标明出处:攻城狮2015
有需要可以加VX