/************************************************************************
* I.MX6 shutdown by software
* 声明:
* 有时候我们的系统可能并没有像手机那样的开关机键,所以我么这个时候
* 需要提供软件关机功能,本文直接通过JNI操作设备节点进行控制,并没有采用
* STUB来控制,当然目前对这块的操作也不熟练。
*
* 2015-12-20 深圳 南山平山村 曾剑锋
***********************************************************************/ \\\\\\\\\\\\\\-*- 目录 -*-///////////////
| 一、参考文档:
| 二、修改按键驱动程序:
| 三、板级文件注册按键设备:
| 四、添加shutdown设备节点,便于控制:
| 五、关闭关机时的提示框:
| 六、关闭watchdog:
| 七、使用JNI进行测试:
| 八、JNI对应的Java文件:
---------------------------------------- 一、参考文档:
Android开发 调用系统隐藏API
http://www.pocketdigi.com/20130519/1058.html
定做Android关机界面
http://233.io/article/1019041.html
Android下实现自动关机的方法总结
http://233.io/article/1019041.html 二、修改按键驱动程序:
cat drivers/input/keyboard/gpio_keys.c
......
//主要是为了能够指向input的设备,我们能够在自己函数里实现单独控制
struct input_dev *this_input;
......
/* 添加这个我们自己的函数,并声明为系统全局符号 */
void this_input_report_event(int mode)
{
unsigned int type = EV_KEY; switch (mode) {
case :
// for power off
input_event(this_input, type, KEY_POWER, );
input_sync(this_input); msleep(); input_event(this_input, type, KEY_POWER, );
input_sync(this_input);
break;
case :
// for stand by
input_event(this_input, type, KEY_POWER, );
input_sync(this_input);
input_event(this_input, type, KEY_POWER, );
input_sync(this_input);
break;
case :
// for stand by and wake up
input_event(this_input, type, KEY_POWER, );
input_sync(this_input);
input_event(this_input, type, KEY_POWER, );
input_sync(this_input);
input_event(this_input, type, KEY_POWER, );
input_sync(this_input);
input_event(this_input, type, KEY_POWER, );
input_sync(this_input);
break;
default:
break;
}
}
EXPORT_SYMBOL(this_input_report_event);
......
static int __devinit gpio_keys_probe(struct platform_device *pdev)
{
......
input = input_allocate_device(); this_input = input; //添加这一行,为了能向上发送按键事件 if (!ddata || !input) {
dev_err(dev, "failed to allocate state\n");
error = -ENOMEM;
goto fail1;
}
......
}
...... 三、板级文件注册按键设备:
cat arch/arm/mach-mx6/board-mx6q_sabresd.c
......
//这里随意改的,只要不和其他引脚有冲突就行
#define SABRESD_POWER_OFF IMX_GPIO_NR(3, 29)
......
static struct gpio_keys_button new_sabresd_buttons[] = {
//GPIO_BUTTON(SABRESD_VOLUME_UP, KEY_VOLUMEUP, 1, "volume-up", 0, 1),
//GPIO_BUTTON(SABRESD_VOLUME_DN, KEY_VOLUMEDOWN, 1, "volume-down", 0, 1),
GPIO_BUTTON(SABRESD_POWER_OFF, KEY_POWER, , "power-key", , ),
};
...... 四、添加shutdown设备节点,便于控制:
cat drivers/input/keyboard/shutdown.c
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/gpio.h>
#include <linux/miscdevice.h> /** switch case are in gpio_key.c */
#define THIS_INPUT_SHUTDOWN_SOFTWARE 1
#define THIS_INPUT_STANBY_SOFTWARE 2
#define THIS_INPUT_STANBY_AND_WAKEUP_SOFTWARE 3 extern void this_input_report_event(int mode); static int shutdown_open(struct inode *inode, struct file *file)
{
return ;
} static int shutdown_close(struct inode *inode, struct file *file)
{
return ;
} static ssize_t shutdown_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
{
return ;
} long shutdown_ioctl(struct file * file, unsigned int cmd, unsigned long arg)
{
this_input_report_event(cmd);
} struct file_operations shutdown_fops = {
.owner = THIS_MODULE,
.open = shutdown_open,
.release = shutdown_close,
.read = shutdown_read,
.unlocked_ioctl = shutdown_ioctl,
}; struct miscdevice shutdown_misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = "shutdown",
.fops = &shutdown_fops,
}; int __init shutdown_init(void)
{
int ret; ret = misc_register(&shutdown_misc);
if(ret)
printk("register shutdown FAILED!\n"); return ret;
} void __exit shutdown_exit(void)
{
misc_deregister(&shutdown_misc);
} module_init(shutdown_init);
module_exit(shutdown_exit); MODULE_LICENSE("GPL"); 五、关闭关机时的提示框:
cat frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
......
public class PhoneWindowManager implements WindowManagerPolicy {
......
private final Runnable mPowerLongPress = new Runnable() {
@Override
public void run() {
// The context isn't read
if (mLongPressOnPowerBehavior < ) {
mLongPressOnPowerBehavior = mContext.getResources().getInteger(
com.android.internal.R.integer.config_longPressOnPowerBehavior);
}
int resolvedBehavior = mLongPressOnPowerBehavior;
if (FactoryTest.isLongPressOnPowerOffEnabled()) {
resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
} switch (resolvedBehavior) {
case LONG_PRESS_POWER_NOTHING:
break;
case LONG_PRESS_POWER_GLOBAL_ACTIONS:
mPowerKeyHandled = true;
if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
performAuditoryFeedbackForAccessibilityIfNeed();
}
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
//注释这一样
//showGlobalActionsDialog();
//添加这一行
mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
break;
case LONG_PRESS_POWER_SHUT_OFF:
case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
mPowerKeyHandled = true;
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
break;
}
}
};
......
}
...... 六、关闭watchdog:
cat drivers/watchdog/imx2_wdt.c
......
// 这里主要是I.MX6的watchdog是一旦打开,就不能关闭的,所以在这里想了个办法,堵住,看上去堵住了
static void imx2_wdt_shutdown(struct platform_device *pdev)
{
if (test_bit(IMX2_WDT_STATUS_STARTED, &imx2_wdt.status)) {
/* we are running, we need to delete the timer but will give
* max timeout before reboot will take place */
del_timer_sync(&imx2_wdt.timer); //注释这两行
//imx2_wdt_set_timeout(IMX2_WDT_MAX_TIME);
//imx2_wdt_ping(); //添加这两行
printk("imx2_wdt_stop();");
imx2_wdt_stop(); //再次执行上面的流程,主要为因为有时候不是仅仅一次不是很稳定
del_timer_sync(&imx2_wdt.timer);
imx2_wdt_stop(); dev_crit(imx2_wdt_miscdev.parent,
"Device shutdown: Expect reboot!\n");
}
}
...... 七、使用JNI进行测试:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_android_shutdown_Shutdown */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "android/log.h"
#include <sys/reboot.h> static const char *TAG="GPIO_SHUTDOWN";
#define LOGE(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, TAG, fmt, ##args) #define THIS_INPUT_SHUTDOWN_SOFTWARE 1
#define THIS_INPUT_STANBY_SOFTWARE 2
#define THIS_INPUT_STANBY_AND_WAKEUP_SOFTWARE 3 /*
* Class: com_android_shutdown_Shutdown
* Method: shutdown
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_android_shutdown_Shutdown_shutdown
(JNIEnv * env, jobject thiz) { int fd = open("/dev/shutdown", O_RDWR);
if (fd < ) {
perror("shutdown system faild.\n");
} ioctl(fd, THIS_INPUT_SHUTDOWN_SOFTWARE, ); close(fd); } 八、JNI对应的Java文件:
cat shutdown.java
package com.android.shutdown; public class Shutdown {
native static public void shutdown();
static {
System.loadLibrary("shutdown");
}
}

