From 6eb814ef0bc2255e6d32fb4047e190865850c86f Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 25 Jan 2017 16:45:55 +0800 Subject: [PATCH] Fix some small issues --- .../com/topjohnwu/magisk/SettingsActivity.java | 8 +------- .../com/topjohnwu/magisk/module/ModuleHelper.java | 13 +++++++++++++ .../magisk/superuser/SuRequestActivity.java | 11 ++++++++++- .../java/com/topjohnwu/magisk/utils/Async.java | 9 +++++---- .../java/com/topjohnwu/magisk/utils/Logger.java | 14 ++++++++------ 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java b/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java index 10101a026..e1412b9ed 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java @@ -91,13 +91,7 @@ public class SettingsActivity extends AppCompatActivity { Preference clear = findPreference("clear"); clear.setOnPreferenceClickListener((pref) -> { - SharedPreferences repoMap = getActivity().getSharedPreferences(ModuleHelper.FILE_KEY, Context.MODE_PRIVATE); - repoMap.edit() - .putString(ModuleHelper.ETAG_KEY, "") - .putInt(ModuleHelper.VERSION_KEY, 0) - .apply(); - new Async.LoadRepos(getActivity()).exec(); - Toast.makeText(getActivity(), R.string.repo_cache_cleared, Toast.LENGTH_LONG).show(); + ModuleHelper.clearRepoCache(getActivity()); return true; }); diff --git a/app/src/main/java/com/topjohnwu/magisk/module/ModuleHelper.java b/app/src/main/java/com/topjohnwu/magisk/module/ModuleHelper.java index 1ef42795c..4cc495a56 100644 --- a/app/src/main/java/com/topjohnwu/magisk/module/ModuleHelper.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/ModuleHelper.java @@ -2,11 +2,13 @@ package com.topjohnwu.magisk.module; import android.content.Context; import android.content.SharedPreferences; +import android.widget.Toast; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.ValueSortedMap; @@ -163,4 +165,15 @@ public class ModuleHelper { } } + public static void clearRepoCache(Context context) { + SharedPreferences repoMap = context.getSharedPreferences(FILE_KEY, Context.MODE_PRIVATE); + repoMap.edit() + .remove(ETAG_KEY) + .remove(VERSION_KEY) + .apply(); + Global.Events.repoLoadDone.isTriggered = false; + new Async.LoadRepos(context).exec(); + Toast.makeText(context, R.string.repo_cache_cleared, Toast.LENGTH_SHORT).show(); + } + } diff --git a/app/src/main/java/com/topjohnwu/magisk/superuser/SuRequestActivity.java b/app/src/main/java/com/topjohnwu/magisk/superuser/SuRequestActivity.java index b98172b4b..9eba08db9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/superuser/SuRequestActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/superuser/SuRequestActivity.java @@ -1,6 +1,7 @@ package com.topjohnwu.magisk.superuser; import android.content.ContentValues; +import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; @@ -10,7 +11,10 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.CountDownTimer; import android.support.v7.app.AppCompatActivity; +import android.view.MotionEvent; +import android.view.View; import android.view.Window; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ImageView; @@ -87,10 +91,15 @@ public class SuRequestActivity extends AppCompatActivity { grant_btn.setOnClickListener(v -> handleAction(true, timeoutList[timeout.getSelectedItemPosition()])); deny_btn.setOnClickListener(v -> handleAction(false, timeoutList[timeout.getSelectedItemPosition()])); - suPopup.setOnClickListener(v -> { + suPopup.setOnClickListener((v) -> { timer.cancel(); deny_btn.setText(getString(R.string.deny, "")); }); + timeout.setOnTouchListener((v, event) -> { + timer.cancel(); + deny_btn.setText(getString(R.string.deny, "")); + return false; + }); timer.start(); 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 7290a6ff4..0da57cf23 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java @@ -194,7 +194,7 @@ public class Async { publishProgress(mContext.getString(R.string.copying_msg)); mCachedFile = new File(mContext.getCacheDir().getAbsolutePath() + "/install.zip"); if (mCachedFile.exists() && !mCachedFile.delete()) { - Log.e(Logger.TAG, "FlashZip: Error while deleting already existing file"); + Logger.error("FlashZip: Error while deleting already existing file"); throw new IOException(); } try ( @@ -203,15 +203,16 @@ public class Async { ) { byte buffer[] = new byte[1024]; int length; + if (in == null) throw new FileNotFoundException(); while ((length = in.read(buffer)) > 0) { outputStream.write(buffer, 0, length); } Logger.dev("FlashZip: File created successfully - " + mCachedFile.getPath()); } catch (FileNotFoundException e) { - Log.e(Logger.TAG, "FlashZip: Invalid Uri"); + Logger.error("FlashZip: Invalid Uri"); throw e; } catch (IOException e) { - Log.e(Logger.TAG, "FlashZip: Error in creating file"); + Logger.error("FlashZip: Error in creating file"); throw e; } } @@ -331,7 +332,7 @@ public class Async { } @Override - protected void onPostExecute(Void aVoid) { + protected void onPostExecute(Void v) { Global.Events.blockDetectionDone.trigger(); } } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java b/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java index 1a36f6755..d287c79ac 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java @@ -7,26 +7,28 @@ import com.topjohnwu.magisk.Global; public class Logger { public static final String TAG = "Magisk"; - public static final String DEV_TAG = "Magisk: DEV"; - public static final String DEBUG_TAG = "Magisk: DEBUG"; public static void debug(String msg) { - Log.d(DEBUG_TAG, msg); + Log.d(TAG, "DEBUG: " + msg); + } + + public static void error(String msg) { + Log.e(TAG, "ERROR: " + msg); } public static void dev(String msg, Object... args) { if (Global.Configs.devLogging) { if (args.length == 1 && args[0] instanceof Throwable) { - Log.d(DEV_TAG, msg, (Throwable) args[0]); + Log.d(TAG, "DEV: " + msg, (Throwable) args[0]); } else { - Log.d(DEV_TAG, String.format(msg, args)); + Log.d(TAG, "DEV: " + String.format(msg, args)); } } } public static void dev(String msg) { if (Global.Configs.devLogging) { - Log.d(DEV_TAG, msg); + Log.d(TAG, "DEBUG: " + msg); } }