分类 Android 下的文章

查看具体键值

kernel/msm-4.9/include/uapi/linux/input-event-codes.hframeworks/base/data/keyboards/Generic.kl 这个里面都可以看到 home 对应的是 172.

修改 dtsi

vim kernel/msm-4.9/arch/arm64/boot/dts/qcom/sq808-evk/qm215-qrd.dtsi

&soc {
        gpio_keys {

                home {
                        label = "home";
                        gpios = <&tlmm 127 0x1>;
                        linux,input-type = <1>;
                        linux,code = <172>;
                        debounce-interval = <15>;
                        linux,can-disable;
                        gpio-key,wakeup;
                };

        };
}

设置开机唤醒

vim frameworks/base/core/java/android/view/KeyEvent.java

    /** @hide */
    public static final boolean isWakeKey(int keyCode) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
            case KeyEvent.KEYCODE_MENU:
            case KeyEvent.KEYCODE_WAKEUP:
            case KeyEvent.KEYCODE_PAIRING:
            case KeyEvent.KEYCODE_STEM_1:
            case KeyEvent.KEYCODE_STEM_2:
            case KeyEvent.KEYCODE_STEM_3:
            case KeyEvent.KEYCODE_HOME:
                return true;
        }
        return false;
    }

参考:

Android添加一个新的按键
https://blog.csdn.net/ccskyer/article/details/10226807?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-1.no_search_link&spm=1001.2101.3001.4242.2

android添加按键(二) 添加按键流程、出现问题
https://blog.csdn.net/lintao8613/article/details/82378798?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-0.no_search_link&spm=1001.2101.3001.4242.1

Android 10 新增物理按键
https://blog.csdn.net/a546036242/article/details/121012512?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

新增物理按键处理流程-Android
https://blog.csdn.net/qq_34211365/article/details/103169774?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

android8.1 添加物理按键流程
https://blog.csdn.net/tt11212/article/details/87608373

Android 10.0 framework层KeyEvent按键添加流程
https://blog.csdn.net/baidu_41666295/article/details/120262180?spm=1001.2101.3001.6650.13&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-13.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-13.no_search_link

Linux下的按键驱动
https://blog.csdn.net/mike8825/article/details/51672975?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link

Android Q 按键添加流程详解
https://blog.csdn.net/wjky2014/article/details/111351038?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-8.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-8.no_search_link

Android下添加自定义按键值
https://blog.csdn.net/u012966861/article/details/77969153?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link

Android键值添加和调试
https://blog.csdn.net/u013894427/article/details/78088260?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link

安卓添加按键流程
https://blog.csdn.net/qq_50764711/article/details/111352245?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-4.no_search_link&spm=1001.2101.3001.4242.3

添加按键
https://blog.csdn.net/qq_20395637/article/details/102777378?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

增加或修改(键盘)按键
https://blog.csdn.net/weixin_38451161/article/details/80291106?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

android定制化软件修改或添加按键驱动的核心操作步骤讲解
https://blog.csdn.net/acm2008/article/details/7065546?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

安卓添加按键驱动
https://blog.csdn.net/jaych/article/details/38065497

android添加按键驱动,android按键驱动开发实例2(增加一个新按键)
https://blog.csdn.net/weixin_33379878/article/details/117618160?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link

android系统移植之按键驱动篇
https://blog.csdn.net/armeasy/article/details/6713642?spm=1001.2101.3001.6650.10&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-10.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-10.no_search_link

Android 增加(键盘)按键
https://www.cnblogs.com/dyufei/p/6612790.html

Android系统input按键处理流程(从驱动到framework)
https://blog.csdn.net/jwq2011/article/details/51234811?spm=1001.2101.3001.6650.9&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.no_search_link

Android下添加新的自定义键值和按键处理流程
https://blog.csdn.net/tkwxty/article/details/43338921?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8.no_search_link

android gpio-keys 按键驱动分析(一) key layout文件
https://blog.csdn.net/clam_zxf/article/details/73849413?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-5.no_search_link&spm=1001.2101.3001.4242.4

[RK3288][Android6.0] 系统按键驱动流程分析
https://blog.csdn.net/kris_fei/article/details/77894406?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

android 按键 驱动程序,android按键驱动研究.pdf
https://blog.csdn.net/weixin_42551260/article/details/117577179?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

