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
b18b5c4f
Commit
b18b5c4f
authored
Aug 07, 2016
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update disable method (requires Magisk v2)
parent
4752b077
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
99 deletions
+131
-99
vcs.xml
.idea/vcs.xml
+1
-1
build.gradle
app/build.gradle
+3
-3
MainActivity.java
app/src/main/java/com/topjohnwu/magisk/MainActivity.java
+90
-77
activity_main.xml
app/src/main/res/layout/activity_main.xml
+37
-18
No files found.
.idea/vcs.xml
View file @
b18b5c4f
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"
$PROJECT_DIR$
"
vcs=
"Git"
/>
<mapping
directory=
""
vcs=
"Git"
/>
</component>
</component>
</project>
</project>
\ No newline at end of file
app/build.gradle
View file @
b18b5c4f
...
@@ -2,14 +2,14 @@ apply plugin: 'com.android.application'
...
@@ -2,14 +2,14 @@ apply plugin: 'com.android.application'
android
{
android
{
compileSdkVersion
24
compileSdkVersion
24
buildToolsVersion
"24.0.
0
"
buildToolsVersion
"24.0.
1
"
defaultConfig
{
defaultConfig
{
applicationId
"com.topjohnwu.magisk"
applicationId
"com.topjohnwu.magisk"
minSdkVersion
21
minSdkVersion
21
targetSdkVersion
24
targetSdkVersion
24
versionCode
1
versionCode
2
versionName
"1.
0
"
versionName
"1.
1
"
}
}
buildTypes
{
buildTypes
{
release
{
release
{
...
...
app/src/main/java/com/topjohnwu/magisk/MainActivity.java
View file @
b18b5c4f
...
@@ -4,76 +4,107 @@ import android.app.Activity;
...
@@ -4,76 +4,107 @@ import android.app.Activity;
import
android.graphics.Color
;
import
android.graphics.Color
;
import
android.os.AsyncTask
;
import
android.os.AsyncTask
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.util.Log
;
import
android.view.View
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.Switch
;
import
android.widget.Switch
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
java.io.BufferedReader
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.DataOutputStream
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
public
class
MainActivity
extends
Activity
{
public
class
MainActivity
extends
Activity
{
private
String
suPATH
;
private
Switch
selinuxSwitch
;
private
String
xbinPATH
;
private
Switch
rootSwitch
,
selinuxSwitch
;
private
TextView
rootStatus
,
selinuxStatus
,
safetyNet
,
permissive
;
private
TextView
rootStatus
,
selinuxStatus
,
safetyNet
,
permissive
;
private
Button
rootButton
;
private
EditText
countdown
;
private
String
execute
(
String
command
)
{
StringBuffer
output
=
new
StringBuffer
();
Process
p
;
try
{
p
=
Runtime
.
getRuntime
().
exec
(
command
);
p
.
waitFor
();
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
p
.
getInputStream
()));
protected
class
callSU
extends
AsyncTask
<
String
,
Void
,
String
[]>
{
String
line
=
""
;
while
((
line
=
reader
.
readLine
())!=
null
)
{
output
.
append
(
line
+
"\n"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
String
response
=
output
.
toString
();
return
response
;
}
private
void
updateStatus
()
{
String
selinux
=
execute
(
"getenforce"
);
if
((
new
File
(
"/system/xbin/su"
).
exists
()))
{
rootStatus
.
setText
(
"Mounted"
);
rootStatus
.
setTextColor
(
Color
.
RED
);
safetyNet
.
setText
(
"Root mounted and enabled. Safety Net (Android Pay) will NOT work"
);
safetyNet
.
setTextColor
(
Color
.
RED
);
rootButton
.
setEnabled
(
true
);
}
else
{
rootStatus
.
setText
(
"Not Mounted"
);
rootStatus
.
setTextColor
(
Color
.
GREEN
);
safetyNet
.
setText
(
"Safety Net (Android Pay) should work, but no root temporarily"
);
safetyNet
.
setTextColor
(
Color
.
GREEN
);
rootButton
.
setEnabled
(
false
);
}
selinuxStatus
.
setText
(
selinux
);
if
(
selinux
.
equals
(
"Enforcing\n"
))
{
selinuxStatus
.
setTextColor
(
Color
.
GREEN
);
selinuxSwitch
.
setChecked
(
true
);
permissive
.
setText
(
"SELinux is enforced"
);
permissive
.
setTextColor
(
Color
.
GREEN
);
}
else
{
selinuxStatus
.
setTextColor
(
Color
.
RED
);
selinuxSwitch
.
setChecked
(
false
);
permissive
.
setText
(
"Only turn off SELinux if necessary!"
);
permissive
.
setTextColor
(
Color
.
RED
);
}
}
protected
class
SU
extends
AsyncTask
<
String
,
Void
,
Void
>
{
@Override
@Override
protected
String
[]
doInBackground
(
String
...
params
)
{
protected
Void
doInBackground
(
String
...
params
)
{
String
[]
results
=
new
String
[
2
];
try
{
try
{
Process
su
=
Runtime
.
getRuntime
().
exec
(
suPATH
);
Process
su
=
Runtime
.
getRuntime
().
exec
(
"su"
);
DataOutputStream
out
=
new
DataOutputStream
(
su
.
getOutputStream
());
DataOutputStream
out
=
new
DataOutputStream
(
su
.
getOutputStream
());
DataInputStream
in
=
new
DataInputStream
(
su
.
getInputStream
());
for
(
String
command
:
params
)
{
for
(
int
i
=
0
;
i
<
params
.
length
;
++
i
)
{
out
.
writeBytes
(
command
+
"\n"
);
out
.
writeBytes
(
params
[
i
]
+
"\n"
);
out
.
flush
();
out
.
flush
();
}
}
out
.
writeBytes
(
"if [ -z $(which su) ]; then echo 0; else echo 1; fi;\n"
);
out
.
flush
();
results
[
0
]
=
in
.
readLine
();
out
.
writeBytes
(
"getenforce\n"
);
out
.
flush
();
results
[
1
]
=
in
.
readLine
();
out
.
writeBytes
(
"exit\n"
);
out
.
writeBytes
(
"exit\n"
);
out
.
flush
();
out
.
flush
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
results
;
return
null
;
}
}
@Override
protected
void
onPostExecute
(
String
[]
results
)
{
if
(
results
[
0
].
equals
(
"1"
))
{
rootStatus
.
setText
(
"Mounted"
);
rootStatus
.
setTextColor
(
Color
.
RED
);
rootSwitch
.
setChecked
(
true
);
safetyNet
.
setText
(
"Root mounted and enabled. Safety Net (Android Pay) will NOT work"
);
safetyNet
.
setTextColor
(
Color
.
RED
);
}
else
{
rootStatus
.
setText
(
"Not Mounted"
);
rootStatus
.
setTextColor
(
Color
.
GREEN
);
rootSwitch
.
setChecked
(
false
);
safetyNet
.
setText
(
"Safety Net (Android Pay) should work, but no root temporarily"
);
safetyNet
.
setTextColor
(
Color
.
GREEN
);
}
selinuxStatus
.
setText
(
results
[
1
]);
@Override
protected
void
onPostExecute
(
Void
aVoid
)
{
if
(
results
[
1
].
equals
(
"Enforcing"
))
{
final
Handler
handler
=
new
Handler
();
selinuxStatus
.
setTextColor
(
Color
.
GREEN
);
handler
.
postDelayed
(
new
Runnable
()
{
selinuxSwitch
.
setChecked
(
true
);
@Override
permissive
.
setText
(
"SELinux is enforced"
);
public
void
run
()
{
permissive
.
setTextColor
(
Color
.
GREEN
);
updateStatus
();
}
else
{
}
selinuxStatus
.
setTextColor
(
Color
.
RED
);
},
1500
);
selinuxSwitch
.
setChecked
(
false
);
permissive
.
setText
(
"Only turn off SELinux if necessary!"
);
permissive
.
setTextColor
(
Color
.
RED
);
}
}
}
}
}
...
@@ -81,46 +112,28 @@ public class MainActivity extends Activity {
...
@@ -81,46 +112,28 @@ public class MainActivity extends Activity {
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
boolean
rooted
=
true
;
if
(!(
new
File
(
"/magisk/phh/su"
)).
exists
())
{
setContentView
(
R
.
layout
.
no_root
);
File
phh
=
new
File
(
"/magisk/phh/su"
);
File
supersu
=
new
File
(
"/su/bin/su"
);
if
(!
supersu
.
exists
())
{
if
(!
phh
.
exists
())
{
setContentView
(
R
.
layout
.
no_root
);
rooted
=
false
;
}
else
{
suPATH
=
"/magisk/phh/su"
;
xbinPATH
=
"/magisk/phh/xbin"
;
}
}
else
{
}
else
{
suPATH
=
"/su/bin/su"
;
xbinPATH
=
"/su/xbin"
;
}
if
(
rooted
)
{
setContentView
(
R
.
layout
.
activity_main
);
setContentView
(
R
.
layout
.
activity_main
);
rootSwitch
=
(
Switch
)
findViewById
(
R
.
id
.
root_switch
);
selinuxSwitch
=
(
Switch
)
findViewById
(
R
.
id
.
permissive_switch
);
selinuxSwitch
=
(
Switch
)
findViewById
(
R
.
id
.
permissive_switch
);
rootStatus
=
(
TextView
)
findViewById
(
R
.
id
.
root_status
);
rootStatus
=
(
TextView
)
findViewById
(
R
.
id
.
root_status
);
selinuxStatus
=
(
TextView
)
findViewById
(
R
.
id
.
selinux_status
);
selinuxStatus
=
(
TextView
)
findViewById
(
R
.
id
.
selinux_status
);
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
);
countdown
=
(
EditText
)
findViewById
(
R
.
id
.
countdown
);
rootButton
=
(
Button
)
findViewById
(
R
.
id
.
rootButton
);
(
new
callSU
()).
execute
();
updateStatus
();
root
Switch
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
root
Button
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
@Override
public
void
onClick
(
View
view
)
{
public
void
onClick
(
View
view
)
{
Switch
s
=
(
Switch
)
view
;
int
timeout
;
if
(
s
.
isChecked
())
{
timeout
=
Integer
.
parseInt
(
countdown
.
getText
().
toString
())
*
60
;
(
new
callSU
()).
execute
(
"mount -o bind "
+
xbinPATH
+
" /system/xbin"
);
(
new
SU
()).
execute
(
"setprop magisk.timeout "
+
String
.
valueOf
(
timeout
),
"setprop magisk.phhsu 0"
);
}
else
{
(
new
callSU
()).
execute
(
"umount /system/xbin"
);
}
}
}
});
});
...
@@ -129,9 +142,9 @@ public class MainActivity extends Activity {
...
@@ -129,9 +142,9 @@ public class MainActivity extends Activity {
public
void
onClick
(
View
view
)
{
public
void
onClick
(
View
view
)
{
Switch
s
=
(
Switch
)
view
;
Switch
s
=
(
Switch
)
view
;
if
(
s
.
isChecked
())
{
if
(
s
.
isChecked
())
{
(
new
call
SU
()).
execute
(
"setenforce 1"
);
(
new
SU
()).
execute
(
"setenforce 1"
);
}
else
{
}
else
{
(
new
call
SU
()).
execute
(
"setenforce 0"
);
(
new
SU
()).
execute
(
"setenforce 0"
);
}
}
}
}
});
});
...
...
app/src/main/res/layout/activity_main.xml
View file @
b18b5c4f
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
xmlns:tools=
"http://schemas.android.com/tools"
android:focusableInTouchMode=
"true"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:paddingBottom=
"@dimen/activity_vertical_margin"
android:paddingBottom=
"@dimen/activity_vertical_margin"
...
@@ -24,7 +25,7 @@
...
@@ -24,7 +25,7 @@
<TextView
<TextView
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"(
root access
)"
android:text=
"(
unavailable
)"
android:id=
"@+id/root_status"
android:id=
"@+id/root_status"
android:textStyle=
"bold"
android:textStyle=
"bold"
android:layout_toEndOf=
"@+id/root_label"
android:layout_toEndOf=
"@+id/root_label"
...
@@ -46,7 +47,7 @@
...
@@ -46,7 +47,7 @@
<TextView
<TextView
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"(
root access
)"
android:text=
"(
unavailable
)"
android:id=
"@+id/selinux_status"
android:id=
"@+id/selinux_status"
android:textStyle=
"bold"
android:textStyle=
"bold"
android:layout_below=
"@+id/root_status"
android:layout_below=
"@+id/root_status"
...
@@ -58,7 +59,7 @@
...
@@ -58,7 +59,7 @@
<TextView
<TextView
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"(
root access
)"
android:text=
"(
unavailable
)"
android:id=
"@+id/safety_net"
android:id=
"@+id/safety_net"
android:layout_below=
"@+id/selinux_label"
android:layout_below=
"@+id/selinux_label"
android:layout_alignParentStart=
"true"
android:layout_alignParentStart=
"true"
...
@@ -69,7 +70,7 @@
...
@@ -69,7 +70,7 @@
<TextView
<TextView
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"(
root access
)"
android:text=
"(
unavailable
)"
android:id=
"@+id/permissive"
android:id=
"@+id/permissive"
android:layout_below=
"@+id/safety_net"
android:layout_below=
"@+id/safety_net"
android:layout_alignParentStart=
"true"
android:layout_alignParentStart=
"true"
...
@@ -77,19 +78,6 @@
...
@@ -77,19 +78,6 @@
android:layout_marginLeft=
"10dp"
android:layout_marginLeft=
"10dp"
android:textSize=
"15sp"
/>
android:textSize=
"15sp"
/>
<Switch
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Root Mount Toggle"
android:id=
"@+id/root_switch"
android:layout_marginTop=
"10dp"
android:textSize=
"20sp"
android:switchPadding=
"20dp"
android:layout_below=
"@+id/permissive"
android:layout_alignParentStart=
"true"
android:layout_marginLeft=
"10dp"
/>
<Switch
<Switch
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
...
@@ -98,8 +86,39 @@
...
@@ -98,8 +86,39 @@
android:layout_marginTop=
"20dp"
android:layout_marginTop=
"20dp"
android:textSize=
"20sp"
android:textSize=
"20sp"
android:switchPadding=
"20dp"
android:switchPadding=
"20dp"
android:layout_below=
"@+id/
root_switch
"
android:layout_below=
"@+id/
countdown
"
android:layout_alignParentStart=
"true"
android:layout_alignParentStart=
"true"
android:layout_marginLeft=
"10dp"
/>
android:layout_marginLeft=
"10dp"
/>
<EditText
android:layout_width=
"50dp"
android:layout_height=
"wrap_content"
android:inputType=
"number"
android:id=
"@+id/countdown"
android:layout_below=
"@+id/permissive"
android:layout_alignParentStart=
"true"
android:textAlignment=
"center"
android:text=
"5"
android:layout_marginTop=
"10dp"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textAppearance=
"?android:attr/textAppearanceMedium"
android:text=
"minutes"
android:id=
"@+id/textMin"
android:layout_alignBottom=
"@+id/countdown"
android:layout_toEndOf=
"@+id/countdown"
android:layout_marginBottom=
"10dp"
android:layout_marginLeft=
"5dp"
android:layout_marginRight=
"5dp"
/>
<Button
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Disable root"
android:id=
"@+id/rootButton"
android:layout_alignTop=
"@+id/countdown"
android:layout_toEndOf=
"@+id/textMin"
/>
</RelativeLayout>
</RelativeLayout>
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