From 441e603bc099af5a08b709993c3b4b1add7c1624 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 27 Sep 2016 15:51:38 +0800 Subject: [PATCH] Update FlashZip to use Uri --- app/src/main/AndroidManifest.xml | 2 +- .../com/topjohnwu/magisk/MagiskFragment.java | 9 +- .../com/topjohnwu/magisk/ModulesAdapter.java | 220 ++------------- .../com/topjohnwu/magisk/ReposAdapter.java | 6 +- .../com/topjohnwu/magisk/module/Module.java | 24 +- .../magisk/receivers/DownloadReceiver.java | 6 +- .../com/topjohnwu/magisk/utils/Async.java | 264 ++++++------------ app/src/main/res/layout/list_item_module.xml | 126 +++------ app/src/main/res/values/strings.xml | 7 +- 9 files changed, 160 insertions(+), 504 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 658f47ac7..d8444dde1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,7 +24,7 @@ tools:ignore="AllowBackup,GoogleAppIndexingWarning"> diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java b/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java index 9842327b7..89c870099 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java @@ -4,6 +4,7 @@ import android.app.Fragment; import android.content.Intent; import android.content.res.TypedArray; import android.graphics.Color; +import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; @@ -138,8 +139,8 @@ public class MagiskFragment extends Fragment { getActivity(), new DownloadReceiver(getString(R.string.magisk)) { @Override - public void task(File file) { - new Async.FlashZIP(mContext, mName, file.getPath()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); + public void task(Uri uri) { + new Async.FlashZIP(mContext, uri).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); } }, Utils.magiskLink, "latest_magisk.zip")) @@ -164,10 +165,10 @@ public class MagiskFragment extends Fragment { .setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive(getActivity(), new DownloadReceiver() { @Override - public void task(File file) { + public void task(Uri uri) { Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE); install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - install.setData(FileProvider.getUriForFile(mContext, "com.topjohnwu.magisk.provider", file)); + install.setData(uri); mContext.startActivity(install); } }, diff --git a/app/src/main/java/com/topjohnwu/magisk/ModulesAdapter.java b/app/src/main/java/com/topjohnwu/magisk/ModulesAdapter.java index b39b177b0..98a6b6993 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ModulesAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/ModulesAdapter.java @@ -5,6 +5,7 @@ import android.animation.ValueAnimator; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; +import android.net.Uri; import android.os.AsyncTask; import android.preference.PreferenceManager; import android.support.v7.app.AlertDialog; @@ -38,29 +39,17 @@ import butterknife.ButterKnife; public class ModulesAdapter extends RecyclerView.Adapter { + //@BindView(R.id.expand_layout) LinearLayout expandedLayout; + private final List mList; - private final List mListToUpdate = new ArrayList<>(); - List mExpandedList; - @BindView(R.id.expand_layout) - LinearLayout expandedLayout; private View viewMain; private Context context; private final Utils.ItemClickListener chboxListener; private final Utils.ItemClickListener deleteBtnListener; private final Utils.ItemClickListener unDeleteBtnListener; - private boolean alertUpdate, ignoreAlertUpdate; public ModulesAdapter(List list, Utils.ItemClickListener chboxListener, Utils.ItemClickListener deleteBtnListener, Utils.ItemClickListener undeleteBtnListener) { - alertUpdate = false; this.mList = list; - mExpandedList = new ArrayList<>(mList.size()); - for (int i = 0; i < mList.size(); i++) { - mExpandedList.add(false); - if (mList.get(i).isUpdateAvailable()) { - alertUpdate = true; - mListToUpdate.add(mList.get(i)); - } - } this.chboxListener = chboxListener; this.deleteBtnListener = deleteBtnListener; this.unDeleteBtnListener = undeleteBtnListener; @@ -78,85 +67,24 @@ public class ModulesAdapter extends RecyclerView.Adapter iterRepo = mListToUpdate.iterator(); - while (iterRepo.hasNext()) { - Module mModule = iterRepo.next(); - DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> { - switch (which) { - case DialogInterface.BUTTON_POSITIVE: - DownloadReceiver receiver = new DownloadReceiver() { - @Override - public void task(File file) { - Log.d("Magisk", "Task firing"); - new Async.FlashZIP(context, mModule.getId(), file.toString()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); - } - }; - String filename = mModule.getId().replace(" ", "") + ".zip"; - Utils.downloadAndReceive(context, receiver, mModule.getmZipUrl(), filename); - - break; - - case DialogInterface.BUTTON_NEGATIVE: - ignoreAlertUpdate = true; - SharedPreferences.Editor editor = prefs.edit(); - editor.putBoolean("ignoreUpdateAlerts", ignoreAlertUpdate); - editor.apply(); - break; - } - }; - AlertDialog.Builder builder; - String theme = PreferenceManager.getDefaultSharedPreferences(context).getString("theme", ""); - if (theme.equals("Dark")) { - builder = new AlertDialog.Builder(context,R.style.AlertDialog_dh); - } else { - builder = new AlertDialog.Builder(context); - } - builder.setMessage("An update is available for " + mModule.getName() + ". Would you like to install it?").setPositiveButton("Yes", dialogClickListener) - .setNegativeButton("No", dialogClickListener).show(); - mListToUpdate.remove(mModule); - } - } + String author = module.getAuthor(); + String versionName = module.getVersion(); + String description = module.getDescription(); + if (versionName != null) { + holder.versionName.setText(versionName); + } + if (author != null) { + holder.author.setText(context.getString(R.string.author, author)); + } + if (description != null) { + holder.description.setText(description); } - View.OnClickListener oCl = view -> { - if (view.getId() == holder.changeLog.getId()) { - new WebWindow("Changelog", module.getmLogUrl(), context); - } - if (view.getId() == holder.authorLink.getId()) { - new WebWindow("Donate", module.getDonateUrl(), context); - } - if (view.getId() == holder.supportLink.getId()) { - new WebWindow("Support", module.getSupportUrl(), context); - } - }; - - holder.authorLink.setOnClickListener(oCl); - holder.changeLog.setOnClickListener(oCl); - holder.supportLink.setOnClickListener(oCl); holder.checkBox.setChecked(module.isEnabled()); holder.checkBox.setOnCheckedChangeListener((compoundButton, b) -> chboxListener.onItemClick(compoundButton, holder.getAdapterPosition())); @@ -190,33 +118,14 @@ public class ModulesAdapter extends RecyclerView.Adapter { - int position = getAdapterPosition(); - Log.d("Magisk", "ReposFragment: CLICK. " + position + " and " + mExpandedList.get(position)); - - if (mExpandedList.get(position)) { - collapse(expandLayout); - } else { - expand(expandLayout); - } - mExpandedList.set(position, !mExpandedList.get(position)); - - }); if (!Shell.rootAccess()) { checkBox.setEnabled(false); delete.setEnabled(false); } } - - private void expand(View view) { - - // set Visible - - - Log.d("Magisk", "ReposFragment: Expand anim called " + mMeasuredHeight + " and " + view.getId()); - view.setVisibility(View.VISIBLE); - mAnimator.start(); - } - - private void collapse(View view) { - int finalHeight = view.getHeight(); - ValueAnimator mAnimator = slideAnimator(finalHeight, 0); - Log.d("Magisk", "ReposFragment: Collapse anim called " + finalHeight + " and " + view.getId()); - - mAnimator.addListener(new Animator.AnimatorListener() { - @Override - public void onAnimationEnd(Animator animator) { - // Height=0, but it set visibility to GONE - view.setVisibility(View.GONE); - } - - @Override - public void onAnimationStart(Animator animator) { - } - - @Override - public void onAnimationCancel(Animator animator) { - } - - @Override - public void onAnimationRepeat(Animator animator) { - } - }); - mAnimator.start(); - } - - private ValueAnimator slideAnimator(int start, int end) { - - ValueAnimator animator = ValueAnimator.ofInt(start, end); - - animator.addUpdateListener(valueAnimator -> { - // Update Height - int value = (Integer) valueAnimator.getAnimatedValue(); - - ViewGroup.LayoutParams layoutParams = expandLayout - .getLayoutParams(); - layoutParams.height = value; - expandLayout.setLayoutParams(layoutParams); - }); - return animator; - } } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ReposAdapter.java b/app/src/main/java/com/topjohnwu/magisk/ReposAdapter.java index 386793d40..094f70fe1 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ReposAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/ReposAdapter.java @@ -6,6 +6,7 @@ import android.animation.ValueAnimator; import android.content.Context; import android.content.SharedPreferences; import android.graphics.Color; +import android.net.Uri; import android.os.AsyncTask; import android.preference.PreferenceManager; import android.support.v7.widget.RecyclerView; @@ -147,9 +148,8 @@ public class ReposAdapter extends RecyclerView.Adapter DownloadReceiver receiver = new DownloadReceiver() { @Override - public void task(File file) { - Log.d("Magisk", "Task firing"); - new Async.FlashZIP(context, repo.getId(), file.toString()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); + public void task(Uri uri) { + new Async.FlashZIP(context, uri, repo.getName() + "-v" + repo.getVersion()); } }; String filename = repo.getId().replace(" ", "") + ".zip"; diff --git a/app/src/main/java/com/topjohnwu/magisk/module/Module.java b/app/src/main/java/com/topjohnwu/magisk/module/Module.java index 16fb6e270..c6ffb920d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/module/Module.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/Module.java @@ -1,11 +1,5 @@ package com.topjohnwu.magisk.module; -import android.content.Context; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; -import android.util.Log; - -import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Utils; @@ -13,13 +7,10 @@ public class Module extends BaseModule { private String mRemoveFile; private String mDisableFile; - - private String mZipUrl, mLogUrl; private boolean mEnable, mRemove, mUpdateAvailable = false; - public Module(Context context, String path) { + public Module(String path) { - super(); parseProps(Utils.readFile(path + "/module.prop")); mRemoveFile = path + "/remove"; @@ -33,13 +24,7 @@ public class Module extends BaseModule { if (mName == null) mName = mId; - if (mDescription == null) - mDescription = context.getString(R.string.no_info_provided); - - if (mVersion == null) - mVersion = context.getString(R.string.no_info_provided); - - Logger.dh("Module id: " + mId); + Logger.dh("Creating Module, id: " + mId); mEnable = !Utils.itemExist(mDisableFile); mRemove = Utils.itemExist(mRemoveFile); @@ -52,12 +37,11 @@ public class Module extends BaseModule { repo.setInstalled(); if (repo.getVersionCode() > mVersionCode) { repo.setUpdate(); + mUpdateAvailable = true; } } } - public String getmLogUrl() {return mLogUrl; } - public void createDisableFile() { mEnable = !Utils.createFile(mDisableFile); } @@ -82,8 +66,6 @@ public class Module extends BaseModule { return mRemove; } - public String getmZipUrl() { return mZipUrl; } - public boolean isUpdateAvailable() { return mUpdateAvailable; } } \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java b/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java index 8e86f03f0..4dafb1d23 100644 --- a/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/DownloadReceiver.java @@ -38,8 +38,8 @@ public abstract class DownloadReceiver extends BroadcastReceiver { 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); + Uri uri = Uri.parse(c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))); + task(uri); break; default: Toast.makeText(context, R.string.download_file_error, Toast.LENGTH_LONG).show(); @@ -54,5 +54,5 @@ public abstract class DownloadReceiver extends BroadcastReceiver { downloadID = id; } - public abstract void task(File file); + public void task(Uri uri) {} } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java index 74f9575b0..8e112244b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java @@ -3,9 +3,12 @@ package com.topjohnwu.magisk.utils; import android.app.ProgressDialog; import android.content.ContentResolver; import android.content.Context; +import android.content.DialogInterface; import android.net.Uri; import android.os.AsyncTask; +import android.os.Environment; import android.preference.PreferenceManager; +import android.renderscript.ScriptGroup; import android.support.v7.app.AlertDialog; import android.util.Log; import android.widget.Toast; @@ -73,21 +76,10 @@ public class Async { @Override protected Void doInBackground(Void... voids) { + String jsonStr = WebRequest.makeWebServiceCall(Utils.UPDATE_JSON, WebRequest.GET); try { - HttpURLConnection c = (HttpURLConnection) new URL(Utils.UPDATE_JSON).openConnection(); - c.setRequestMethod("GET"); - c.setInstanceFollowRedirects(false); - c.setDoOutput(false); - c.connect(); + JSONObject json = new JSONObject(jsonStr); - BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream())); - StringBuilder sb = new StringBuilder(); - String line; - while ((line = br.readLine()) != null) { - sb.append(line); - } - br.close(); - JSONObject json = new JSONObject(sb.toString()); JSONObject magisk = json.getJSONObject("magisk"); JSONObject app = json.getJSONObject("app"); JSONObject root = json.getJSONObject("root"); @@ -102,9 +94,7 @@ public class Async { Utils.phhLink = root.getString("phh"); Utils.supersuLink = root.getString("supersu"); - - } catch (IOException | JSONException ignored) { - } + } catch (JSONException ignored) {} return null; } @@ -116,87 +106,16 @@ public class Async { .setTitle(R.string.no_magisk_title) .setMessage(R.string.no_magisk_msg) .setCancelable(true) - .setPositiveButton(R.string.download_install, (dialogInterface, i) -> new AlertDialog.Builder(mContext) - .setTitle(R.string.root_method_title) - .setItems(new String[]{mContext.getString(R.string.phh), mContext.getString(R.string.supersu)}, (dialogInterface1, root) -> { - DownloadReceiver rootReceiver; - String link, filename; - switch (root) { - case 0: - link = Utils.phhLink; - filename = "phhsu.zip"; - rootReceiver = new DownloadReceiver(mContext.getString(R.string.phh)) { - @Override - public void task(File file) { - new FlashZIP(mContext, mName, file.getPath()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); - } - }; - break; - case 1: - link = Utils.supersuLink; - filename = "supersu.zip"; - rootReceiver = new DownloadReceiver(mContext.getString(R.string.supersu)) { - @Override - public void task(File file) { - new FlashZIP(mContext, mName, file.getPath()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); - } - }; - break; - default: - rootReceiver = null; - link = filename = null; + .setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.downloadAndReceive( + mContext, + new DownloadReceiver(mContext.getString(R.string.magisk)) { + @Override + public void task(Uri uri) { + new FlashZIP(mContext, uri).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); } - DownloadReceiver magiskReceiver = new DownloadReceiver(mContext.getString(R.string.magisk)) { - @Override - public void task(File file) { - Context temp = mContext; - new FlashZIP(mContext, mName, file.getPath()) { - @Override - protected void done() { - Utils.downloadAndReceive(temp, rootReceiver, link, filename); - } - }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); - } - }; - Utils.downloadAndReceive(mContext, magiskReceiver, Utils.magiskLink, "latest_magisk.zip"); - }) - .show()) - .setNegativeButton(R.string.no_thanks, null) - .show(); - } else if (Shell.rootStatus == 2) { - new AlertDialog.Builder(mContext) - .setTitle(R.string.root_system) - .setMessage(R.string.root_system_msg) - .setCancelable(true) - .setPositiveButton(R.string.download_install, (dialogInterface, i) -> new AlertDialog.Builder(mContext) - .setTitle(R.string.root_method_title) - .setItems(new String[]{mContext.getString(R.string.phh), mContext.getString(R.string.supersu)}, (dialogInterface1, root) -> { - switch (root) { - case 0: - Utils.downloadAndReceive( - mContext, - new DownloadReceiver(mContext.getString(R.string.phh)) { - @Override - public void task(File file) { - new FlashZIP(mContext, mName, file.getPath()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); - } - }, - Utils.phhLink, "phhsu.zip"); - break; - case 1: - Utils.downloadAndReceive( - mContext, - new DownloadReceiver(mContext.getString(R.string.supersu)) { - @Override - public void task(File file) { - new FlashZIP(mContext, mName, file.getPath()).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); - } - }, - Utils.supersuLink, "supersu.zip"); - break; - } - }) - .show()) + }, + Utils.magiskLink, + "latest_magisk.zip")) .setNegativeButton(R.string.no_thanks, null) .show(); } @@ -220,12 +139,12 @@ public class Async { for (String mod : magisk) { Logger.dh("Adding modules from " + mod); - ModulesFragment.listModules.add(new Module(mContext, mod)); + ModulesFragment.listModules.add(new Module(mod)); } for (String mod : magiskCache) { Logger.dh("Adding cache modules from " + mod); - Module cacheMod = new Module(mContext, mod); + Module cacheMod = new Module(mod); // Prevent people forgot to change module.prop cacheMod.setCache(); ModulesFragment.listModules.add(cacheMod); @@ -264,126 +183,107 @@ public class Async { private String mPath, mName; private Uri mUri; private ProgressDialog progress; - private File mFile; + private File mFile, sdFile; private Context mContext; private List ret; - private boolean deleteFileAfter; + private boolean copyToSD; - public FlashZIP(Context context, String name, String path) { + public FlashZIP(Context context, Uri uri, String name) { mContext = context; + mUri = uri; mName = name; - mPath = path; - deleteFileAfter = false; + copyToSD = true; } - public FlashZIP(Context context, Uri uRi) { + public FlashZIP(Context context, Uri uri) { mContext = context; - mUri = uRi; - deleteFileAfter = true; - - String file; - FileInfo fileInfo = FileUtils.getFileInfo(context, mUri); - - Logger.dh("Utils: FlashZip Running, " + fileInfo.getPath()); - String filename = fileInfo.getPath(); - String idStr = filename.substring(filename.lastIndexOf('/') + 1); - if (!idStr.contains(".zip")) { - Logger.dh("Async: Improper name, cancelling " + idStr); - this.cancel(true); - progress.cancel(); - } - file = mContext.getFilesDir() + "/" + idStr; - - ContentResolver contentResolver = mContext.getContentResolver(); - //contentResolver.takePersistableUriPermission(mUri, flags); - try { - InputStream in = contentResolver.openInputStream(mUri); - Log.d("Magisk", "Firing inputStream"); - mFile = createFileFromInputStream(in, file); - if (mFile != null) { - mPath = mFile.getPath(); - Logger.dh("Async: Mpath is " + mPath); - } else { - Log.e("Magisk", "Async: error creating file " + mUri.getPath()); - this.cancel(true); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - - // TODO handle non-primary volumes - + mUri = uri; + mName = uri.getLastPathSegment(); + copyToSD = false; } - private static File createFileFromInputStream(InputStream inputStream, String fileName) { - - try { - File f = new File(fileName); - f.setWritable(true, false); - OutputStream outputStream = new FileOutputStream(f); - byte buffer[] = new byte[1024]; - int length; - - while ((length = inputStream.read(buffer)) > 0) { - outputStream.write(buffer, 0, length); - } - - outputStream.close(); - inputStream.close(); - Logger.dh("Async: File created successfully - " + f.getPath()); - return f; - - } catch (IOException e) { - System.out.println("error in creating a file"); - e.printStackTrace(); + private static void createFileFromInputStream(InputStream inputStream, File f) throws IOException { + if (f.exists() && !f.delete()) { + throw new IOException(); + } + f.setWritable(true, false); + OutputStream outputStream = new FileOutputStream(f); + byte buffer[] = new byte[1024]; + int length; + while ((length = inputStream.read(buffer)) > 0) { + outputStream.write(buffer, 0, length); } - return null; + outputStream.close(); + Logger.dh("FlashZip: File created successfully - " + f.getPath()); } @Override protected void onPreExecute() { super.onPreExecute(); - progress = ProgressDialog.show(mContext, mContext.getString(R.string.zip_install_progress_title), mContext.getString(R.string.zip_install_progress_msg, mName)); } @Override protected Boolean doInBackground(Void... voids) { - if (mPath == null) { - Log.e("Magisk", "Utils: Error, flashZIP called without a valid zip file to flash."); + Logger.dh("FlashZip Running... " + mName); + InputStream in; + try { + try { + in = mContext.getContentResolver().openInputStream(mUri); + mFile = new File(mContext.getFilesDir().getAbsolutePath() + "/install.zip"); + createFileFromInputStream(in, mFile); + } catch (FileNotFoundException e) { + Log.e("Magisk", "FlashZip: Invalid Uri"); + throw e; + } catch (IOException e) { + Log.e("Magisk", "FlashZip: Error in creating file"); + throw e; + } + } catch (Throwable e) { this.cancel(true); progress.cancel(); + e.printStackTrace(); return false; } - if (!Shell.rootAccess()) { - return false; - } else { + if (Shell.rootAccess()) { ret = Shell.su( - "rm -rf /data/tmp", - "mkdir -p /data/tmp", - "cp -af " + mPath + " /data/tmp/install.zip", - "unzip -o /data/tmp/install.zip META-INF/com/google/android/* -d /data/tmp", - "BOOTMODE=true sh /data/tmp/META-INF/com/google/android/update-binary dummy 1 /data/tmp/install.zip", + "unzip -o " + mFile.getPath() + " META-INF/com/google/android/* -d " + mFile.getParent(), + "BOOTMODE=true sh " + mFile.getParent() + "/META-INF/com/google/android/update-binary dummy 1 "+ mFile.getPath(), "if [ $? -eq 0 ]; then echo true; else echo false; fi" ); - Logger.dh("Async: ret is " + ret); - return ret != null && Boolean.parseBoolean(ret.get(ret.size() - 1)); + Logger.dh("FlashZip: Console log:\n" + ret); } + // Copy the file to sdcard + if (copyToSD) { + try { + sdFile = new File(Environment.getExternalStorageDirectory() + "/MagiskManager/" + (mName.contains(".zip") ? mName : mName + ".zip")); + if ((!sdFile.getParentFile().exists() && !sdFile.getParentFile().mkdirs()) || (sdFile.exists() && !sdFile.delete())) { + throw new IOException(); + } + createFileFromInputStream(in, sdFile); + assert in != null; + in.close(); + } catch (IOException e) { + Log.e("Magisk", "FlashZip: Unable to copy to sdcard"); + e.printStackTrace(); + } + } + mFile.delete(); + return ret == null || !Boolean.parseBoolean(ret.get(ret.size() - 1)); } @Override protected void onPostExecute(Boolean result) { super.onPostExecute(result); - //Shell.su("rm -rf /data/tmp"); - if (deleteFileAfter) { - Shell.su("rm -rf " + mPath); - Log.d("Magisk", "Utils: Deleting file " + mPath); - } progress.dismiss(); if (!result) { - Toast.makeText(mContext, mContext.getString(R.string.manual_install, mPath), Toast.LENGTH_LONG).show(); + if (sdFile == null) { + Toast.makeText(mContext, mContext.getString(R.string.install_error), Toast.LENGTH_LONG).show(); + } else { + Toast.makeText(mContext, mContext.getString(R.string.manual_install, mPath), Toast.LENGTH_LONG).show(); + } return; } done(); @@ -393,14 +293,14 @@ public class Async { AlertDialog.Builder builder; String theme = PreferenceManager.getDefaultSharedPreferences(mContext).getString("theme", ""); if (theme.equals("Dark")) { - builder = new AlertDialog.Builder(mContext,R.style.AlertDialog_dh); + builder = new AlertDialog.Builder(mContext, R.style.AlertDialog_dh); } else { builder = new AlertDialog.Builder(mContext); } builder .setTitle(R.string.reboot_title) .setMessage(R.string.reboot_msg) - .setPositiveButton(R.string.reboot, (dialogInterface1, i) -> Shell.su("reboot")) + .setPositiveButton(R.string.reboot, (dialogInterface1, i) -> Shell.su("sh -c reboot")) .setNegativeButton(R.string.no_thanks, null) .show(); } diff --git a/app/src/main/res/layout/list_item_module.xml b/app/src/main/res/layout/list_item_module.xml index 8ed40d379..b5649a314 100644 --- a/app/src/main/res/layout/list_item_module.xml +++ b/app/src/main/res/layout/list_item_module.xml @@ -41,18 +41,51 @@ android:layout_alignParentStart="true" android:layout_below="@id/title" android:textAppearance="?android:attr/textAppearanceSmall" + android:text="@string/no_info_provided" android:textColor="@android:color/tertiary_text_dark" android:textIsSelectable="false" android:textStyle="bold|italic"/> + + + + + + + android:paddingTop="20dp"> - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9b8d1f3f2..0cddd7b39 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -54,7 +54,7 @@ Module will not be removed at next reboot Module will be disabled at next reboot Module will be enabled at next reboot - Created by + Created by %1$s Save to SD @@ -83,12 +83,12 @@ No root access, functionality limited No thanks Accessibility service required for Magisk auto-unroot feature - Magisk Manager %1$s Update! New version v%2$s of %1$s is available!\nChangelog:\n%3$s Download and install Error downloading file - File downloaded in %1$s\nFlash it in recovery manually + Installation error! + Error in flashing file, zip file placed in %1$s\nFlash it in recovery manually Installation succeeded! Do you want to reboot now? Reboot @@ -101,6 +101,7 @@ SuperSU It seems that you have incompatible root installed\nDo you want to install Magisk compatible root now? + MagiskRox666 GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus Downloads