1
1
/*
2
- * Copyright (C) 2017 Peter Gregus for GravityBox Project (C3C076@xda)
2
+ * Copyright (C) 2018 Peter Gregus for GravityBox Project (C3C076@xda)
3
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
4
* you may not use this file except in compliance with the License.
5
5
* You may obtain a copy of the License at
15
15
16
16
package com .ceco .oreo .gravitybox ;
17
17
18
+ import java .lang .reflect .Method ;
19
+
18
20
import android .content .Context ;
19
21
import android .os .SystemClock ;
20
22
import de .robv .android .xposed .XC_MethodHook ;
@@ -27,37 +29,60 @@ public class ModDialerOOS {
27
29
private static final String TAG = "GB:ModDialerOOS" ;
28
30
private static final boolean DEBUG = false ;
29
31
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
+ };
31
39
32
40
private static void log (String message ) {
33
41
XposedBridge .log (TAG + ": " + message );
34
42
}
35
43
44
+ private static XSharedPreferences mPrefs ;
36
45
private static long mLastPrefReloadMs ;
37
46
38
47
public static void initInCallUi (final XSharedPreferences prefs , final ClassLoader classLoader ) {
39
48
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 );
49
61
}
50
62
}
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" );
54
68
}
55
69
}
56
70
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 () {
58
83
if (SystemClock .uptimeMillis () - mLastPrefReloadMs > 10000 ) {
59
84
mLastPrefReloadMs = SystemClock .uptimeMillis ();
60
- prefs .reload ();
85
+ mPrefs .reload ();
61
86
if (DEBUG ) log ("Expired prefs reloaded" );
62
87
}
63
88
}
0 commit comments