Add tabs to log fragment
This commit is contained in:
parent
959ed7f866
commit
ca9334b2df
@ -49,9 +49,12 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
|
|
||||||
compile 'com.android.support:recyclerview-v7:25.1.0'
|
compile 'com.android.support:recyclerview-v7:25.1.0'
|
||||||
compile 'com.android.support:cardview-v7:25.1.0'
|
compile 'com.android.support:cardview-v7:25.1.0'
|
||||||
compile 'com.android.support:design:25.1.0'
|
compile 'com.android.support:design:25.1.0'
|
||||||
|
compile 'com.android.support:support-v4:25.1.0'
|
||||||
|
compile 'com.android.support:support-v13:25.1.0'
|
||||||
compile 'com.jakewharton:butterknife:8.4.0'
|
compile 'com.jakewharton:butterknife:8.4.0'
|
||||||
compile 'com.google.code.gson:gson:2.8.0'
|
compile 'com.google.code.gson:gson:2.8.0'
|
||||||
compile 'com.github.clans:fab:1.6.4'
|
compile 'com.github.clans:fab:1.6.4'
|
||||||
@ -60,6 +63,5 @@ dependencies {
|
|||||||
compile 'com.madgag.spongycastle:pkix:1.54.0.0'
|
compile 'com.madgag.spongycastle:pkix:1.54.0.0'
|
||||||
compile 'com.madgag.spongycastle:pg:1.54.0.0'
|
compile 'com.madgag.spongycastle:pg:1.54.0.0'
|
||||||
compile 'com.google.android.gms:play-services-safetynet:9.0.1'
|
compile 'com.google.android.gms:play-services-safetynet:9.0.1'
|
||||||
compile 'com.android.support:support-v4:25.1.0'
|
|
||||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
|
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@ public class Global {
|
|||||||
public static String releaseNoteLink;
|
public static String releaseNoteLink;
|
||||||
public static int SNCheckResult = -1;
|
public static int SNCheckResult = -1;
|
||||||
public static String bootBlock = null;
|
public static String bootBlock = null;
|
||||||
|
public static boolean isSuClient = false;
|
||||||
|
public static String suVersion = null;
|
||||||
}
|
}
|
||||||
public static class Data {
|
public static class Data {
|
||||||
public static ValueSortedMap<String, Repo> repoMap = new ValueSortedMap<>();
|
public static ValueSortedMap<String, Repo> repoMap = new ValueSortedMap<>();
|
||||||
@ -56,6 +58,11 @@ public class Global {
|
|||||||
Configs.isDarkTheme = prefs.getBoolean("dark_theme", false);
|
Configs.isDarkTheme = prefs.getBoolean("dark_theme", false);
|
||||||
Configs.devLogging = prefs.getBoolean("developer_logging", false);
|
Configs.devLogging = prefs.getBoolean("developer_logging", false);
|
||||||
Configs.shellLogging = prefs.getBoolean("shell_logging", false);
|
Configs.shellLogging = prefs.getBoolean("shell_logging", false);
|
||||||
|
List<String> ret = Shell.sh("su -v");
|
||||||
|
if (Utils.isValidShellResponse(ret)) {
|
||||||
|
Info.suVersion = ret.get(0);
|
||||||
|
Info.isSuClient = Info.suVersion.toUpperCase().contains("MAGISK");
|
||||||
|
}
|
||||||
updateMagiskInfo();
|
updateMagiskInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,40 +1,17 @@
|
|||||||
package com.topjohnwu.magisk;
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Intent;
|
import android.app.FragmentManager;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.support.design.widget.TabLayout;
|
||||||
import android.os.Handler;
|
import android.support.v13.app.FragmentPagerAdapter;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.v4.view.ViewPager;
|
||||||
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.LayoutInflater;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.HorizontalScrollView;
|
|
||||||
import android.widget.ProgressBar;
|
|
||||||
import android.widget.ScrollView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.utils.Async;
|
import java.util.ArrayList;
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
@ -43,46 +20,32 @@ import butterknife.Unbinder;
|
|||||||
|
|
||||||
public class LogFragment extends Fragment {
|
public class LogFragment extends Fragment {
|
||||||
|
|
||||||
private static final String MAGISK_LOG = "/cache/magisk.log";
|
|
||||||
|
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
@BindView(R.id.txtLog) TextView txtLog;
|
|
||||||
@BindView(R.id.svLog) ScrollView svLog;
|
|
||||||
@BindView(R.id.hsvLog) HorizontalScrollView hsvLog;
|
|
||||||
|
|
||||||
@BindView(R.id.progressBar) ProgressBar progressBar;
|
@BindView(R.id.container) ViewPager viewPager;
|
||||||
|
@BindView(R.id.tab) TabLayout tab;
|
||||||
|
|
||||||
private MenuItem mClickedMenuItem;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
super.onCreate(savedInstanceState);
|
Bundle savedInstanceState) {
|
||||||
setHasOptionsMenu(true);
|
// Inflate the layout for this fragment
|
||||||
|
View v = inflater.inflate(R.layout.fragment_log, container, false);
|
||||||
|
unbinder = ButterKnife.bind(this, v);
|
||||||
|
|
||||||
|
ViewPagerAdapter adapter = new ViewPagerAdapter(getChildFragmentManager());
|
||||||
|
|
||||||
|
adapter.addTab(new MagiskLogFragment(), getString(R.string.magisk));
|
||||||
|
|
||||||
|
if (Global.Info.isSuClient) {
|
||||||
|
adapter.addTab(new SuLogFragment(), getString(R.string.superuser));
|
||||||
|
tab.setupWithViewPager(viewPager);
|
||||||
|
tab.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
viewPager.setAdapter(adapter);
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
||||||
View view = inflater.inflate(R.layout.fragment_log, container, false);
|
|
||||||
unbinder = ButterKnife.bind(this, view);
|
|
||||||
|
|
||||||
txtLog.setTextIsSelectable(true);
|
return v;
|
||||||
|
|
||||||
new LogManager().read();
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
getActivity().setTitle(R.string.log);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
new LogManager().read();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -91,168 +54,38 @@ public class LogFragment extends Fragment {
|
|||||||
unbinder.unbind();
|
unbinder.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class ViewPagerAdapter extends FragmentPagerAdapter {
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
||||||
inflater.inflate(R.menu.menu_log, menu);
|
List<Fragment> fragmentList;
|
||||||
|
List<String> titleList;
|
||||||
|
|
||||||
|
public ViewPagerAdapter(FragmentManager fm) {
|
||||||
|
super(fm);
|
||||||
|
fragmentList = new ArrayList<>();
|
||||||
|
titleList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public Fragment getItem(int position) {
|
||||||
mClickedMenuItem = item;
|
return fragmentList.get(position);
|
||||||
switch (item.getItemId()) {
|
|
||||||
case R.id.menu_refresh:
|
|
||||||
new LogManager().read();
|
|
||||||
return true;
|
|
||||||
case R.id.menu_send:
|
|
||||||
new LogManager().send();
|
|
||||||
return true;
|
|
||||||
case R.id.menu_save:
|
|
||||||
new LogManager().save();
|
|
||||||
return true;
|
|
||||||
case R.id.menu_clear:
|
|
||||||
new LogManager().clear();
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
public int getCount() {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
return fragmentList.size();
|
||||||
if (requestCode == 0) {
|
|
||||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
||||||
if (mClickedMenuItem != null) {
|
|
||||||
new Handler().postDelayed(() -> onOptionsItemSelected(mClickedMenuItem), 500);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Snackbar.make(txtLog, R.string.permissionNotGranted, Snackbar.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LogManager extends Async.RootTask<Object, Void, Object> {
|
|
||||||
|
|
||||||
int mode;
|
|
||||||
File targetFile;
|
|
||||||
|
|
||||||
@SuppressLint("DefaultLocale")
|
|
||||||
@Override
|
|
||||||
protected Object doInBackground(Object... params) {
|
|
||||||
mode = (int) params[0];
|
|
||||||
switch (mode) {
|
|
||||||
case 0:
|
|
||||||
List<String> logList = Utils.readFile(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 "";
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
Shell.su("echo > " + MAGISK_LOG);
|
|
||||||
Snackbar.make(txtLog, R.string.logs_cleared, Snackbar.LENGTH_SHORT).show();
|
|
||||||
return "";
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
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",
|
|
||||||
now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,
|
|
||||||
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
|
|
||||||
now.get(Calendar.MINUTE), now.get(Calendar.SECOND));
|
|
||||||
|
|
||||||
targetFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/MagiskManager/" + filename);
|
|
||||||
|
|
||||||
if ((!targetFile.getParentFile().exists() && !targetFile.getParentFile().mkdirs())
|
|
||||||
|| (targetFile.exists() && !targetFile.delete()))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
List<String> in = Utils.readFile(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Object o) {
|
public CharSequence getPageTitle(int position) {
|
||||||
if (o == null) return;
|
return titleList.get(position);
|
||||||
boolean bool;
|
|
||||||
String llog;
|
|
||||||
switch (mode) {
|
|
||||||
case 0:
|
|
||||||
case 1:
|
|
||||||
llog = (String) o;
|
|
||||||
progressBar.setVisibility(View.GONE);
|
|
||||||
if (TextUtils.isEmpty(llog))
|
|
||||||
txtLog.setText(R.string.log_is_empty);
|
|
||||||
else
|
|
||||||
txtLog.setText(llog);
|
|
||||||
svLog.post(() -> svLog.scrollTo(0, txtLog.getHeight()));
|
|
||||||
hsvLog.post(() -> hsvLog.scrollTo(0, 0));
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
bool = (boolean) o;
|
|
||||||
if (bool)
|
|
||||||
Toast.makeText(getActivity(), targetFile.toString(), Toast.LENGTH_LONG).show();
|
|
||||||
else
|
|
||||||
Toast.makeText(getActivity(), getString(R.string.logs_save_failed), Toast.LENGTH_LONG).show();
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
bool = (boolean) o;
|
|
||||||
if (bool) {
|
|
||||||
Intent sendIntent = new Intent();
|
|
||||||
sendIntent.setAction(Intent.ACTION_SEND);
|
|
||||||
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(targetFile));
|
|
||||||
sendIntent.setType("application/html");
|
|
||||||
startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.menuSend)));
|
|
||||||
} else {
|
|
||||||
Toast.makeText(getActivity(), getString(R.string.logs_save_failed), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addTab(Fragment fragment, String title) {
|
||||||
|
fragmentList.add(fragment);
|
||||||
|
titleList.add(title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read() {
|
|
||||||
exec(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
exec(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
exec(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void send() {
|
|
||||||
exec(3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
258
app/src/main/java/com/topjohnwu/magisk/MagiskLogFragment.java
Normal file
258
app/src/main/java/com/topjohnwu/magisk/MagiskLogFragment.java
Normal file
@ -0,0 +1,258 @@
|
|||||||
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.net.Uri;
|
||||||
|
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;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.HorizontalScrollView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.ScrollView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.utils.Async;
|
||||||
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
|
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;
|
||||||
|
import butterknife.Unbinder;
|
||||||
|
|
||||||
|
public class MagiskLogFragment extends Fragment {
|
||||||
|
|
||||||
|
private static final String MAGISK_LOG = "/cache/magisk.log";
|
||||||
|
|
||||||
|
private Unbinder unbinder;
|
||||||
|
@BindView(R.id.txtLog) TextView txtLog;
|
||||||
|
@BindView(R.id.svLog) ScrollView svLog;
|
||||||
|
@BindView(R.id.hsvLog) HorizontalScrollView hsvLog;
|
||||||
|
|
||||||
|
@BindView(R.id.progressBar) ProgressBar progressBar;
|
||||||
|
|
||||||
|
private MenuItem mClickedMenuItem;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setHasOptionsMenu(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.fragment_magisk_log, container, false);
|
||||||
|
unbinder = ButterKnife.bind(this, view);
|
||||||
|
|
||||||
|
txtLog.setTextIsSelectable(true);
|
||||||
|
|
||||||
|
new LogManager().read();
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
getActivity().setTitle(R.string.log);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
new LogManager().read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
unbinder.unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
inflater.inflate(R.menu.menu_log, menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
mClickedMenuItem = item;
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.menu_refresh:
|
||||||
|
new LogManager().read();
|
||||||
|
return true;
|
||||||
|
case R.id.menu_send:
|
||||||
|
new LogManager().send();
|
||||||
|
return true;
|
||||||
|
case R.id.menu_save:
|
||||||
|
new LogManager().save();
|
||||||
|
return true;
|
||||||
|
case R.id.menu_clear:
|
||||||
|
new LogManager().clear();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
if (requestCode == 0) {
|
||||||
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
if (mClickedMenuItem != null) {
|
||||||
|
new Handler().postDelayed(() -> onOptionsItemSelected(mClickedMenuItem), 500);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Snackbar.make(txtLog, R.string.permissionNotGranted, Snackbar.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LogManager extends Async.RootTask<Object, Void, Object> {
|
||||||
|
|
||||||
|
int mode;
|
||||||
|
File targetFile;
|
||||||
|
|
||||||
|
@SuppressLint("DefaultLocale")
|
||||||
|
@Override
|
||||||
|
protected Object doInBackground(Object... params) {
|
||||||
|
mode = (int) params[0];
|
||||||
|
switch (mode) {
|
||||||
|
case 0:
|
||||||
|
List<String> logList = Utils.readFile(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 "";
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
Shell.su("echo > " + MAGISK_LOG);
|
||||||
|
Snackbar.make(txtLog, R.string.logs_cleared, Snackbar.LENGTH_SHORT).show();
|
||||||
|
return "";
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
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",
|
||||||
|
now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,
|
||||||
|
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
|
||||||
|
now.get(Calendar.MINUTE), now.get(Calendar.SECOND));
|
||||||
|
|
||||||
|
targetFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/MagiskManager/" + filename);
|
||||||
|
|
||||||
|
if ((!targetFile.getParentFile().exists() && !targetFile.getParentFile().mkdirs())
|
||||||
|
|| (targetFile.exists() && !targetFile.delete()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
List<String> in = Utils.readFile(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Object o) {
|
||||||
|
if (o == null) return;
|
||||||
|
boolean bool;
|
||||||
|
String llog;
|
||||||
|
switch (mode) {
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
llog = (String) o;
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
|
if (TextUtils.isEmpty(llog))
|
||||||
|
txtLog.setText(R.string.log_is_empty);
|
||||||
|
else
|
||||||
|
txtLog.setText(llog);
|
||||||
|
svLog.post(() -> svLog.scrollTo(0, txtLog.getHeight()));
|
||||||
|
hsvLog.post(() -> hsvLog.scrollTo(0, 0));
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
bool = (boolean) o;
|
||||||
|
if (bool)
|
||||||
|
Toast.makeText(getActivity(), targetFile.toString(), Toast.LENGTH_LONG).show();
|
||||||
|
else
|
||||||
|
Toast.makeText(getActivity(), getString(R.string.logs_save_failed), Toast.LENGTH_LONG).show();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
bool = (boolean) o;
|
||||||
|
if (bool) {
|
||||||
|
Intent sendIntent = new Intent();
|
||||||
|
sendIntent.setAction(Intent.ACTION_SEND);
|
||||||
|
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(targetFile));
|
||||||
|
sendIntent.setType("application/html");
|
||||||
|
startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.menuSend)));
|
||||||
|
} else {
|
||||||
|
Toast.makeText(getActivity(), getString(R.string.logs_save_failed), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void read() {
|
||||||
|
exec(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
exec(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
exec(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send() {
|
||||||
|
exec(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -147,14 +147,14 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private void checkHideSection() {
|
private void checkHideSection() {
|
||||||
Menu menu = navigationView.getMenu();
|
Menu menu = navigationView.getMenu();
|
||||||
menu.findItem(R.id.magiskhide).setVisible(Global.Info.magiskVersion >= 8 &&
|
if (Shell.rootAccess()) {
|
||||||
prefs.getBoolean("magiskhide", false) && Shell.rootAccess());
|
menu.findItem(R.id.magiskhide).setVisible(
|
||||||
menu.findItem(R.id.modules).setVisible(Global.Info.magiskVersion >= 4 &&
|
Global.Info.magiskVersion >= 8 && prefs.getBoolean("magiskhide", false));
|
||||||
Shell.rootAccess());
|
menu.findItem(R.id.modules).setVisible(Global.Info.magiskVersion >= 4);
|
||||||
menu.findItem(R.id.downloads).setVisible(Global.Info.magiskVersion >= 4 &&
|
menu.findItem(R.id.downloads).setVisible(Global.Info.magiskVersion >= 4);
|
||||||
Shell.rootAccess());
|
menu.findItem(R.id.log).setVisible(true);
|
||||||
menu.findItem(R.id.log).setVisible(Shell.rootAccess());
|
menu.findItem(R.id.superuser).setVisible(Global.Info.isSuClient);
|
||||||
menu.findItem(R.id.install).setVisible(Shell.rootAccess());
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void navigate(int itemId, boolean now) {
|
public void navigate(int itemId, boolean now) {
|
||||||
|
@ -176,12 +176,11 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis
|
|||||||
rootStatusText.setText(R.string.not_rooted);
|
rootStatusText.setText(R.string.not_rooted);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
List<String> stats = Shell.sh("su -v");
|
if (Global.Info.suVersion != null) {
|
||||||
if (Utils.isValidShellResponse(stats)) {
|
|
||||||
color = colorOK;
|
color = colorOK;
|
||||||
image = R.drawable.ic_check_circle;
|
image = R.drawable.ic_check_circle;
|
||||||
rootStatusText.setText(R.string.proper_root);
|
rootStatusText.setText(R.string.proper_root);
|
||||||
rootInfoText.setText(stats.get(0));
|
rootInfoText.setText(Global.Info.suVersion);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case -1:
|
case -1:
|
||||||
|
20
app/src/main/java/com/topjohnwu/magisk/SuLogFragment.java
Normal file
20
app/src/main/java/com/topjohnwu/magisk/SuLogFragment.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
public class SuLogFragment extends Fragment {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
// Inflate the layout for this fragment
|
||||||
|
return inflater.inflate(R.layout.fragment_su_log, container, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,36 +1,27 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<LinearLayout
|
||||||
<ScrollView android:id="@+id/svLog"
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="?attr/actionBarSize">
|
|
||||||
|
|
||||||
<HorizontalScrollView
|
|
||||||
android:id="@+id/hsvLog"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:ignore="ScrollViewSize">
|
android:orientation="vertical"
|
||||||
|
android:layout_marginTop="?attr/actionBarSize"
|
||||||
|
tools:context="com.topjohnwu.magisk.LogFragment">
|
||||||
|
|
||||||
<TextView
|
<android.support.design.widget.TabLayout
|
||||||
android:id="@+id/txtLog"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="8dp"
|
android:background="?attr/colorPrimary"
|
||||||
android:textIsSelectable="true"/>
|
android:id="@+id/tab"
|
||||||
|
app:tabPaddingEnd="20dp"
|
||||||
|
app:tabPaddingStart="20dp"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
<ProgressBar
|
</android.support.design.widget.TabLayout>
|
||||||
android:id="@+id/progressBar"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"/>
|
|
||||||
|
|
||||||
|
|
||||||
|
<android.support.v4.view.ViewPager
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:id="@+id/container"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</HorizontalScrollView>
|
|
||||||
|
|
||||||
</ScrollView>
|
|
36
app/src/main/res/layout/fragment_magisk_log.xml
Normal file
36
app/src/main/res/layout/fragment_magisk_log.xml
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ScrollView android:id="@+id/svLog"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="?attr/actionBarSize">
|
||||||
|
|
||||||
|
<HorizontalScrollView
|
||||||
|
android:id="@+id/hsvLog"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:ignore="ScrollViewSize">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtLog"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:textIsSelectable="true"/>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progressBar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</HorizontalScrollView>
|
||||||
|
|
||||||
|
</ScrollView>
|
28
app/src/main/res/layout/fragment_su_log.xml
Normal file
28
app/src/main/res/layout/fragment_su_log.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
tools:context="com.topjohnwu.magisk.SuLogFragment">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/empty_rv"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:fontFamily="sans-serif-light"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/log_is_empty"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:textStyle="italic"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/recyclerView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:dividerHeight="@dimen/card_divider_space"
|
||||||
|
app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -20,7 +20,7 @@
|
|||||||
android:id="@+id/superuser"
|
android:id="@+id/superuser"
|
||||||
android:icon="@drawable/ic_superuser"
|
android:icon="@drawable/ic_superuser"
|
||||||
android:title="@string/superuser"
|
android:title="@string/superuser"
|
||||||
android:visible="true"/>
|
android:visible="false"/>
|
||||||
|
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<!--Universal-->
|
<!--Universal-->
|
||||||
<string name="app_name" translatable="false">Magisk Manager</string>
|
|
||||||
<string name="magisk" translatable="false">Magisk</string>
|
|
||||||
|
|
||||||
<!--Welcome Activity-->
|
<!--Welcome Activity-->
|
||||||
<string name="navigation_drawer_open">Otwórz szufladę nawigacji</string>
|
<string name="navigation_drawer_open">Otwórz szufladę nawigacji</string>
|
||||||
@ -43,7 +41,6 @@
|
|||||||
<string name="keep_dm_verity">Keep dm-verity</string>
|
<string name="keep_dm_verity">Keep dm-verity</string>
|
||||||
<string name="current_magisk_title">Zainstalowana Wersja Magisk: v%1$s</string>
|
<string name="current_magisk_title">Zainstalowana Wersja Magisk: v%1$s</string>
|
||||||
<string name="install_magisk_title">Ostatnia Wersja Magisk: v%1$.1f</string>
|
<string name="install_magisk_title">Ostatnia Wersja Magisk: v%1$.1f</string>
|
||||||
<string name="magiskify" translatable="false">Magiskify</string>
|
|
||||||
|
|
||||||
<!--Module Fragment-->
|
<!--Module Fragment-->
|
||||||
<string name="no_info_provided">(Nie umieszczono informacji)</string>
|
<string name="no_info_provided">(Nie umieszczono informacji)</string>
|
||||||
@ -114,8 +111,6 @@
|
|||||||
|
|
||||||
<!--Settings Activity -->
|
<!--Settings Activity -->
|
||||||
<string name="settings_general_category">Ogólne</string>
|
<string name="settings_general_category">Ogólne</string>
|
||||||
<string name="settings_theme_title">Motyw</string>
|
|
||||||
<string name="settings_theme_summary">Wybierz motyw</string>
|
|
||||||
<string name="theme_default">Domyślny</string>
|
<string name="theme_default">Domyślny</string>
|
||||||
<string name="theme_dark">Ciemny</string>
|
<string name="theme_dark">Ciemny</string>
|
||||||
<string name="settings_clear_cache_title">Wyczyść Cache Repozytorium</string>
|
<string name="settings_clear_cache_title">Wyczyść Cache Repozytorium</string>
|
||||||
|
@ -169,4 +169,7 @@
|
|||||||
<string name="su_revoke_title">Revoke?</string>
|
<string name="su_revoke_title">Revoke?</string>
|
||||||
<string name="su_revoke_msg">Confirm to revoke %1$s rights?</string>
|
<string name="su_revoke_msg">Confirm to revoke %1$s rights?</string>
|
||||||
|
|
||||||
|
<!-- TODO: Remove or change this placeholder text -->
|
||||||
|
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user