Android System 自定义KEY事件及驱动
https://blog.csdn.net/qq_31829527/article/details/105954489

Android按键消息处理
https://blog.csdn.net/peng_cao/article/details/8627369?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-1.no_search_link

android 按键处理流程,Android系统input按键处理流程(从驱动到framework)
https://blog.csdn.net/weixin_30727701/article/details/117601107?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

2021-1-4 Android 添加新的键值并上报从驱动到上层
https://blog.csdn.net/qq_37858386/article/details/112170827

aw9523芯片按键失效问问题分析
https://ciellee.blog.csdn.net/article/details/101553530

Android中对标准内核的按键映射以及按键驱动
https://blog.csdn.net/xiaobaiing/article/details/45565123?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-0.no_search_link&spm=1001.2101.3001.4242.1

kernel按键上报键值的映射
https://blog.csdn.net/u013986340/article/details/101022488

Android系统按键上报流程及其转化
https://blog.csdn.net/weixin_44008788/article/details/118755916

AndroidR Input子系统(5)解析“.kl“文件
https://blog.csdn.net/qq_34211365/article/details/109687690

Android记录输入事件研究
https://blog.csdn.net/infsafe/article/details/6120280?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

Android 按键流程分析笔记
https://blog.csdn.net/luozirong/article/details/52799745?spm=1001.2101.3001.6650.17&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-17.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-17.no_search_link

Android按键事件处理流程 KeyEvent
https://blog.csdn.net/pengjin1985/article/details/39233011?spm=1001.2101.3001.6650.16&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-16.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-16.no_search_link

Android返回键处理、任务和home键处理
https://blog.csdn.net/HUandroid/article/details/72733494?spm=1001.2101.3001.6650.15&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-15.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-15.no_search_link

Android平台Home键处理机制
https://blog.csdn.net/galensphang/article/details/9821355?spm=1001.2101.3001.6650.13&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-13.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-13.no_search_link

Android8.0 按键事件处理流程
https://blog.csdn.net/w1070216393/article/details/84261996?spm=1001.2101.3001.6650.14&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-14.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-14.no_search_link

android长按home键流程
https://blog.csdn.net/harhy/article/details/8724779?spm=1001.2101.3001.6650.10&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-10.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-10.no_search_link

Android源码解析(二十七)-->HOME事件流程
https://blog.csdn.net/qq_23547831/article/details/51475929?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link

Android源码解析(二十八)-->电源开关机按键事件流程
https://blog.csdn.net/qq_23547831/article/details/51487978?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-0.no_search_link&spm=1001.2101.3001.4242.1

Android源码基础解析之电源开关机按键事件流程
https://blog.csdn.net/qq_35559358/article/details/78647031?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-5.no_search_link&spm=1001.2101.3001.4242.4

android 捕获home键
https://blog.csdn.net/zhzhyang0313/article/details/6995553?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

Android捕获home按键 以及实体键捕获
https://blog.csdn.net/qwertyuiop159158/article/details/52900065?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-1.no_search_link&spm=1001.2101.3001.4242.2

Android 底层按键获取
https://blog.csdn.net/linan_nwu/article/details/8222011?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-1.no_search_link

Android 读取按键及Touch Panel
https://blog.csdn.net/hgl868/article/details/6860116

高通驱动实现 GPIO 中断上报键值
https://ciellee.blog.csdn.net/article/details/101312350?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link

AndroidQ 打通应用层到HAL层---(HAL模块实现)
https://blog.csdn.net/qq_34211365/article/details/105492973

Android源码解析(三十)-->触摸事件分发流程
https://blog.csdn.net/qq_23547831/article/details/51530671?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-12.no_search_link&spm=1001.2101.3001.4242.7

android实现home键功能
https://blog.csdn.net/twtje0304_01/article/details/77914161#:~:text=Android%20%E7%9A%84%20Home%20%E6%8C%89%20%E9%94%AE%E5%8A%9F%E8%83%BD%20%E6%98%AF%E5%B0%86%E6%A1%8C%E9%9D%A2Activity%E6%8B%89%E5%88%B0Activity%E6%A0%88%E9%A1%B6%EF%BC%8C%20%E6%98%BE%E7%A4%BA%20%E7%B3%BB%E7%BB%9F%E6%A1%8C%E9%9D%A2%EF%BC%8C%E4%BB%A5%E6%AD%A4%E6%9D%A5,%28%29%3B%20intent.addCategory%20%28Intent.CATEGORY_%20HOME%29%3B%20intent.setAction%20%28Intent.ACTION_MAIN%29%3B%20startActivity%20%28in

