Skip to content

Commit 514a9a7

Browse files
committed
Dialer: fixed call recording for OOS beta
1 parent 8aaa3da commit 514a9a7

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

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

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017 Peter Gregus for GravityBox Project (C3C076@xda)
2+
* Copyright (C) 2018 Peter Gregus for GravityBox Project (C3C076@xda)
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -15,6 +15,8 @@
1515

1616
package com.ceco.oreo.gravitybox;
1717

18+
import java.lang.reflect.Method;
19+
1820
import android.content.Context;
1921
import android.os.SystemClock;
2022
import de.robv.android.xposed.XC_MethodHook;
@@ -27,37 +29,60 @@ public class ModDialerOOS {
2729
private static final String TAG = "GB:ModDialerOOS";
2830
private static final boolean DEBUG = false;
2931

30-
private static final String CLASS_PHONE_UTILS = "com.android.incallui.oneplus.OPPhoneUtils";
32+
private static final String[] CLASS_PHONE_UTILS = new String[] {
33+
"com.android.incallui.oneplus.OPPhoneUtils", "com.android.incallui.oneplus.s"
34+
};
35+
36+
private static final String[] METHOD_SUPPORTS_CALL_RECORDING = new String[] {
37+
"isSupportCallRecorder", "AN"
38+
};
3139

3240
private static void log(String message) {
3341
XposedBridge.log(TAG + ": " + message);
3442
}
3543

44+
private static XSharedPreferences mPrefs;
3645
private static long mLastPrefReloadMs;
3746

3847
public static void initInCallUi(final XSharedPreferences prefs, final ClassLoader classLoader) {
3948
if (DEBUG) log("initInCallUi");
40-
try {
41-
XposedHelpers.findAndHookMethod(CLASS_PHONE_UTILS, classLoader,
42-
"isSupportCallRecorder", Context.class, new XC_MethodHook() {
43-
@Override
44-
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
45-
reloadPrefsIfExpired(prefs);
46-
if (prefs.getBoolean(GravityBoxSettings.PREF_KEY_OOS_CALL_RECORDING, false)) {
47-
param.setResult(true);
48-
if (DEBUG) log("isSupportCallRecorder: forced to return true");
49+
mPrefs = prefs;
50+
51+
Method method = null;
52+
for (String cName : CLASS_PHONE_UTILS) {
53+
Class<?> clazz = XposedHelpers.findClassIfExists(cName, classLoader);
54+
if (clazz != null) {
55+
for (String mName : METHOD_SUPPORTS_CALL_RECORDING) {
56+
method = XposedHelpers.findMethodExactIfExists(
57+
cName, classLoader, mName, Context.class);
58+
if (method != null) {
59+
XposedBridge.hookMethod(method, supportsCallRecordingHook);
60+
if (DEBUG) log("isSupportCallRecorder found in " + cName + " as " + mName);
4961
}
5062
}
51-
});
52-
} catch (Throwable t) {
53-
GravityBox.log(TAG, t);
63+
}
64+
}
65+
66+
if (method == null) {
67+
GravityBox.log(TAG, "Unable to identify isSupportCallRecorder method");
5468
}
5569
}
5670

57-
private static void reloadPrefsIfExpired(final XSharedPreferences prefs) {
71+
private static XC_MethodHook supportsCallRecordingHook = new XC_MethodHook() {
72+
@Override
73+
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
74+
reloadPrefsIfExpired();
75+
if (mPrefs.getBoolean(GravityBoxSettings.PREF_KEY_OOS_CALL_RECORDING, false)) {
76+
param.setResult(true);
77+
if (DEBUG) log("isSupportCallRecorder: forced to return true");
78+
}
79+
}
80+
};
81+
82+
private static void reloadPrefsIfExpired() {
5883
if (SystemClock.uptimeMillis() - mLastPrefReloadMs > 10000) {
5984
mLastPrefReloadMs = SystemClock.uptimeMillis();
60-
prefs.reload();
85+
mPrefs.reload();
6186
if (DEBUG) log("Expired prefs reloaded");
6287
}
6388
}

0 commit comments

Comments
 (0)