I.MX6 shutdown by software的更多相关文章

  1. Windows Registry Security Check

    catalog . Windows注册表 . Windows注册表包含的攻击向量 . 注册表安全配置基线标定 1. Windows注册表 注册表(Registry,繁体中文版Windows称之为登录档 ...

  2. 入侵检测中需要监控的注册表路径研究(Windows Registry Security Check)

    1. Windows注册表简介 注册表(Registry,繁体中文版Windows称之为登录档)是Microsoft Windows中的一个重要的数据库,用于存储系统和应用程序的设置信息.早在Wind ...

  3. 如何设置ESXi中的虚拟机随主机一同启动?

    笔者新装了几台ESXi的主机, 其中一台上面运行着一台安装了vCenter的虚拟机.  笔者一路默认, 也没改什么设置. 在试图解决其他问题的过程中, 笔者重启了ESXi. 后来发现vCente登不进 ...

  4. I.MX6 android shutdown 内核崩溃

    /**************************************************************************** * I.MX6 android shutdo ...

  5. I.MX6 android 移除shutdown功能

    /************************************************************************ * I.MX6 android 移除shutdown ...

  6. I.MX6 Android shutdown shell command

    /******************************************************************************* * I.MX6 Android shu ...

  7. ora-01033:oracle initialization or shutdown in progress 解决方法

    今天研究Oracle遇到了这个问题ora-01033:oracle initialization or shutdown in progress,经过分析研究终于解决了,写下来纪念一下.我的库是ora ...

  8. I.MX6 Ethernet UI patch failed

    /*********************************************************************** * I.MX6 Ethernet UI patch f ...

  9. I.MX6 Linux udev porting

    /*********************************************************************** * I.MX6 Linux udev porting ...

随机推荐

  1. 自绘按钮,添加Color属性(转载)

    在标准的Windows程序中所有按钮均没有颜色.因此Delphi提供的所有按钮组件也均无颜色属性,有时你可能做了一个五颜六色的程序界面,而按钮颜色可能很不相称. 在此本人提供一种用自定义组件制作有颜色 ...

  2. 如何在Windows7(IIS7)环境下安装 PHP

    一.安装IIS7 打开(1)[程序和功能],然后点击(2)[打开或关闭Windows功能] 勾选(1)[IIS管理控制台]和(2)CGI,然后点击[确定]按钮,等待安装完成.这个过程可能需要系统安装光 ...

  3. hdu 4352 XHXJ's LIS 数位DP

    数位DP!dp[i][j][k]:第i位数,状态为j,长度为k 代码如下: #include<iostream> #include<stdio.h> #include<a ...

  4. MFC中错误知识总结(一)

    1.在继承与派生中,单目:表示派生,双目::表示继承,例如 class A { public: void c(); }; class B: public A {}; //类B继承类A void A:: ...

  5. Jmeter 快速入门教程(三-2) -- 设置集结点

    集合点:简单来理解一下,虽然我们的“性能测试”理解为“多用户并发测试”,但真正的并发是不存在的,为了更真实的实现并发这感念,我们可以在需要压力的地方设置集合点, 还拿那个用户和密码的地方,每到输入用户 ...

  6. Spring框架学习之第3节

    model层(业务层+dao层+持久层) spring开发提倡接口编程,配合di技术可以更好的达到层与层之间的解耦 举例: 现在我们体验一下spring的di配合接口编程,完成一个字母大小写转换的案例 ...

  7. IOS 视频分解图片、图片合成视频

    在IOS视频处理中,视频分解图片和图片合成视频是IOS视频处理中经常遇到的问题,这篇博客就这两个部分对IOS视频图像的相互转换做一下分析. (1)视频分解图片 这里视频分解图片使用的是AVAssetI ...

  8. Android笔记——导入Github开源项目CircleRefreshLayout

    百度n久都找不到android studio导入第三方类库的正确方法,纠结睡不着 ,最后终于蒙到了方法,原来想太多了  ---------------------------------------- ...

  9. Head First HTML5 Programming笔记--chapter1 认识HTML5

    升级到HTML5 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 //EN" "http://www.w3.org/TR/ ...

  10. #-webkit-autofill##google#启用表单自动填充时,如何覆盖黄色背景

    google和opera浏览器的表单自动填充后,输入框均会变成黄色背景,黑色字体.如下图. 这样的话会与网页的整体设计风格不一致,怎样自定义样式,来覆盖黄色背景. 首先来看看是什么导致的,右键查看元素 ...