From 56f57c20a20a14bc64cd398b78110145c28ae3e8 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 19 Jul 2017 18:01:22 +0800 Subject: [PATCH] Update AsyncTasks to prevent memory leak --- .../topjohnwu/magisk/MagiskLogFragment.java | 122 +++++++++--------- .../topjohnwu/magisk/asyncs/CheckUpdates.java | 15 ++- .../com/topjohnwu/magisk/asyncs/FlashZip.java | 71 +++++----- .../com/topjohnwu/magisk/asyncs/LoadApps.java | 11 +- .../topjohnwu/magisk/asyncs/LoadModules.java | 8 +- .../topjohnwu/magisk/asyncs/LoadRepos.java | 13 +- .../topjohnwu/magisk/asyncs/MagiskHide.java | 12 +- .../topjohnwu/magisk/asyncs/ParallelTask.java | 29 ++++- .../magisk/asyncs/ProcessRepoZip.java | 8 +- .../com/topjohnwu/magisk/utils/Shell.java | 21 ++- .../topjohnwu/magisk/utils/StreamGobbler.java | 7 +- .../com/topjohnwu/magisk/utils/Utils.java | 17 --- 12 files changed, 193 insertions(+), 141 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskLogFragment.java b/app/src/main/java/com/topjohnwu/magisk/MagiskLogFragment.java index 92b6872c0..c11a5ddaa 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskLogFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskLogFragment.java @@ -1,17 +1,13 @@ package com.topjohnwu.magisk; -import android.Manifest; import android.annotation.SuppressLint; -import android.app.Activity; import android.content.pm.PackageManager; -import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.Snackbar; -import android.support.v4.app.ActivityCompat; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.Menu; @@ -28,13 +24,12 @@ import android.widget.Toast; import com.topjohnwu.magisk.asyncs.ParallelTask; import com.topjohnwu.magisk.components.Fragment; import com.topjohnwu.magisk.components.SnackbarMaker; -import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.magisk.utils.Shell; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Calendar; -import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; @@ -67,7 +62,7 @@ public class MagiskLogFragment extends Fragment { txtLog.setTextIsSelectable(true); - new LogManager(getActivity()).read(); + new LogManager().read(); return view; } @@ -81,7 +76,7 @@ public class MagiskLogFragment extends Fragment { @Override public void onResume() { super.onResume(); - new LogManager(getActivity()).read(); + new LogManager().read(); } @Override @@ -100,13 +95,13 @@ public class MagiskLogFragment extends Fragment { mClickedMenuItem = item; switch (item.getItemId()) { case R.id.menu_refresh: - new LogManager(getActivity()).read(); + new LogManager().read(); return true; case R.id.menu_save: - new LogManager(getActivity()).save(); + new LogManager().save(); return true; case R.id.menu_clear: - new LogManager(getActivity()).clear(); + new LogManager().clear(); return true; default: return true; @@ -129,29 +124,19 @@ public class MagiskLogFragment extends Fragment { private class LogManager extends ParallelTask { - int mode; - File targetFile; - - LogManager(Activity activity) { - super(activity); - } + private int mode; + private File targetFile; @SuppressLint("DefaultLocale") @Override protected Object doInBackground(Object... params) { + MagiskManager magiskManager = MagiskLogFragment.this.getApplication(); mode = (int) params[0]; switch (mode) { case 0: - List logList = Utils.readFile(magiskManager.shell, MAGISK_LOG); - - if (Utils.isValidShellResponse(logList)) { - StringBuilder llog = new StringBuilder(15 * 10 * 1024); - for (String s : logList) { - llog.append(s).append("\n"); - } - return llog.toString(); - } - return ""; + StringBuildingList logList = new StringBuildingList(); + magiskManager.shell.su(logList, "cat " + MAGISK_LOG); + return logList.toString(); case 1: magiskManager.shell.su_raw("echo > " + MAGISK_LOG); @@ -159,17 +144,6 @@ public class MagiskLogFragment extends Fragment { return ""; case 2: - if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); - } - return false; - } - - if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { - return false; - } - Calendar now = Calendar.getInstance(); String filename = String.format( "magisk_%s_%04d%02d%02d_%02d%02d%02d.log", "error", @@ -184,19 +158,14 @@ public class MagiskLogFragment extends Fragment { return false; } - List in = Utils.readFile(magiskManager.shell, MAGISK_LOG); - - if (Utils.isValidShellResponse(in)) { - try (FileWriter out = new FileWriter(targetFile)) { - for (String line : in) - out.write(line + "\n"); - return true; - } catch (IOException e) { - e.printStackTrace(); - return false; - } + try (FileWriter out = new FileWriter(targetFile)) { + FileWritingList fileWritingList = new FileWritingList(out); + magiskManager.shell.su(fileWritingList, "cat " + MAGISK_LOG); + } catch (IOException e) { + e.printStackTrace(); + return false; } - return false; + return true; } return null; } @@ -204,12 +173,10 @@ public class MagiskLogFragment extends Fragment { @Override protected void onPostExecute(Object o) { if (o == null) return; - boolean bool; - String llog; switch (mode) { case 0: case 1: - llog = (String) o; + String llog = (String) o; progressBar.setVisibility(View.GONE); if (TextUtils.isEmpty(llog)) txtLog.setText(R.string.log_is_empty); @@ -219,27 +186,64 @@ public class MagiskLogFragment extends Fragment { hsvLog.post(() -> hsvLog.scrollTo(0, 0)); break; case 2: - bool = (boolean) o; + boolean bool = (boolean) o; if (bool) { - Toast.makeText(getActivity(), targetFile.toString(), Toast.LENGTH_LONG).show(); + MagiskLogFragment.this.getApplication().toast(targetFile.toString(), Toast.LENGTH_LONG); } else { - Toast.makeText(getActivity(), getString(R.string.logs_save_failed), Toast.LENGTH_LONG).show(); + MagiskLogFragment.this.getApplication().toast(R.string.logs_save_failed, Toast.LENGTH_LONG); } break; } } - public void read() { + void read() { exec(0); } - public void clear() { + void clear() { exec(1); } - public void save() { + void save() { exec(2); } } + private static class StringBuildingList extends Shell.AbstractList { + + StringBuilder builder; + + StringBuildingList() { + builder = new StringBuilder(); + } + + @Override + public boolean add(String s) { + builder.append(s).append("\n"); + return true; + } + + @Override + public String toString() { + return builder.toString(); + } + } + + private static class FileWritingList extends Shell.AbstractList { + + private FileWriter writer; + + FileWritingList(FileWriter out) { + writer = out; + } + + @Override + public boolean add(String s) { + try { + writer.write(s + "\n"); + } catch (IOException ignored) {} + return true; + } + } + } diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java index 2da16d2f5..a7d4fb00f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java @@ -3,6 +3,7 @@ package com.topjohnwu.magisk.asyncs; import android.content.Context; import com.topjohnwu.magisk.BuildConfig; +import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.WebService; @@ -15,17 +16,19 @@ public class CheckUpdates extends ParallelTask { private boolean showNotification = false; - public CheckUpdates(Context context, boolean b) { - this(context); - showNotification = b; + public CheckUpdates(Context context) { + super(context); } - public CheckUpdates(Context context) { - magiskManager = Utils.getMagiskManager(context); + public CheckUpdates(Context context, boolean b) { + super(context); + showNotification = b; } @Override protected Void doInBackground(Void... voids) { + MagiskManager magiskManager = getMagiskManager(); + if (magiskManager == null) return null; String jsonStr = WebService.request(UPDATE_JSON, WebService.GET); try { JSONObject json = new JSONObject(jsonStr); @@ -44,6 +47,8 @@ public class CheckUpdates extends ParallelTask { @Override protected void onPostExecute(Void v) { + MagiskManager magiskManager = getMagiskManager(); + if (magiskManager == null) return; if (showNotification && magiskManager.updateNotification) { if (BuildConfig.VERSION_CODE < magiskManager.remoteManagerVersionCode) { Utils.showManagerUpdate(magiskManager); diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/FlashZip.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/FlashZip.java index 6a9af3613..3a68947db 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/FlashZip.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/FlashZip.java @@ -1,6 +1,6 @@ package com.topjohnwu.magisk.asyncs; -import android.app.Activity; +import android.content.Context; import android.net.Uri; import android.text.TextUtils; @@ -26,44 +26,22 @@ public class FlashZip extends ParallelTask { private String mFilename; private AdaptiveList mList; - public FlashZip(Activity context, Uri uri, AdaptiveList list) { + public FlashZip(Context context, Uri uri, AdaptiveList list) { super(context); mUri = uri; mList = list; - mCachedFile = new File(magiskManager.getCacheDir(), "install.zip"); - mScriptFile = new File(magiskManager.getCacheDir(), "/META-INF/com/google/android/update-binary"); + mCachedFile = new File(context.getCacheDir(), "install.zip"); + mScriptFile = new File(context.getCacheDir(), "/META-INF/com/google/android/update-binary"); mCheckFile = new File(mScriptFile.getParent(), "updater-script"); // Try to get the filename ourselves - mFilename = Utils.getNameFromUri(magiskManager, mUri); - } - - private void copyToCache() throws Exception { - mList.add(magiskManager.getString(R.string.copying_msg)); - - mCachedFile.delete(); - try ( - InputStream in = magiskManager.getContentResolver().openInputStream(mUri); - OutputStream outputStream = new FileOutputStream(mCachedFile) - ) { - byte buffer[] = new byte[1024]; - int length; - if (in == null) throw new FileNotFoundException(); - while ((length = in.read(buffer)) > 0) - outputStream.write(buffer, 0, length); - } catch (FileNotFoundException e) { - mList.add("! Invalid Uri"); - throw e; - } catch (IOException e) { - mList.add("! Cannot copy to cache"); - throw e; - } + mFilename = Utils.getNameFromUri(context, mUri); } private boolean unzipAndCheck() throws Exception { ZipUtils.unzip(mCachedFile, mCachedFile.getParentFile(), "META-INF/com/google/android"); - List ret = Utils.readFile(magiskManager.shell, mCheckFile.getPath()); + List ret = Utils.readFile(getShell(), mCheckFile.getPath()); return Utils.isValidShellResponse(ret) && ret.get(0).contains("#MAGISK"); } @@ -80,8 +58,28 @@ public class FlashZip extends ParallelTask { @Override protected Integer doInBackground(Void... voids) { + MagiskManager magiskManager = getMagiskManager(); + if (magiskManager == null) return -1; try { - copyToCache(); + mList.add(magiskManager.getString(R.string.copying_msg)); + + mCachedFile.delete(); + try ( + InputStream in = magiskManager.getContentResolver().openInputStream(mUri); + OutputStream outputStream = new FileOutputStream(mCachedFile) + ) { + if (in == null) throw new FileNotFoundException(); + byte buffer[] = new byte[1024]; + int length; + while ((length = in.read(buffer)) > 0) + outputStream.write(buffer, 0, length); + } catch (FileNotFoundException e) { + mList.add("! Invalid Uri"); + throw e; + } catch (IOException e) { + mList.add("! Cannot copy to cache"); + throw e; + } if (!unzipAndCheck()) return 0; mList.add(magiskManager.getString(R.string.zip_install_progress_msg, mFilename)); magiskManager.shell.su(mList, @@ -99,6 +97,8 @@ public class FlashZip extends ParallelTask { // -1 = error, manual install; 0 = invalid zip; 1 = success @Override protected void onPostExecute(Integer result) { + MagiskManager magiskManager = getMagiskManager(); + if (magiskManager == null) return; magiskManager.shell.su_raw( "rm -rf " + mCachedFile.getParent() + "/*", "rm -rf " + MagiskManager.TMP_FOLDER_PATH @@ -106,19 +106,16 @@ public class FlashZip extends ParallelTask { switch (result) { case -1: mList.add(magiskManager.getString(R.string.install_error)); - Utils.showUriSnack(activity, mUri); - break; + Utils.showUriSnack(getActivity(), mUri); + return; case 0: mList.add(magiskManager.getString(R.string.invalid_zip)); - break; + return; case 1: - onSuccess(); + // Success break; } + new LoadModules(magiskManager).exec(); super.onPostExecute(result); } - - protected void onSuccess() { - new LoadModules(activity).exec(); - } } diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/LoadApps.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/LoadApps.java index 3efa36d3d..ec38297b7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/LoadApps.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/LoadApps.java @@ -1,9 +1,10 @@ package com.topjohnwu.magisk.asyncs; -import android.app.Activity; +import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.adapters.ApplicationAdapter; import java.util.Collections; @@ -12,12 +13,14 @@ import java.util.List; public class LoadApps extends ParallelTask { - public LoadApps(Activity context) { + public LoadApps(Context context) { super(context); } @Override protected Void doInBackground(Void... voids) { + MagiskManager magiskManager = getMagiskManager(); + if (magiskManager == null) return null; PackageManager pm = magiskManager.getPackageManager(); List list = pm.getInstalledApplications(0); for (Iterator i = list.iterator(); i.hasNext(); ) { @@ -34,6 +37,8 @@ public class LoadApps extends ParallelTask { @Override protected void onPostExecute(Void v) { - new MagiskHide(activity).list(); + MagiskManager magiskManager = getMagiskManager(); + if (magiskManager == null) return; + new MagiskHide(magiskManager).list(); } } diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/LoadModules.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/LoadModules.java index 18911d6a3..de8161524 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/LoadModules.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/LoadModules.java @@ -1,6 +1,6 @@ package com.topjohnwu.magisk.asyncs; -import android.app.Activity; +import android.content.Context; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.module.BaseModule; @@ -11,12 +11,14 @@ import com.topjohnwu.magisk.utils.ValueSortedMap; public class LoadModules extends ParallelTask { - public LoadModules(Activity context) { + public LoadModules(Context context) { super(context); } @Override protected Void doInBackground(Void... voids) { + MagiskManager magiskManager = getMagiskManager(); + if (magiskManager == null) return null; Logger.dev("LoadModules: Loading modules"); magiskManager.moduleMap = new ValueSortedMap<>(); @@ -35,6 +37,8 @@ public class LoadModules extends ParallelTask { @Override protected void onPostExecute(Void v) { + MagiskManager magiskManager = getMagiskManager(); + if (magiskManager == null) return; magiskManager.moduleLoadDone.trigger(); super.onPostExecute(v); } diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/LoadRepos.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/LoadRepos.java index 42cf8bdd9..37f41435c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/LoadRepos.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/LoadRepos.java @@ -1,9 +1,10 @@ package com.topjohnwu.magisk.asyncs; -import android.app.Activity; +import android.content.Context; import android.content.SharedPreferences; import android.text.TextUtils; +import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.database.RepoDatabaseHelper; import com.topjohnwu.magisk.module.BaseModule; import com.topjohnwu.magisk.module.Repo; @@ -41,11 +42,11 @@ public class LoadRepos extends ParallelTask { private RepoDatabaseHelper repoDB; private SharedPreferences prefs; - public LoadRepos(Activity context) { + public LoadRepos(Context context) { super(context); - prefs = magiskManager.prefs; + prefs = getMagiskManager().prefs; String prefsPath = context.getApplicationInfo().dataDir + "/shared_prefs"; - repoDB = new RepoDatabaseHelper(magiskManager); + repoDB = new RepoDatabaseHelper(context); // Legacy data cleanup File old = new File(prefsPath, "RepoMap.xml"); if (old.exists() || !prefs.getString("repomap", "empty").equals("empty")) { @@ -154,6 +155,8 @@ public class LoadRepos extends ParallelTask { @Override protected Void doInBackground(Void... voids) { + MagiskManager magiskManager = getMagiskManager(); + if (magiskManager == null) return null; Logger.dev("LoadRepos: Loading repos"); cached = repoDB.getRepoMap(false); @@ -183,6 +186,8 @@ public class LoadRepos extends ParallelTask { @Override protected void onPostExecute(Void v) { + MagiskManager magiskManager = getMagiskManager(); + if (magiskManager == null) return; magiskManager.repoLoadDone.trigger(); super.onPostExecute(v); } diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/MagiskHide.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/MagiskHide.java index 9bd1f2f34..531829c74 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/MagiskHide.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/MagiskHide.java @@ -1,6 +1,8 @@ package com.topjohnwu.magisk.asyncs; -import android.app.Activity; +import android.content.Context; + +import com.topjohnwu.magisk.MagiskManager; import java.util.List; @@ -8,12 +10,14 @@ public class MagiskHide extends ParallelTask { private boolean isList = false; - public MagiskHide(Activity context) { + public MagiskHide(Context context) { super(context); } @Override protected Void doInBackground(Object... params) { + MagiskManager magiskManager = getMagiskManager(); + if (magiskManager == null) return null; String command = (String) params[0]; List ret = magiskManager.shell.su("magiskhide --" + command); if (isList) { @@ -24,6 +28,8 @@ public class MagiskHide extends ParallelTask { @Override protected void onPostExecute(Void v) { + MagiskManager magiskManager = getMagiskManager(); + if (magiskManager == null) return; if (isList) { magiskManager.magiskHideDone.trigger(); } @@ -48,7 +54,7 @@ public class MagiskHide extends ParallelTask { public void list() { isList = true; - if (magiskManager == null) return; + if (getMagiskManager() == null) return; exec("ls"); } diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/ParallelTask.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/ParallelTask.java index 9400fe1f8..188fb96c5 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/ParallelTask.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/ParallelTask.java @@ -1,23 +1,44 @@ package com.topjohnwu.magisk.asyncs; import android.app.Activity; +import android.content.Context; import android.os.AsyncTask; import com.topjohnwu.magisk.MagiskManager; +import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; +import java.lang.ref.WeakReference; + public abstract class ParallelTask extends AsyncTask { - protected Activity activity; - protected MagiskManager magiskManager; + private WeakReference weakActivity; + private WeakReference weakMagiskManager; private Runnable callback = null; public ParallelTask() {} + public ParallelTask(Context context) { + weakMagiskManager = new WeakReference<>(Utils.getMagiskManager(context)); + } + public ParallelTask(Activity context) { - activity = context; - magiskManager = Utils.getMagiskManager(context); + this((Context) context); + weakActivity = new WeakReference<>(context); + } + + protected Activity getActivity() { + return weakActivity.get(); + } + + protected MagiskManager getMagiskManager() { + return weakMagiskManager.get(); + } + + protected Shell getShell() { + MagiskManager magiskManager = getMagiskManager(); + return magiskManager == null ? null : getMagiskManager().shell; } @SuppressWarnings("unchecked") diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java index e99467027..3ecd63e5d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java @@ -32,6 +32,8 @@ public class ProcessRepoZip extends ParallelTask { @Override protected void onPreExecute() { + Activity activity = getActivity(); + if (activity == null) return; progressDialog = ProgressDialog.show(activity, activity.getString(R.string.zip_process_title), activity.getString(R.string.zip_process_msg)); @@ -39,6 +41,8 @@ public class ProcessRepoZip extends ParallelTask { @Override protected Boolean doInBackground(Void... params) { + Activity activity = getActivity(); + if (activity == null) return null; try { // Create temp file @@ -84,6 +88,8 @@ public class ProcessRepoZip extends ParallelTask { @Override protected void onPostExecute(Boolean result) { + Activity activity = getActivity(); + if (activity == null) return; progressDialog.dismiss(); if (result) { if (Shell.rootAccess() && mInstall) { @@ -92,7 +98,7 @@ public class ProcessRepoZip extends ParallelTask { Utils.showUriSnack(activity, mUri); } } else { - magiskManager.toast(R.string.process_error, Toast.LENGTH_LONG); + Utils.getMagiskManager(activity).toast(R.string.process_error, Toast.LENGTH_LONG); } } } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java b/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java index b3383858c..af71d39c7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java @@ -8,6 +8,7 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.Collection; import java.util.List; /** @@ -116,7 +117,7 @@ public class Shell { } } - public void sh(List output, String... commands) { + public void sh(Collection output, String... commands) { if (!isValid) return; try { shellProcess.exitValue(); @@ -144,8 +145,24 @@ public class Shell { sh_raw(commands); } - public void su(List output, String... commands) { + public void su(Collection output, String... commands) { if (!rootAccess()) return; sh(output, commands); } + + public static abstract class AbstractList extends java.util.AbstractList { + + @Override + public abstract boolean add(E e); + + @Override + public E get(int i) { + return null; + } + + @Override + public int size() { + return 0; + } + } } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/StreamGobbler.java b/app/src/main/java/com/topjohnwu/magisk/utils/StreamGobbler.java index 014407b49..3544cb422 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/StreamGobbler.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/StreamGobbler.java @@ -6,7 +6,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.util.List; +import java.util.Collection; /** * Modified by topjohnwu, based on Chainfire's libsuperuser @@ -15,8 +15,7 @@ import java.util.List; public class StreamGobbler extends Thread { private BufferedReader reader = null; - private List writer = null; - private boolean isRoot = false; + private Collection writer = null; /** *

StreamGobbler constructor

@@ -28,7 +27,7 @@ public class StreamGobbler extends Thread { * @param inputStream InputStream to read from * @param outputList {@literal List} to write to, or null */ - public StreamGobbler(InputStream inputStream, List outputList) { + public StreamGobbler(InputStream inputStream, Collection outputList) { try { while (inputStream.available() != 0) { inputStream.skip(inputStream.available()); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 4ff21872e..613bd051f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -108,23 +108,6 @@ public class Utils { .replace("#", "").replace("@", "").replace("*", ""); } - public static String detectBootImage(Shell shell) { - String[] commands = { - "for PARTITION in kern-a KERN-A android_boot ANDROID_BOOT kernel KERNEL boot BOOT lnx LNX; do", - "BOOTIMAGE=`readlink /dev/block/by-name/$PARTITION || " + - "readlink /dev/block/platform/*/by-name/$PARTITION || " + - "readlink /dev/block/platform/*/*/by-name/$PARTITION`", - "if [ ! -z \"$BOOTIMAGE\" ]; then break; fi", - "done", - "echo \"$BOOTIMAGE\"" - }; - List ret = shell.su(commands); - if (isValidShellResponse(ret)) { - return ret.get(0); - } - return null; - } - public static boolean lowercaseContains(CharSequence string, CharSequence nonNullLowercaseSearch) { return !TextUtils.isEmpty(string) && string.toString().toLowerCase().contains(nonNullLowercaseSearch); }