Skip to content

Commit 69c45f4

Browse files
committed
OOS: Dialer: reworked call recording enabler
- should survive firmware updates - enables call recorder specific Phone settings (auto call recording, etc.)
1 parent 24d29d6 commit 69c45f4

File tree

2 files changed

+43
-48
lines changed

2 files changed

+43
-48
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,13 @@ public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
252252
ModTelecom.init(prefs, lpparam.classLoader);
253253
}
254254

255-
if (Utils.isOxygenOsRom() &&
256-
lpparam.packageName.equals((ModDialerOOS.PACKAGE_NAME_IN_CALL_UI))) {
257-
ModDialerOOS.initInCallUi(prefs, lpparam.classLoader);
255+
if (Utils.isOxygenOsRom()) {
256+
if (lpparam.packageName.equals((ModDialerOOS.PACKAGE_NAME_DIALER))) {
257+
ModDialerOOS.initDialer(prefs, lpparam.classLoader);
258+
}
259+
if (lpparam.packageName.equals(ModDialerOOS.PACKAGE_NAME_IN_CALL_UI)) {
260+
ModDialerOOS.initInCallUi(prefs, lpparam.classLoader);
261+
}
258262
}
259263
}
260264
}

src/com/ceco/oreo/gravitybox/ModDialerOOS.java

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,23 @@
1515

1616
package com.ceco.oreo.gravitybox;
1717

18-
import java.lang.reflect.Method;
19-
2018
import android.content.Context;
19+
import android.os.Bundle;
2120
import android.os.SystemClock;
21+
import android.provider.Settings;
2222
import de.robv.android.xposed.XC_MethodHook;
2323
import de.robv.android.xposed.XSharedPreferences;
2424
import de.robv.android.xposed.XposedBridge;
2525
import de.robv.android.xposed.XposedHelpers;
2626

2727
public class ModDialerOOS {
2828
public static final String PACKAGE_NAME_IN_CALL_UI = "com.android.incallui";
29+
public static final String PACKAGE_NAME_DIALER = "com.android.dialer";
30+
public static final String CLASS_DIALER_SETTINGS_ACTIVITY = "com.oneplus.dialer.settings.OPDialerSettingsActivity";
31+
public static final String CLASS_IN_CALL_ACTIVITY = "com.android.incallui.InCallActivity";
2932
private static final String TAG = "GB:ModDialerOOS";
3033
private static final boolean DEBUG = false;
3134

32-
private static class CallRecordingInfo {
33-
String className;
34-
String methodName;
35-
CallRecordingInfo(String cn, String mn) {
36-
className = cn;
37-
methodName = mn;
38-
}
39-
}
40-
41-
private static final CallRecordingInfo[] CALL_RECORDING_INFO = new CallRecordingInfo[] {
42-
new CallRecordingInfo("com.android.incallui.oneplus.f", "Td"), /* OP3T Beta 29 */
43-
new CallRecordingInfo("com.android.incallui.oneplus.a", "bz"), /* OP5 Beta 11 */
44-
new CallRecordingInfo("com.android.incallui.oneplus.r", "Om"), /* OP3T Beta 28 */
45-
new CallRecordingInfo("com.android.incallui.oneplus.f", "SI"), /* OP5T Beta 8 */
46-
new CallRecordingInfo("com.android.incallui.oneplus.s", "AN"), /* OP3T Beta 27 */
47-
new CallRecordingInfo("com.android.incallui.oneplus.OPPhoneUtils", "isSupportCallRecorder") /* OOS 5.0.2 */
48-
};
49-
5035
private static void log(String message) {
5136
XposedBridge.log(TAG + ": " + message);
5237
}
@@ -58,41 +43,47 @@ public static void initInCallUi(final XSharedPreferences prefs, final ClassLoade
5843
if (DEBUG) log("initInCallUi");
5944
mPrefs = prefs;
6045

61-
Method method = null;
62-
for (CallRecordingInfo crInfo : CALL_RECORDING_INFO) {
63-
Class<?> clazz = XposedHelpers.findClassIfExists(crInfo.className, classLoader);
64-
if (clazz != null) {
65-
method = XposedHelpers.findMethodExactIfExists(
66-
clazz, crInfo.methodName, Context.class);
67-
if (method != null) {
68-
XposedBridge.hookMethod(method, supportsCallRecordingHook);
69-
if (DEBUG) log("isSupportCallRecorder found in " + crInfo.className + " as " + crInfo.methodName);
70-
break;
46+
XposedHelpers.findAndHookMethod(CLASS_IN_CALL_ACTIVITY, classLoader,
47+
"onCreate", Bundle.class, new XC_MethodHook() {
48+
@Override
49+
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
50+
reloadPrefsIfExpired();
51+
if (mPrefs.getBoolean(GravityBoxSettings.PREF_KEY_OOS_CALL_RECORDING, false)) {
52+
enableCallRecording((Context)param.thisObject);
7153
}
7254
}
73-
}
74-
75-
if (method == null) {
76-
GravityBox.log(TAG, "Unable to identify isSupportCallRecorder method");
77-
}
55+
});
7856
}
7957

80-
private static XC_MethodHook supportsCallRecordingHook = new XC_MethodHook() {
81-
@Override
82-
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
83-
reloadPrefsIfExpired();
84-
if (mPrefs.getBoolean(GravityBoxSettings.PREF_KEY_OOS_CALL_RECORDING, false)) {
85-
param.setResult(true);
86-
if (DEBUG) log("isSupportCallRecorder: forced to return true");
58+
public static void initDialer(final XSharedPreferences prefs, final ClassLoader classLoader) {
59+
if (DEBUG) log("initDialer");
60+
mPrefs = prefs;
61+
62+
XposedHelpers.findAndHookMethod(CLASS_DIALER_SETTINGS_ACTIVITY, classLoader,
63+
"onCreate", Bundle.class, new XC_MethodHook() {
64+
@Override
65+
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
66+
reloadPrefsIfExpired();
67+
if (mPrefs.getBoolean(GravityBoxSettings.PREF_KEY_OOS_CALL_RECORDING, false)) {
68+
enableCallRecording((Context)param.thisObject);
69+
}
8770
}
88-
}
89-
};
71+
});
72+
}
9073

9174
private static void reloadPrefsIfExpired() {
92-
if (SystemClock.uptimeMillis() - mLastPrefReloadMs > 10000) {
75+
if (mPrefs != null && SystemClock.uptimeMillis() - mLastPrefReloadMs > 10000) {
9376
mLastPrefReloadMs = SystemClock.uptimeMillis();
9477
mPrefs.reload();
9578
if (DEBUG) log("Expired prefs reloaded");
9679
}
9780
}
81+
82+
private static void enableCallRecording(Context ctx) {
83+
if (ctx != null) {
84+
Settings.Global.putInt(ctx.getContentResolver(),
85+
"op_voice_recording_supported_by_mcc", 1);
86+
if (DEBUG) log(ctx.getPackageName() + ": forcing op_voice_recording_supported_by_mcc");
87+
}
88+
}
9889
}

0 commit comments

Comments
 (0)