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
af88b7c8
Commit
af88b7c8
authored
Jan 31, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move more code to app-core
parent
40916877
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
64 deletions
+81
-64
SuConnector.java
...src/main/java/com/topjohnwu/magisk/utils/SuConnector.java
+61
-0
SuLogger.java
...re/src/main/java/com/topjohnwu/magisk/utils/SuLogger.java
+7
-61
GeneralReceiver.java
...java/com/topjohnwu/magisk/components/GeneralReceiver.java
+13
-3
No files found.
app-core/src/main/java/com/topjohnwu/magisk/utils/SuConnector.java
0 → 100644
View file @
af88b7c8
package
com
.
topjohnwu
.
magisk
.
utils
;
import
android.net.LocalSocket
;
import
android.net.LocalSocketAddress
;
import
android.os.Bundle
;
import
android.text.TextUtils
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
public
abstract
class
SuConnector
{
private
LocalSocket
socket
;
protected
DataOutputStream
out
;
protected
DataInputStream
in
;
protected
SuConnector
(
String
name
)
throws
IOException
{
socket
=
new
LocalSocket
();
socket
.
connect
(
new
LocalSocketAddress
(
name
,
LocalSocketAddress
.
Namespace
.
ABSTRACT
));
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
];
in
.
readFully
(
buf
);
return
new
String
(
buf
,
"UTF-8"
);
}
public
Bundle
readSocketInput
()
throws
IOException
{
Bundle
bundle
=
new
Bundle
();
while
(
true
)
{
String
name
=
readString
();
if
(
TextUtils
.
equals
(
name
,
"eof"
))
break
;
bundle
.
putString
(
name
,
readString
());
}
return
bundle
;
}
public
void
response
()
{
try
{
onResponse
();
out
.
flush
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
in
.
close
();
out
.
close
();
socket
.
close
();
}
catch
(
IOException
ignored
)
{
}
}
protected
abstract
void
onResponse
()
throws
IOException
;
}
app
/src/full/java/com/topjohnwu/magisk/utils/SuConnecto
r.java
→
app
-core/src/main/java/com/topjohnwu/magisk/utils/SuLogge
r.java
View file @
af88b7c8
...
...
@@ -2,74 +2,20 @@ package com.topjohnwu.magisk.utils;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.net.LocalSocket
;
import
android.net.LocalSocketAddress
;
import
android.os.Bundle
;
import
android.os.Process
;
import
android.text.TextUtils
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.App
;
import
com.topjohnwu.magisk.Config
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.container.Policy
;
import
com.topjohnwu.magisk.container.SuLogEntry
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.util.Date
;
public
abstract
class
Su
Connecto
r
{
public
abstract
class
Su
Logge
r
{
private
LocalSocket
socket
;
protected
DataOutputStream
out
;
protected
DataInputStream
in
;
public
SuConnector
(
String
name
)
throws
IOException
{
socket
=
new
LocalSocket
();
socket
.
connect
(
new
LocalSocketAddress
(
name
,
LocalSocketAddress
.
Namespace
.
ABSTRACT
));
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
];
in
.
readFully
(
buf
);
return
new
String
(
buf
,
"UTF-8"
);
}
public
Bundle
readSocketInput
()
throws
IOException
{
Bundle
bundle
=
new
Bundle
();
while
(
true
)
{
String
name
=
readString
();
if
(
TextUtils
.
equals
(
name
,
"eof"
))
break
;
bundle
.
putString
(
name
,
readString
());
}
return
bundle
;
}
public
void
response
()
{
try
{
onResponse
();
out
.
flush
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
try
{
in
.
close
();
out
.
close
();
socket
.
close
();
}
catch
(
IOException
ignored
)
{
}
}
protected
abstract
void
onResponse
()
throws
IOException
;
public
static
void
handleLogs
(
Intent
intent
)
{
public
void
handleLogs
(
Intent
intent
)
{
int
fromUid
=
intent
.
getIntExtra
(
"from.uid"
,
-
1
);
if
(
fromUid
<
0
)
return
;
...
...
@@ -118,15 +64,13 @@ public abstract class SuConnector {
app
.
mDB
.
addLog
(
log
);
}
private
static
void
handleNotify
(
Policy
policy
)
{
String
message
=
App
.
self
.
getString
(
policy
.
policy
==
Policy
.
ALLOW
?
R
.
string
.
su_allow_toast
:
R
.
string
.
su_deny_toast
,
policy
.
appName
);
private
void
handleNotify
(
Policy
policy
)
{
if
(
policy
.
notification
&&
(
int
)
Config
.
get
(
Config
.
Key
.
SU_NOTIFICATION
)
==
Config
.
Value
.
NOTIFICATION_TOAST
)
Utils
.
toast
(
message
,
Toast
.
LENGTH_SHORT
);
Utils
.
toast
(
getMessage
(
policy
)
,
Toast
.
LENGTH_SHORT
);
}
public
static
void
handleNotify
(
Intent
intent
)
{
public
void
handleNotify
(
Intent
intent
)
{
int
fromUid
=
intent
.
getIntExtra
(
"from.uid"
,
-
1
);
if
(
fromUid
<
0
)
return
;
if
(
fromUid
==
Process
.
myUid
())
return
;
...
...
@@ -137,4 +81,6 @@ public abstract class SuConnector {
handleNotify
(
policy
);
}
catch
(
PackageManager
.
NameNotFoundException
ignored
)
{}
}
public
abstract
String
getMessage
(
Policy
policy
);
}
app/src/full/java/com/topjohnwu/magisk/components/GeneralReceiver.java
View file @
af88b7c8
...
...
@@ -9,16 +9,26 @@ import com.topjohnwu.magisk.App;
import
com.topjohnwu.magisk.ClassMap
;
import
com.topjohnwu.magisk.Config
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.SuRequestActivity
;
import
com.topjohnwu.magisk.container.Policy
;
import
com.topjohnwu.magisk.uicomponents.Notifications
;
import
com.topjohnwu.magisk.uicomponents.Shortcuts
;
import
com.topjohnwu.magisk.utils.DownloadApp
;
import
com.topjohnwu.magisk.utils.Su
Connecto
r
;
import
com.topjohnwu.magisk.utils.Su
Logge
r
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.ShellUtils
;
public
class
GeneralReceiver
extends
BroadcastReceiver
{
private
static
SuLogger
SU_LOGGER
=
new
SuLogger
()
{
@Override
public
String
getMessage
(
Policy
policy
)
{
return
App
.
self
.
getString
(
policy
.
policy
==
Policy
.
ALLOW
?
R
.
string
.
su_allow_toast
:
R
.
string
.
su_deny_toast
,
policy
.
appName
);
}
};
private
String
getPkg
(
Intent
i
)
{
return
i
.
getData
()
==
null
?
""
:
i
.
getData
().
getEncodedSchemeSpecificPart
();
}
...
...
@@ -44,10 +54,10 @@ public class GeneralReceiver extends BroadcastReceiver {
app
.
startActivity
(
i
);
break
;
case
"log"
:
S
uConnector
.
handleLogs
(
intent
);
S
U_LOGGER
.
handleLogs
(
intent
);
break
;
case
"notify"
:
S
uConnector
.
handleNotify
(
intent
);
S
U_LOGGER
.
handleNotify
(
intent
);
break
;
case
"boot"
:
default
:
...
...
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