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
7eadc74f
Commit
7eadc74f
authored
Aug 22, 2016
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proper module management
parent
3ad06c40
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
18 deletions
+60
-18
Module.java
app/src/main/java/com/topjohnwu/magisk/model/Module.java
+7
-7
LogFragment.java
app/src/main/java/com/topjohnwu/magisk/ui/LogFragment.java
+2
-2
MainActivity.java
app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.java
+6
-6
ModulesFragment.java
...rc/main/java/com/topjohnwu/magisk/ui/ModulesFragment.java
+1
-1
Utils.java
app/src/main/java/com/topjohnwu/magisk/ui/utils/Utils.java
+44
-2
No files found.
app/src/main/java/com/topjohnwu/magisk/model/Module.java
View file @
7eadc74f
...
@@ -46,23 +46,23 @@ public class Module {
...
@@ -46,23 +46,23 @@ public class Module {
}
}
public
void
createDisableFile
()
{
public
void
createDisableFile
()
{
Utils
.
executeCommand
(
"touch "
+
mDisableFile
.
getPath
());
Utils
.
su
(
"touch "
+
mDisableFile
.
getPath
());
}
}
public
boolean
removeDisableFile
()
{
public
void
removeDisableFile
()
{
return
mDisableFile
.
delete
(
);
Utils
.
su
(
"rm -f "
+
mDisableFile
.
getPath
()
);
}
}
public
boolean
isEnabled
()
{
public
boolean
isEnabled
()
{
return
mDisableFile
.
exists
();
return
!
mDisableFile
.
exists
();
}
}
public
void
createRemoveFile
()
{
public
void
createRemoveFile
()
{
Utils
.
executeCommand
(
"touch "
+
mRemoveFile
.
getPath
());
Utils
.
su
(
"touch "
+
mRemoveFile
.
getPath
());
}
}
public
boolean
deleteRemoveFile
()
{
public
void
deleteRemoveFile
()
{
return
mRemoveFile
.
delete
(
);
Utils
.
su
(
"rm -f "
+
mRemoveFile
.
getPath
()
);
}
}
public
boolean
willBeRemoved
()
{
public
boolean
willBeRemoved
()
{
...
...
app/src/main/java/com/topjohnwu/magisk/ui/LogFragment.java
View file @
7eadc74f
...
@@ -226,8 +226,8 @@ public class LogFragment extends Fragment {
...
@@ -226,8 +226,8 @@ public class LogFragment extends Fragment {
@Override
@Override
protected
void
onPreExecute
()
{
protected
void
onPreExecute
()
{
Utils
.
executeCommand
(
"chmod 777
/cache"
);
Utils
.
su
(
"chmod 755
/cache"
);
Utils
.
executeCommand
(
"chmod 777
/cache/magisk.log"
);
Utils
.
su
(
"chmod 644
/cache/magisk.log"
);
txtLog
.
setText
(
""
);
txtLog
.
setText
(
""
);
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.java
View file @
7eadc74f
...
@@ -11,7 +11,7 @@ import com.topjohnwu.magisk.R;
...
@@ -11,7 +11,7 @@ import com.topjohnwu.magisk.R;
import
java.io.File
;
import
java.io.File
;
import
static
com
.
topjohnwu
.
magisk
.
ui
.
utils
.
Utils
.
executeCommand
;
import
static
com
.
topjohnwu
.
magisk
.
ui
.
utils
.
Utils
.
su
;
public
class
MainActivity
extends
Activity
{
public
class
MainActivity
extends
Activity
{
...
@@ -32,13 +32,13 @@ public class MainActivity extends Activity {
...
@@ -32,13 +32,13 @@ public class MainActivity extends Activity {
safetyNet
=
(
TextView
)
findViewById
(
R
.
id
.
safety_net
);
safetyNet
=
(
TextView
)
findViewById
(
R
.
id
.
safety_net
);
permissive
=
(
TextView
)
findViewById
(
R
.
id
.
permissive
);
permissive
=
(
TextView
)
findViewById
(
R
.
id
.
permissive
);
suPath
=
executeCommand
(
"getprop magisk.supath"
);
suPath
=
su
(
"getprop magisk.supath"
);
updateStatus
();
updateStatus
();
rootToggle
.
setOnCheckedChangeListener
(
new
CompoundButton
.
OnCheckedChangeListener
()
{
rootToggle
.
setOnCheckedChangeListener
(
new
CompoundButton
.
OnCheckedChangeListener
()
{
@Override
@Override
public
void
onCheckedChanged
(
CompoundButton
compoundButton
,
boolean
b
)
{
public
void
onCheckedChanged
(
CompoundButton
compoundButton
,
boolean
b
)
{
executeCommand
(
b
?
"setprop magisk.root 1"
:
"setprop magisk.root 0"
);
su
(
b
?
"setprop magisk.root 1"
:
"setprop magisk.root 0"
);
updateStatus
();
updateStatus
();
}
}
});
});
...
@@ -46,7 +46,7 @@ public class MainActivity extends Activity {
...
@@ -46,7 +46,7 @@ public class MainActivity extends Activity {
selinuxToggle
.
setOnCheckedChangeListener
(
new
CompoundButton
.
OnCheckedChangeListener
()
{
selinuxToggle
.
setOnCheckedChangeListener
(
new
CompoundButton
.
OnCheckedChangeListener
()
{
@Override
@Override
public
void
onCheckedChanged
(
CompoundButton
compoundButton
,
boolean
b
)
{
public
void
onCheckedChanged
(
CompoundButton
compoundButton
,
boolean
b
)
{
executeCommand
(
b
?
"setenforce 1"
:
"setenforce 0"
);
su
(
b
?
"setenforce 1"
:
"setenforce 0"
);
updateStatus
();
updateStatus
();
}
}
});
});
...
@@ -55,9 +55,9 @@ public class MainActivity extends Activity {
...
@@ -55,9 +55,9 @@ public class MainActivity extends Activity {
}
}
private
void
updateStatus
()
{
private
void
updateStatus
()
{
String
selinux
=
executeCommand
(
"getenforce"
);
String
selinux
=
su
(
"getenforce"
);
magiskVersion
.
setText
(
getString
(
R
.
string
.
magisk_version
,
executeCommand
(
"getprop magisk.version"
)));
magiskVersion
.
setText
(
getString
(
R
.
string
.
magisk_version
,
su
(
"getprop magisk.version"
)));
selinuxStatus
.
setText
(
selinux
);
selinuxStatus
.
setText
(
selinux
);
if
(
selinux
.
equals
(
"Enforcing"
))
{
if
(
selinux
.
equals
(
"Enforcing"
))
{
...
...
app/src/main/java/com/topjohnwu/magisk/ui/ModulesFragment.java
View file @
7eadc74f
...
@@ -88,7 +88,7 @@ public class ModulesFragment extends Fragment {
...
@@ -88,7 +88,7 @@ public class ModulesFragment extends Fragment {
}
}
});
});
Utils
.
executeCommand
(
"chmod 777
/cache"
);
Utils
.
su
(
"chmod 755
/cache"
);
File
[]
magiskCache
=
new
File
(
MAGISK_CACHE_PATH
).
listFiles
(
new
FileFilter
()
{
File
[]
magiskCache
=
new
File
(
MAGISK_CACHE_PATH
).
listFiles
(
new
FileFilter
()
{
@Override
@Override
...
...
app/src/main/java/com/topjohnwu/magisk/ui/utils/Utils.java
View file @
7eadc74f
...
@@ -6,8 +6,11 @@ import eu.chainfire.libsuperuser.Shell;
...
@@ -6,8 +6,11 @@ import eu.chainfire.libsuperuser.Shell;
public
class
Utils
{
public
class
Utils
{
public
static
String
executeCommand
(
String
...
commands
)
{
public
static
final
String
suPath
=
sh
(
"getprop magisk.supath"
);
List
<
String
>
result
=
Shell
.
SU
.
run
(
commands
);
public
static
final
boolean
rootAccess
=
isRoot
();
public
static
String
sh
(
String
...
commands
)
{
List
<
String
>
result
=
Shell
.
SH
.
run
(
commands
);
StringBuilder
builder
=
new
StringBuilder
();
StringBuilder
builder
=
new
StringBuilder
();
for
(
String
s
:
result
)
{
for
(
String
s
:
result
)
{
...
@@ -17,4 +20,43 @@ public class Utils {
...
@@ -17,4 +20,43 @@ public class Utils {
return
builder
.
toString
();
return
builder
.
toString
();
}
}
public
static
String
su
(
String
...
commands
)
{
List
<
String
>
result
=
Shell
.
run
(
Utils
.
suPath
+
"/su"
,
commands
,
null
,
false
);
StringBuilder
builder
=
new
StringBuilder
();
for
(
String
s
:
result
)
{
builder
.
append
(
s
);
}
Shell
.
SU
.
available
();
return
builder
.
toString
();
}
public
static
boolean
isRoot
()
{
String
[]
availableTestCommands
=
new
String
[]
{
"echo -BOC-"
,
"id"
};
List
<
String
>
ret
=
Shell
.
run
(
Utils
.
suPath
+
"/su"
,
availableTestCommands
,
null
,
false
);
if
(
ret
==
null
)
return
false
;
// Taken from libsuperuser
// this is only one of many ways this can be done
boolean
echo_seen
=
false
;
for
(
String
line
:
ret
)
{
if
(
line
.
contains
(
"uid="
))
{
// id command is working, let's see if we are actually root
return
line
.
contains
(
"uid=0"
);
}
else
if
(
line
.
contains
(
"-BOC-"
))
{
// if we end up here, at least the su command starts some kind
// of shell, let's hope it has root privileges - no way to know without
// additional native binaries
echo_seen
=
true
;
}
}
return
echo_seen
;
}
}
}
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