android4.4(kitkat),如何让APP可以直接写入SMS短信

以下代码的修改是针对android平台研发的,另外如果没有系统源码的情况下,通过逆向修改ROM中的对应文件,也是可以做到的。

之所以有这样需求,是因为假如是你自己的ROM,需要对自己的某个APP授予SMS写入权限,可以通过修改如下代码中的OTHERSMS_PACKAGE_NAME,换成你自己APP的package name就可以了。

如果类似QQ通讯录这种应用,在可以获取ROOT 的权限下,能不能做到呢,我认为也是可以实现的,可以在内存中注入相关的代码片段,尝试分析了一下QQ通讯录,发现它里面在获取ROOT后,是有注入操作的,但不是实现下面的功能,QQ通讯录当前的版本在Android 4.4 (KitKat)上,仍然存在问题。

不多说了,直接上代码,自己研究喽~

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
diff --git a/src/java/com/android/internal/telephony/SmsApplication.java b/src/java/com/android/internal/telephony/SmsApplication.java
index 0582df8..39dee4c 100644
--- a/src/java/com/android/internal/telephony/SmsApplication.java
+++ b/src/java/com/android/internal/telephony/SmsApplication.java
@@ -49,6 +49,7 @@ public final class SmsApplication {
static final String LOG_TAG = "SmsApplication";
private static final String PHONE_PACKAGE_NAME = "com.android.phone";
private static final String BLUETOOTH_PACKAGE_NAME = "com.android.bluetooth";
+    private static final String OTHERSMS_PACKAGE_NAME = "com.example.demo";
 
private static final String SCHEME_SMS = "sms";
private static final String SCHEME_SMSTO = "smsto";
@@ -357,6 +358,20 @@ public final class SmsApplication {
// No BT app on this device
Rlog.e(LOG_TAG, "Bluetooth package not found: " + BLUETOOTH_PACKAGE_NAME);
}
+
+                try {
+                    PackageInfo info = packageManager.getPackageInfo(OTHERSMS_PACKAGE_NAME, 0);
+                    int mode = appOps.checkOp(AppOpsManager.OP_WRITE_SMS, info.applicationInfo.uid,
+                            OTHERSMS_PACKAGE_NAME);
+                    if (mode != AppOpsManager.MODE_ALLOWED) {
+                        Rlog.e(LOG_TAG, OTHERSMS_PACKAGE_NAME + " lost OP_WRITE_SMS:  (fixing)");
+                        appOps.setMode(AppOpsManager.OP_WRITE_SMS, info.applicationInfo.uid,
+                                OTHERSMS_PACKAGE_NAME, AppOpsManager.MODE_ALLOWED);
+                    }
+                } catch (NameNotFoundException e) {
+                    // No BT app on this device
+                    Rlog.e(LOG_TAG, "3rd sms package not found: " + OTHERSMS_PACKAGE_NAME);
+                }
}
}
return applicationData;
 
欢迎转载:http://www.yinqisen.cn/blog-310.html
posted @ 2016-09-14 09:51  鹤骨松姿  阅读(1038)  评论(0编辑  收藏  举报