修改默认HOME键打开的界面

这篇文章展示了如何修改Android源码,使得按下Home键时,不发送默认的Homeintent,而是根据NVRAM中的数据决定打开不同的界面。通过读取NVRAM数据并解析,选择是否添加android.intent.category.HOME_CLIFE类别到intent中。
摘要由CSDN通过智能技术生成

项目场景:

按home键的时候,不发送home的intent,修改掉,打开其他界面

代码

diff --git a/alps/frameworks/base/Android.bp b/alps/frameworks/base/Android.bp
index 37bfc439aa..3e78c82846 100644
--- a/alps/frameworks/base/Android.bp
+++ b/alps/frameworks/base/Android.bp
@@ -785,6 +785,7 @@ java_defaults {
         "android.hardware.vibrator-V1.3-java",
         "android.hardware.wifi-V1.0-java-constants",
         "devicepolicyprotosnano",
+               "vendor.mediatek.hardware.nvram-V1.0-java",
     ],

     required: [
diff --git a/alps/frameworks/base/services/Android.bp b/alps/frameworks/base/services/Android.bp
index b08d1a8095..25ca50ed37 100644
--- a/alps/frameworks/base/services/Android.bp
+++ b/alps/frameworks/base/services/Android.bp
@@ -36,6 +36,7 @@ java_library {
         "services.usb",
         "services.voiceinteraction",
         "android.hidl.base-V1.0-java",
+               "vendor.mediatek.hardware.nvram-V1.0-java",
     ],

     libs: [
diff --git a/alps/frameworks/base/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/alps/frameworks/base/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index 7c39d29a70..3be814e23b 100755
--- a/alps/frameworks/base/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/alps/frameworks/base/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -298,6 +298,8 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import com.android.internal.util.HexDump;
+import vendor.mediatek.hardware.nvram.V1_0.INvram;

@@ -5874,10 +5876,46 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
         intent.setComponent(mTopComponent);
         intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
         if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
-            intent.addCategory(Intent.CATEGORY_HOME);
+            //intent.addCategory(Intent.CATEGORY_HOME);
+                       int launcherindex=readNvRAMData();
+                       if(launcherindex==0){
+                               intent.addCategory("android.intent.category.HOME_CLIFE");
+                       }else{
+                               intent.addCategory(Intent.CATEGORY_HOME);
+                       }
         }
         return intent;
     }
+
+       private final String NVTAG="NvRAMUtil";
+    private final String PRODUCT_INFO_FILENAME = "/mnt/vendor/nvdata/APCFG/APRDEB/PRODUCT_INFO";
+    private int mSize=1024;
+    private int mOffset=774;
+    public  int readNvRAMData() {
+        int targets = 0;
+        try {
+            String buff = null;
+            INvram agent = INvram.getService();
+            Log.i(NVTAG, "readData from "+PRODUCT_INFO_FILENAME);
+            if (agent != null) {
+                buff = agent.readFileByName(PRODUCT_INFO_FILENAME, mSize);
+            }
+            byte[] buffArr = HexDump.hexStringToByteArray(buff.substring(0, buff.length() - 1));
+            byte[] dataArr=new byte[4];
+
+            System.arraycopy(buffArr,mOffset,dataArr,0,4);
+            Log.i(NVTAG, "readData 1111: buffArr=" + Arrays.toString(dataArr));
+
+//            targets = (dataArr[0] & 0xff) | ((dataArr[1] << 8) & 0xff00) | ((dataArr[2] << 24) >>> 8) | (dataArr[3] << 24);
+            targets = (dataArr[0] & 0xff) | ((dataArr[1] << 8) & 0xff00) | ((dataArr[2] << 24) >> 8 & 0xff0000) | (dataArr[3] << 24);
+
+            Log.i(NVTAG, "readData: buffArr=" + Arrays.toString(dataArr) + ", targets == " + targets);
+        } catch (Exception e) {
+            Log.e(NVTAG, "readData exception:" + e.getLocalizedMessage());
+            e.printStackTrace();
+        }
+        return targets;
+    }

     /**
      * Return the intent set with {@link Intent#CATEGORY_SECONDARY_HOME} to resolve secondary home

解决方案:

这里根据NVRAM的值来获取选择,mk文件中要添加编译,nvram的使用请看

NVRAM APP层使用
NVRAM修改蓝牙MAC
NVRAM动态修改开机logo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xuyewen288

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值