Android HOME键那些事
https://blog.csdn.net/imyfriend/article/details/8293399
Android 按下Home键
https://blog.csdn.net/greatdaocaoren/article/details/75009580
Android 监听Home键
https://www.jianshu.com/p/d215bc8e1b3d
【Android】Android处理Home键方法小结
https://www.cnblogs.com/rayray/p/3408179.html

直接使用 sql 语句

        SQLiteDatabase db = analysisDBOpenHelper.getReadableDatabase();
        String find = "select count(*) from " + "info";
        Cursor cursor = db.rawQuery(find, null);
        cursor.moveToFirst();
        return cursor.getLong(0);

使用接口

return sqLiteDatabase.query(TABLENAME, null, null, null, null, null, null).getCount();

参考:

sqlite的rawQuery和query的一个问题总结
https://blog.csdn.net/HarryWeasley/article/details/40212127
sqlite数据库的问题
https://bbs.csdn.net/topics/390907936?page=1#post-398362317

问题现象

  • 未插耳机右上角有耳机图标
  • 设置内调节 mediacall volume 没有声音输出,但是拉动其他 ringalarm 有声音输出;确定音源文件也是有的。

原因

可以了解设置内的每个音量条的策略都是不一样的,ringalarm 都是默认强制从喇叭输出,但是 media 的插入耳机后则是由耳机输出,因此就出现以上问题了。

解决方法

所以该问题的实际原因就是不插耳机出现耳机图标的问题,只要让正常情况下使用扬声器输出,而不是耳机输出即可。

kernel/msm-4.9/arch/arm64/boot/dts/qcom/sq808-evk/qm215-audio.dtsi

qcom,msm-mbhc-hphl-swh = <1>;
qcom,msm-mbhc-gnd-swh = <0>;

packages/apps/Settings/res/values-zh-rCN/arrays.xml

@@ -37,6 +37,7 @@
     <item msgid="2693197579676214668">"5 分钟"</item>
     <item msgid="1955784331962974678">"10 分钟"</item>
     <item msgid="5578717731965793584">"30 分钟"</item>
+    <item msgid="1781492122915870416">"永不休眠"</item>
   </string-array>
   <string-array name="dream_timeout_entries">
     <item msgid="1999412608953538363">"永不"</item>

packages/apps/Settings/res/values/arrays.xml

@@ -48,6 +48,7 @@
         <item>5 minutes</item>
         <item>10 minutes</item>
         <item>30 minutes</item>
+        <item>Never</item>
     </string-array>

     <!-- Do not translate. -->
@@ -66,6 +67,8 @@
         <item>600000</item>
         <!-- Do not translate. -->
         <item>1800000</item>
+        <!-- Do not translate. -->
+        <item>2147483647</item>
     </string-array>

     <!-- Display settings.  The delay in inactivity before the dream is shown. These are shown in a list dialog. -->

packages/apps/Settings/src/com/android/settings/display/TimeoutPreferenceController.java

@@ -85,8 +85,10 @@ public class TimeoutPreferenceController extends AbstractPreferenceController im
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         try {
-            int value = Integer.parseInt((String) newValue);
-            Settings.System.putInt(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, value);
+            //+Begin mantis-66494 Modified for never goto sleep by james.zheng 2020-12-24
+            long value = Integer.parseInt((String) newValue);
+            Settings.System.putLong(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, value);
+            //-End mantis-66494 Modified for never goto sleep by james.zheng 2020-12-24
             updateTimeoutPreferenceDescription((TimeoutListPreference) preference, value);
         } catch (NumberFormatException e) {
             Log.e(TAG, "could not persist screen timeout setting", e);
@@ -120,9 +122,15 @@ public class TimeoutPreferenceController extends AbstractPreferenceController im
         } else {
             final CharSequence timeoutDescription = getTimeoutDescription(
                     currentTimeout, entries, values);
+            //+Begin mantis-66494 Modified for never goto sleep by james.zheng 2020-12-24
+            if(currentTimeout == 2147483647){
+                summary = timeoutDescription.toString();
+            } else {
+            //-End mantis-66494 Modified for never goto sleep by james.zheng 2020-12-24
             summary = timeoutDescription == null
                     ? ""
                     : mContext.getString(R.string.screen_timeout_summary, timeoutDescription);
+            }
         }
         preference.setSummary(summary);
     }

