Skip to content

Commit 94120a2

Browse files
committed
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.
1 parent 9ee2e8f commit 94120a2

File tree

4 files changed

+49
-25
lines changed

4 files changed

+49
-25
lines changed

src/com/ceco/gm2/gravitybox/FixCallerIdMms.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@
2525

2626
public class FixCallerIdMms {
2727
public static final String PACKAGE_NAME = "com.android.mms";
28-
public static final String TAG = "GB:FixCallerIdMms";
29-
public static final String CLASS_CONTACTS_CACHE = "com.android.mms.data.Contact$ContactsCache";
28+
public static final String ALT_PACKAGE_NAME = "com.lenovo.ideafriend";
29+
private static final String TAG = "GB:FixCallerIdMms";
30+
private static String CLASS_CONTACTS_CACHE = "com.android.mms.data.Contact$ContactsCache";
3031
private static final int STATIC_KEY_BUFFER_MAXIMUM_LENGTH = 5;
3132
private static final boolean DEBUG = false;
3233

33-
public static void init(final XSharedPreferences prefs, ClassLoader classLoader) {
34-
XposedBridge.log(TAG + ": init");
34+
private static void log(String message) {
35+
XposedBridge.log(TAG + ": " + message);
36+
}
37+
38+
public static void init(final XSharedPreferences prefs, ClassLoader classLoader, String appUri) {
39+
if (DEBUG) log("init (" + appUri + ")");
40+
41+
if (appUri.equals(ALT_PACKAGE_NAME)) {
42+
CLASS_CONTACTS_CACHE = "com.lenovo.ideafriend.mms.android.data.Contact$ContactsCache";
43+
}
3544

3645
try {
3746
final Class<?> contactsCacheClass = XposedHelpers.findClass(CLASS_CONTACTS_CACHE, classLoader);
@@ -62,9 +71,7 @@ protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
6271
if (resultCount > 0) {
6372
retVal = keyBuffer.toString();
6473
}
65-
if (DEBUG) {
66-
XposedBridge.log(TAG + ": key(" + phoneNumber + "); retVal='" + retVal + "'");
67-
}
74+
if (DEBUG) log("key(" + phoneNumber + "); retVal='" + retVal + "'");
6875
return retVal;
6976
}
7077
});
@@ -76,10 +83,8 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
7683
String key = (String) param.getResult();
7784
if (key.length() > STATIC_KEY_BUFFER_MAXIMUM_LENGTH)
7885
key = key.substring(0, key.length() - 1);
79-
if (DEBUG) {
80-
XposedBridge.log(TAG + ": getKey(): original retVal='" + param.getResult() + "'; " +
81-
"new retVal='" + key + "'");
82-
}
86+
if (DEBUG) log("getKey(): original retVal='" + param.getResult() + "'; " +
87+
"new retVal='" + key + "'");
8388
param.setResult(key);
8489
}
8590
});

src/com/ceco/gm2/gravitybox/FixMmsWakelock.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828

