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
62523c81
Commit
62523c81
authored
Sep 30, 2016
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Shell logging
parent
0f5465c5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
2 deletions
+22
-2
build.gradle
app/build.gradle
+1
-1
Logger.java
app/src/main/java/com/topjohnwu/magisk/utils/Logger.java
+8
-0
Shell.java
app/src/main/java/com/topjohnwu/magisk/utils/Shell.java
+3
-1
StreamGobbler.java
...c/main/java/com/topjohnwu/magisk/utils/StreamGobbler.java
+10
-0
No files found.
app/build.gradle
View file @
62523c81
...
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
...
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android
{
android
{
compileSdkVersion
24
compileSdkVersion
24
buildToolsVersion
"24.0.
3
"
buildToolsVersion
"24.0.
2
"
defaultConfig
{
defaultConfig
{
applicationId
"com.topjohnwu.magisk"
applicationId
"com.topjohnwu.magisk"
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Logger.java
View file @
62523c81
...
@@ -9,6 +9,8 @@ public class Logger {
...
@@ -9,6 +9,8 @@ public class Logger {
private
static
final
String
LOG_TAG
=
"Magisk: DEV"
;
private
static
final
String
LOG_TAG
=
"Magisk: DEV"
;
private
static
final
boolean
logShell
=
true
;
public
static
void
dev
(
String
msg
,
Object
...
args
)
{
public
static
void
dev
(
String
msg
,
Object
...
args
)
{
Context
context
=
null
;
Context
context
=
null
;
try
{
try
{
...
@@ -37,6 +39,12 @@ public class Logger {
...
@@ -37,6 +39,12 @@ public class Logger {
}
}
}
}
public
static
void
shell
(
boolean
root
,
String
msg
)
{
if
(
logShell
)
{
Log
.
d
(
root
?
"SU"
:
"SH"
,
msg
);
}
}
private
static
Application
getApplicationUsingReflection
()
throws
Exception
{
private
static
Application
getApplicationUsingReflection
()
throws
Exception
{
return
(
Application
)
Class
.
forName
(
"android.app.AppGlobals"
)
return
(
Application
)
Class
.
forName
(
"android.app.AppGlobals"
)
.
getMethod
(
"getInitialApplication"
).
invoke
(
null
,
(
Object
[])
null
);
.
getMethod
(
"getInitialApplication"
).
invoke
(
null
,
(
Object
[])
null
);
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Shell.java
View file @
62523c81
...
@@ -42,7 +42,7 @@ public class Shell {
...
@@ -42,7 +42,7 @@ public class Shell {
}
}
rootSTDIN
=
new
DataOutputStream
(
rootShell
.
getOutputStream
());
rootSTDIN
=
new
DataOutputStream
(
rootShell
.
getOutputStream
());
rootSTDOUT
=
new
StreamGobbler
(
rootShell
.
getInputStream
(),
rootOutList
);
rootSTDOUT
=
new
StreamGobbler
(
rootShell
.
getInputStream
(),
rootOutList
,
true
);
rootSTDOUT
.
start
();
rootSTDOUT
.
start
();
List
<
String
>
ret
=
su
(
"echo -BOC-"
,
"id"
);
List
<
String
>
ret
=
su
(
"echo -BOC-"
,
"id"
);
...
@@ -82,6 +82,7 @@ public class Shell {
...
@@ -82,6 +82,7 @@ public class Shell {
for
(
String
write
:
commands
)
{
for
(
String
write
:
commands
)
{
STDIN
.
write
((
write
+
"\n"
).
getBytes
(
"UTF-8"
));
STDIN
.
write
((
write
+
"\n"
).
getBytes
(
"UTF-8"
));
STDIN
.
flush
();
STDIN
.
flush
();
Logger
.
shell
(
false
,
write
);
}
}
STDIN
.
write
(
"exit\n"
.
getBytes
(
"UTF-8"
));
STDIN
.
write
(
"exit\n"
.
getBytes
(
"UTF-8"
));
STDIN
.
flush
();
STDIN
.
flush
();
...
@@ -149,6 +150,7 @@ public class Shell {
...
@@ -149,6 +150,7 @@ public class Shell {
for
(
String
write
:
commands
)
{
for
(
String
write
:
commands
)
{
STDIN
.
write
((
write
+
"\n"
).
getBytes
(
"UTF-8"
));
STDIN
.
write
((
write
+
"\n"
).
getBytes
(
"UTF-8"
));
STDIN
.
flush
();
STDIN
.
flush
();
Logger
.
shell
(
true
,
write
);
}
}
if
(
newShell
)
{
if
(
newShell
)
{
STDIN
.
write
(
"exit\n"
.
getBytes
(
"UTF-8"
));
STDIN
.
write
(
"exit\n"
.
getBytes
(
"UTF-8"
));
...
...
app/src/main/java/com/topjohnwu/magisk/utils/StreamGobbler.java
View file @
62523c81
...
@@ -14,6 +14,7 @@ public class StreamGobbler extends Thread {
...
@@ -14,6 +14,7 @@ public class StreamGobbler extends Thread {
private
BufferedReader
reader
=
null
;
private
BufferedReader
reader
=
null
;
private
List
<
String
>
writer
=
null
;
private
List
<
String
>
writer
=
null
;
private
boolean
isRoot
=
false
;
/**
/**
* <p>StreamGobbler constructor</p>
* <p>StreamGobbler constructor</p>
...
@@ -30,6 +31,12 @@ public class StreamGobbler extends Thread {
...
@@ -30,6 +31,12 @@ public class StreamGobbler extends Thread {
writer
=
outputList
;
writer
=
outputList
;
}
}
public
StreamGobbler
(
InputStream
inputStream
,
List
<
String
>
outputList
,
boolean
root
)
{
reader
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
));
writer
=
outputList
;
isRoot
=
root
;
}
@Override
@Override
public
void
run
()
{
public
void
run
()
{
// keep reading the InputStream until it ends (or an error occurs)
// keep reading the InputStream until it ends (or an error occurs)
...
@@ -37,6 +44,9 @@ public class StreamGobbler extends Thread {
...
@@ -37,6 +44,9 @@ public class StreamGobbler extends Thread {
String
line
;
String
line
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
while
((
line
=
reader
.
readLine
())
!=
null
)
{
writer
.
add
(
line
);
writer
.
add
(
line
);
if
(!
line
.
equals
(
"-root-done-"
)
&&
!
line
.
isEmpty
())
{
Logger
.
shell
(
isRoot
,
"OUT: "
+
line
);
}
}
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
// reader probably closed, expected exit condition
// 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