Skip to content

Commit 2fd8a5d

Browse files
committed
feat: enhance folder selection for WhatsApp integration in lite mode
1 parent 520221a commit 2fd8a5d

File tree

4 files changed

+39
-32
lines changed

4 files changed

+39
-32
lines changed

app/src/main/java/com/wmods/wppenhacer/preference/FileSelectPreference.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import android.content.ContentResolver;
66
import android.content.Context;
77
import android.content.Intent;
8+
import android.content.pm.PackageInfo;
89
import android.content.pm.PackageManager;
910
import android.net.Uri;
1011
import android.os.Build;
1112
import android.os.Environment;
13+
import android.provider.Settings;
1214
import android.util.AttributeSet;
1315
import android.widget.Toast;
1416

@@ -66,7 +68,7 @@ private void showAlertPermission() {
6668
builder.setTitle(R.string.storage_permission);
6769
builder.setMessage(R.string.permission_storage);
6870
builder.setPositiveButton(R.string.allow, (dialog, which) -> {
69-
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
71+
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
7072
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7173
intent.setData(Uri.fromParts("package", getContext().getPackageName(), null));
7274
getContext().startActivity(intent);
@@ -79,8 +81,34 @@ private void showAlertPermission() {
7981
public boolean onPreferenceClick(@NonNull Preference preference) {
8082

8183
if (getSharedPreferences().getBoolean("lite_mode", false)) {
84+
String packageName = "";
85+
PackageInfo packageInfo = null;
86+
for (var possiblePackage : new String[]{"com.whatsapp", "com.whatsapp.w4b"}) {
87+
try {
88+
packageInfo = getContext().getApplicationContext().getPackageManager().getPackageInfo(possiblePackage, PackageManager.GET_ACTIVITIES);
89+
packageName = possiblePackage;
90+
break;
91+
} catch (PackageManager.NameNotFoundException ignored) {
92+
}
93+
}
94+
if (packageInfo == null) {
95+
Utils.showToast("Unable to find WhatsApp package, please select the folder manually in the next screen", Toast.LENGTH_LONG);
96+
return true;
97+
}
98+
99+
String className = null;
100+
for (var activity : packageInfo.activities) {
101+
if (activity.name.endsWith("SettingsNotifications")) {
102+
className = activity.name;
103+
break;
104+
}
105+
}
106+
if (className == null) {
107+
Utils.showToast("Unable to find the activity to select folder, please select it manually in the next screen", Toast.LENGTH_LONG);
108+
return true;
109+
}
82110
Intent intent = new Intent();
83-
intent.setClassName("com.whatsapp", ActivityController.EXPORTED_ACTIVITY);
111+
intent.setClassName(packageName, className);
84112
intent.putExtra("key", getKey());
85113
intent.putExtra("download_mode", true);
86114
((Activity) getContext()).startActivityForResult(intent, LiteMode.REQUEST_FOLDER);

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public class WppCore {
6060
private static SQLiteDatabase mWaDatabase;
6161
public static BaseClient client;
6262
private static Object mCachedMessageStore;
63-
private static Class<?> mSettingsNotificationsClass;
6463
private static Method convertLidToJid;
6564

6665
private static Object mWaJidMapRepository;
@@ -86,10 +85,6 @@ public static void Initialize(ClassLoader loader, XSharedPreferences pref) throw
8685
convChatField = Unobfuscator.loadAntiRevokeConvChatField(loader);
8786
chatJidField = Unobfuscator.loadAntiRevokeChatJidField(loader);
8887

89-
// Settings notifications activity (required for
90-
// ActivityController.EXPORTED_ACTIVITY)
91-
mSettingsNotificationsClass = getSettingsNotificationsActivityClass(loader);
92-
9388
// StartUpPrefs
9489
var startPrefsConfig = Unobfuscator.loadStartPrefsConfig(loader);
9590
XposedBridge.hookMethod(startPrefsConfig, new XC_MethodHook() {
@@ -339,17 +334,6 @@ public synchronized static Class getAboutActivityClass(@NonNull ClassLoader load
339334
: XposedHelpers.findClass("com.whatsapp.settings.ui.About", loader);
340335
}
341336

342-
public synchronized static Class getSettingsNotificationsActivityClass(@NonNull ClassLoader loader) {
343-
if (mSettingsNotificationsClass != null)
344-
return mSettingsNotificationsClass;
345-
346-
Class oldClass = XposedHelpers.findClassIfExists("com.whatsapp.settings.SettingsNotifications", loader);
347-
348-
return oldClass != null
349-
? oldClass
350-
: XposedHelpers.findClass("com.whatsapp.settings.ui.SettingsNotifications", loader);
351-
}
352-
353337
public synchronized static Class getDataUsageActivityClass(@NonNull ClassLoader loader) {
354338
Class oldClass = XposedHelpers.findClassIfExists("com.whatsapp.settings.SettingsDataUsageActivity", loader);
355339

app/src/main/java/com/wmods/wppenhacer/xposed/features/others/ActivityController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;
2121
import com.wmods.wppenhacer.xposed.utils.ResId;
2222

23+
import org.luckypray.dexkit.query.enums.StringMatchType;
24+
2325
import java.lang.reflect.Constructor;
2426
import java.lang.reflect.InvocationTargetException;
2527
import java.util.ArrayList;
@@ -31,7 +33,6 @@
3133

3234
public class ActivityController extends Feature {
3335

34-
public static final String EXPORTED_ACTIVITY = WppCore.getSettingsNotificationsActivityClass(ClassLoader.getSystemClassLoader()).getName();
3536
private static String Key;
3637

3738
public ActivityController(@NonNull ClassLoader classLoader, @NonNull XSharedPreferences preferences) {
@@ -41,7 +42,7 @@ public ActivityController(@NonNull ClassLoader classLoader, @NonNull XSharedPref
4142
@Override
4243
public void doHook() throws Throwable {
4344

44-
var clazz = XposedHelpers.findClass(EXPORTED_ACTIVITY, classLoader);
45+
var clazz = Unobfuscator.findFirstClassUsingName(classLoader, StringMatchType.EndsWith,".SettingsNotifications");
4546
Class<?> statusDistribution = Unobfuscator.loadStatusDistributionClass(classLoader);
4647

4748
XposedHelpers.findAndHookMethod(Activity.class, "onCreate", Bundle.class, new XC_MethodHook() {

changelog.txt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
[ADDED]
22
* Added Monet colors and some others for WAE
33
* Added Monet colors for WhatsApp
4-
* Added Call Recording feature (Voice/Video as Audio)
5-
* Call Recording Toast Toggle: Added option to show/hide recording toast notifications (default: off)
6-
* [EXPERIMENTAL] Use "Force Restore Backup" option in Chat Backup settings to restore backups after login.
7-
* Global Search: Added comprehensive search functionality across all app settings and features.
8-
* Recover deleted for me message: Added option to recover deleted for me messages.
4+
* Added Call Recording feature (Voice/Video as Audio) (Thanks to @mubashardev)
5+
* Call Recording Toast Toggle: Added option to show/hide recording toast notifications (default: off) (Thanks to @mubashardev)
6+
* [EXPERIMENTAL] Use "Force Restore Backup" option in Chat Backup settings to restore backups after login (Thanks to @mubashardev)
7+
* Global Search: Added comprehensive search functionality across all app settings and features. (Thanks to @mubashardev)
8+
* Recover deleted for me message: Added option to recover deleted for me messages. (Thanks to @mubashardev)
9+
* Added Contributors section in About page to acknowledge the efforts of contributors. (Thanks to @mubashardev)
910

1011
[IMPROVEMENTS]
1112
- Original timestamp: Added option to show original timestamp of **Delete for me** messages.
1213

1314
[Fixed]
14-
* Fixed compatibility with version 2.26.6.XX
15-
* Fixed high-quality profile picture download
16-
* Fixed bug in IGStatus where dragging would case the user to switch tabs.
1715
* Fixed OriginFMessageField not found error
18-
* Fixed media quality selector
19-
* Fixed issue when sending high-resolution videos
20-
* Fixed landscape video issue
2116
* Fixed profile picture download for old contacts
22-
* Fixed bug in Update Checker
2317
* Optimized initial app load

0 commit comments

Comments
 (0)