2929
public class FixMmsWakelock {
3030
public static final String PACKAGE_NAME = "com.android.mms";
31+
public static final String ALT_PACKAGE_NAME = "com.lenovo.ideafriend";
3132
private static final String TAG = "GB:FixMmsWakelock";
32-
private static final String CLASS_MMS_RECEIVER = "com.android.mms.transaction.MmsSystemEventReceiver";
33-
private static final String CLASS_SMS_RECEIVER = "com.android.mms.transaction.SmsReceiver";
34-
private static final String CLASS_CB_MNOTIF = "com.android.mms.transaction.CBMessagingNotification";
35-
private static final String CLASS_MNOTIF = "com.android.mms.transaction.MessagingNotification";
36-
private static final String CLASS_NOTIF_PROFILE = "com.android.mms.transaction.MessagingNotification$NotificationProfile";
33+
private static String CLASS_MMS_RECEIVER = "com.android.mms.transaction.MmsSystemEventReceiver";
34+
private static String CLASS_SMS_RECEIVER = "com.android.mms.transaction.SmsReceiver";
35+
private static String CLASS_CB_MNOTIF = "com.android.mms.transaction.CBMessagingNotification";
36+
private static String CLASS_MNOTIF = "com.android.mms.transaction.MessagingNotification";
37+
private static String CLASS_NOTIF_PROFILE = "com.android.mms.transaction.MessagingNotification$NotificationProfile";
3738
private static final boolean DEBUG = false;
3839

3940
private static Unhook mSmsPmHook = null;
@@ -47,7 +48,16 @@ private static void log(String message) {
4748
XposedBridge.log(TAG + ": " + message);
4849
}
4950

50-
public static void init(final XSharedPreferences prefs, final ClassLoader classLoader) {
51+
public static void init(final XSharedPreferences prefs, final ClassLoader classLoader, String appUri) {
52+
if (DEBUG) log("init (" + appUri + ")");
53+
54+
if (appUri.equals(ALT_PACKAGE_NAME)) {
55+
CLASS_MMS_RECEIVER = "com.lenovo.ideafriend.mms.android.transaction.MmsSystemEventReceiver";
56+
CLASS_SMS_RECEIVER = "com.lenovo.ideafriend.mms.android.transaction.SmsReceiver";
57+
CLASS_CB_MNOTIF = "com.lenovo.ideafriend.mms.android.transaction.CBMessagingNotification";
58+
CLASS_MNOTIF = "com.lenovo.ideafriend.mms.android.transaction.MessagingNotification";
59+
}
60+
5161
try {
5262
final Class<?> mmsReceiverClass = XposedHelpers.findClass(CLASS_MMS_RECEIVER, classLoader);
5363
XposedHelpers.findAndHookMethod(mmsReceiverClass,

src/com/ceco/gm2/gravitybox/GravityBox.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,12 @@ public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
122122
ModSignalIconHide.init(prefs, lpparam.classLoader);
123123
}
124124

125-
if (prefs.getBoolean(GravityBoxSettings.PREF_KEY_FIX_CALLER_ID_MMS, false) &&
126-
lpparam.packageName.equals(FixCallerIdMms.PACKAGE_NAME)) {
127-
FixCallerIdMms.init(prefs, lpparam.classLoader);
125+
if (prefs.getBoolean(GravityBoxSettings.PREF_KEY_FIX_CALLER_ID_MMS, false)) {
126+
if (lpparam.packageName.equals(FixCallerIdMms.PACKAGE_NAME)) {
127+
FixCallerIdMms.init(prefs, lpparam.classLoader, FixCallerIdMms.PACKAGE_NAME);
128+
} else if (lpparam.packageName.equals(FixCallerIdMms.ALT_PACKAGE_NAME)) {
129+
FixCallerIdMms.init(prefs, lpparam.classLoader, FixCallerIdMms.ALT_PACKAGE_NAME);
130+
}
128131
}
129132

130133
if (prefs.getBoolean(GravityBoxSettings.PREF_KEY_FIX_CALENDAR, false) &&
@@ -147,9 +150,12 @@ public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
147150
FixDevOptions.init(prefs, lpparam.classLoader);
148151
}
149152

150-
if (prefs.getBoolean(GravityBoxSettings.PREF_KEY_FIX_MMS_WAKELOCK, false) &&
151-
lpparam.packageName.equals(FixMmsWakelock.PACKAGE_NAME)) {
152-
FixMmsWakelock.init(prefs, lpparam.classLoader);
153+
if (prefs.getBoolean(GravityBoxSettings.PREF_KEY_FIX_MMS_WAKELOCK, false)) {
154+
if (lpparam.packageName.equals(FixMmsWakelock.PACKAGE_NAME)) {
155+
FixMmsWakelock.init(prefs, lpparam.classLoader, FixMmsWakelock.PACKAGE_NAME);
156+
} else if (lpparam.packageName.equals(FixMmsWakelock.ALT_PACKAGE_NAME)) {
157+
FixMmsWakelock.init(prefs, lpparam.classLoader, FixMmsWakelock.ALT_PACKAGE_NAME);
158+
}
153159
}
154160

155161
if (lpparam.packageName.equals(ModAudioSettings.PACKAGE_NAME)) {

src/com/ceco/gm2/gravitybox/GravityBoxSettings.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ public class GravityBoxSettings extends Activity implements GravityBoxResultRece
151151
public static final String PREF_KEY_CRT_OFF_EFFECT = "pref_crt_off_effect";
152152
public static final String PREF_KEY_UNPLUG_TURNS_ON_SCREEN = "pref_unplug_turns_on_screen";
153153
public static final String PREF_KEY_ENGINEERING_MODE = "pref_engineering_mode";
154-
public static final String APP_MESSAGING = "com.android.mms";
154+
public static final String STOCK_APP_MESSAGING = "com.android.mms";
155+
public static final String ALT_APP_MESSAGING = "com.lenovo.ideafriend";
155156
public static final String APP_ENGINEERING_MODE = "com.mediatek.engineermode";
156157
public static final String APP_ENGINEERING_MODE_CLASS = "com.mediatek.engineermode.EngineerMode";
157158
public static final String PREF_KEY_DUAL_SIM_RINGER = "pref_dual_sim_ringer";
@@ -942,8 +943,10 @@ public void onCreate(Bundle savedInstanceState) {
942943
mPrefCatMedia.removePreference(mPrefLinkVolumes);
943944
mPrefCatFixes.removePreference(mPrefFixCallerIDPhone);
944945
}
945-
if (!isAppInstalled(APP_MESSAGING)) {
946+
if (!isAppInstalled(STOCK_APP_MESSAGING)) {
946947
mPrefCatPhone.removePreference(mPrefCatPhoneMessaging);
948+
}
949+
if (!isAppInstalled(STOCK_APP_MESSAGING) && !isAppInstalled(ALT_APP_MESSAGING)) {
947950
mPrefCatFixes.removePreference(mPrefFixCallerIDMms);
948951
mPrefCatFixes.removePreference(mPrefFixMmsWakelock);
949952
}

0 commit comments

Comments
 (0)