15
15
16
16
package com .ceco .oreo .gravitybox ;
17
17
18
- import java .lang .reflect .Method ;
19
-
20
18
import android .content .Context ;
19
+ import android .os .Bundle ;
21
20
import android .os .SystemClock ;
21
+ import android .provider .Settings ;
22
22
import de .robv .android .xposed .XC_MethodHook ;
23
23
import de .robv .android .xposed .XSharedPreferences ;
24
24
import de .robv .android .xposed .XposedBridge ;
25
25
import de .robv .android .xposed .XposedHelpers ;
26
26
27
27
public class ModDialerOOS {
28
28
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" ;
29
32
private static final String TAG = "GB:ModDialerOOS" ;
30
33
private static final boolean DEBUG = false ;
31
34
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
-
50
35
private static void log (String message ) {
51
36
XposedBridge .log (TAG + ": " + message );
52
37
}
@@ -58,41 +43,47 @@ public static void initInCallUi(final XSharedPreferences prefs, final ClassLoade
58
43
if (DEBUG ) log ("initInCallUi" );
59
44
mPrefs = prefs ;
60
45
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 );
71
53
}
72
54
}
73
- }
74
-
75
- if (method == null ) {
76
- GravityBox .log (TAG , "Unable to identify isSupportCallRecorder method" );
77
- }
55
+ });
78
56
}
79
57
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
+ }
87
70
}
88
- }
89
- };
71
+ });
72
+ }
90
73
91
74
private static void reloadPrefsIfExpired () {
92
- if (SystemClock .uptimeMillis () - mLastPrefReloadMs > 10000 ) {
75
+ if (mPrefs != null && SystemClock .uptimeMillis () - mLastPrefReloadMs > 10000 ) {
93
76
mLastPrefReloadMs = SystemClock .uptimeMillis ();
94
77
mPrefs .reload ();
95
78
if (DEBUG ) log ("Expired prefs reloaded" );
96
79
}
97
80
}
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
+ }
98
89
}
0 commit comments