Fix some small issues

This commit is contained in:
topjohnwu 2017-01-25 16:45:55 +08:00
parent bcc695234c
commit 6eb814ef0b
5 changed files with 37 additions and 18 deletions

View File

@ -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;
});

View File

@ -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();
}
}

View File

@ -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();

View File

@ -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();
}
}

View File

@ -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);
}
}