准备好开机 logo 的 png 图片。

最好是同分辨率的图片,否则可能背景色会变为白色。

制作 splash.img

  1. 把 png 放到 device/qcom/common/display/logo 里面。
  2. python ./logo_gen.py logo_xyz.png 生成 splash.img

烧录 开机 logo

  1. adb root
  2. adb reboot bootloader
  3. fastboot flash splash .\splash.img
  4. fastboot reboot

参考:

https://blog.csdn.net/u014296677/article/details/78423137
https://blog.csdn.net/csdnxialei/article/details/87461635
https://blog.csdn.net/qq_27061049/article/details/117752715
https://blog.csdn.net/yandongqiangZHRJ/article/details/8585273
https://www.cnblogs.com/zzb-Dream-90Time/p/7403098.html

转自: https://blog.csdn.net/qq_37858386/article/details/103834675

Android APP:检测实体按键事件

一、检测点击按键事件一般不对手机上的输入按键进行处理,直接由系统按照默认情况操作。

当然有时为了改善用户体验,需要让应用拦截按键事件,并进行额外处理。 要想监控按键事件,首先得知道每个按键的编码,这样才能根据不同的编码值进行相应的处理。监听器OnKeyListener只会检测控制键,不会检测文本键。实际测试发现HOME、SWICH、POWER普通的app是接收不到事件的,这几个事件在framew里面处理了。

二、部分控制键KEYCODE

三、测试代码

1、android_studio_app\keyeventdemo\app\src\main\java\com\example\keyeventdemo\MainActivity.java

    package com.example.keyeventdemo;

    import android.os.Bundle;
    import android.os.Handler;
    import android.support.v7.app.AppCompatActivity;
    import android.view.KeyEvent;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.TextView;
    public class MainActivity extends AppCompatActivity {
        private TextView key_result;
        private String desc = "";
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            key_result = (TextView) findViewById(R.id.key_result);
        }
      @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            key_result = (TextView) findViewById(R.id.key_result);
        }

       @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            desc = String.format("%sphysical key coce is %d", desc, keyCode);
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                desc = String.format("%s, KEYCODE_BACK", desc);
            } else if (keyCode == KeyEvent.KEYCODE_MENU) {
                desc = String.format("%s, KEYCODE_MENU", desc);
            } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                desc = String.format("%s, KEYCODE_VOLUME_UP", desc);
            } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
                desc = String.format("%s, KEYCODE_VOLUME_DOWN", desc);
            }else  {
                desc = String.format("%s, KEYCODE_VOLUME is unknown", desc);
            }
            desc = desc + "\n";
            key_result.setText(desc);
            //返回true表示不再响应系统动作,返回false表示继续响应系统动作
            return true;
          // return  false;
        }
    }

2、布局文件 activity_main.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="5dp">

        <TextView
            android:id="@+id/tv_hard"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:gravity="center"
            android:text="please press the physics button"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/key_result"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="16sp" />

    </LinearLayout>

- 阅读剩余部分 -

永久关闭SELinux
https://zhuanlan.zhihu.com/p/336648934

android+关闭selinux权限问题,记录Android开发中SELINUX权限问题-Go语言中文社区
https://blog.csdn.net/weixin_39600704/article/details/117757795

Android程序报错: 权限问题java.io.FileNotFoundException: ……:open failed: EACCES (Permission denied)
https://blog.csdn.net/tm_6666/article/details/106792314?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-2.highlightwordscore&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-2.highlightwordscore

操作sys/device下文件节点的三种方法
https://blog.csdn.net/tanliyin/article/details/72723229?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-9.highlightwordscore&spm=1001.2101.3001.4242.6

读取设备节点/sys/class/XX :Android java.io.FileNotFoundException: open failed: EACCES (Permission denied)
https://blog.csdn.net/wds1181977/article/details/54967110

充电指示灯控制中SELinux权限问题
https://blog.csdn.net/mickeymousemei123/article/details/99828287

LED节点访问增加selinux权限记录
https://blog.csdn.net/wangwei6227/article/details/86648876

