以下代碼的修改是針對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