add zip handler to start install from a diff app

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/267/head
androidacy-user 1 year ago
parent cb20fb4a8f
commit efd5391ef8

@ -250,6 +250,7 @@ configurations {
dependencies {
// UI
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation "androidx.activity:activity:1.7.0-alpha02"
implementation 'androidx.emoji2:emoji2:1.2.0'
implementation 'androidx.emoji2:emoji2-views-helper:1.2.0'
implementation 'androidx.preference:preference:1.2.0'

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="QueryAllPackagesPermission">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
android:enableOnBackInvokedCallback="true"
tools:ignore="QueryAllPackagesPermission"
tools:targetApi="tiramisu">
<uses-sdk tools:overrideLibrary="io.sentry.android" />
@ -12,7 +13,8 @@
</queries>
<!-- Wifi is not the only way to get an internet connection -->
<uses-feature android:name="android.hardware.wifi" android:required="false" />
<uses-feature
android:name="android.hardware.wifi" android:required="false" />
<!-- Retrieve online modules -->
<uses-permission android:name="android.permission.INTERNET" />
@ -23,9 +25,7 @@
<!-- Open config apps for applications -->
<uses-permission-sdk-23 android:name="android.permission.QUERY_ALL_PACKAGES" />
<!-- Supposed to fix bugs with old firmware, only requested on pre Marshmallow -->
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="22" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- Post background notifications -->
<uses-permission-sdk-23 android:name="android.permission.POST_NOTIFICATIONS" />
@ -83,6 +83,19 @@
<action android:name="${applicationId}.intent.action.INSTALL_MODULE_INTERNAL" />
</intent-filter> -->
</activity>
<!-- We can handle zip files -->
<activity
android:name="com.fox2code.mmm.utils.ZipFileOpener"
android:exported="true"
android:theme="@style/Theme.MagiskModuleManager">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/zip" />
<data android:mimeType="application/x-zip-compressed" />
<data android:scheme="content" />
</intent-filter>
</activity>
<activity
android:name=".markdown.MarkdownActivity"
android:exported="false"
@ -115,8 +128,8 @@
</provider>
<provider
android:authorities="${applicationId}.file-provider"
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.file-provider"
android:exported="false"
android:grantUriPermissions="true">

@ -149,7 +149,7 @@ public enum NotificationType implements NotificationTypeCst {
}
};
private static boolean needPatch(File target) throws IOException {
public static boolean needPatch(File target) throws IOException {
try (ZipFile zipFile = new ZipFile(target)) {
return zipFile.getEntry("module.prop") == null &&
zipFile.getEntry("anykernel.sh") == null &&

@ -182,7 +182,6 @@ public final class AndroidacyRepoData extends RepoData {
try {
HttpURLConnection connection = (HttpURLConnection) new URL("https://" + this.host + "/ping").openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
connection.connect();
if (connection.getResponseCode() != 200 && connection.getResponseCode() != 204) {

@ -1,5 +1,6 @@
package com.fox2code.mmm.installer;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
@ -21,6 +22,7 @@ import com.fox2code.foxcompat.FoxActivity;
import com.fox2code.mmm.AppUpdateManager;
import com.fox2code.mmm.BuildConfig;
import com.fox2code.mmm.Constants;
import com.fox2code.mmm.MainActivity;
import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.R;
import com.fox2code.mmm.XHooks;
@ -744,6 +746,7 @@ public class InstallerActivity extends FoxActivity {
return compatInstallScript;
}
@SuppressLint("RestrictedApi")
@SuppressWarnings("SameParameterValue")
private void setInstallStateFinished(boolean success, String message, String optionalLink) {
this.installerTerminal.disableAnsi();
@ -755,7 +758,12 @@ public class InstallerActivity extends FoxActivity {
} else toDelete = null;
this.runOnUiThread(() -> {
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, 0);
this.setOnBackPressedCallback(null);
// Set the back press to finish the activity and return to the main activity
this.setOnBackPressedCallback(a -> {
this.finishAndRemoveTask();
startActivity(new Intent(this, MainActivity.class));
return true;
});
this.setDisplayHomeAsUpEnabled(true);
this.progressIndicator.setVisibility(View.GONE);

@ -0,0 +1,75 @@
package com.fox2code.mmm.utils;
import static androidx.fragment.app.FragmentManager.TAG;
import android.annotation.SuppressLint;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.fox2code.foxcompat.FoxActivity;
import com.fox2code.mmm.BuildConfig;
import com.fox2code.mmm.R;
import com.fox2code.mmm.installer.InstallerInitializer;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
public class ZipFileOpener extends FoxActivity {
// Adds us as a handler for zip files, so we can pass them to the installer
// We should have a content uri provided to us.
@SuppressLint("RestrictedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (BuildConfig.DEBUG) {
Log.d("ZipFileOpener", "onCreate: " + getIntent());
}
File zipFile;
Uri uri = getIntent().getData();
if (uri == null) {
Toast.makeText(this, R.string.zip_load_failed, Toast.LENGTH_LONG).show();
finish();
return;
}
// Try to copy the file to our cache
try {
zipFile = File.createTempFile("module", ".zip", getCacheDir());
try (InputStream inputStream = getContentResolver().openInputStream(uri); FileOutputStream outputStream = new FileOutputStream(zipFile)) {
if (inputStream == null) {
Log.e(TAG, "onCreate: Failed to open input stream");
Toast.makeText(this, R.string.zip_load_failed, Toast.LENGTH_LONG).show();
finishAndRemoveTask();
return;
}
byte[] buffer = new byte[4096];
int read;
while ((read = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, read);
}
}
} catch (
Exception e) {
Log.e(TAG, "onCreate: Failed to copy zip file", e);
Toast.makeText(this, R.string.zip_load_failed, Toast.LENGTH_LONG).show();
finishAndRemoveTask();
return;
}
// Ensure zip is not empty
if (zipFile.length() == 0) {
Log.e(TAG, "onCreate: Zip file is empty");
Toast.makeText(this, R.string.zip_load_failed, Toast.LENGTH_LONG).show();
finishAndRemoveTask();
return;
}
// Pass the file to the installer
FoxActivity compatActivity = FoxActivity.getFoxActivity(this);
IntentHelper.openInstaller(compatActivity, zipFile.getAbsolutePath(),
compatActivity.getString(
R.string.local_install_title), null, null, false,
BuildConfig.DEBUG && // Use debug mode if no root
InstallerInitializer.peekMagiskPath() == null);
}
}

@ -267,5 +267,5 @@
<string name="androidacy_update_needed">This app is outdated.</string>
<string name="androidacy_update_needed_message">Please update the app to the latest version.</string>
<string name="androidacy_webview_update_required">Your webview is outdated! Please update it.</string><string name="language_cta">Don\'t see your language?</string><string name="language_cta_desc">Help us by translating it! Tap here to find out more.</string>
<string name="source_code_summary"><b>Commit</b> %1$s @ %2$s</string>
<string name="source_code_summary"><b>Commit</b> %1$s @ %2$s</string><string name="no_file_provided">No file was provided when trying to open zip.</string><string name="zip_load_failed">Could not load the zip file</string>
</resources>

Loading…
Cancel
Save