Selinux SeAndroid理解
https://blog.csdn.net/bsxiaomage/article/details/51126826

SELinux权限问题解决方法
https://blog.csdn.net/w2064004678/article/details/105515244/

记录Android开发中SELINUX权限问题
https://blog.csdn.net/maowendi/article/details/105564908

android:sharedUserId="android.uid.system" 的使用
https://blog.csdn.net/m0_38094058/article/details/82628731

关于android:sharedUserId="android.uid.system" 的使用
https://blog.csdn.net/MYBOYER/article/details/104902159

selinux常见neverallow项解决方法与常用命令
https://blog.csdn.net/k663514387/article/details/107983037

Android P系统编译报错SELinux违反Neverallow
https://blog.csdn.net/Sunxiaolin2016/article/details/91435362

[Android Framework]Android 11 SELinux avc权限解决方法
http://www.zyiz.net/tech/detail-259152.html

Android SELiunx 权限添加
https://blog.51cto.com/u_15127678/2800306

深刻理解SELinux SEAndroid
https://www.shangmayuan.com/a/d7ccd609100e479fad0952d6.html

Neverallow failures occurred Error while expanding policy in AOSP10
https://discuss.96boards.org/t/neverallow-failures-occurred-error-while-expanding-policy-in-aosp10/9712

Need some Guide with a Android SELinux Build Error
https://stackoverflow.com/questions/58956629/need-some-guide-with-a-android-selinux-build-error

SELINUX安全访问机制,配置
https://www.codenong.com/cs110875925/

【Android笔记】Android应用层读取驱动设备节点
https://www.jianshu.com/p/e4a8549a903c

selinux 问题集锦
https://blog.csdn.net/chenpuo/article/details/116456987

linux sysfs文件系统(三)属性文件读写原理分析
https://blog.csdn.net/oqqYuJi12345678/article/details/101849978

Android 上层应用读写设备节点
https://blog.csdn.net/huhuayouxu/article/details/53783799?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-0.no_search_link&spm=1001.2101.3001.4242.1

Android app如何正确读写系统sys设备节点
https://blog.csdn.net/u014341735/article/details/51244258

Selinux机制介绍与添加流程
https://blog.csdn.net/hjlgs/article/details/98958141
android 开发串口中遇到的权限问题 (个人笔记)
https://blog.csdn.net/only_you_zj/article/details/80098192 Android串口设备热插拔,ttyACM、ttyUSB权限修改
https://blog.csdn.net/u013595260/article/details/119496169
android _5.1 _串口权限
https://blog.csdn.net/izhetu/article/details/52311450
Android 串口相关权限问题
https://blog.csdn.net/qq_39734379/article/details/80525389
android读写串口的权限问题
https://blog.csdn.net/dddxxxx/article/details/53635966

深入理解SELinux SEAndroid(第一部分)
https://blog.csdn.net/innost/article/details/19299937
SELinux/SEAndroid 实例简述(一) 基础概念
https://blog.csdn.net/shell812/article/details/54930027
SELinux/SEAndroid 实例简述(二) TE语言规则
https://blog.csdn.net/shell812/article/details/54930246
SELinux/SEAndroid 实例简述(三)实例看SELinux/SEAndroid
https://blog.csdn.net/shell812/article/details/58596377
【selinux】selinux加prop,hal层读取
https://blog.csdn.net/qq_38091632/article/details/113831585

转自: https://blog.csdn.net/vviccc/article/details/108806893

1 原理

在init启动时就直接设置selinux_is_enforcing强制返回为false。这样 开机启动后 执行

$getenforce

操作时 获取到的是 Permissive,即 SELinux 关闭状态。

2 修改方案(Android O)

