Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
316ec98e
Commit
316ec98e
authored
Jul 04, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite Magisk log fragment
parent
cf58545a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
108 deletions
+50
-108
MagiskLogFragment.java
src/full/java/com/topjohnwu/magisk/MagiskLogFragment.java
+50
-108
No files found.
src/full/java/com/topjohnwu/magisk/MagiskLogFragment.java
View file @
316ec98e
...
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk;
...
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk;
import
android.Manifest
;
import
android.Manifest
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.Nullable
;
import
android.support.design.widget.Snackbar
;
import
android.support.design.widget.Snackbar
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
...
@@ -15,20 +16,18 @@ import android.widget.HorizontalScrollView;
...
@@ -15,20 +16,18 @@ import android.widget.HorizontalScrollView;
import
android.widget.ProgressBar
;
import
android.widget.ProgressBar
;
import
android.widget.ScrollView
;
import
android.widget.ScrollView
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.asyncs.ParallelTask
;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.
superuser.CallbackList
;
import
com.topjohnwu.
magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.ShellUtils
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.L
ocale
;
import
java.util.L
ist
;
import
butterknife.BindView
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
import
butterknife.ButterKnife
;
...
@@ -49,11 +48,7 @@ public class MagiskLogFragment extends Fragment {
...
@@ -49,11 +48,7 @@ public class MagiskLogFragment extends Fragment {
View
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_magisk_log
,
container
,
false
);
View
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_magisk_log
,
container
,
false
);
unbinder
=
ButterKnife
.
bind
(
this
,
view
);
unbinder
=
ButterKnife
.
bind
(
this
,
view
);
setHasOptionsMenu
(
true
);
setHasOptionsMenu
(
true
);
txtLog
.
setTextIsSelectable
(
true
);
txtLog
.
setTextIsSelectable
(
true
);
new
LogManager
().
read
();
return
view
;
return
view
;
}
}
...
@@ -66,7 +61,7 @@ public class MagiskLogFragment extends Fragment {
...
@@ -66,7 +61,7 @@ public class MagiskLogFragment extends Fragment {
@Override
@Override
public
void
onResume
()
{
public
void
onResume
()
{
super
.
onResume
();
super
.
onResume
();
new
LogManager
().
read
();
readLogs
();
}
}
@Override
@Override
...
@@ -84,120 +79,67 @@ public class MagiskLogFragment extends Fragment {
...
@@ -84,120 +79,67 @@ public class MagiskLogFragment extends Fragment {
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
switch
(
item
.
getItemId
())
{
switch
(
item
.
getItemId
())
{
case
R
.
id
.
menu_refresh
:
case
R
.
id
.
menu_refresh
:
new
LogManager
().
read
();
readLogs
();
return
true
;
return
true
;
case
R
.
id
.
menu_save
:
case
R
.
id
.
menu_save
:
runWithPermission
(
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
runWithPermission
(
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
this
::
saveLogs
);
()
->
new
LogManager
().
save
());
return
true
;
return
true
;
case
R
.
id
.
menu_clear
:
case
R
.
id
.
menu_clear
:
new
LogManager
().
clear
();
clearLogs
();
return
true
;
return
true
;
default
:
default
:
return
true
;
return
true
;
}
}
}
}
private
class
LogManager
extends
ParallelTask
<
Object
,
Void
,
Object
>
{
public
void
readLogs
()
{
Shell
.
Async
.
su
(
new
Shell
.
Async
.
Callback
()
{
private
int
mode
;
@Override
private
File
targetFile
;
public
void
onTaskResult
(
@Nullable
List
<
String
>
out
,
@Nullable
List
<
String
>
err
)
{
progressBar
.
setVisibility
(
View
.
GONE
);
LogManager
()
{
if
(
ShellUtils
.
isValidOutput
(
out
))
{
super
(
MagiskLogFragment
.
this
.
getActivity
());
txtLog
.
setText
(
TextUtils
.
join
(
"\n"
,
out
));
}
else
{
txtLog
.
setText
(
R
.
string
.
log_is_empty
);
}
svLog
.
postDelayed
(()
->
svLog
.
fullScroll
(
ScrollView
.
FOCUS_DOWN
),
100
);
hsvLog
.
postDelayed
(()
->
hsvLog
.
fullScroll
(
ScrollView
.
FOCUS_LEFT
),
100
);
}
}
@Override
@Override
protected
Object
doInBackground
(
Object
...
params
)
{
public
void
onTaskError
(
@NonNull
Throwable
throwable
)
{
mode
=
(
int
)
params
[
0
];
txtLog
.
setText
(
R
.
string
.
log_is_empty
);
switch
(
mode
)
{
}
case
0
:
},
"cat "
+
Const
.
MAGISK_LOG
+
" | tail -n 5000"
);
StringBuilder
builder
=
new
StringBuilder
();
CallbackList
<
String
>
logs
=
new
CallbackList
<
String
>()
{
@Override
public
void
onAddElement
(
String
s
)
{
builder
.
append
(
s
).
append
(
'\n'
);
}
}
};
Shell
.
Sync
.
su
(
logs
,
"cat "
+
Const
.
MAGISK_LOG
+
" | tail -n 5000"
);
return
builder
;
case
1
:
Shell
.
Async
.
su
(
"echo -n > "
+
Const
.
MAGISK_LOG
);
SnackbarMaker
.
make
(
txtLog
,
R
.
string
.
logs_cleared
,
Snackbar
.
LENGTH_SHORT
).
show
();
return
""
;
case
2
:
public
void
saveLogs
()
{
Calendar
now
=
Calendar
.
getInstance
();
Calendar
now
=
Calendar
.
getInstance
();
String
filename
=
String
.
format
(
Locale
.
US
,
String
filename
=
Utils
.
fmt
(
"magisk_log_%04d%02d%02d_%02d%02d%02d.log"
,
"magisk_log_%04d%02d%02d_%02d%02d%02d.log"
,
now
.
get
(
Calendar
.
YEAR
),
now
.
get
(
Calendar
.
MONTH
)
+
1
,
now
.
get
(
Calendar
.
YEAR
),
now
.
get
(
Calendar
.
MONTH
)
+
1
,
now
.
get
(
Calendar
.
DAY_OF_MONTH
),
now
.
get
(
Calendar
.
HOUR_OF_DAY
),
now
.
get
(
Calendar
.
DAY_OF_MONTH
),
now
.
get
(
Calendar
.
HOUR_OF_DAY
),
now
.
get
(
Calendar
.
MINUTE
),
now
.
get
(
Calendar
.
SECOND
));
now
.
get
(
Calendar
.
MINUTE
),
now
.
get
(
Calendar
.
SECOND
));
targetFile
=
new
File
(
Const
.
EXTERNAL_PATH
+
"/logs"
,
filename
);
File
targetFile
=
new
File
(
Const
.
EXTERNAL_PATH
+
"/logs"
,
filename
);
targetFile
.
getParentFile
().
mkdirs
();
if
((!
targetFile
.
getParentFile
().
exists
()
&&
!
targetFile
.
getParentFile
().
mkdirs
())
||
(
targetFile
.
exists
()
&&
!
targetFile
.
delete
()))
{
return
false
;
}
try
(
FileWriter
out
=
new
FileWriter
(
targetFile
))
{
CallbackList
<
String
>
list
=
new
CallbackList
<
String
>()
{
@Override
public
void
onAddElement
(
String
s
)
{
try
{
try
{
out
.
write
(
s
);
targetFile
.
createNewFile
();
out
.
write
(
"\n"
);
}
catch
(
IOException
ignored
)
{}
}
};
Shell
.
Sync
.
su
(
list
,
"cat "
+
Const
.
MAGISK_LOG
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
;
return
false
;
}
return
true
;
}
}
return
null
;
Shell
.
Async
.
su
(
new
Shell
.
Async
.
Callback
()
{
}
@Override
@Override
protected
void
onPostExecute
(
Object
o
)
{
public
void
onTaskResult
(
@Nullable
List
<
String
>
out
,
@Nullable
List
<
String
>
err
)
{
if
(
o
==
null
)
return
;
SnackbarMaker
.
make
(
txtLog
,
targetFile
.
getPath
(),
Snackbar
.
LENGTH_SHORT
).
show
();
switch
(
mode
)
{
case
0
:
case
1
:
CharSequence
llog
=
(
CharSequence
)
o
;
progressBar
.
setVisibility
(
View
.
GONE
);
if
(
TextUtils
.
isEmpty
(
llog
))
txtLog
.
setText
(
R
.
string
.
log_is_empty
);
else
txtLog
.
setText
(
llog
);
svLog
.
postDelayed
(()
->
svLog
.
fullScroll
(
ScrollView
.
FOCUS_DOWN
),
100
);
hsvLog
.
postDelayed
(()
->
hsvLog
.
fullScroll
(
ScrollView
.
FOCUS_LEFT
),
100
);
break
;
case
2
:
boolean
bool
=
(
boolean
)
o
;
if
(
bool
)
{
MagiskManager
.
toast
(
targetFile
.
getPath
(),
Toast
.
LENGTH_LONG
);
}
else
{
MagiskManager
.
toast
(
R
.
string
.
logs_save_failed
,
Toast
.
LENGTH_LONG
);
}
break
;
}
}
void
read
()
{
exec
(
0
);
}
}
void
clear
()
{
@Override
exec
(
1
);
public
void
onTaskError
(
@NonNull
Throwable
throwable
)
{}
},
"cat "
+
Const
.
MAGISK_LOG
+
" > "
+
targetFile
);
}
}
void
save
()
{
public
void
clearLogs
()
{
exec
(
2
);
Shell
.
Async
.
su
(
"echo -n > "
+
Const
.
MAGISK_LOG
);
}
SnackbarMaker
.
make
(
txtLog
,
R
.
string
.
logs_cleared
,
Snackbar
.
LENGTH_SHORT
).
show
();
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment