From 94120a23a64ea8b8f0a4b79c74984dbda9527bf0 Mon Sep 17 00:00:00 2001 From: Bruno Martins Date: Mon, 4 Nov 2013 21:09:25 +0000 Subject: [PATCH] FixCallerIdPhone and FixMmsWakelock: added support for ideaFriend Some Lenovo devices (such as A820) come with ideaFriend installed instead of AOSP Messaging app. Apparently, the methods that need to be 'hooked' are the same, being the only changes its classes. --- .../ceco/gm2/gravitybox/FixCallerIdMms.java | 27 +++++++++++-------- .../ceco/gm2/gravitybox/FixMmsWakelock.java | 22 ++++++++++----- src/com/ceco/gm2/gravitybox/GravityBox.java | 18 ++++++++----- .../gm2/gravitybox/GravityBoxSettings.java | 7 +++-- 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/com/ceco/gm2/gravitybox/FixCallerIdMms.java b/src/com/ceco/gm2/gravitybox/FixCallerIdMms.java index 700d7db8e9..a14b841dd4 100644 --- a/src/com/ceco/gm2/gravitybox/FixCallerIdMms.java +++ b/src/com/ceco/gm2/gravitybox/FixCallerIdMms.java @@ -25,13 +25,22 @@ public class FixCallerIdMms { public static final String PACKAGE_NAME = "com.android.mms"; - public static final String TAG = "GB:FixCallerIdMms"; - public static final String CLASS_CONTACTS_CACHE = "com.android.mms.data.Contact$ContactsCache"; + public static final String ALT_PACKAGE_NAME = "com.lenovo.ideafriend"; + private static final String TAG = "GB:FixCallerIdMms"; + private static String CLASS_CONTACTS_CACHE = "com.android.mms.data.Contact$ContactsCache"; private static final int STATIC_KEY_BUFFER_MAXIMUM_LENGTH = 5; private static final boolean DEBUG = false; - public static void init(final XSharedPreferences prefs, ClassLoader classLoader) { - XposedBridge.log(TAG + ": init"); + private static void log(String message) { + XposedBridge.log(TAG + ": " + message); + } + + public static void init(final XSharedPreferences prefs, ClassLoader classLoader, String appUri) { + if (DEBUG) log("init (" + appUri + ")"); + + if (appUri.equals(ALT_PACKAGE_NAME)) { + CLASS_CONTACTS_CACHE = "com.lenovo.ideafriend.mms.android.data.Contact$ContactsCache"; + } try { final Class contactsCacheClass = XposedHelpers.findClass(CLASS_CONTACTS_CACHE, classLoader); @@ -62,9 +71,7 @@ protected Object replaceHookedMethod(MethodHookParam param) throws Throwable { if (resultCount > 0) { retVal = keyBuffer.toString(); } - if (DEBUG) { - XposedBridge.log(TAG + ": key(" + phoneNumber + "); retVal='" + retVal + "'"); - } + if (DEBUG) log("key(" + phoneNumber + "); retVal='" + retVal + "'"); return retVal; } }); @@ -76,10 +83,8 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { String key = (String) param.getResult(); if (key.length() > STATIC_KEY_BUFFER_MAXIMUM_LENGTH) key = key.substring(0, key.length() - 1); - if (DEBUG) { - XposedBridge.log(TAG + ": getKey(): original retVal='" + param.getResult() + "'; " + - "new retVal='" + key + "'"); - } + if (DEBUG) log("getKey(): original retVal='" + param.getResult() + "'; " + + "new retVal='" + key + "'"); param.setResult(key); } }); diff --git a/src/com/ceco/gm2/gravitybox/FixMmsWakelock.java b/src/com/ceco/gm2/gravitybox/FixMmsWakelock.java index 344686b62b..30944710dc 100644 --- a/src/com/ceco/gm2/gravitybox/FixMmsWakelock.java +++ b/src/com/ceco/gm2/gravitybox/FixMmsWakelock.java @@ -28,12 +28,13 @@ public class FixMmsWakelock { public static final String PACKAGE_NAME = "com.android.mms"; + public static final String ALT_PACKAGE_NAME = "com.lenovo.ideafriend"; private static final String TAG = "GB:FixMmsWakelock"; - private static final String CLASS_MMS_RECEIVER = "com.android.mms.transaction.MmsSystemEventReceiver"; - private static final String CLASS_SMS_RECEIVER = "com.android.mms.transaction.SmsReceiver"; - private static final String CLASS_CB_MNOTIF = "com.android.mms.transaction.CBMessagingNotification"; - private static final String CLASS_MNOTIF = "com.android.mms.transaction.MessagingNotification"; - private static final String CLASS_NOTIF_PROFILE = "com.android.mms.transaction.MessagingNotification$NotificationProfile"; + private static String CLASS_MMS_RECEIVER = "com.android.mms.transaction.MmsSystemEventReceiver"; + private static String CLASS_SMS_RECEIVER = "com.android.mms.transaction.SmsReceiver"; + private static String CLASS_CB_MNOTIF = "com.android.mms.transaction.CBMessagingNotification"; + private static String CLASS_MNOTIF = "com.android.mms.transaction.MessagingNotification"; + private static String CLASS_NOTIF_PROFILE = "com.android.mms.transaction.MessagingNotification$NotificationProfile"; private static final boolean DEBUG = false; private static Unhook mSmsPmHook = null; @@ -47,7 +48,16 @@ private static void log(String message) { XposedBridge.log(TAG + ": " + message); } - public static void init(final XSharedPreferences prefs, final ClassLoader classLoader) { + public static void init(final XSharedPreferences prefs, final ClassLoader classLoader, String appUri) { + if (DEBUG) log("init (" + appUri + ")"); + + if (appUri.equals(ALT_PACKAGE_NAME)) { + CLASS_MMS_RECEIVER = "com.lenovo.ideafriend.mms.android.transaction.MmsSystemEventReceiver"; + CLASS_SMS_RECEIVER = "com.lenovo.ideafriend.mms.android.transaction.SmsReceiver"; + CLASS_CB_MNOTIF = "com.lenovo.ideafriend.mms.android.transaction.CBMessagingNotification"; + CLASS_MNOTIF = "com.lenovo.ideafriend.mms.android.transaction.MessagingNotification"; + } + try { final Class mmsReceiverClass = XposedHelpers.findClass(CLASS_MMS_RECEIVER, classLoader); XposedHelpers.findAndHookMethod(mmsReceiverClass, diff --git a/src/com/ceco/gm2/gravitybox/GravityBox.java b/src/com/ceco/gm2/gravitybox/GravityBox.java index fb7c85835d..8a566fca90 100644 --- a/src/com/ceco/gm2/gravitybox/GravityBox.java +++ b/src/com/ceco/gm2/gravitybox/GravityBox.java @@ -122,9 +122,12 @@ public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable { ModSignalIconHide.init(prefs, lpparam.classLoader); } - if (prefs.getBoolean(GravityBoxSettings.PREF_KEY_FIX_CALLER_ID_MMS, false) && - lpparam.packageName.equals(FixCallerIdMms.PACKAGE_NAME)) { - FixCallerIdMms.init(prefs, lpparam.classLoader); + if (prefs.getBoolean(GravityBoxSettings.PREF_KEY_FIX_CALLER_ID_MMS, false)) { + if (lpparam.packageName.equals(FixCallerIdMms.PACKAGE_NAME)) { + FixCallerIdMms.init(prefs, lpparam.classLoader, FixCallerIdMms.PACKAGE_NAME); + } else if (lpparam.packageName.equals(FixCallerIdMms.ALT_PACKAGE_NAME)) { + FixCallerIdMms.init(prefs, lpparam.classLoader, FixCallerIdMms.ALT_PACKAGE_NAME); + } } if (prefs.getBoolean(GravityBoxSettings.PREF_KEY_FIX_CALENDAR, false) && @@ -147,9 +150,12 @@ public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable { FixDevOptions.init(prefs, lpparam.classLoader); } - if (prefs.getBoolean(GravityBoxSettings.PREF_KEY_FIX_MMS_WAKELOCK, false) && - lpparam.packageName.equals(FixMmsWakelock.PACKAGE_NAME)) { - FixMmsWakelock.init(prefs, lpparam.classLoader); + if (prefs.getBoolean(GravityBoxSettings.PREF_KEY_FIX_MMS_WAKELOCK, false)) { + if (lpparam.packageName.equals(FixMmsWakelock.PACKAGE_NAME)) { + FixMmsWakelock.init(prefs, lpparam.classLoader, FixMmsWakelock.PACKAGE_NAME); + } else if (lpparam.packageName.equals(FixMmsWakelock.ALT_PACKAGE_NAME)) { + FixMmsWakelock.init(prefs, lpparam.classLoader, FixMmsWakelock.ALT_PACKAGE_NAME); + } } if (lpparam.packageName.equals(ModAudioSettings.PACKAGE_NAME)) { diff --git a/src/com/ceco/gm2/gravitybox/GravityBoxSettings.java b/src/com/ceco/gm2/gravitybox/GravityBoxSettings.java index 52dc9a9ac3..aa0e0aa177 100644 --- a/src/com/ceco/gm2/gravitybox/GravityBoxSettings.java +++ b/src/com/ceco/gm2/gravitybox/GravityBoxSettings.java @@ -151,7 +151,8 @@ public class GravityBoxSettings extends Activity implements GravityBoxResultRece public static final String PREF_KEY_CRT_OFF_EFFECT = "pref_crt_off_effect"; public static final String PREF_KEY_UNPLUG_TURNS_ON_SCREEN = "pref_unplug_turns_on_screen"; public static final String PREF_KEY_ENGINEERING_MODE = "pref_engineering_mode"; - public static final String APP_MESSAGING = "com.android.mms"; + public static final String STOCK_APP_MESSAGING = "com.android.mms"; + public static final String ALT_APP_MESSAGING = "com.lenovo.ideafriend"; public static final String APP_ENGINEERING_MODE = "com.mediatek.engineermode"; public static final String APP_ENGINEERING_MODE_CLASS = "com.mediatek.engineermode.EngineerMode"; public static final String PREF_KEY_DUAL_SIM_RINGER = "pref_dual_sim_ringer"; @@ -942,8 +943,10 @@ public void onCreate(Bundle savedInstanceState) { mPrefCatMedia.removePreference(mPrefLinkVolumes); mPrefCatFixes.removePreference(mPrefFixCallerIDPhone); } - if (!isAppInstalled(APP_MESSAGING)) { + if (!isAppInstalled(STOCK_APP_MESSAGING)) { mPrefCatPhone.removePreference(mPrefCatPhoneMessaging); + } + if (!isAppInstalled(STOCK_APP_MESSAGING) && !isAppInstalled(ALT_APP_MESSAGING)) { mPrefCatFixes.removePreference(mPrefFixCallerIDMms); mPrefCatFixes.removePreference(mPrefFixMmsWakelock); }