From 04170af745399035c8bf7a6ee95492ae1f305f26 Mon Sep 17 00:00:00 2001 From: AbdurazaaqMohammed Date: Mon, 16 Dec 2024 22:21:24 -0400 Subject: [PATCH] 2.1.4 Fix bug fetching list of splits for some split APKs from APKMirror (https://github.com/AbdurazaaqMohammed/AntiSplit-M/issues/116) Fix bug: base.apk was shown ticked by default but was not actually selected --- app/build.gradle.kts | 4 +- .../AntiSplit/main/DeviceSpecsUtil.java | 38 +++++++++------ .../AntiSplit/main/MainActivity.java | 46 +++++++++---------- 3 files changed, 48 insertions(+), 40 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 2b8670d2..2cb14f57 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -10,8 +10,8 @@ android { applicationId = "com.abdurazaaqmohammed.AntiSplit" minSdk = 19 targetSdk = 35 - versionCode = 41 - versionName = "2.1.3" + versionCode = 42 + versionName = "2.1.4" multiDexEnabled = true } diff --git a/app/src/main/java/com/abdurazaaqmohammed/AntiSplit/main/DeviceSpecsUtil.java b/app/src/main/java/com/abdurazaaqmohammed/AntiSplit/main/DeviceSpecsUtil.java index faa485ca..56953cfe 100644 --- a/app/src/main/java/com/abdurazaaqmohammed/AntiSplit/main/DeviceSpecsUtil.java +++ b/app/src/main/java/com/abdurazaaqmohammed/AntiSplit/main/DeviceSpecsUtil.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.function.Consumer; public class DeviceSpecsUtil { @@ -34,33 +35,40 @@ public DeviceSpecsUtil(Context context) { this.densityType = getDeviceDpi(); } + private List getListOfSplitsFromFile(File file) throws IOException { + List splits = new ArrayList<>(); + // Do not close this ZipFile it could be used later in merger + (zipFile = new ArchiveFile(file)).createZipEntryMap().forEach(inputSource -> { + String name = inputSource.getName(); + if (name.endsWith(".apk")) splits.add(name); + }); + + return splits; + } + public List getListOfSplits(Uri splitAPKUri) throws IOException { List splits = new ArrayList<>(); + File file = new File(FileUtils.getPath(splitAPKUri, context)); + if(file.canRead()) return getListOfSplitsFromFile(file); - try (InputStream is = FileUtils.getInputStream(splitAPKUri, context); + try (InputStream is = context.getContentResolver().openInputStream(splitAPKUri); ZipFileInput zis = new ZipFileInput(is)) { ZipFileHeader header; while ((header = zis.readFileHeader()) != null) { final String name = header.getFileName(); if (name.endsWith(".apk")) splits.add(name); } - } - - if(splits.size() < 2) { - File file = new File(FileUtils.getPath(splitAPKUri, context)); - boolean couldNotRead = !file.canRead(); + } catch (Exception e) { try(InputStream is = context.getContentResolver().openInputStream(splitAPKUri)) { - if(couldNotRead) FileUtils.copyFile(is, file = new File(context.getCacheDir(), file.getName())); - } - ZipEntryMap entries = (zipFile = new ArchiveFile(file)).createZipEntryMap(); - // Do not close this ZipFile it could be used later in merger - for(InputSource inputSource : entries.toArray()) { - String name = inputSource.getName(); - if (name.endsWith(".apk")) splits.add(name); + FileUtils.copyFile(is, file = new File(context.getCacheDir(), file.getName())); + return getListOfSplitsFromFile(file); } } - - return splits; + if(splits.size() > 1) return splits; + try(InputStream is = context.getContentResolver().openInputStream(splitAPKUri)) { + FileUtils.copyFile(is, file = new File(context.getCacheDir(), file.getName())); + return getListOfSplitsFromFile(file); + } } public static boolean isArch(String thisSplit) { diff --git a/app/src/main/java/com/abdurazaaqmohammed/AntiSplit/main/MainActivity.java b/app/src/main/java/com/abdurazaaqmohammed/AntiSplit/main/MainActivity.java index 790bb38d..988ab221 100644 --- a/app/src/main/java/com/abdurazaaqmohammed/AntiSplit/main/MainActivity.java +++ b/app/src/main/java/com/abdurazaaqmohammed/AntiSplit/main/MainActivity.java @@ -130,7 +130,7 @@ protected void onCreate(Bundle savedInstanceState) { SharedPreferences settings = getSharedPreferences("set", Context.MODE_PRIVATE); boolean dark = (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES; setTheme(theme = settings.getInt("theme", dark - ? com.google.android.material.R.style.Theme_Material3_Dark_NoActionBar : com.google.android.material.R.style.Theme_Material3_Light_NoActionBar)); + ? com.google.android.material.R.style.Theme_Material3_Dark_NoActionBar : com.google.android.material.R.style.Theme_Material3_Light_NoActionBar)); DeviceSpecsUtil = new DeviceSpecsUtil(this); @@ -208,9 +208,9 @@ protected void onCreate(Bundle savedInstanceState) { EditText searchBar = dialogView.findViewById(R.id.search_bar); View clearButton = dialogView.findViewById(R.id.clear_button); - // if(theme == R.style.Theme_MyApp_Black) + // if(theme == R.style.Theme_MyApp_Black) clearButton.setOnClickListener(v -> searchBar.setText("")); - // else dialogView.findViewById(R.id.tilly).setEndIconMode(TextInputLayout.END_ICON_CLEAR_TEXT); + // else dialogView.findViewById(R.id.tilly).setEndIconMode(TextInputLayout.END_ICON_CLEAR_TEXT); searchBar.addTextChangedListener(new TextWatcher() { @Override @@ -290,9 +290,9 @@ public void afterTextChanged(Editable s) { MaterialButtonToggleGroup themeButtons = settingsDialog.findViewById(R.id.themeToggleGroup); themeButtons.check( systemTheme ? R.id.systemThemeButton : - theme == com.google.android.material.R.style.Theme_Material3_Light_NoActionBar ? R.id.lightThemeButton : - theme == com.google.android.material.R.style.Theme_Material3_Dark_NoActionBar ? R.id.darkThemeButton : - R.id.blackThemeButton + theme == com.google.android.material.R.style.Theme_Material3_Light_NoActionBar ? R.id.lightThemeButton : + theme == com.google.android.material.R.style.Theme_Material3_Dark_NoActionBar ? R.id.darkThemeButton : + R.id.blackThemeButton ); themeButtons.addOnButtonCheckedListener((group, checkedId, isChecked) -> { if (isChecked) { @@ -484,8 +484,8 @@ private void checkStoragePerm() { public static boolean doesNotHaveStoragePerm(Context context) { return Build.VERSION.SDK_INT > 22 && (LegacyUtils.supportsWriteExternalStorage ? - context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED : - !Environment.isExternalStorageManager()); + context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED : + !Environment.isExternalStorageManager()); } @Override @@ -510,7 +510,7 @@ protected void onPause() { NestedScrollView scrollView; @Override - public void onLog(CharSequence msg) { + public void onLog(CharSequence msg) { runOnUiThread(() -> { logField.append(new StringBuilder(msg).append('\n')); scrollView.post(() -> scrollView.fullScroll(View.FOCUS_DOWN)); @@ -641,12 +641,12 @@ protected Void doInBackground(Uri... uris) { } } Merger.run( - activity.urisAreSplitApks ? activity.splitAPKUri : null, - cacheDir, - uris[0], - activity, - splits, - signApk); + activity.urisAreSplitApks ? activity.splitAPKUri : null, + cacheDir, + uris[0], + activity, + splits, + signApk); } else try(ApkBundle bundle = new ApkBundle()) { bundle.loadApkDirectory(new File(activity.getPackageManager().getPackageInfo(packageNameFromAppList, 0).applicationInfo.sourceDir).getParentFile(), false, activity); Merger.run(bundle, cacheDir, uris[0], activity, signApk); @@ -686,7 +686,7 @@ public static void toggleAnimation(MainActivity context, boolean on) { } else { loadingImage.setVisibility(View.GONE); - // loadingImage.clearAnimation(); + // loadingImage.clearAnimation(); } }); } @@ -861,12 +861,12 @@ protected void onPostExecute(String[] result) { title.setTextSize(size); title.setGravity(Gravity.CENTER); activity.runOnUiThread(new MaterialAlertDialogBuilder(activity).setCustomTitle(title).setView(changelogText).setPositiveButton(rss.getString(R.string.dl), (dialog, which) -> { - if (Build.VERSION.SDK_INT < 29) activity.checkStoragePerm(); - ((DownloadManager) activity.getSystemService(DOWNLOAD_SERVICE)).enqueue(new DownloadManager.Request(Uri.parse(link)) - .setTitle(filename).setDescription(filename).setMimeType("application/vnd.android.package-archive") - .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename) - .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE | DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)); - }).setNegativeButton("Go to GitHub Release", (dialog, which) -> activity.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://github.com/AbdurazaaqMohammed/AntiSplit-M/releases/latest")))).setNeutralButton(rss.getString(R.string.cancel), null).create()::show); + if (Build.VERSION.SDK_INT < 29) activity.checkStoragePerm(); + ((DownloadManager) activity.getSystemService(DOWNLOAD_SERVICE)).enqueue(new DownloadManager.Request(Uri.parse(link)) + .setTitle(filename).setDescription(filename).setMimeType("application/vnd.android.package-archive") + .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename) + .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE | DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)); + }).setNegativeButton("Go to GitHub Release", (dialog, which) -> activity.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://github.com/AbdurazaaqMohammed/AntiSplit-M/releases/latest")))).setNeutralButton(rss.getString(R.string.cancel), null).create()::show); } else if (toast) activity.runOnUiThread(() -> Toast.makeText(activity, rss.getString(R.string.no_update_found), Toast.LENGTH_SHORT).show()); } catch (Exception ignored) { if (toast) activity.runOnUiThread(() -> Toast.makeText(activity, "Failed to check for update", Toast.LENGTH_SHORT).show()); @@ -983,7 +983,7 @@ public void showApkSelectionDialog() { styleAlertDialog(ad); for (int i = 5; i < apkNames.length; i++) { if (com.abdurazaaqmohammed.AntiSplit.main.DeviceSpecsUtil.isBaseApk(apkNames[i])) { - ad.getListView().setItemChecked(i, true); + ad.getListView().setItemChecked(i, checkedItems[i] = true); break; } }