Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit efd5391

Browse files
add zip handler to start install from a diff app
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent cb20fb4 commit efd5391

File tree

7 files changed

+108
-12
lines changed

7 files changed

+108
-12
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ configurations {
250250
dependencies {
251251
// UI
252252
implementation 'androidx.appcompat:appcompat:1.5.1'
253+
implementation "androidx.activity:activity:1.7.0-alpha02"
253254
implementation 'androidx.emoji2:emoji2:1.2.0'
254255
implementation 'androidx.emoji2:emoji2-views-helper:1.2.0'
255256
implementation 'androidx.preference:preference:1.2.0'

app/src/main/AndroidManifest.xml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
4-
tools:ignore="QueryAllPackagesPermission">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
3+
android:enableOnBackInvokedCallback="true"
4+
tools:ignore="QueryAllPackagesPermission"
5+
tools:targetApi="tiramisu">
56

67
<uses-sdk tools:overrideLibrary="io.sentry.android" />
78

@@ -12,7 +13,8 @@
1213
</queries>
1314

1415
<!-- Wifi is not the only way to get an internet connection -->
15-
<uses-feature android:name="android.hardware.wifi" android:required="false" />
16+
<uses-feature
17+
android:name="android.hardware.wifi" android:required="false" />
1618

1719
<!-- Retrieve online modules -->
1820
<uses-permission android:name="android.permission.INTERNET" />
@@ -23,9 +25,7 @@
2325
<!-- Open config apps for applications -->
2426
<uses-permission-sdk-23 android:name="android.permission.QUERY_ALL_PACKAGES" />
2527
<!-- Supposed to fix bugs with old firmware, only requested on pre Marshmallow -->
26-
<uses-permission
27-
android:name="android.permission.READ_EXTERNAL_STORAGE"
28-
android:maxSdkVersion="22" />
28+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
2929
<!-- Post background notifications -->
3030
<uses-permission-sdk-23 android:name="android.permission.POST_NOTIFICATIONS" />
3131

@@ -83,6 +83,19 @@
8383
<action android:name="${applicationId}.intent.action.INSTALL_MODULE_INTERNAL" />
8484
</intent-filter> -->
8585
</activity>
86+
<!-- We can handle zip files -->
87+
<activity
88+
android:name="com.fox2code.mmm.utils.ZipFileOpener"
89+
android:exported="true"
90+
android:theme="@style/Theme.MagiskModuleManager">
91+
<intent-filter>
92+
<action android:name="android.intent.action.VIEW" />
93+
<category android:name="android.intent.category.DEFAULT" />
94+
<data android:mimeType="application/zip" />
95+
<data android:mimeType="application/x-zip-compressed" />
96+
<data android:scheme="content" />
97+
</intent-filter>
98+
</activity>
8699
<activity
87100
android:name=".markdown.MarkdownActivity"
88101
android:exported="false"
@@ -115,8 +128,8 @@
115128
</provider>
116129

117130
<provider
118-
android:authorities="${applicationId}.file-provider"
119131
android:name="androidx.core.content.FileProvider"
132+
android:authorities="${applicationId}.file-provider"
120133
android:exported="false"
121134
android:grantUriPermissions="true">
122135

app/src/main/java/com/fox2code/mmm/NotificationType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public boolean shouldRemove() {
149149
}
150150
};
151151

152-
private static boolean needPatch(File target) throws IOException {
152+
public static boolean needPatch(File target) throws IOException {
153153
try (ZipFile zipFile = new ZipFile(target)) {
154154
return zipFile.getEntry("module.prop") == null &&
155155
zipFile.getEntry("anykernel.sh") == null &&

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ protected boolean prepare() throws NoSuchAlgorithmException {
182182
try {
183183
HttpURLConnection connection = (HttpURLConnection) new URL("https://" + this.host + "/ping").openConnection();
184184
connection.setRequestMethod("GET");
185-
connection.setConnectTimeout(5000);
186185
connection.setReadTimeout(5000);
187186
connection.connect();
188187
if (connection.getResponseCode() != 200 && connection.getResponseCode() != 204) {

app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fox2code.mmm.installer;
22

3+
import android.annotation.SuppressLint;
34
import android.content.Intent;
45
import android.content.pm.PackageManager;
56
import android.graphics.Color;
@@ -21,6 +22,7 @@
2122
import com.fox2code.mmm.AppUpdateManager;
2223
import com.fox2code.mmm.BuildConfig;
2324
import com.fox2code.mmm.Constants;
25+
import com.fox2code.mmm.MainActivity;
2426
import com.fox2code.mmm.MainApplication;
2527
import com.fox2code.mmm.R;
2628
import com.fox2code.mmm.XHooks;
@@ -744,6 +746,7 @@ private File extractInstallScript(String script) {
744746
return compatInstallScript;
745747
}
746748

749+
@SuppressLint("RestrictedApi")
747750
@SuppressWarnings("SameParameterValue")
748751
private void setInstallStateFinished(boolean success, String message, String optionalLink) {
749752
this.installerTerminal.disableAnsi();
@@ -755,7 +758,12 @@ private void setInstallStateFinished(boolean success, String message, String opt
755758
} else toDelete = null;
756759
this.runOnUiThread(() -> {
757760
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, 0);
758-
this.setOnBackPressedCallback(null);
761+
// Set the back press to finish the activity and return to the main activity
762+
this.setOnBackPressedCallback(a -> {
763+
this.finishAndRemoveTask();
764+
startActivity(new Intent(this, MainActivity.class));
765+
return true;
766+
});
759767
this.setDisplayHomeAsUpEnabled(true);
760768
this.progressIndicator.setVisibility(View.GONE);
761769

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.fox2code.mmm.utils;
2+
3+
import static androidx.fragment.app.FragmentManager.TAG;
4+
5+
import android.annotation.SuppressLint;
6+
import android.net.Uri;
7+
import android.os.Bundle;
8+
import android.util.Log;
9+
import android.widget.Toast;
10+
11+
import com.fox2code.foxcompat.FoxActivity;
12+
import com.fox2code.mmm.BuildConfig;
13+
import com.fox2code.mmm.R;
14+
import com.fox2code.mmm.installer.InstallerInitializer;
15+
16+
import java.io.File;
17+
import java.io.FileOutputStream;
18+
import java.io.InputStream;
19+
20+
public class ZipFileOpener extends FoxActivity {
21+
// Adds us as a handler for zip files, so we can pass them to the installer
22+
// We should have a content uri provided to us.
23+
@SuppressLint("RestrictedApi")
24+
@Override
25+
protected void onCreate(Bundle savedInstanceState) {
26+
super.onCreate(savedInstanceState);
27+
if (BuildConfig.DEBUG) {
28+
Log.d("ZipFileOpener", "onCreate: " + getIntent());
29+
}
30+
File zipFile;
31+
Uri uri = getIntent().getData();
32+
if (uri == null) {
33+
Toast.makeText(this, R.string.zip_load_failed, Toast.LENGTH_LONG).show();
34+
finish();
35+
return;
36+
}
37+
// Try to copy the file to our cache
38+
try {
39+
zipFile = File.createTempFile("module", ".zip", getCacheDir());
40+
try (InputStream inputStream = getContentResolver().openInputStream(uri); FileOutputStream outputStream = new FileOutputStream(zipFile)) {
41+
if (inputStream == null) {
42+
Log.e(TAG, "onCreate: Failed to open input stream");
43+
Toast.makeText(this, R.string.zip_load_failed, Toast.LENGTH_LONG).show();
44+
finishAndRemoveTask();
45+
return;
46+
}
47+
byte[] buffer = new byte[4096];
48+
int read;
49+
while ((read = inputStream.read(buffer)) != -1) {
50+
outputStream.write(buffer, 0, read);
51+
}
52+
}
53+
} catch (
54+
Exception e) {
55+
Log.e(TAG, "onCreate: Failed to copy zip file", e);
56+
Toast.makeText(this, R.string.zip_load_failed, Toast.LENGTH_LONG).show();
57+
finishAndRemoveTask();
58+
return;
59+
}
60+
// Ensure zip is not empty
61+
if (zipFile.length() == 0) {
62+
Log.e(TAG, "onCreate: Zip file is empty");
63+
Toast.makeText(this, R.string.zip_load_failed, Toast.LENGTH_LONG).show();
64+
finishAndRemoveTask();
65+
return;
66+
}
67+
// Pass the file to the installer
68+
FoxActivity compatActivity = FoxActivity.getFoxActivity(this);
69+
IntentHelper.openInstaller(compatActivity, zipFile.getAbsolutePath(),
70+
compatActivity.getString(
71+
R.string.local_install_title), null, null, false,
72+
BuildConfig.DEBUG && // Use debug mode if no root
73+
InstallerInitializer.peekMagiskPath() == null);
74+
}
75+
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,5 +267,5 @@
267267
<string name="androidacy_update_needed">This app is outdated.</string>
268268
<string name="androidacy_update_needed_message">Please update the app to the latest version.</string>
269269
<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>
270-
<string name="source_code_summary"><b>Commit</b> %1$s @ %2$s</string>
270+
<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>
271271
</resources>

0 commit comments

Comments
 (0)