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
821726e7
Commit
821726e7
authored
Jan 20, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switch to libsu
parent
759e905c
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
71 additions
and
340 deletions
+71
-340
build.gradle
build.gradle
+1
-0
FlashActivity.java
src/main/java/com/topjohnwu/magisk/FlashActivity.java
+5
-5
MagiskFragment.java
src/main/java/com/topjohnwu/magisk/MagiskFragment.java
+1
-1
MagiskLogFragment.java
src/main/java/com/topjohnwu/magisk/MagiskLogFragment.java
+10
-11
MagiskManager.java
src/main/java/com/topjohnwu/magisk/MagiskManager.java
+31
-2
MainActivity.java
src/main/java/com/topjohnwu/magisk/MainActivity.java
+1
-1
ModulesFragment.java
src/main/java/com/topjohnwu/magisk/ModulesFragment.java
+1
-1
SettingsActivity.java
src/main/java/com/topjohnwu/magisk/SettingsActivity.java
+1
-1
SplashActivity.java
src/main/java/com/topjohnwu/magisk/SplashActivity.java
+1
-1
ApplicationAdapter.java
...ava/com/topjohnwu/magisk/adapters/ApplicationAdapter.java
+1
-1
ModulesAdapter.java
...in/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java
+1
-1
CheckSafetyNet.java
...main/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java
+1
-1
FlashZip.java
src/main/java/com/topjohnwu/magisk/asyncs/FlashZip.java
+1
-1
HideManager.java
src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java
+1
-1
InstallMagisk.java
src/main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java
+4
-5
LoadModules.java
src/main/java/com/topjohnwu/magisk/asyncs/LoadModules.java
+1
-1
ProcessRepoZip.java
...main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java
+1
-1
RestoreImages.java
src/main/java/com/topjohnwu/magisk/asyncs/RestoreImages.java
+1
-1
CallbackList.java
...ain/java/com/topjohnwu/magisk/container/CallbackList.java
+0
-22
SuDatabaseHelper.java
.../java/com/topjohnwu/magisk/database/SuDatabaseHelper.java
+1
-1
PackageReceiver.java
.../java/com/topjohnwu/magisk/receivers/PackageReceiver.java
+1
-1
RebootReceiver.java
...n/java/com/topjohnwu/magisk/receivers/RebootReceiver.java
+1
-1
OnBootIntentService.java
...va/com/topjohnwu/magisk/services/OnBootIntentService.java
+1
-1
Const.java
src/main/java/com/topjohnwu/magisk/utils/Const.java
+1
-8
Shell.java
src/main/java/com/topjohnwu/magisk/utils/Shell.java
+0
-207
ShowUI.java
src/main/java/com/topjohnwu/magisk/utils/ShowUI.java
+1
-0
StreamGobbler.java
src/main/java/com/topjohnwu/magisk/utils/StreamGobbler.java
+0
-63
Utils.java
src/main/java/com/topjohnwu/magisk/utils/Utils.java
+1
-0
No files found.
build.gradle
View file @
821726e7
...
@@ -55,6 +55,7 @@ repositories {
...
@@ -55,6 +55,7 @@ repositories {
dependencies
{
dependencies
{
implementation
fileTree
(
include:
[
'*.jar'
],
dir:
'libs'
)
implementation
fileTree
(
include:
[
'*.jar'
],
dir:
'libs'
)
implementation
project
(
':crypto'
)
implementation
project
(
':crypto'
)
implementation
'com.github.topjohnwu:libsu:0.1.0'
implementation
'com.android.support:recyclerview-v7:27.0.2'
implementation
'com.android.support:recyclerview-v7:27.0.2'
implementation
'com.android.support:cardview-v7:27.0.2'
implementation
'com.android.support:cardview-v7:27.0.2'
implementation
'com.android.support:design:27.0.2'
implementation
'com.android.support:design:27.0.2'
...
...
src/main/java/com/topjohnwu/magisk/FlashActivity.java
View file @
821726e7
...
@@ -16,9 +16,9 @@ import android.widget.Toast;
...
@@ -16,9 +16,9 @@ import android.widget.Toast;
import
com.topjohnwu.magisk.asyncs.FlashZip
;
import
com.topjohnwu.magisk.asyncs.FlashZip
;
import
com.topjohnwu.magisk.asyncs.InstallMagisk
;
import
com.topjohnwu.magisk.asyncs.InstallMagisk
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.container.CallbackList
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.ShellCallbackVector
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.FileWriter
;
...
@@ -96,10 +96,10 @@ public class FlashActivity extends Activity {
...
@@ -96,10 +96,10 @@ public class FlashActivity extends Activity {
reboot
.
setVisibility
(
View
.
GONE
);
reboot
.
setVisibility
(
View
.
GONE
);
logs
=
new
ArrayList
<>();
logs
=
new
ArrayList
<>();
List
<
String
>
console
=
new
CallbackList
<
String
>
()
{
ShellCallbackVector
console
=
new
ShellCallbackVector
()
{
@Override
@Override
public
synchronized
void
onAddElement
(
String
e
)
{
public
void
onShellOutput
(
String
s
)
{
logs
.
add
(
e
);
logs
.
add
(
s
);
flashLogs
.
setText
(
TextUtils
.
join
(
"\n"
,
this
));
flashLogs
.
setText
(
TextUtils
.
join
(
"\n"
,
this
));
sv
.
postDelayed
(()
->
sv
.
fullScroll
(
ScrollView
.
FOCUS_DOWN
),
10
);
sv
.
postDelayed
(()
->
sv
.
fullScroll
(
ScrollView
.
FOCUS_DOWN
),
10
);
}
}
...
...
src/main/java/com/topjohnwu/magisk/MagiskFragment.java
View file @
821726e7
...
@@ -22,10 +22,10 @@ import com.topjohnwu.magisk.asyncs.CheckUpdates;
...
@@ -22,10 +22,10 @@ import com.topjohnwu.magisk.asyncs.CheckUpdates;
import
com.topjohnwu.magisk.components.AlertDialogBuilder
;
import
com.topjohnwu.magisk.components.AlertDialogBuilder
;
import
com.topjohnwu.magisk.components.ExpandableView
;
import
com.topjohnwu.magisk.components.ExpandableView
;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.ShowUI
;
import
com.topjohnwu.magisk.utils.ShowUI
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
import
butterknife.BindColor
;
import
butterknife.BindColor
;
import
butterknife.BindView
;
import
butterknife.BindView
;
...
...
src/main/java/com/topjohnwu/magisk/MagiskLogFragment.java
View file @
821726e7
...
@@ -21,8 +21,9 @@ import com.topjohnwu.magisk.asyncs.ParallelTask;
...
@@ -21,8 +21,9 @@ import com.topjohnwu.magisk.asyncs.ParallelTask;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.ShellCallback
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.FileWriter
;
...
@@ -188,7 +189,7 @@ public class MagiskLogFragment extends Fragment {
...
@@ -188,7 +189,7 @@ public class MagiskLogFragment extends Fragment {
}
}
}
}
private
static
class
StringBuildingList
extends
Shell
.
AbstractList
<
String
>
{
private
static
class
StringBuildingList
extends
Shell
Callback
{
StringBuilder
builder
;
StringBuilder
builder
;
...
@@ -196,18 +197,17 @@ public class MagiskLogFragment extends Fragment {
...
@@ -196,18 +197,17 @@ public class MagiskLogFragment extends Fragment {
builder
=
new
StringBuilder
();
builder
=
new
StringBuilder
();
}
}
@Override
public
boolean
add
(
String
s
)
{
builder
.
append
(
s
).
append
(
"\n"
);
return
true
;
}
public
CharSequence
getCharSequence
()
{
public
CharSequence
getCharSequence
()
{
return
builder
;
return
builder
;
}
}
@Override
public
void
onShellOutput
(
String
s
)
{
builder
.
append
(
s
).
append
(
"\n"
);
}
}
}
private
static
class
FileWritingList
extends
Shell
.
AbstractList
<
String
>
{
private
static
class
FileWritingList
extends
Shell
Callback
{
private
FileWriter
writer
;
private
FileWriter
writer
;
...
@@ -216,11 +216,10 @@ public class MagiskLogFragment extends Fragment {
...
@@ -216,11 +216,10 @@ public class MagiskLogFragment extends Fragment {
}
}
@Override
@Override
public
boolean
add
(
String
s
)
{
public
void
onShellOutput
(
String
s
)
{
try
{
try
{
writer
.
write
(
s
+
"\n"
);
writer
.
write
(
s
+
"\n"
);
}
catch
(
IOException
ignored
)
{}
}
catch
(
IOException
ignored
)
{}
return
true
;
}
}
}
}
...
...
src/main/java/com/topjohnwu/magisk/MagiskManager.java
View file @
821726e7
...
@@ -14,16 +14,20 @@ import com.topjohnwu.magisk.container.Module;
...
@@ -14,16 +14,20 @@ import com.topjohnwu.magisk.container.Module;
import
com.topjohnwu.magisk.database.RepoDatabaseHelper
;
import
com.topjohnwu.magisk.database.RepoDatabaseHelper
;
import
com.topjohnwu.magisk.database.SuDatabaseHelper
;
import
com.topjohnwu.magisk.database.SuDatabaseHelper
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.ShellContainer
;
import
com.topjohnwu.superuser.ShellInitializer
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.lang.ref.WeakReference
;
import
java.lang.ref.WeakReference
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Map
;
public
class
MagiskManager
extends
Application
{
public
class
MagiskManager
extends
Application
implements
ShellContainer
{
// Global weak reference to self
// Global weak reference to self
private
static
WeakReference
<
MagiskManager
>
weakSelf
;
private
static
WeakReference
<
MagiskManager
>
weakSelf
;
...
@@ -85,6 +89,21 @@ public class MagiskManager extends Application {
...
@@ -85,6 +89,21 @@ public class MagiskManager extends Application {
public
MagiskManager
()
{
public
MagiskManager
()
{
weakSelf
=
new
WeakReference
<>(
this
);
weakSelf
=
new
WeakReference
<>(
this
);
Shell
.
setFlags
(
Shell
.
FLAG_MOUNT_MASTER
);
Shell
.
setGlobalContainer
(
this
);
Shell
.
setInitializer
(
new
ShellInitializer
()
{
@Override
public
void
onRootShellInit
(
Shell
shell
)
{
try
(
InputStream
in
=
MagiskManager
.
get
().
getAssets
().
open
(
Const
.
UTIL_FUNCTIONS
))
{
shell
.
loadInputStream
(
in
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
shell
.
run_raw
(
"export PATH="
+
Const
.
BUSYBOX_PATH
+
":$PATH"
,
"mount_partitions"
,
"run_migrations"
);
}
});
}
}
@Override
@Override
...
@@ -110,6 +129,16 @@ public class MagiskManager extends Application {
...
@@ -110,6 +129,16 @@ public class MagiskManager extends Application {
loadConfig
();
loadConfig
();
}
}
@Override
public
Shell
getShell
()
{
return
shell
;
}
@Override
public
void
setShell
(
Shell
shell
)
{
this
.
shell
=
shell
;
}
public
static
MagiskManager
get
()
{
public
static
MagiskManager
get
()
{
return
weakSelf
.
get
();
return
weakSelf
.
get
();
}
}
...
...
src/main/java/com/topjohnwu/magisk/MainActivity.java
View file @
821726e7
...
@@ -19,9 +19,9 @@ import android.view.View;
...
@@ -19,9 +19,9 @@ import android.view.View;
import
com.topjohnwu.magisk.asyncs.MarkDownWindow
;
import
com.topjohnwu.magisk.asyncs.MarkDownWindow
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
...
...
src/main/java/com/topjohnwu/magisk/ModulesFragment.java
View file @
821726e7
...
@@ -20,9 +20,9 @@ import com.topjohnwu.magisk.asyncs.LoadModules;
...
@@ -20,9 +20,9 @@ import com.topjohnwu.magisk.asyncs.LoadModules;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.container.Module
;
import
com.topjohnwu.magisk.container.Module
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
...
src/main/java/com/topjohnwu/magisk/SettingsActivity.java
View file @
821726e7
...
@@ -23,9 +23,9 @@ import com.topjohnwu.magisk.asyncs.HideManager;
...
@@ -23,9 +23,9 @@ import com.topjohnwu.magisk.asyncs.HideManager;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.FingerprintHelper
;
import
com.topjohnwu.magisk.utils.FingerprintHelper
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
import
java.util.Locale
;
import
java.util.Locale
;
...
...
src/main/java/com/topjohnwu/magisk/SplashActivity.java
View file @
821726e7
...
@@ -17,8 +17,8 @@ import com.topjohnwu.magisk.asyncs.UpdateRepos;
...
@@ -17,8 +17,8 @@ import com.topjohnwu.magisk.asyncs.UpdateRepos;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.services.UpdateCheckService
;
import
com.topjohnwu.magisk.services.UpdateCheckService
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
public
class
SplashActivity
extends
Activity
{
public
class
SplashActivity
extends
Activity
{
...
...
src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java
View file @
821726e7
...
@@ -18,9 +18,9 @@ import com.topjohnwu.magisk.R;
...
@@ -18,9 +18,9 @@ import com.topjohnwu.magisk.R;
import
com.topjohnwu.magisk.asyncs.ParallelTask
;
import
com.topjohnwu.magisk.asyncs.ParallelTask
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
...
...
src/main/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java
View file @
821726e7
...
@@ -14,7 +14,7 @@ import android.widget.TextView;
...
@@ -14,7 +14,7 @@ import android.widget.TextView;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.container.Module
;
import
com.topjohnwu.magisk.container.Module
;
import
com.topjohnwu.
magisk.utils
.Shell
;
import
com.topjohnwu.
superuser
.Shell
;
import
java.util.List
;
import
java.util.List
;
...
...
src/main/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java
View file @
821726e7
...
@@ -4,9 +4,9 @@ import android.app.Activity;
...
@@ -4,9 +4,9 @@ import android.app.Activity;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.WebService
;
import
com.topjohnwu.magisk.utils.WebService
;
import
com.topjohnwu.superuser.Shell
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.BufferedOutputStream
;
...
...
src/main/java/com/topjohnwu/magisk/asyncs/FlashZip.java
View file @
821726e7
...
@@ -8,9 +8,9 @@ import android.view.View;
...
@@ -8,9 +8,9 @@ import android.view.View;
import
com.topjohnwu.magisk.FlashActivity
;
import
com.topjohnwu.magisk.FlashActivity
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.ZipUtils
;
import
com.topjohnwu.magisk.utils.ZipUtils
;
import
com.topjohnwu.superuser.Shell
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.BufferedOutputStream
;
...
...
src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java
View file @
821726e7
...
@@ -8,9 +8,9 @@ import com.topjohnwu.crypto.JarMap;
...
@@ -8,9 +8,9 @@ import com.topjohnwu.crypto.JarMap;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.ZipUtils
;
import
com.topjohnwu.magisk.utils.ZipUtils
;
import
com.topjohnwu.superuser.Shell
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
...
...
src/main/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java
View file @
821726e7
...
@@ -12,9 +12,9 @@ import com.topjohnwu.magisk.FlashActivity;
...
@@ -12,9 +12,9 @@ import com.topjohnwu.magisk.FlashActivity;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.container.TarEntry
;
import
com.topjohnwu.magisk.container.TarEntry
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.ZipUtils
;
import
com.topjohnwu.magisk.utils.ZipUtils
;
import
com.topjohnwu.superuser.Shell
;
import
org.kamranzafar.jtar.TarInputStream
;
import
org.kamranzafar.jtar.TarInputStream
;
import
org.kamranzafar.jtar.TarOutputStream
;
import
org.kamranzafar.jtar.TarOutputStream
;
...
@@ -178,7 +178,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
...
@@ -178,7 +178,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
// Force non-root shell
// Force non-root shell
Shell
shell
;
Shell
shell
;
if
(
Shell
.
rootAccess
())
if
(
Shell
.
rootAccess
())
shell
=
new
Shell
(
"sh"
);
shell
=
Shell
.
new
Shell
(
"sh"
);
else
else
shell
=
Shell
.
getShell
();
shell
=
Shell
.
getShell
();
...
@@ -192,8 +192,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
...
@@ -192,8 +192,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
if
(
TextUtils
.
equals
(
console
.
get
(
console
.
size
()
-
1
),
"Failed!"
))
if
(
TextUtils
.
equals
(
console
.
get
(
console
.
size
()
-
1
),
"Failed!"
))
return
false
;
return
false
;
shell
.
run
(
null
,
null
,
shell
.
run
(
"mv -f new-boot.img ../"
,
"mv -f new-boot.img ../"
,
"mv bin/busybox busybox"
,
"mv bin/busybox busybox"
,
"rm -rf bin *.img update-binary"
,
"rm -rf bin *.img update-binary"
,
"cd /"
);
"cd /"
);
...
@@ -212,7 +211,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
...
@@ -212,7 +211,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
)
{
)
{
SignBoot
.
doSignature
(
"/boot"
,
in
,
out
,
keyIn
,
certIn
);
SignBoot
.
doSignature
(
"/boot"
,
in
,
out
,
keyIn
,
certIn
);
}
}
shell
.
run_raw
(
false
,
false
,
"mv -f "
+
signed
+
" "
+
patched_boot
);
shell
.
run_raw
(
"mv -f "
+
signed
+
" "
+
patched_boot
);
}
}
switch
(
mode
)
{
switch
(
mode
)
{
...
...
src/main/java/com/topjohnwu/magisk/asyncs/LoadModules.java
View file @
821726e7
...
@@ -4,7 +4,7 @@ import com.topjohnwu.magisk.MagiskManager;
...
@@ -4,7 +4,7 @@ import com.topjohnwu.magisk.MagiskManager;
import
com.topjohnwu.magisk.container.Module
;
import
com.topjohnwu.magisk.container.Module
;
import
com.topjohnwu.magisk.container.ValueSortedMap
;
import
com.topjohnwu.magisk.container.ValueSortedMap
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.
magisk.utils
.Shell
;
import
com.topjohnwu.
superuser
.Shell
;
import
java.util.List
;
import
java.util.List
;
...
...
src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java
View file @
821726e7
...
@@ -13,10 +13,10 @@ import com.topjohnwu.magisk.FlashActivity;
...
@@ -13,10 +13,10 @@ import com.topjohnwu.magisk.FlashActivity;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.WebService
;
import
com.topjohnwu.magisk.utils.WebService
;
import
com.topjohnwu.magisk.utils.ZipUtils
;
import
com.topjohnwu.magisk.utils.ZipUtils
;
import
com.topjohnwu.superuser.Shell
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.BufferedOutputStream
;
...
...
src/main/java/com/topjohnwu/magisk/asyncs/RestoreImages.java
View file @
821726e7
...
@@ -4,8 +4,8 @@ import android.widget.Toast;
...
@@ -4,8 +4,8 @@ import android.widget.Toast;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
import
java.util.List
;
import
java.util.List
;
...
...
src/main/java/com/topjohnwu/magisk/container/CallbackList.java
deleted
100644 → 0
View file @
759e905c
package
com
.
topjohnwu
.
magisk
.
container
;
import
android.os.Handler
;
import
java.util.ArrayList
;
public
abstract
class
CallbackList
<
E
>
extends
ArrayList
<
E
>
{
private
Handler
handler
;
protected
CallbackList
()
{
handler
=
new
Handler
();
}
public
abstract
void
onAddElement
(
E
e
);
public
synchronized
boolean
add
(
E
e
)
{
boolean
ret
=
super
.
add
(
e
);
handler
.
post
(()
->
onAddElement
(
e
));
return
ret
;
}
}
src/main/java/com/topjohnwu/magisk/database/SuDatabaseHelper.java
View file @
821726e7
...
@@ -15,8 +15,8 @@ import com.topjohnwu.magisk.R;
...
@@ -15,8 +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
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
import
java.io.File
;
import
java.io.File
;
import
java.text.DateFormat
;
import
java.text.DateFormat
;
...
...
src/main/java/com/topjohnwu/magisk/receivers/PackageReceiver.java
View file @
821726e7
...
@@ -6,8 +6,8 @@ import android.content.Intent;
...
@@ -6,8 +6,8 @@ import android.content.Intent;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
public
class
PackageReceiver
extends
BroadcastReceiver
{
public
class
PackageReceiver
extends
BroadcastReceiver
{
@Override
@Override
...
...
src/main/java/com/topjohnwu/magisk/receivers/RebootReceiver.java
View file @
821726e7
...
@@ -4,7 +4,7 @@ import android.content.BroadcastReceiver;
...
@@ -4,7 +4,7 @@ import android.content.BroadcastReceiver;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
com.topjohnwu.
magisk.utils
.Shell
;
import
com.topjohnwu.
superuser
.Shell
;
public
class
RebootReceiver
extends
BroadcastReceiver
{
public
class
RebootReceiver
extends
BroadcastReceiver
{
@Override
@Override
...
...
src/main/java/com/topjohnwu/magisk/services/OnBootIntentService.java
View file @
821726e7
...
@@ -8,8 +8,8 @@ import android.support.v4.app.NotificationCompat;
...
@@ -8,8 +8,8 @@ import android.support.v4.app.NotificationCompat;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
public
class
OnBootIntentService
extends
IntentService
{
public
class
OnBootIntentService
extends
IntentService
{
...
...
src/main/java/com/topjohnwu/magisk/utils/Const.java
View file @
821726e7
...
@@ -27,6 +27,7 @@ public class Const {
...
@@ -27,6 +27,7 @@ public class Const {
// Paths
// Paths
public
static
final
String
MAGISK_DISABLE_FILE
=
"/cache/.disable_magisk"
;
public
static
final
String
MAGISK_DISABLE_FILE
=
"/cache/.disable_magisk"
;
public
static
final
String
BUSYBOX_PATH
=
"/sbin/.core/busybox"
;
public
static
final
String
TMP_FOLDER_PATH
=
"/dev/tmp"
;
public
static
final
String
TMP_FOLDER_PATH
=
"/dev/tmp"
;
public
static
final
String
MAGISK_LOG
=
"/cache/magisk.log"
;
public
static
final
String
MAGISK_LOG
=
"/cache/magisk.log"
;
public
static
final
File
EXTERNAL_PATH
=
new
File
(
Environment
.
getExternalStorageDirectory
(),
"MagiskManager"
);
public
static
final
File
EXTERNAL_PATH
=
new
File
(
Environment
.
getExternalStorageDirectory
(),
"MagiskManager"
);
...
@@ -37,14 +38,6 @@ public class Const {
...
@@ -37,14 +38,6 @@ public class Const {
public
static
final
int
SNET_VER
=
7
;
public
static
final
int
SNET_VER
=
7
;
public
static
final
int
MIN_MODULE_VER
=
1400
;
public
static
final
int
MIN_MODULE_VER
=
1400
;
public
static
String
BUSYBOX_PATH
()
{
if
(
Utils
.
itemExist
(
"/sbin/.core/busybox/busybox"
))
{
return
"/sbin/.core/busybox"
;
}
else
{
return
"/dev/magisk/bin"
;
}
}
public
static
String
MAGISK_PATH
()
{
public
static
String
MAGISK_PATH
()
{
if
(
Utils
.
itemExist
(
"/sbin/.core/img"
))
{
if
(
Utils
.
itemExist
(
"/sbin/.core/img"
))
{
return
"/sbin/.core/img"
;
return
"/sbin/.core/img"
;
...
...
src/main/java/com/topjohnwu/magisk/utils/Shell.java
deleted
100644 → 0
View file @
759e905c
package
com
.
topjohnwu
.
magisk
.
utils
;
import
android.text.TextUtils
;
import
com.topjohnwu.magisk.MagiskManager
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
/**
* Modified by topjohnwu, based on Chainfire's libsuperuser
*/
public
class
Shell
{
// -2 = not initialized; -1 = no shell; 0 = non root shell; 1 = root shell
public
static
int
status
=
-
2
;
private
final
Process
process
;
private
final
OutputStream
STDIN
;
private
final
InputStream
STDOUT
;
private
final
InputStream
STDERR
;
private
static
void
testRootShell
(
Shell
shell
)
throws
IOException
{
shell
.
STDIN
.
write
((
"id\n"
).
getBytes
(
"UTF-8"
));
shell
.
STDIN
.
flush
();
String
s
=
new
BufferedReader
(
new
InputStreamReader
(
shell
.
STDOUT
)).
readLine
();
if
(
TextUtils
.
isEmpty
(
s
)
||
!
s
.
contains
(
"uid=0"
))
{
shell
.
STDIN
.
close
();
shell
.
STDIN
.
close
();
throw
new
IOException
();
}
}
public
Shell
(
String
command
)
throws
IOException
{
process
=
Runtime
.
getRuntime
().
exec
(
command
);
STDIN
=
process
.
getOutputStream
();
STDOUT
=
process
.
getInputStream
();
STDERR
=
process
.
getErrorStream
();
}
public
static
Shell
getShell
()
{
MagiskManager
mm
=
MagiskManager
.
get
();
boolean
needNewShell
=
mm
.
shell
==
null
;
if
(!
needNewShell
)
{
try
{
mm
.
shell
.
process
.
exitValue
();
// The process is dead
needNewShell
=
true
;
}
catch
(
IllegalThreadStateException
ignored
)
{
// This should be the expected result
}
}
if
(
needNewShell
)
{
status
=
1
;
try
{
mm
.
shell
=
new
Shell
(
"su --mount-master"
);
testRootShell
(
mm
.
shell
);
}
catch
(
IOException
e
)
{
// Mount master not implemented
try
{
mm
.
shell
=
new
Shell
(
"su"
);
testRootShell
(
mm
.
shell
);
}
catch
(
IOException
e1
)
{
// No root exists
status
=
0
;
try
{
mm
.
shell
=
new
Shell
(
"sh"
);
}
catch
(
IOException
e2
)
{
status
=
-
1
;
return
null
;
}
}
}
if
(
rootAccess
())
{
// Load utility shell scripts
try
(
InputStream
in
=
mm
.
getAssets
().
open
(
Const
.
UTIL_FUNCTIONS
))
{
mm
.
shell
.
loadInputStream
(
in
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// Root shell initialization
mm
.
shell
.
run_raw
(
false
,
false
,
"export PATH="
+
Const
.
BUSYBOX_PATH
()
+
":$PATH"
,
"mount_partitions"
,
"run_migrations"
);
}
}
return
mm
.
shell
;
}
public
static
boolean
rootAccess
()
{
if
(
status
==
-
2
)
getShell
();
return
status
>
0
;
}
public
void
run
(
Collection
<
String
>
output
,
Collection
<
String
>
error
,
String
...
commands
)
{
StreamGobbler
out
,
err
;
synchronized
(
process
)
{
try
{
out
=
new
StreamGobbler
(
STDOUT
,
output
);
err
=
new
StreamGobbler
(
STDERR
,
error
);
out
.
start
();
err
.
start
();
run_raw
(
output
!=
null
,
error
!=
null
,
commands
);
STDIN
.
write
(
"echo \'-shell-done-\'\necho \'-shell-done-\' >&2\n"
.
getBytes
(
"UTF-8"
));
STDIN
.
flush
();
try
{
out
.
join
();
err
.
join
();
}
catch
(
InterruptedException
ignored
)
{}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
process
.
destroy
();
}
}
}
public
void
run_raw
(
boolean
stdout
,
boolean
stderr
,
String
...
commands
)
{
String
suffix
=
"\n"
;
if
(!
stderr
)
suffix
=
" 2>/dev/null"
+
suffix
;
if
(!
stdout
)
suffix
=
" >/dev/null"
+
suffix
;
synchronized
(
process
)
{
try
{
for
(
String
command
:
commands
)
{
Logger
.
shell
(
true
,
command
);
STDIN
.
write
((
command
+
suffix
).
getBytes
(
"UTF-8"
));
STDIN
.
flush
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
process
.
destroy
();
}
}
}
public
void
loadInputStream
(
InputStream
in
)
{
synchronized
(
process
)
{
try
{
Utils
.
inToOut
(
in
,
STDIN
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
public
static
List
<
String
>
sh
(
String
...
commands
)
{
List
<
String
>
res
=
new
ArrayList
<>();
sh
(
res
,
commands
);
return
res
;
}
public
static
void
sh
(
Collection
<
String
>
output
,
String
...
commands
)
{
Shell
shell
=
getShell
();
if
(
shell
==
null
)
return
;
shell
.
run
(
output
,
null
,
commands
);
}
public
static
void
sh_raw
(
String
...
commands
)
{
Shell
shell
=
getShell
();
if
(
shell
==
null
)
return
;
shell
.
run_raw
(
false
,
false
,
commands
);
}
public
static
List
<
String
>
su
(
String
...
commands
)
{
if
(!
rootAccess
())
return
sh
();
return
sh
(
commands
);
}
public
static
void
su
(
Collection
<
String
>
output
,
String
...
commands
)
{
if
(!
rootAccess
())
return
;
sh
(
output
,
commands
);
}
public
static
void
su_raw
(
String
...
commands
)
{
if
(!
rootAccess
())
return
;
sh_raw
(
commands
);
}
public
static
abstract
class
AbstractList
<
E
>
extends
java
.
util
.
AbstractList
<
E
>
{
@Override
public
abstract
boolean
add
(
E
e
);
@Override
public
E
get
(
int
i
)
{
return
null
;
}
@Override
public
int
size
()
{
return
0
;
}
}
}
src/main/java/com/topjohnwu/magisk/utils/ShowUI.java
View file @
821726e7
...
@@ -22,6 +22,7 @@ import com.topjohnwu.magisk.components.AlertDialogBuilder;
...
@@ -22,6 +22,7 @@ import com.topjohnwu.magisk.components.AlertDialogBuilder;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
com.topjohnwu.magisk.receivers.ManagerUpdate
;
import
com.topjohnwu.magisk.receivers.ManagerUpdate
;
import
com.topjohnwu.magisk.receivers.RebootReceiver
;
import
com.topjohnwu.magisk.receivers.RebootReceiver
;
import
com.topjohnwu.superuser.Shell
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
...
...
src/main/java/com/topjohnwu/magisk/utils/StreamGobbler.java
deleted
100644 → 0
View file @
759e905c
package
com
.
topjohnwu
.
magisk
.
utils
;
import
android.text.TextUtils
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.util.Collection
;
import
java.util.Collections
;
/**
* Modified by topjohnwu, based on Chainfire's libsuperuser
*/
public
class
StreamGobbler
extends
Thread
{
private
BufferedReader
reader
;
private
Collection
<
String
>
writer
;
/**
* <p>StreamGobbler constructor</p>
*
* <p>We use this class because sh STDOUT and STDERR should be read as quickly as
* possible to prevent a deadlock from occurring, or Process.waitFor() never
* returning (as the buffer is full, pausing the native process)</p>
*
* @param in InputStream to read from
* @param out {@literal List<String>} to write to, or null
*/
public
StreamGobbler
(
InputStream
in
,
Collection
<
String
>
out
)
{
try
{
while
(
in
.
available
()
!=
0
)
{
in
.
skip
(
in
.
available
());
}
}
catch
(
IOException
ignored
)
{}
reader
=
new
BufferedReader
(
new
InputStreamReader
(
in
));
writer
=
out
==
null
?
null
:
Collections
.
synchronizedCollection
(
out
);
}
@Override
public
void
run
()
{
// keep reading the InputStream until it ends (or an error occurs)
try
{
String
line
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
if
(
TextUtils
.
equals
(
line
,
"-shell-done-"
))
return
;
if
(
writer
!=
null
)
writer
.
add
(
line
);
Logger
.
shell
(
false
,
line
);
}
}
catch
(
IOException
e
)
{
// reader probably closed, expected exit condition
}
// make sure our stream is closed and resources will be freed
try
{
reader
.
close
();
}
catch
(
IOException
e
)
{
// read already closed
}
}
}
src/main/java/com/topjohnwu/magisk/utils/Utils.java
View file @
821726e7
...
@@ -29,6 +29,7 @@ import com.topjohnwu.magisk.R;
...
@@ -29,6 +29,7 @@ import com.topjohnwu.magisk.R;
import
com.topjohnwu.magisk.SplashActivity
;
import
com.topjohnwu.magisk.SplashActivity
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
com.topjohnwu.superuser.Shell
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
...
...
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