Skip to content

Commit d8820d7

Browse files
committed
Improve Call Privacy
1 parent ea4bf3d commit d8820d7

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

app/src/main/java/com/wmods/wppenhacer/xposed/core/FeatureLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
import com.wmods.wppenhacer.xposed.features.privacy.HideReceipt;
7171
import com.wmods.wppenhacer.xposed.features.privacy.HideSeen;
7272
import com.wmods.wppenhacer.xposed.features.privacy.HideTagForward;
73-
import com.wmods.wppenhacer.xposed.features.privacy.TypePrivacy;
73+
import com.wmods.wppenhacer.xposed.features.privacy.TypingPrivacy;
7474
import com.wmods.wppenhacer.xposed.features.privacy.ViewOnce;
7575
import com.wmods.wppenhacer.xposed.utils.DesignUtils;
7676
import com.wmods.wppenhacer.xposed.utils.ResId;
@@ -243,7 +243,7 @@ private static void plugins(@NonNull ClassLoader loader, @NonNull XSharedPrefere
243243
ShowOnline.class,
244244
DndMode.class,
245245
FreezeLastSeen.class,
246-
TypePrivacy.class,
246+
TypingPrivacy.class,
247247
HideChat.class,
248248
HideReceipt.class,
249249
HideSeen.class,

app/src/main/java/com/wmods/wppenhacer/xposed/features/privacy/CallPrivacy.java

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
import de.robv.android.xposed.XposedHelpers;
2323

2424
public class CallPrivacy extends Feature {
25-
public CallPrivacy(@NonNull ClassLoader loader, @NonNull XSharedPreferences preferences) {
26-
super(loader, preferences);
27-
}
2825

2926
/**
3027
* @noinspection unchecked
@@ -45,7 +42,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
4542
var callId = XposedHelpers.callMethod(callinfo, "getCallId");
4643
var type = Integer.parseInt(prefs.getString("call_privacy", "0"));
4744
Tasker.sendTaskerEvent(WppCore.getContactName(userJid), WppCore.stripJID(WppCore.getRawString(userJid)), "call_received");
48-
var blockCall = checkCallBlock(userJid, type);
45+
var blockCall = checkCallBlock(userJid, PrivacyType.getByValue(type));
4946
if (!blockCall) return;
5047
var clazzVoip = XposedHelpers.findClass("com.whatsapp.voipcalling.Voip", classLoader);
5148
var rejectType = prefs.getString("call_type", "no_internet");
@@ -82,7 +79,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
8279
if (!prefs.getString("call_type", "no_internet").equals("no_internet")) return;
8380
var userJid = param.args[0];
8481
var type = Integer.parseInt(prefs.getString("call_privacy", "0"));
85-
var block = checkCallBlock(userJid, type);
82+
var block = checkCallBlock(userJid, PrivacyType.getByValue(type));
8683
if (block) {
8784
param.setResult(1);
8885
}
@@ -92,27 +89,38 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
9289

9390
}
9491

95-
public boolean checkCallBlock(Object userJid, int type) throws IllegalAccessException, InvocationTargetException {
92+
93+
public CallPrivacy(@NonNull ClassLoader loader, @NonNull XSharedPreferences preferences) {
94+
super(loader, preferences);
95+
}
96+
97+
public boolean checkCallBlock(Object userJid, PrivacyType type) throws IllegalAccessException, InvocationTargetException {
9698
var jid = WppCore.stripJID(WppCore.getRawString(userJid));
99+
logDebug("checkCallBlock: " + jid);
100+
logDebug("checkCallBlock: " + type);
97101
if (jid == null) return false;
102+
98103
var customprivacy = CustomPrivacy.getJSON(jid);
99104

100-
if (type == 1) {
105+
if (type == PrivacyType.ALL_BLOCKED) {
101106
return customprivacy.optBoolean("BlockCall", true);
102107
}
103108

104-
if (type == 0) {
109+
if (type == PrivacyType.ALL_PERMITTED) {
105110
return customprivacy.optBoolean("BlockCall", false);
106111
}
107112

113+
if (type == PrivacyType.ONLY_UNKNOWN && customprivacy.optBoolean("BlockCall", false)) {
114+
return true;
115+
}
116+
108117
switch (type) {
109-
case 2:
110-
if (WppCore.stripJID(jid).equals(jid)) {
111-
jid = jid.split("\\.")[0] + "@s.whatsapp.net";
112-
}
118+
case ONLY_UNKNOWN:
119+
jid += "@s.whatsapp.net";
113120
var contactName = WppCore.getSContactName(WppCore.createUserJid(jid), true);
121+
logDebug("contactName: " + contactName);
114122
return TextUtils.isEmpty(contactName) || contactName.equals(jid);
115-
case 3:
123+
case BACKLIST:
116124
var callBlockList = prefs.getString("call_block_contacts", "[]");
117125
var blockList = Arrays.stream(callBlockList.substring(1, callBlockList.length() - 1).split(", ")).map(String::trim).collect(Collectors.toCollection(ArrayList::new));
118126
for (var blockNumber : blockList) {
@@ -121,7 +129,7 @@ public boolean checkCallBlock(Object userJid, int type) throws IllegalAccessExce
121129
}
122130
}
123131
return false;
124-
case 4:
132+
case WHITELIST:
125133
var callWhiteList = prefs.getString("call_white_contacts", "[]");
126134
var whiteList = Arrays.stream(callWhiteList.substring(1, callWhiteList.length() - 1).split(", ")).map(String::trim).collect(Collectors.toCollection(ArrayList::new));
127135
for (var whiteNumber : whiteList) {
@@ -134,6 +142,29 @@ public boolean checkCallBlock(Object userJid, int type) throws IllegalAccessExce
134142
return false;
135143
}
136144

145+
public enum PrivacyType {
146+
ALL_PERMITTED(0),
147+
ALL_BLOCKED(1),
148+
ONLY_UNKNOWN(2),
149+
BACKLIST(3),
150+
WHITELIST(4);
151+
152+
private final int value;
153+
154+
PrivacyType(int i) {
155+
this.value = i;
156+
}
157+
158+
public static PrivacyType getByValue(int value) {
159+
for (PrivacyType type : PrivacyType.values()) {
160+
if (type.value == value) {
161+
return type;
162+
}
163+
}
164+
return null;
165+
}
166+
}
167+
137168

138169
@NonNull
139170
@Override

app/src/main/java/com/wmods/wppenhacer/xposed/features/privacy/TypePrivacy.java renamed to app/src/main/java/com/wmods/wppenhacer/xposed/features/privacy/TypingPrivacy.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
import de.robv.android.xposed.XSharedPreferences;
1313
import de.robv.android.xposed.XposedBridge;
1414

15-
public class TypePrivacy extends Feature {
15+
public class TypingPrivacy extends Feature {
1616

17-
public TypePrivacy(ClassLoader loader, XSharedPreferences preferences) {
17+
public TypingPrivacy(ClassLoader loader, XSharedPreferences preferences) {
1818
super(loader, preferences);
1919
}
2020

@@ -44,6 +44,6 @@ protected void beforeHookedMethod(MethodHookParam param) {
4444
@NonNull
4545
@Override
4646
public String getPluginName() {
47-
return "Ghost Mode";
47+
return "Typing Privacy";
4848
}
4949
}

0 commit comments

Comments
 (0)