Commit 830fde80 authored by topjohnwu's avatar topjohnwu

Download with DownloadManager

parent c44ce77e
# Magisk Manager
Because I love to stay on cutting edge, the project can only be compiled on Android Studio Version 2.2.0+ (currently in beta)
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
//apply plugin: 'android-apt'
android {
compileSdkVersion 24
......@@ -11,13 +11,21 @@ android {
targetSdkVersion 24
versionCode 4
versionName "2.0"
jackOptions {
enabled true
}
}
buildTypes {
release {
minifyEnabled false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
......@@ -26,6 +34,6 @@ dependencies {
compile 'com.android.support:cardview-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}
......@@ -26,6 +26,15 @@
<activity
android:name=".AboutActivity"
android:theme="@style/AppTheme.Transparent"/>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.topjohnwu.magisk.provider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>
</manifest>
\ No newline at end of file
......@@ -85,10 +85,6 @@ public class ModulesFragment extends Fragment {
@Override
protected Void doInBackground(Void... voids) {
listModules.clear();
listModulesCache.clear();
listModules.clear();
listModulesCache.clear();
List<String> magisk = Utils.getModList(MAGISK_PATH);
......@@ -98,7 +94,6 @@ public class ModulesFragment extends Fragment {
listModules.add(new Module(mod));
}
}
if (!magiskCache.isEmpty()) {
for (String mod : magiskCache) {
listModulesCache.add(new Module(mod));
......
......@@ -2,6 +2,7 @@ package com.topjohnwu.magisk;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
......@@ -63,20 +64,14 @@ public class RootFragment extends Fragment {
new updateUI().execute();
rootToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
Shell.su(b ? "setprop magisk.root 1" : "setprop magisk.root 0");
new updateUI().execute();
}
rootToggle.setOnClickListener(toggle -> {
Shell.su(((CompoundButton) toggle).isChecked() ? "setprop magisk.root 1" : "setprop magisk.root 0");
new Handler().postDelayed(() -> new updateUI().execute(), 1000);
});
selinuxToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
Shell.su(b ? "setenforce 1" : "setenforce 0");
new updateUI().execute();
}
selinuxToggle.setOnClickListener(toggle -> {
Shell.su(((CompoundButton) toggle).isChecked() ? "setenforce 1" : "setenforce 0");
new Handler().postDelayed(() -> new updateUI().execute(), 1000);
});
return view;
......@@ -132,7 +127,6 @@ public class RootFragment extends Fragment {
}
if (new File("/system/framework/twframework.jar").exists()) {
selinuxToggleView.setVisibility(View.GONE);
selinuxStatus.append("\n" + getString(R.string.selinux_samsung_info));
}
......
......@@ -71,12 +71,7 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
if (savedInstanceState == null) {
mDrawerHandler.removeCallbacksAndMessages(null);
mDrawerHandler.postDelayed(new Runnable() {
@Override
public void run() {
navigate(mSelectedId);
}
}, 250);
mDrawerHandler.postDelayed(() -> navigate(mSelectedId), 250);
}
navigationView.setNavigationItemSelectedListener(this);
......@@ -103,12 +98,7 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
public boolean onNavigationItemSelected(@NonNull final MenuItem menuItem) {
mSelectedId = menuItem.getItemId();
mDrawerHandler.removeCallbacksAndMessages(null);
mDrawerHandler.postDelayed(new Runnable() {
@Override
public void run() {
navigate(menuItem.getItemId());
}
}, 250);
mDrawerHandler.postDelayed(() -> navigate(menuItem.getItemId()), 250);
drawer.closeDrawer(GravityCompat.START);
return true;
......
package com.topjohnwu.magisk.utils;
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
import com.topjohnwu.magisk.R;
import java.io.File;
/**
* Created by topjohnwu on 2016/8/27.
*/
public abstract class DownloadReceiver extends BroadcastReceiver{
public Context context;
DownloadManager downloadManager;
long downloadID;
public DownloadReceiver(long downloadID) {
this.downloadID = downloadID;
}
@Override
public void onReceive(Context context, Intent intent) {
this.context = context;
downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
String action = intent.getAction();
if(DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)){
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(downloadID);
Cursor c = downloadManager.query(query);
if (c.moveToFirst()) {
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
int status = c.getInt(columnIndex);
switch (status) {
case DownloadManager.STATUS_SUCCESSFUL:
File file = new File(Uri.parse(c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))).getPath());
task(file);
break;
default:
Toast.makeText(context, R.string.error_download_file, Toast.LENGTH_LONG).show();
break;
}
context.unregisterReceiver(this);
}
}
}
public abstract void task(File file);
}
......@@ -14,10 +14,8 @@ import java.util.List;
public class Shell {
public static String suPath;
// -1 = problematic/unknown issue; 0 = not rooted; 1 = properly rooted; 2 = improperly rooted;
public static int rootStatus = 0;
public static int rootStatus;
private static Process rootShell;
private static DataOutputStream rootSTDIN;
......@@ -29,27 +27,27 @@ public class Shell {
}
private static void init() {
List<String> ret = sh("getprop magisk.supath");
if(!ret.isEmpty()) {
suPath = ret.get(0) + "/su";
try {
rootShell = Runtime.getRuntime().exec(sh("getprop magisk.supath").get(0) + "/su");
rootStatus = 1;
} else {
suPath = "su";
} catch (IOException e) {
try {
// Improper root
rootShell = Runtime.getRuntime().exec("su");
rootStatus = 2;
} catch (IOException err) {
// No root
rootStatus = 0;
return;
}
}
try {
rootShell = Runtime.getRuntime().exec(suPath);
rootSTDIN = new DataOutputStream(rootShell.getOutputStream());
rootSTDOUT = new StreamGobbler(rootShell.getInputStream(), rootOutList);
rootSTDOUT.start();
} catch (IOException e) {
// runtime error! No binary found! Means no root
rootStatus = 0;
return;
}
ret = su("echo -BOC-", "id");
List<String> ret = su("echo -BOC-", "id");
if (ret == null) {
// Something wrong with root, not allowed?
rootStatus = -1;
......@@ -74,7 +72,6 @@ public class Shell {
if (rootAccess()) {
rootSTDIN.write("exit\n".getBytes("UTF-8"));
rootSTDIN.flush();
rootSTDIN.flush();
rootShell.waitFor();
rootSTDIN.close();
rootSTDOUT.join();
......@@ -133,17 +130,18 @@ public class Shell {
rootOutList.clear();
try {
try {
for (String write : commands) {
rootSTDIN.write((write + "\n").getBytes("UTF-8"));
rootSTDIN.flush();
}
rootSTDIN.write(("echo \' \'\n").getBytes("UTF-8"));
rootSTDIN.flush();
rootSTDIN.write(("echo \'-done-\'\n").getBytes("UTF-8"));
rootSTDIN.flush();
} catch (IOException e) {
if (!e.getMessage().contains("EPIPE")) {
throw e;
return null;
}
}
......@@ -154,21 +152,18 @@ public class Shell {
return null;
} catch (IllegalThreadStateException e) {
// Process still running, gobble output until done
if (rootOutList != null && !rootOutList.isEmpty()) {
if (rootOutList.get(rootOutList.size() - 1).equals("-done-")) {
rootOutList.remove(rootOutList.size() - 1);
int end = rootOutList.size() - 1;
if (rootOutList != null && end > 0) {
if (rootOutList.get(end).equals("-done-")) {
rootOutList.remove(end);
rootOutList.remove(end - 1);
break;
}
}
rootSTDOUT.join(100);
try { rootSTDOUT.join(100); } catch (InterruptedException err) { return null; }
}
}
} catch (IOException | InterruptedException e) {
// shell probably not found
return null;
}
return new ArrayList<>(rootOutList);
}
}
......@@ -36,7 +36,6 @@ public class StreamGobbler extends Thread {
try {
String line;
while ((line = reader.readLine()) != null) {
if (!line.replaceAll("\\s", "").isEmpty())
writer.add(line);
}
} catch (IOException e) {
......
......@@ -37,7 +37,7 @@ public class Utils {
public static List<String> readFile(String path) {
List<String> ret;
ret = Shell.sh("cat " + path);
if (ret.isEmpty() && Shell.rootAccess()) ret = Shell.su("cat " + path, "echo \' \'");
if (ret.isEmpty() && Shell.rootAccess()) ret = Shell.su("cat " + path);
return ret;
}
......
......@@ -12,14 +12,14 @@
<string name="root_mounted">Root mounted</string>
<string name="root_mounted_info">Root mounted and enabled. Safety Net (Android Pay) will NOT work</string>
<string name="root_unmounted">Root not mounted</string>
<string name="root_unmounted_info">Safety Net (Android Pay) should work, but no root temporarily</string>
<string name="root_unmounted_info">Safety Net (Android Pay) should work, but no root temporarily\nYou might need to manually add a card in Android Pay app to refresh the root status of AP</string>
<string name="root_system">Improperly Installed</string>
<string name="root_system_info">Root improperly installed. Safety Net (Android Pay) will NOT work, and impossible to toggle</string>
<string name="selinux_error_info">SELinux Status Unknown</string>
<string name="selinux_enforcing_info">SELinux is enforced</string>
<string name="selinux_permissive_info">SELinux is permissive\nOnly turn off SELinux if necessary!</string>
<string name="selinux_samsung_info">Samsung do not support switching SELinux status!</string>
<string name="selinux_samsung_info">Samsung need custom kernel for switching SELinux status!</string>
<string name="root_toggle">Root Toggle</string>
<string name="selinux_toggle">SELinux Toggle</string>
......
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external_files" path="."/>
</paths>
\ No newline at end of file
......@@ -6,8 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.android.tools.build:gradle:2.2.0-beta1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment