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
ae05dce9
Commit
ae05dce9
authored
Oct 19, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve Shell and logging
parent
9ebe372a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
23 deletions
+32
-23
Logger.java
app/src/main/java/com/topjohnwu/magisk/utils/Logger.java
+4
-6
Shell.java
app/src/main/java/com/topjohnwu/magisk/utils/Shell.java
+27
-16
StreamGobbler.java
...c/main/java/com/topjohnwu/magisk/utils/StreamGobbler.java
+1
-1
No files found.
app/src/main/java/com/topjohnwu/magisk/utils/Logger.java
View file @
ae05dce9
...
...
@@ -2,8 +2,6 @@ package com.topjohnwu.magisk.utils;
import
android.util.Log
;
import
com.topjohnwu.magisk.MagiskManager
;
import
java.util.Locale
;
public
class
Logger
{
...
...
@@ -27,13 +25,13 @@ public class Logger {
error
(
String
.
format
(
Locale
.
US
,
fmt
,
args
));
}
public
static
void
shell
(
String
line
)
{
public
static
void
shell
(
boolean
in
,
String
line
)
{
if
(
SHELL_LOGGING
)
{
Log
.
d
(
DEBUG_TAG
,
"SHELL: "
+
line
);
Log
.
d
(
DEBUG_TAG
,
(
in
?
"SHELLIN : "
:
"SHELLOUT: "
)
+
line
);
}
}
public
static
void
shell
(
String
fmt
,
Object
...
args
)
{
shell
(
String
.
format
(
Locale
.
US
,
fmt
,
args
));
public
static
void
shell
(
boolean
in
,
String
fmt
,
Object
...
args
)
{
shell
(
in
,
String
.
format
(
Locale
.
US
,
fmt
,
args
));
}
}
app/src/main/java/com/topjohnwu/magisk/utils/Shell.java
View file @
ae05dce9
...
...
@@ -19,8 +19,8 @@ import java.util.List;
public
class
Shell
{
// -1 = no shell; 0 = non root shell; 1 = root shell
public
static
int
status
;
// -
2 = not initialized; -
1 = no shell; 0 = non root shell; 1 = root shell
public
static
int
status
=
-
2
;
private
final
Process
process
;
private
final
OutputStream
STDIN
;
...
...
@@ -84,16 +84,25 @@ public class Shell {
}
public
static
boolean
rootAccess
()
{
if
(
status
==
-
2
)
getShell
();
return
status
>
0
;
}
public
void
run
(
Collection
<
String
>
output
,
String
...
commands
)
{
synchronized
(
process
)
{
StreamGobbler
out
=
new
StreamGobbler
(
STDOUT
,
output
);
out
.
start
();
run_raw
(
true
,
commands
);
run_raw
(
true
,
"echo \'-shell-done-\'"
);
try
{
out
.
join
();
}
catch
(
InterruptedException
ignored
)
{}
try
{
StreamGobbler
out
=
new
StreamGobbler
(
STDOUT
,
output
);
out
.
start
();
run_raw
(
true
,
commands
);
STDIN
.
write
(
"echo \'-shell-done-\'\n"
.
getBytes
(
"UTF-8"
));
STDIN
.
flush
();
try
{
out
.
join
();
}
catch
(
InterruptedException
ignored
)
{}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
process
.
destroy
();
}
}
}
...
...
@@ -101,7 +110,7 @@ public class Shell {
synchronized
(
process
)
{
try
{
for
(
String
command
:
commands
)
{
Logger
.
shell
(
command
);
Logger
.
shell
(
true
,
command
);
STDIN
.
write
((
command
+
(
stdout
?
"\n"
:
" >/dev/null\n"
)).
getBytes
(
"UTF-8"
));
STDIN
.
flush
();
}
...
...
@@ -113,15 +122,17 @@ public class Shell {
}
public
void
loadInputStream
(
InputStream
in
)
{
try
{
int
read
;
byte
[]
bytes
=
new
byte
[
4096
];
while
((
read
=
in
.
read
(
bytes
))
!=
-
1
)
{
STDIN
.
write
(
bytes
,
0
,
read
);
synchronized
(
process
)
{
try
{
int
read
;
byte
[]
bytes
=
new
byte
[
4096
];
while
((
read
=
in
.
read
(
bytes
))
!=
-
1
)
{
STDIN
.
write
(
bytes
,
0
,
read
);
}
STDIN
.
flush
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
STDIN
.
flush
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/utils/StreamGobbler.java
View file @
ae05dce9
...
...
@@ -46,7 +46,7 @@ public class StreamGobbler extends Thread {
if
(
TextUtils
.
equals
(
line
,
"-shell-done-"
))
return
;
writer
.
add
(
line
);
Logger
.
shell
(
line
);
Logger
.
shell
(
false
,
line
);
}
}
catch
(
IOException
e
)
{
// reader probably closed, expected exit condition
...
...
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