板子連結: http://www.itayga.com/contact.html.
程式碼路徑:frameworks\base\packages\SystemUI\src\com\android\systemui\globalactions\GlobalActionsDialog.java
private final class PowerAction extends SinglePressAction implements LongPressAction {
private PowerAction() {
super(R.drawable.ic_lock_power_off,
R.string.global_action_power_off);
}
@Override
public boolean onLongPress() {
UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
if (!um.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
mWindowManagerFuncs.reboot(true);
return true;
}
return false;
}
@Override
public boolean showDuringKeyguard() {
return true;
}
@Override
public boolean showBeforeProvisioning() {
return true;
}
@Override
public void onPress() {
// shutdown by making sure radio and power are handled accordingly.
//mWindowManagerFuncs.shutdown();
Log.d("tyzc","mWindowManagerFuncs.shutdown(false ");
setNodeString("/sys/devices/system/cpu/cpufreq/policy0/scaling_governor","userspace");
//更改cpu
setNodeString("/sys/devices/system/cpu/cpufreq/policy0/scaling_setspeed","1008000");
//更改頻率
mWindowManagerFuncs.shutdown();
}
}
public static boolean setNodeString(String path,String value){
try {
BufferedWriter bufWriter = null;
bufWriter = new BufferedWriter(new FileWriter(path));
bufWriter.write(value); // 寫入資料
bufWriter.close();
Log.d("tyzc","Rewrite the node--"+path+"--to--"+value+" success!");
} catch (IOException e) {
e.printStackTrace();
Log.d("tyzc","Rewrite the node--"+path+"--to--"+value+"--failure!");
//如果失敗,可能是節點的許可權不夠,在init.rc檔案中新增
//chown system system /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
//chmod 0666 /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
return false;
}
return true;
}