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
7fc00c44
Commit
7fc00c44
authored
Oct 28, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Buffer OutputStream to prevent broken pipe error
parent
2efc423c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
24 deletions
+47
-24
SuRequestActivity.java
...src/full/java/com/topjohnwu/magisk/SuRequestActivity.java
+16
-14
SuConnector.java
...src/full/java/com/topjohnwu/magisk/utils/SuConnector.java
+31
-10
No files found.
app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java
View file @
7fc00c44
...
@@ -48,6 +48,11 @@ public class SuRequestActivity extends BaseActivity {
...
@@ -48,6 +48,11 @@ public class SuRequestActivity extends BaseActivity {
class
SuConnectorV1
extends
SuConnector
{
class
SuConnectorV1
extends
SuConnector
{
SuConnectorV1
(
String
name
)
throws
IOException
{
SuConnectorV1
(
String
name
)
throws
IOException
{
super
(
name
);
}
@Override
public
void
connect
(
String
name
)
throws
IOException
{
socket
.
connect
(
new
LocalSocketAddress
(
name
,
LocalSocketAddress
.
Namespace
.
FILESYSTEM
));
socket
.
connect
(
new
LocalSocketAddress
(
name
,
LocalSocketAddress
.
Namespace
.
FILESYSTEM
));
new
FileObserver
(
name
)
{
new
FileObserver
(
name
)
{
@Override
@Override
...
@@ -60,28 +65,25 @@ public class SuRequestActivity extends BaseActivity {
...
@@ -60,28 +65,25 @@ public class SuRequestActivity extends BaseActivity {
}
}
@Override
@Override
public
void
response
()
{
public
void
onResponse
()
throws
IOException
{
try
(
OutputStream
out
=
getOutputStream
())
{
out
.
write
((
policy
.
policy
==
Policy
.
ALLOW
?
"socket:ALLOW"
:
"socket:DENY"
).
getBytes
());
out
.
write
((
policy
.
policy
==
Policy
.
ALLOW
?
"socket:ALLOW"
:
"socket:DENY"
).
getBytes
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
class
SuConnectorV2
extends
SuConnector
{
class
SuConnectorV2
extends
SuConnector
{
SuConnectorV2
(
String
name
)
throws
IOException
{
SuConnectorV2
(
String
name
)
throws
IOException
{
super
(
name
);
}
@Override
public
void
connect
(
String
name
)
throws
IOException
{
socket
.
connect
(
new
LocalSocketAddress
(
name
,
LocalSocketAddress
.
Namespace
.
ABSTRACT
));
socket
.
connect
(
new
LocalSocketAddress
(
name
,
LocalSocketAddress
.
Namespace
.
ABSTRACT
));
}
}
@Override
@Override
public
void
response
()
{
public
void
onResponse
()
throws
IOException
{
try
(
DataOutputStream
out
=
getOutputStream
())
{
out
.
writeInt
(
policy
.
policy
);
out
.
writeInt
(
policy
.
policy
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
...
@@ -119,9 +121,9 @@ public class SuRequestActivity extends BaseActivity {
...
@@ -119,9 +121,9 @@ public class SuRequestActivity extends BaseActivity {
// Get policy
// Get policy
Intent
intent
=
getIntent
();
Intent
intent
=
getIntent
();
try
{
try
{
String
socketName
=
intent
.
getStringExtra
(
"socket"
);
connector
=
intent
.
getIntExtra
(
"version"
,
1
)
==
1
?
connector
=
intent
.
getIntExtra
(
"version"
,
1
)
==
1
?
new
SuConnectorV1
(
intent
.
getStringExtra
(
"socket"
))
:
new
SuConnectorV1
(
socketName
)
:
new
SuConnectorV2
(
socketName
);
new
SuConnectorV2
(
intent
.
getStringExtra
(
"socket"
));
Bundle
bundle
=
connector
.
readSocketInput
();
Bundle
bundle
=
connector
.
readSocketInput
();
int
uid
=
Integer
.
parseInt
(
bundle
.
getString
(
"uid"
));
int
uid
=
Integer
.
parseInt
(
bundle
.
getString
(
"uid"
));
policy
=
mm
.
mDB
.
getPolicy
(
uid
);
policy
=
mm
.
mDB
.
getPolicy
(
uid
);
...
...
app/src/full/java/com/topjohnwu/magisk/utils/SuConnector.java
View file @
7fc00c44
...
@@ -15,6 +15,8 @@ import com.topjohnwu.magisk.R;
...
@@ -15,6 +15,8 @@ import com.topjohnwu.magisk.R;
import
com.topjohnwu.magisk.container.Policy
;
import
com.topjohnwu.magisk.container.Policy
;
import
com.topjohnwu.magisk.container.SuLogEntry
;
import
com.topjohnwu.magisk.container.SuLogEntry
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.DataInputStream
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -23,31 +25,50 @@ import java.util.Date;
...
@@ -23,31 +25,50 @@ import java.util.Date;
public
abstract
class
SuConnector
{
public
abstract
class
SuConnector
{
protected
LocalSocket
socket
=
new
LocalSocket
();
protected
LocalSocket
socket
=
new
LocalSocket
();
protected
DataOutputStream
out
;
protected
DataInputStream
in
;
private
String
readString
(
DataInputStream
is
)
throws
IOException
{
public
SuConnector
(
String
name
)
throws
IOException
{
int
len
=
is
.
readInt
();
connect
(
name
);
out
=
new
DataOutputStream
(
new
BufferedOutputStream
(
socket
.
getOutputStream
()));
in
=
new
DataInputStream
(
new
BufferedInputStream
(
socket
.
getInputStream
()));
}
private
String
readString
()
throws
IOException
{
int
len
=
in
.
readInt
();
byte
[]
buf
=
new
byte
[
len
];
byte
[]
buf
=
new
byte
[
len
];
i
s
.
readFully
(
buf
);
i
n
.
readFully
(
buf
);
return
new
String
(
buf
);
return
new
String
(
buf
,
"UTF-8"
);
}
}
public
Bundle
readSocketInput
()
throws
IOException
{
public
Bundle
readSocketInput
()
throws
IOException
{
Bundle
bundle
=
new
Bundle
();
Bundle
bundle
=
new
Bundle
();
DataInputStream
is
=
new
DataInputStream
(
socket
.
getInputStream
());
while
(
true
)
{
while
(
true
)
{
String
name
=
readString
(
is
);
String
name
=
readString
();
if
(
TextUtils
.
equals
(
name
,
"eof"
))
if
(
TextUtils
.
equals
(
name
,
"eof"
))
break
;
break
;
bundle
.
putString
(
name
,
readString
(
is
));
bundle
.
putString
(
name
,
readString
());
}
}
return
bundle
;
return
bundle
;
}
}
protected
DataOutputStream
getOutputStream
()
throws
IOException
{
public
void
response
()
{
return
new
DataOutputStream
(
socket
.
getOutputStream
());
try
{
onResponse
();
out
.
flush
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
in
.
close
();
out
.
close
();
socket
.
close
();
}
catch
(
IOException
ignored
)
{
}
}
}
public
abstract
void
response
();
public
abstract
void
connect
(
String
name
)
throws
IOException
;
protected
abstract
void
onResponse
()
throws
IOException
;
public
static
void
handleLogs
(
Intent
intent
,
int
version
)
{
public
static
void
handleLogs
(
Intent
intent
,
int
version
)
{
...
...
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