Skip to content

Commit

Permalink
2.1.4
Browse files Browse the repository at this point in the history
Fix bug fetching list of splits for some split APKs from APKMirror (#116)
Fix bug: base.apk was shown ticked by default but was not actually selected
  • Loading branch information
AbdurazaaqMohammed committed Dec 17, 2024
1 parent 65e8904 commit 04170af
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 40 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.function.Consumer;


public class DeviceSpecsUtil {
Expand All @@ -34,33 +35,40 @@ public DeviceSpecsUtil(Context context) {
this.densityType = getDeviceDpi();
}

private List<String> getListOfSplitsFromFile(File file) throws IOException {
List<String> 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<String> getListOfSplits(Uri splitAPKUri) throws IOException {
List<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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.<TextInputLayout>findViewById(R.id.tilly).setEndIconMode(TextInputLayout.END_ICON_CLEAR_TEXT);
// else dialogView.<TextInputLayout>findViewById(R.id.tilly).setEndIconMode(TextInputLayout.END_ICON_CLEAR_TEXT);

searchBar.addTextChangedListener(new TextWatcher() {
@Override
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -686,7 +686,7 @@ public static void toggleAnimation(MainActivity context, boolean on) {
}
else {
loadingImage.setVisibility(View.GONE);
// loadingImage.clearAnimation();
// loadingImage.clearAnimation();
}
});
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 04170af

Please sign in to comment.