修改文件为:system/core/init/init.cpp,修改内容如下:

    @@ -571,7 +571,7 @@ static void selinux_init_all_handles(void)
     }

     enum selinux_enforcing_status { SELINUX_PERMISSIVE, SELINUX_ENFORCING };
    -
    +#if 0
     static selinux_enforcing_status selinux_status_from_cmdline() {
         selinux_enforcing_status status = SELINUX_ENFORCING;

    @@ -583,13 +583,17 @@ static selinux_enforcing_status selinux_status_from_cmdline() {

         return status;
     }
    +#endif

     static bool selinux_is_enforcing(void)
     {
    +   return false;
    +#if 0
         if (ALLOW_PERMISSIVE_SELINUX) {
             return selinux_status_from_cmdline() == SELINUX_ENFORCING;
         }
         return true;
    +#endif
     }

     static int audit_callback(void *data, security_class_t /*cls*/, char *buf, size_t len) {

3 修改方案(Android Q)

修改文件为:system/core/init/selinux.cpp,修改内容如下:

     selabel_handle* sehandle = nullptr;

     enum EnforcingStatus { SELINUX_PERMISSIVE, SELINUX_ENFORCING };
    -
    +#if 0
     EnforcingStatus StatusFromCmdline() {
         EnforcingStatus status = SELINUX_ENFORCING;

    @@ -95,12 +95,15 @@ EnforcingStatus StatusFromCmdline() {

         return status;
     }
    -
    +#endif
     bool IsEnforcing() {
    +#if 0
         if (ALLOW_PERMISSIVE_SELINUX) {
             return StatusFromCmdline() == SELINUX_ENFORCING;
         }
         return true;
    +#endif
    +    return false;
     }

     // Forks, executes the provided program in the child, and waits for the completion in the parent.

转自: https://note.youdao.com/ynoteshare/index.html?id=a5e6662dc0b4a2c0d929fdcf6bdea975&type=note&_time=1638928207538

验证是否是权限问题。

1.机器首先需要有root权限,执行setenforce 0,执行完getenforce显示Permissive就成功了; 2.修改代码 system/core/init/init.c

bool is_enforcing = selinux_is_enforcing();
+is_enforcing=false;
INFO("SELinux: security_setenforce(%d)\n", is_enforcing);  

先模块编译system/core/init/,然后再编译bootimage

如果以上处理完成后,问题得到解决,则说明是Selinux权限限制导致的该问题;

项目处理:

<38>[   22.872478] type=1400 audit(1325376041.960:3): avc: denied { read write } for pid=585 comm="system_server" name="au_interrupt" dev="tmpfs" ino=11449 scontext=u:r:system_server:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
<38>[   22.896195] type=1400 audit(1325376041.960:4): avc: denied { open } for pid=585 comm="system_server" path="/dev/au_interrupt" dev="tmpfs" ino=11449 scontext=u:r:system_server:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
<6>[   23.009953] lowmemorykiller: lowmem_shrink: convert oom_adj to oom_score_adj:

1.使用adb shell进入/dev/au_interrupt,执行ls -Z查看此设备的属性设置,此时显示是u:object_r:device:s0 ,对此device进行重新定义;

device\intel\baytrail\sepolicy\file_contexts-->/dev/au_interrupt                 u:object_r:au_interrupt_device:s0
device\intel\baytrail\sepolicy\device.te-->type au_interrupt_device, dev_type;

编译后全部升级,再次进入/dev/下查看ls -Z属性,此时应显示为 u:object_r:au_interrupt_device:s0; (restorecon /dev/au_interrupt 重新加载属性,然后ls -Z;也可以将此命令写入rc文件)

2.线程名称是system_server,所以进入system_server.te对其进行权限赋值操作;

allow system_server au_interrupt_device:chr_file {read write open};

如一行LOG:

<5>[ 17.285600].(0)[503:idmap]type=1400 audit(1356999072.320:202): avc: denied {create } for pid=503 comm="idmap" name="overlays.list" scontext=u:r:zygote:s0
tcontext=u:object_r:resource_cache_data_file:s0 tclass=file

即表明idmap 这个process, 使用zygote 的source context, 访问/data/resource_cache 目录,并创建文件时,被SELinux 拒绝访问。

为了规避这种权限放大情况, 我们需要细化访问目标(Object) 的SELinux Label, 做到按需申请.

通常会由三步构成 3.1 定义相关的SELinux type. 比如上述案例, 在 device/mediatek/common/sepolicy/device.te 添加

type tfa9897_device, dev_type;

3.2 绑定文件与SELinux type. 比如上述案例, 在 device/mediatek/common/sepolicy/file_contexts 添加

/dev/tfa9897(/.*)? u:object_r:tfa9897_device:s0

3.3 添加对应process/domain 的访问权限. 比如上述案例, 在 device/mediatek/common/sepolicy/mediaserver.te 添加

allow mediaserver tfa9897_device:chr_file { open read write };

- 阅读剩余部分 -