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
914b7ee0
Commit
914b7ee0
authored
Jul 30, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start moving things outside of top Application class
parent
e39f83ed
Hide whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
237 additions
and
214 deletions
+237
-214
FlashActivity.java
app/src/full/java/com/topjohnwu/magisk/FlashActivity.java
+1
-1
Global.java
app/src/full/java/com/topjohnwu/magisk/Global.java
+58
-0
MagiskFragment.java
app/src/full/java/com/topjohnwu/magisk/MagiskFragment.java
+18
-18
MagiskManager.java
app/src/full/java/com/topjohnwu/magisk/MagiskManager.java
+2
-71
MainActivity.java
app/src/full/java/com/topjohnwu/magisk/MainActivity.java
+3
-3
SettingsActivity.java
app/src/full/java/com/topjohnwu/magisk/SettingsActivity.java
+6
-6
SplashActivity.java
app/src/full/java/com/topjohnwu/magisk/SplashActivity.java
+6
-6
ApplicationAdapter.java
...ava/com/topjohnwu/magisk/adapters/ApplicationAdapter.java
+3
-3
CheckSafetyNet.java
...full/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java
+4
-4
CheckUpdates.java
...c/full/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java
+14
-13
FlashZip.java
app/src/full/java/com/topjohnwu/magisk/asyncs/FlashZip.java
+2
-1
HideManager.java
...rc/full/java/com/topjohnwu/magisk/asyncs/HideManager.java
+3
-2
InstallMagisk.java
.../full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java
+8
-7
LoadModules.java
...rc/full/java/com/topjohnwu/magisk/asyncs/LoadModules.java
+3
-2
MarkDownWindow.java
...full/java/com/topjohnwu/magisk/asyncs/MarkDownWindow.java
+2
-1
ProcessRepoZip.java
...full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java
+2
-2
RestoreImages.java
.../full/java/com/topjohnwu/magisk/asyncs/RestoreImages.java
+3
-3
UpdateRepos.java
...rc/full/java/com/topjohnwu/magisk/asyncs/UpdateRepos.java
+2
-1
InstallMethodDialog.java
.../com/topjohnwu/magisk/components/InstallMethodDialog.java
+4
-3
MagiskInstallDialog.java
.../com/topjohnwu/magisk/components/MagiskInstallDialog.java
+6
-5
ManagerInstallDialog.java
...com/topjohnwu/magisk/components/ManagerInstallDialog.java
+5
-4
UninstallDialog.java
...java/com/topjohnwu/magisk/components/UninstallDialog.java
+3
-2
MagiskDatabaseHelper.java
...a/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java
+7
-7
RepoDatabaseHelper.java
...ava/com/topjohnwu/magisk/database/RepoDatabaseHelper.java
+2
-1
ShortcutReceiver.java
...java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java
+5
-10
UpdateCheckService.java
...ava/com/topjohnwu/magisk/services/UpdateCheckService.java
+3
-4
SuReceiver.java
.../full/java/com/topjohnwu/magisk/superuser/SuReceiver.java
+3
-2
Const.java
app/src/full/java/com/topjohnwu/magisk/utils/Const.java
+3
-3
FingerprintHelper.java
...ll/java/com/topjohnwu/magisk/utils/FingerprintHelper.java
+3
-2
NotificationMgr.java
...full/java/com/topjohnwu/magisk/utils/NotificationMgr.java
+7
-6
RootUtils.java
app/src/full/java/com/topjohnwu/magisk/utils/RootUtils.java
+18
-18
Utils.java
app/src/full/java/com/topjohnwu/magisk/utils/Utils.java
+28
-3
No files found.
app/src/full/java/com/topjohnwu/magisk/FlashActivity.java
View file @
914b7ee0
...
...
@@ -75,7 +75,7 @@ public class FlashActivity extends Activity {
e
.
printStackTrace
();
return
;
}
MagiskManager
.
toast
(
logFile
.
getPath
(),
Toast
.
LENGTH_LONG
);
Global
.
toast
(
logFile
.
getPath
(),
Toast
.
LENGTH_LONG
);
}
@Override
...
...
app/src/full/java/com/topjohnwu/magisk/Global.java
0 → 100644
View file @
914b7ee0
package
com
.
topjohnwu
.
magisk
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.superuser.ShellUtils
;
import
java.lang.ref.WeakReference
;
public
class
Global
{
// Global app instance
public
static
WeakReference
<
MagiskManager
>
weakApp
;
public
static
Handler
mainHandler
=
new
Handler
(
Looper
.
getMainLooper
());
// Current status
public
static
String
magiskVersionString
;
public
static
int
magiskVersionCode
=
-
1
;
public
static
boolean
magiskHide
;
// Update Info
public
static
String
remoteMagiskVersionString
;
public
static
int
remoteMagiskVersionCode
=
-
1
;
public
static
String
magiskLink
;
public
static
String
magiskNoteLink
;
public
static
String
remoteManagerVersionString
;
public
static
int
remoteManagerVersionCode
=
-
1
;
public
static
String
managerLink
;
public
static
String
managerNoteLink
;
public
static
String
uninstallerLink
;
// Install flags
public
static
boolean
keepVerity
=
false
;
public
static
boolean
keepEnc
=
false
;
public
static
void
loadMagiskInfo
()
{
try
{
magiskVersionString
=
ShellUtils
.
fastCmd
(
"magisk -v"
).
split
(
":"
)[
0
];
magiskVersionCode
=
Integer
.
parseInt
(
ShellUtils
.
fastCmd
(
"magisk -V"
));
String
s
=
ShellUtils
.
fastCmd
((
magiskVersionCode
>=
Const
.
MAGISK_VER
.
RESETPROP_PERSIST
?
"resetprop -p "
:
"getprop "
)
+
Const
.
MAGISKHIDE_PROP
);
magiskHide
=
s
.
isEmpty
()
||
Integer
.
parseInt
(
s
)
!=
0
;
}
catch
(
NumberFormatException
ignored
)
{}
}
public
static
MagiskManager
MM
()
{
return
weakApp
.
get
();
}
public
static
void
toast
(
CharSequence
msg
,
int
duration
)
{
mainHandler
.
post
(()
->
Toast
.
makeText
(
MM
(),
msg
,
duration
).
show
());
}
public
static
void
toast
(
int
resId
,
int
duration
)
{
mainHandler
.
post
(()
->
Toast
.
makeText
(
MM
(),
resId
,
duration
).
show
());
}
}
app/src/full/java/com/topjohnwu/magisk/MagiskFragment.java
View file @
914b7ee0
...
...
@@ -119,7 +119,7 @@ public class MagiskFragment extends Fragment
shownDialog
=
true
;
// Show Manager update first
if
(
mm
.
remoteManagerVersionCode
>
BuildConfig
.
VERSION_CODE
)
{
if
(
Global
.
remoteManagerVersionCode
>
BuildConfig
.
VERSION_CODE
)
{
new
ManagerInstallDialog
((
Activity
)
requireActivity
()).
show
();
return
;
}
...
...
@@ -146,10 +146,10 @@ public class MagiskFragment extends Fragment
expandableContainer
.
expandLayout
=
expandLayout
;
setupExpandable
();
keepVerityChkbox
.
setChecked
(
mm
.
keepVerity
);
keepVerityChkbox
.
setOnCheckedChangeListener
((
view
,
checked
)
->
mm
.
keepVerity
=
checked
);
keepEncChkbox
.
setChecked
(
mm
.
keepEnc
);
keepEncChkbox
.
setOnCheckedChangeListener
((
view
,
checked
)
->
mm
.
keepEnc
=
checked
);
keepVerityChkbox
.
setChecked
(
Global
.
keepVerity
);
keepVerityChkbox
.
setOnCheckedChangeListener
((
view
,
checked
)
->
Global
.
keepVerity
=
checked
);
keepEncChkbox
.
setChecked
(
Global
.
keepEnc
);
keepEncChkbox
.
setOnCheckedChangeListener
((
view
,
checked
)
->
Global
.
keepEnc
=
checked
);
mSwipeRefreshLayout
.
setOnRefreshListener
(
this
);
updateUI
();
...
...
@@ -159,7 +159,7 @@ public class MagiskFragment extends Fragment
@Override
public
void
onRefresh
()
{
mm
.
loadMagiskInfo
();
Global
.
loadMagiskInfo
();
updateUI
();
magiskUpdateText
.
setText
(
R
.
string
.
checking_for_updates
);
...
...
@@ -170,8 +170,8 @@ public class MagiskFragment extends Fragment
mm
.
safetyNetDone
.
reset
();
mm
.
updateCheckDone
.
reset
();
mm
.
remoteMagiskVersionString
=
null
;
mm
.
remoteMagiskVersionCode
=
-
1
;
Global
.
remoteMagiskVersionString
=
null
;
Global
.
remoteMagiskVersionCode
=
-
1
;
collapse
();
shownDialog
=
false
;
...
...
@@ -214,7 +214,7 @@ public class MagiskFragment extends Fragment
boolean
hasNetwork
=
Download
.
checkNetworkStatus
(
mm
);
boolean
hasRoot
=
Shell
.
rootAccess
();
boolean
isUpToDate
=
mm
.
magiskVersionCode
>
Const
.
MAGISK_VER
.
UNIFIED
;
boolean
isUpToDate
=
Global
.
magiskVersionCode
>
Const
.
MAGISK_VER
.
UNIFIED
;
magiskUpdate
.
setVisibility
(
hasNetwork
?
View
.
VISIBLE
:
View
.
GONE
);
safetyNetCard
.
setVisibility
(
hasNetwork
?
View
.
VISIBLE
:
View
.
GONE
);
...
...
@@ -223,14 +223,14 @@ public class MagiskFragment extends Fragment
int
image
,
color
;
if
(
mm
.
magiskVersionCode
<
0
)
{
if
(
Global
.
magiskVersionCode
<
0
)
{
color
=
colorBad
;
image
=
R
.
drawable
.
ic_cancel
;
magiskVersionText
.
setText
(
R
.
string
.
magisk_version_error
);
}
else
{
color
=
colorOK
;
image
=
R
.
drawable
.
ic_check_circle
;
magiskVersionText
.
setText
(
getString
(
R
.
string
.
current_magisk_title
,
"v"
+
mm
.
magiskVersionString
));
magiskVersionText
.
setText
(
getString
(
R
.
string
.
current_magisk_title
,
"v"
+
Global
.
magiskVersionString
));
}
magiskStatusIcon
.
setImageResource
(
image
);
...
...
@@ -240,7 +240,7 @@ public class MagiskFragment extends Fragment
private
void
updateCheckUI
()
{
int
image
,
color
;
if
(
mm
.
remoteMagiskVersionCode
<
0
)
{
if
(
Global
.
remoteMagiskVersionCode
<
0
)
{
color
=
colorNeutral
;
image
=
R
.
drawable
.
ic_help
;
magiskUpdateText
.
setText
(
R
.
string
.
invalid_update_channel
);
...
...
@@ -248,11 +248,11 @@ public class MagiskFragment extends Fragment
}
else
{
color
=
colorOK
;
image
=
R
.
drawable
.
ic_check_circle
;
magiskUpdateText
.
setText
(
getString
(
R
.
string
.
install_magisk_title
,
"v"
+
mm
.
remoteMagiskVersionString
));
magiskUpdateText
.
setText
(
getString
(
R
.
string
.
install_magisk_title
,
"v"
+
Global
.
remoteMagiskVersionString
));
installButton
.
setVisibility
(
View
.
VISIBLE
);
if
(
mm
.
remoteManagerVersionCode
>
BuildConfig
.
VERSION_CODE
)
{
if
(
Global
.
remoteManagerVersionCode
>
BuildConfig
.
VERSION_CODE
)
{
installText
.
setText
(
getString
(
R
.
string
.
update
,
getString
(
R
.
string
.
app_name
)));
}
else
if
(
mm
.
magiskVersionCode
>
0
&&
mm
.
remoteMagiskVersionCode
>
mm
.
magiskVersionCode
)
{
}
else
if
(
Global
.
magiskVersionCode
>
0
&&
Global
.
remoteMagiskVersionCode
>
Global
.
magiskVersionCode
)
{
installText
.
setText
(
getString
(
R
.
string
.
update
,
getString
(
R
.
string
.
magisk
)));
}
else
{
installText
.
setText
(
R
.
string
.
install
);
...
...
@@ -267,10 +267,10 @@ public class MagiskFragment extends Fragment
mSwipeRefreshLayout
.
setRefreshing
(
false
);
if
(!
shownDialog
)
{
if
(
mm
.
remoteMagiskVersionCode
>
mm
.
magiskVersionCode
||
mm
.
remoteManagerVersionCode
>
BuildConfig
.
VERSION_CODE
)
{
if
(
Global
.
remoteMagiskVersionCode
>
Global
.
magiskVersionCode
||
Global
.
remoteManagerVersionCode
>
BuildConfig
.
VERSION_CODE
)
{
install
();
}
else
if
(
mm
.
remoteMagiskVersionCode
>=
Const
.
MAGISK_VER
.
FIX_ENV
&&
}
else
if
(
Global
.
remoteMagiskVersionCode
>=
Const
.
MAGISK_VER
.
FIX_ENV
&&
!
ShellUtils
.
fastCmdResult
(
"env_check"
))
{
new
EnvFixDialog
(
requireActivity
()).
show
();
}
...
...
app/src/full/java/com/topjohnwu/magisk/MagiskManager.java
View file @
914b7ee0
package
com
.
topjohnwu
.
magisk
;
import
android.app.job.JobInfo
;
import
android.app.job.JobScheduler
;
import
android.content.ComponentName
;
import
android.content.SharedPreferences
;
import
android.content.pm.PackageManager
;
import
android.content.res.Configuration
;
...
...
@@ -16,14 +13,12 @@ import android.widget.Toast;
import
com.topjohnwu.magisk.container.Module
;
import
com.topjohnwu.magisk.database.MagiskDatabaseHelper
;
import
com.topjohnwu.magisk.database.RepoDatabaseHelper
;
import
com.topjohnwu.magisk.services.UpdateCheckService
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.RootUtils
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.ContainerApp
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.ShellUtils
;
import
com.topjohnwu.superuser.io.SuFile
;
import
com.topjohnwu.superuser.io.SuFileInputStream
;
...
...
@@ -39,8 +34,6 @@ import java.util.Map;
public
class
MagiskManager
extends
ContainerApp
{
public
static
WeakReference
<
MagiskManager
>
weakSelf
;
public
static
Handler
mHandler
=
new
Handler
();
public
static
Locale
locale
;
public
static
Locale
defaultLocale
;
...
...
@@ -55,27 +48,11 @@ public class MagiskManager extends ContainerApp {
// Info
public
boolean
hasInit
=
false
;
public
String
magiskVersionString
;
public
int
magiskVersionCode
=
-
1
;
public
String
remoteMagiskVersionString
;
public
int
remoteMagiskVersionCode
=
-
1
;
public
String
remoteManagerVersionString
;
public
int
remoteManagerVersionCode
=
-
1
;
public
String
magiskLink
;
public
String
magiskNoteLink
;
public
String
managerLink
;
public
String
managerNoteLink
;
public
String
uninstallerLink
;
public
boolean
keepVerity
=
false
;
public
boolean
keepEnc
=
false
;
// Data
public
Map
<
String
,
Module
>
moduleMap
;
public
List
<
Locale
>
locales
;
public
boolean
magiskHide
;
public
boolean
isDarkTheme
;
public
int
suRequestTimeout
;
public
int
suLogTimeout
=
14
;
...
...
@@ -95,15 +72,7 @@ public class MagiskManager extends ContainerApp {
public
RepoDatabaseHelper
repoDB
;
public
MagiskManager
()
{
weakSelf
=
new
WeakReference
<>(
this
);
}
public
static
void
toast
(
CharSequence
msg
,
int
duration
)
{
mHandler
.
post
(()
->
Toast
.
makeText
(
weakSelf
.
get
(),
msg
,
duration
).
show
());
}
public
static
void
toast
(
int
resId
,
int
duration
)
{
mHandler
.
post
(()
->
Toast
.
makeText
(
weakSelf
.
get
(),
resId
,
duration
).
show
());
Global
.
weakApp
=
new
WeakReference
<>(
this
);
}
@Override
...
...
@@ -135,10 +104,6 @@ public class MagiskManager extends ContainerApp {
loadConfig
();
}
public
static
MagiskManager
get
()
{
return
weakSelf
.
get
();
}
public
void
setLocale
()
{
localeConfig
=
prefs
.
getString
(
Const
.
Key
.
LOCALE
,
""
);
if
(
localeConfig
.
isEmpty
())
{
...
...
@@ -171,7 +136,7 @@ public class MagiskManager extends ContainerApp {
public
void
writeConfig
()
{
prefs
.
edit
()
.
putBoolean
(
Const
.
Key
.
DARK_THEME
,
isDarkTheme
)
.
putBoolean
(
Const
.
Key
.
MAGISKHIDE
,
magiskHide
)
.
putBoolean
(
Const
.
Key
.
MAGISKHIDE
,
Global
.
magiskHide
)
.
putBoolean
(
Const
.
Key
.
HOSTS
,
Const
.
MAGISK_HOST_FILE
.
exists
())
.
putBoolean
(
Const
.
Key
.
COREONLY
,
Const
.
MAGISK_DISABLE_FILE
.
exists
())
.
putString
(
Const
.
Key
.
SU_REQUEST_TIMEOUT
,
String
.
valueOf
(
suRequestTimeout
))
...
...
@@ -188,40 +153,6 @@ public class MagiskManager extends ContainerApp {
.
apply
();
}
public
void
loadMagiskInfo
()
{
try
{
magiskVersionString
=
ShellUtils
.
fastCmd
(
"magisk -v"
).
split
(
":"
)[
0
];
magiskVersionCode
=
Integer
.
parseInt
(
ShellUtils
.
fastCmd
(
"magisk -V"
));
String
s
=
ShellUtils
.
fastCmd
((
magiskVersionCode
>=
Const
.
MAGISK_VER
.
RESETPROP_PERSIST
?
"resetprop -p "
:
"getprop "
)
+
Const
.
MAGISKHIDE_PROP
);
magiskHide
=
s
.
isEmpty
()
||
Integer
.
parseInt
(
s
)
!=
0
;
}
catch
(
Exception
ignored
)
{}
}
public
void
getDefaultInstallFlags
()
{
keepVerity
=
Boolean
.
parseBoolean
(
ShellUtils
.
fastCmd
(
"echo $KEEPVERITY"
));
keepEnc
=
Boolean
.
parseBoolean
(
ShellUtils
.
fastCmd
(
"echo $KEEPFORCEENCRYPT"
));
}
public
void
setupUpdateCheck
()
{
JobScheduler
scheduler
=
(
JobScheduler
)
getSystemService
(
JOB_SCHEDULER_SERVICE
);
if
(
prefs
.
getBoolean
(
Const
.
Key
.
CHECK_UPDATES
,
true
))
{
if
(
scheduler
.
getAllPendingJobs
().
isEmpty
()
||
Const
.
UPDATE_SERVICE_VER
>
prefs
.
getInt
(
Const
.
Key
.
UPDATE_SERVICE_VER
,
-
1
))
{
ComponentName
service
=
new
ComponentName
(
this
,
UpdateCheckService
.
class
);
JobInfo
info
=
new
JobInfo
.
Builder
(
Const
.
ID
.
UPDATE_SERVICE_ID
,
service
)
.
setRequiredNetworkType
(
JobInfo
.
NETWORK_TYPE_ANY
)
.
setPersisted
(
true
)
.
setPeriodic
(
8
*
60
*
60
*
1000
)
.
build
();
scheduler
.
schedule
(
info
);
}
}
else
{
scheduler
.
cancel
(
Const
.
UPDATE_SERVICE_VER
);
}
}
public
void
dumpPrefs
()
{
// Flush prefs to disk
prefs
.
edit
().
commit
();
...
...
app/src/full/java/com/topjohnwu/magisk/MainActivity.java
View file @
914b7ee0
...
...
@@ -125,12 +125,12 @@ public class MainActivity extends Activity
MagiskManager
mm
=
getMagiskManager
();
Menu
menu
=
navigationView
.
getMenu
();
menu
.
findItem
(
R
.
id
.
magiskhide
).
setVisible
(
Shell
.
rootAccess
()
&&
mm
.
magiskVersionCode
>=
Const
.
MAGISK_VER
.
UNIFIED
Shell
.
rootAccess
()
&&
Global
.
magiskVersionCode
>=
Const
.
MAGISK_VER
.
UNIFIED
&&
mm
.
prefs
.
getBoolean
(
Const
.
Key
.
MAGISKHIDE
,
false
));
menu
.
findItem
(
R
.
id
.
modules
).
setVisible
(!
mm
.
prefs
.
getBoolean
(
Const
.
Key
.
COREONLY
,
false
)
&&
Shell
.
rootAccess
()
&&
mm
.
magiskVersionCode
>=
0
);
Shell
.
rootAccess
()
&&
Global
.
magiskVersionCode
>=
0
);
menu
.
findItem
(
R
.
id
.
downloads
).
setVisible
(!
mm
.
prefs
.
getBoolean
(
Const
.
Key
.
COREONLY
,
false
)
&&
Download
.
checkNetworkStatus
(
this
)
&&
Shell
.
rootAccess
()
&&
mm
.
magiskVersionCode
>=
0
);
&&
Download
.
checkNetworkStatus
(
this
)
&&
Shell
.
rootAccess
()
&&
Global
.
magiskVersionCode
>=
0
);
menu
.
findItem
(
R
.
id
.
log
).
setVisible
(
Shell
.
rootAccess
());
menu
.
findItem
(
R
.
id
.
superuser
).
setVisible
(
Shell
.
rootAccess
()
&&
!(
Const
.
USER_ID
>
0
&&
mm
.
multiuserMode
==
Const
.
Value
.
MULTIUSER_MODE_OWNER_MANAGED
));
...
...
app/src/full/java/com/topjohnwu/magisk/SettingsActivity.java
View file @
914b7ee0
...
...
@@ -108,7 +108,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
findPreference
(
"clear"
).
setOnPreferenceClickListener
((
pref
)
->
{
prefs
.
edit
().
remove
(
Const
.
Key
.
ETAG_KEY
).
apply
();
mm
.
repoDB
.
clearRepo
();
MagiskManager
.
toast
(
R
.
string
.
repo_cache_cleared
,
Toast
.
LENGTH_SHORT
);
Global
.
toast
(
R
.
string
.
repo_cache_cleared
,
Toast
.
LENGTH_SHORT
);
return
true
;
});
...
...
@@ -159,7 +159,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
fingerprint
.
setSummary
(
R
.
string
.
disable_fingerprint
);
}
if
(
mm
.
magiskVersionCode
>=
Const
.
MAGISK_VER
.
MANAGER_HIDE
)
{
if
(
Global
.
magiskVersionCode
>=
Const
.
MAGISK_VER
.
MANAGER_HIDE
)
{
if
(
mm
.
getPackageName
().
equals
(
Const
.
ORIG_PKG_NAME
))
{
hideManager
.
setOnPreferenceClickListener
((
pref
)
->
{
new
HideManager
(
getActivity
()).
exec
();
...
...
@@ -183,8 +183,8 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
Shell
.
su
(
"rm -f /data/local/tmp/manager.apk"
).
exec
();
}
},
mm
.
managerLink
,
Utils
.
fmt
(
"MagiskManager-v%s.apk"
,
mm
.
remoteManagerVersionString
)
Global
.
managerLink
,
Utils
.
fmt
(
"MagiskManager-v%s.apk"
,
Global
.
remoteManagerVersionString
)
);
return
true
;
});
...
...
@@ -206,7 +206,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
if
(!
Shell
.
rootAccess
())
{
prefScreen
.
removePreference
(
magiskCategory
);
generalCatagory
.
removePreference
(
hideManager
);
}
else
if
(
mm
.
magiskVersionCode
<
Const
.
MAGISK_VER
.
UNIFIED
)
{
}
else
if
(
Global
.
magiskVersionCode
<
Const
.
MAGISK_VER
.
UNIFIED
)
{
prefScreen
.
removePreference
(
magiskCategory
);
}
}
...
...
@@ -289,7 +289,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
new
CheckUpdates
().
exec
();
break
;
case
Const
.
Key
.
CHECK_UPDATES
:
mm
.
setupUpdateCheck
();
Utils
.
setupUpdateCheck
();
break
;
}
mm
.
loadConfig
();
...
...
app/src/full/java/com/topjohnwu/magisk/SplashActivity.java
View file @
914b7ee0
...
...
@@ -25,10 +25,10 @@ public class SplashActivity extends Activity {
super
.
onCreate
(
savedInstanceState
);
MagiskManager
mm
=
getMagiskManager
();
// Force create a shell if not created yet
boolean
root
=
Shell
.
rootAccess
();
mm
.
repoDB
=
new
RepoDatabaseHelper
(
this
);
mm
.
loadMagiskInfo
();
mm
.
getDefaultInstallFlags
();
mm
.
loadPrefs
();
// Dynamic detect all locales
...
...
@@ -54,9 +54,9 @@ public class SplashActivity extends Activity {
}
// Magisk working as expected
if
(
Shell
.
rootAccess
()
&&
mm
.
magiskVersionCode
>
0
)
{
if
(
root
&&
Global
.
magiskVersionCode
>
0
)
{
// Update check service
mm
.
setupUpdateCheck
();
Utils
.
setupUpdateCheck
();
// Fire asynctasks
loadModuleTask
.
exec
();
}
...
...
@@ -76,12 +76,12 @@ public class SplashActivity extends Activity {
static
class
LoadLocale
extends
ParallelTask
<
Void
,
Void
,
Void
>
{
@Override
protected
Void
doInBackground
(
Void
...
voids
)
{
MagiskManager
.
get
().
locales
=
Utils
.
getAvailableLocale
();
Global
.
MM
().
locales
=
Utils
.
getAvailableLocale
();
return
null
;
}
@Override
protected
void
onPostExecute
(
Void
aVoid
)
{
MagiskManager
.
get
().
localeDone
.
publish
();
Global
.
MM
().
localeDone
.
publish
();
}
}
}
app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java
View file @
914b7ee0
...
...
@@ -12,7 +12,7 @@ import android.widget.Filter;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
com.topjohnwu.magisk.
MagiskManager
;
import
com.topjohnwu.magisk.
Global
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.asyncs.ParallelTask
;
import
com.topjohnwu.magisk.utils.Const
;
...
...
@@ -37,7 +37,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
fullList
=
showList
=
Collections
.
emptyList
();
hideList
=
Collections
.
emptyList
();
filter
=
new
ApplicationFilter
();
pm
=
MagiskManager
.
get
().
getPackageManager
();
pm
=
Global
.
MM
().
getPackageManager
();
new
LoadApps
().
exec
();
}
...
...
@@ -152,7 +152,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
@Override
protected
void
onPostExecute
(
Void
v
)
{
MagiskManager
.
get
().
magiskHideDone
.
publish
(
false
);
Global
.
MM
().
magiskHideDone
.
publish
(
false
);
}
}
}
app/src/full/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java
View file @
914b7ee0
...
...
@@ -2,7 +2,7 @@ package com.topjohnwu.magisk.asyncs;
import
android.app.Activity
;
import
com.topjohnwu.magisk.
MagiskManager
;
import
com.topjohnwu.magisk.
Global
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.ISafetyNetHelper
;
import
com.topjohnwu.magisk.utils.WebService
;
...
...
@@ -22,7 +22,7 @@ import dalvik.system.DexClassLoader;
public
class
CheckSafetyNet
extends
ParallelTask
<
Void
,
Void
,
Exception
>
{
public
static
final
File
dexPath
=
new
File
(
MagiskManager
.
get
().
getFilesDir
().
getParent
()
+
"/snet"
,
"snet.apk"
);
new
File
(
Global
.
MM
().
getFilesDir
().
getParent
()
+
"/snet"
,
"snet.apk"
);
private
ISafetyNetHelper
helper
;
public
CheckSafetyNet
(
Activity
activity
)
{
...
...
@@ -50,7 +50,7 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
Class
.
class
,
String
.
class
,
Activity
.
class
,
Object
.
class
)
.
invoke
(
null
,
ISafetyNetHelper
.
class
,
dexPath
.
getPath
(),
getActivity
(),
(
ISafetyNetHelper
.
Callback
)
code
->
MagiskManager
.
get
().
safetyNetDone
.
publish
(
false
,
code
));
Global
.
MM
().
safetyNetDone
.
publish
(
false
,
code
));
if
(
helper
.
getVersion
()
!=
Const
.
SNET_VER
)
{
throw
new
Exception
();
}
...
...
@@ -79,7 +79,7 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
helper
.
attest
();
}
else
{
e
.
printStackTrace
();
MagiskManager
.
get
().
safetyNetDone
.
publish
(
false
,
-
1
);
Global
.
MM
().
safetyNetDone
.
publish
(
false
,
-
1
);
}
super
.
onPostExecute
(
e
);
}
...
...
app/src/full/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java
View file @
914b7ee0
package
com
.
topjohnwu
.
magisk
.
asyncs
;
import
com.topjohnwu.magisk.BuildConfig
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.utils.Const
;
import
com.topjohnwu.magisk.utils.NotificationMgr
;
...
...
@@ -51,7 +52,7 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
@Override
protected
Void
doInBackground
(
Void
...
voids
)
{
MagiskManager
mm
=
MagiskManager
.
get
();
MagiskManager
mm
=
Global
.
MM
();
String
jsonStr
=
""
;
switch
(
mm
.
updateChannel
)
{
case
Const
.
Value
.
STABLE_CHANNEL
:
...
...
@@ -73,30 +74,30 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
}
JSONObject
magisk
=
getJson
(
json
,
"magisk"
);
mm
.
remoteMagiskVersionString
=
getString
(
magisk
,
"version"
,
null
);
mm
.
remoteMagiskVersionCode
=
getInt
(
magisk
,
"versionCode"
,
-
1
);
mm
.
magiskLink
=
getString
(
magisk
,
"link"
,
null
);
mm
.
magiskNoteLink
=
getString
(
magisk
,
"note"
,
null
);
Global
.
remoteMagiskVersionString
=
getString
(
magisk
,
"version"
,
null
);
Global
.
remoteMagiskVersionCode
=
getInt
(
magisk
,
"versionCode"
,
-
1
);
Global
.
magiskLink
=
getString
(
magisk
,
"link"
,
null
);
Global
.
magiskNoteLink
=
getString
(
magisk
,
"note"
,
null
);
JSONObject
manager
=
getJson
(
json
,
"app"
);
mm
.
remoteManagerVersionString
=
getString
(
manager
,
"version"
,
null
);
mm
.
remoteManagerVersionCode
=
getInt
(
manager
,
"versionCode"
,
-
1
);
mm
.
managerLink
=
getString
(
manager
,
"link"
,
null
);
mm
.
managerNoteLink
=
getString
(
manager
,
"note"
,
null
);
Global
.
remoteManagerVersionString
=
getString
(
manager
,
"version"
,
null
);
Global
.
remoteManagerVersionCode
=
getInt
(
manager
,
"versionCode"
,
-
1
);
Global
.
managerLink
=
getString
(
manager
,
"link"
,
null
);
Global
.
managerNoteLink
=
getString
(
manager
,
"note"
,
null
);
JSONObject
uninstaller
=
getJson
(
json
,
"uninstaller"
);
mm
.
uninstallerLink
=
getString
(
uninstaller
,
"link"
,
null
);
Global
.
uninstallerLink
=
getString
(
uninstaller
,
"link"
,
null
);
return
null
;
}
@Override
protected
void
onPostExecute
(
Void
v
)
{
MagiskManager
mm
=
MagiskManager
.
get
();
MagiskManager
mm
=
Global
.
MM
();
if
(
showNotification
)
{
if
(
BuildConfig
.
VERSION_CODE
<
mm
.
remoteManagerVersionCode
)
{
if
(
BuildConfig
.
VERSION_CODE
<
Global
.
remoteManagerVersionCode
)
{
NotificationMgr
.
managerUpdate
();
}
else
if
(
mm
.
magiskVersionCode
<
mm
.
remoteMagiskVersionCode
)
{
}
else
if
(
Global
.
magiskVersionCode
<
Global
.
remoteMagiskVersionCode
)
{
NotificationMgr
.
magiskUpdate
();
}
}
...
...
app/src/full/java/com/topjohnwu/magisk/asyncs/FlashZip.java
View file @
914b7ee0
...
...
@@ -5,6 +5,7 @@ import android.net.Uri;
import
android.view.View
;
import
com.topjohnwu.magisk.FlashActivity
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.utils.Const
;
...
...
@@ -44,7 +45,7 @@ public class FlashZip extends ParallelTask<Void, Void, Integer> {
@Override
protected
Integer
doInBackground
(
Void
...
voids
)
{
MagiskManager
mm
=
MagiskManager
.
get
();
MagiskManager
mm
=
Global
.
MM
();
try
{
console
.
add
(
"- Copying zip to temp directory"
);
...
...
app/src/full/java/com/topjohnwu/magisk/asyncs/HideManager.java
View file @
914b7ee0
...
...
@@ -4,6 +4,7 @@ import android.app.Activity;
import
android.app.ProgressDialog
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.utils.Const
;
...
...
@@ -55,7 +56,7 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
@Override
protected
Boolean
doInBackground
(
Void
...
voids
)
{
MagiskManager
mm
=
MagiskManager
.
get
();
MagiskManager
mm
=
Global
.
MM
();
// Generate a new app with random package name
SuFile
repack
=
new
SuFile
(
"/data/local/tmp/repack.apk"
);
...
...
@@ -88,7 +89,7 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
protected
void
onPostExecute
(
Boolean
b
)
{
dialog
.
dismiss
();
if
(!
b
)
{
MagiskManager
.
toast
(
R
.
string
.
hide_manager_fail_toast
,
Toast
.
LENGTH_LONG
);
Global
.
toast
(
R
.
string
.
hide_manager_fail_toast
,
Toast
.
LENGTH_LONG
);
}
super
.
onPostExecute
(
b
);
}
...
...
app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java
View file @
914b7ee0
...
...
@@ -9,6 +9,7 @@ import android.text.TextUtils;
import
android.view.View
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.FlashActivity
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
...
...
@@ -59,7 +60,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
public
InstallMagisk
(
Activity
context
)
{
super
(
context
);
mm
=
MagiskManager
.
get
();
mm
=
Global
.
MM
();
mode
=
FIX_ENV_MODE
;
}
...
...
@@ -129,8 +130,8 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
private
void
extractFiles
(
String
arch
)
throws
IOException
{
console
.
add
(
"- Downloading zip"
);
String
filename
=
Utils
.
fmt
(
"Magisk-v%s(%d).zip"
,
mm
.
remoteMagiskVersionString
,
mm
.
remoteMagiskVersionCode
);
HttpURLConnection
conn
=
WebService
.
mustRequest
(
mm
.
magiskLink
,
null
);
Global
.
remoteMagiskVersionString
,
Global
.
remoteMagiskVersionCode
);
HttpURLConnection
conn
=
WebService
.
mustRequest
(
Global
.
magiskLink
,
null
);
BufferedInputStream
buf
=
new
BufferedInputStream
(
new
ProgressStream
(
conn
));
buf
.
mark
(
Integer
.
MAX_VALUE
);
try
(
OutputStream
out
=
new
FileOutputStream
(
new
File
(
Download
.
EXTERNAL_PATH
,
filename
)))
{
...
...
@@ -204,7 +205,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
// Patch boot image
if
(!
Shell
.
sh
(
"cd "
+
installDir
,
Utils
.
fmt
(
"KEEPFORCEENCRYPT=%b KEEPVERITY=%b sh update-binary indep boot_patch.sh %s"
,
mm
.
keepEnc
,
mm
.
keepVerity
,
mBoot
))
Global
.
keepEnc
,
Global
.
keepVerity
,
mBoot
))
.
to
(
console
,
logs
).
exec
().
isSuccess
())
return
null
;
...
...
@@ -258,7 +259,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
case
DIRECT_MODE:
Shell
.
Job
job
=
Shell
.
su
(
Utils
.
fmt
(
"direct_install %s %s %s"
,
patched
,
mBoot
,
installDir
))
.
to
(
console
,
logs
);
if
(!
mm
.
keepVerity
)
if
(!
Global
.
keepVerity
)
job
.
add
(
"find_dtbo_image"
,
"patch_dtbo_image"
);
job
.
exec
();
break
;
...
...
@@ -331,7 +332,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
List
<
String
>
abis
=
Arrays
.
asList
(
Build
.
SUPPORTED_ABIS
);
String
arch
;
if
(
mm
.
remoteMagiskVersionCode
>=
Const
.
MAGISK_VER
.
SEPOL_REFACTOR
)
{
if
(
Global
.
remoteMagiskVersionCode
>=
Const
.
MAGISK_VER
.
SEPOL_REFACTOR
)
{
// 32-bit only
if
(
abis
.
contains
(
"x86"
))
arch
=
"x86"
;
else
arch
=
"arm"
;
...
...
@@ -368,7 +369,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
protected
void
onPostExecute
(
Boolean
result
)
{
if
(
mode
==
FIX_ENV_MODE
)
{
dialog
.
dismiss
();
MagiskManager
.
toast
(
result
?
R
.
string
.
setup_done
:
R
.
string
.
setup_fail
,
Toast
.
LENGTH_LONG
);
Global
.
toast
(
result
?
R
.
string
.
setup_done
:
R
.
string
.
setup_fail
,
Toast
.
LENGTH_LONG
);
}
else
{
// Running in FlashActivity
FlashActivity
activity
=
(
FlashActivity
)
getActivity
();
...
...
app/src/full/java/com/topjohnwu/magisk/asyncs/LoadModules.java
View file @
914b7ee0
package
com
.
topjohnwu
.
magisk
.
asyncs
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.container.Module
;
import
com.topjohnwu.magisk.container.ValueSortedMap
;
...
...
@@ -15,7 +16,7 @@ public class LoadModules extends ParallelTask<Void, Void, Void> {
@Override
protected
Void
doInBackground
(
Void
...
voids
)
{
MagiskManager
mm
=
MagiskManager
.
get
();
MagiskManager
mm
=
Global
.
MM
();
mm
.
moduleMap
=
new
ValueSortedMap
<>();
for
(
String
name
:
getModList
())
{
...
...
@@ -28,7 +29,7 @@ public class LoadModules extends ParallelTask<Void, Void, Void> {
@Override
protected
void
onPostExecute
(
Void
v
)
{
MagiskManager
.
get
().
moduleLoadDone
.
publish
();
Global
.
MM
().
moduleLoadDone
.
publish
();
super
.
onPostExecute
(
v
);
}
}
app/src/full/java/com/topjohnwu/magisk/asyncs/MarkDownWindow.java
View file @
914b7ee0
...
...
@@ -4,6 +4,7 @@ import android.app.Activity;
import
android.support.v7.app.AlertDialog
;
import
android.webkit.WebView
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.utils.WebService
;
...
...
@@ -38,7 +39,7 @@ public class MarkDownWindow extends ParallelTask<Void, Void, String> {
@Override
protected
String
doInBackground
(
Void
...
voids
)
{
MagiskManager
mm
=
MagiskManager
.
get
();
MagiskManager
mm
=
Global
.
MM
();
String
md
;
if
(
mUrl
!=
null
)
{
md
=
WebService
.
getString
(
mUrl
);
...
...
app/src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java
View file @
914b7ee0
...
...
@@ -9,7 +9,7 @@ import android.support.annotation.NonNull;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.FlashActivity
;
import
com.topjohnwu.magisk.
MagiskManager
;
import
com.topjohnwu.magisk.
Global
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
...
...
@@ -148,7 +148,7 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
SnackbarMaker
.
showUri
(
activity
,
uri
);
}
}
else
{
MagiskManager
.
toast
(
R
.
string
.
process_error
,
Toast
.
LENGTH_LONG
);
Global
.
toast
(
R
.
string
.
process_error
,
Toast
.
LENGTH_LONG
);
}
super
.
onPostExecute
(
result
);
}
...
...
app/src/full/java/com/topjohnwu/magisk/asyncs/RestoreImages.java
View file @
914b7ee0
...
...
@@ -4,7 +4,7 @@ import android.app.Activity;
import
android.app.ProgressDialog
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.
MagiskManager
;
import
com.topjohnwu.magisk.
Global
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.superuser.ShellUtils
;
...
...
@@ -31,9 +31,9 @@ public class RestoreImages extends ParallelTask<Void, Void, Boolean> {
protected
void
onPostExecute
(
Boolean
result
)
{
dialog
.
cancel
();
if
(
result
)
{
MagiskManager
.
toast
(
R
.
string
.
restore_done
,
Toast
.
LENGTH_SHORT
);
Global
.
toast
(
R
.
string
.
restore_done
,
Toast
.
LENGTH_SHORT
);
}
else
{
MagiskManager
.
toast
(
R
.
string
.
restore_fail
,
Toast
.
LENGTH_LONG
);
Global
.
toast
(
R
.
string
.
restore_fail
,
Toast
.
LENGTH_LONG
);
}
}
}
app/src/full/java/com/topjohnwu/magisk/asyncs/UpdateRepos.java
View file @
914b7ee0
...
...
@@ -3,6 +3,7 @@ package com.topjohnwu.magisk.asyncs;
import
android.database.Cursor
;
import
android.text.TextUtils
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.ReposFragment
;
import
com.topjohnwu.magisk.container.Repo
;
...
...
@@ -48,7 +49,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
private
ExecutorService
threadPool
;
public
UpdateRepos
(
boolean
force
)
{
mm
=
MagiskManager
.
get
();
mm
=
Global
.
MM
();
mm
.
repoLoadDone
.
reset
();
forceUpdate
=
force
;
threadPool
=
Executors
.
newFixedThreadPool
(
CORE_POOL_SIZE
);
...
...
app/src/full/java/com/topjohnwu/magisk/components/InstallMethodDialog.java
View file @
914b7ee0
...
...
@@ -7,6 +7,7 @@ import android.support.design.widget.Snackbar;
import
android.support.v7.app.AlertDialog
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.FlashActivity
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
...
...
@@ -27,12 +28,12 @@ class InstallMethodDialog extends AlertDialog.Builder {
Intent
intent
;
switch
(
idx
)
{
case
1
:
if
(
mm
.
remoteMagiskVersionCode
<
1400
)
{
if
(
Global
.
remoteMagiskVersionCode
<
1400
)
{
SnackbarMaker
.
make
(
activity
,
R
.
string
.
no_boot_file_patch_support
,
Snackbar
.
LENGTH_LONG
).
show
();
return
;
}
MagiskManager
.
toast
(
R
.
string
.
boot_file_patch_msg
,
Toast
.
LENGTH_LONG
);
Global
.
toast
(
R
.
string
.
boot_file_patch_msg
,
Toast
.
LENGTH_LONG
);
intent
=
new
Intent
(
Intent
.
ACTION_GET_CONTENT
).
setType
(
"*/*"
);
activity
.
startActivityForResult
(
intent
,
Const
.
ID
.
SELECT_BOOT
,
(
requestCode
,
resultCode
,
data
)
->
{
...
...
@@ -51,7 +52,7 @@ class InstallMethodDialog extends AlertDialog.Builder {
public
void
onDownloadDone
(
Context
context
,
Uri
uri
)
{
SnackbarMaker
.
showUri
(
activity
,
uri
);
}
},
mm
.
magiskLink
,
filename
);
},
Global
.
magiskLink
,
filename
);
break
;
case
2
:
intent
=
new
Intent
(
activity
,
FlashActivity
.
class
)
...
...
app/src/full/java/com/topjohnwu/magisk/components/MagiskInstallDialog.java
View file @
914b7ee0
...
...
@@ -4,6 +4,7 @@ import android.content.Intent;
import
android.net.Uri
;
import
android.text.TextUtils
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.asyncs.MarkDownWindow
;
...
...
@@ -19,7 +20,7 @@ public class MagiskInstallDialog extends CustomAlertDialog {
super
(
activity
);
MagiskManager
mm
=
Utils
.
getMagiskManager
(
activity
);
String
filename
=
Utils
.
fmt
(
"Magisk-v%s(%d).zip"
,
mm
.
remoteMagiskVersionString
,
mm
.
remoteMagiskVersionCode
);
Global
.
remoteMagiskVersionString
,
Global
.
remoteMagiskVersionCode
);
setTitle
(
mm
.
getString
(
R
.
string
.
repo_install_title
,
mm
.
getString
(
R
.
string
.
magisk
)));
setMessage
(
mm
.
getString
(
R
.
string
.
repo_install_msg
,
filename
));
setCancelable
(
true
);
...
...
@@ -37,15 +38,15 @@ public class MagiskInstallDialog extends CustomAlertDialog {
new
InstallMethodDialog
(
activity
,
options
,
filename
).
show
();
});
setNegativeButton
(
R
.
string
.
no_thanks
,
null
);
if
(!
TextUtils
.
isEmpty
(
mm
.
magiskNoteLink
))
{
if
(!
TextUtils
.
isEmpty
(
Global
.
magiskNoteLink
))
{
setNeutralButton
(
R
.
string
.
release_notes
,
(
d
,
i
)
->
{
if
(
mm
.
magiskNoteLink
.
contains
(
"forum.xda-developers"
))
{
if
(
Global
.
magiskNoteLink
.
contains
(
"forum.xda-developers"
))
{
// Open forum links in browser
Intent
openLink
=
new
Intent
(
Intent
.
ACTION_VIEW
,
Uri
.
parse
(
mm
.
magiskNoteLink
));
Intent
openLink
=
new
Intent
(
Intent
.
ACTION_VIEW
,
Uri
.
parse
(
Global
.
magiskNoteLink
));
openLink
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
mm
.
startActivity
(
openLink
);
}
else
{
new
MarkDownWindow
(
activity
,
null
,
mm
.
magiskNoteLink
).
exec
();
new
MarkDownWindow
(
activity
,
null
,
Global
.
magiskNoteLink
).
exec
();
}
});
}
...
...
app/src/full/java/com/topjohnwu/magisk/components/ManagerInstallDialog.java
View file @
914b7ee0
...
...
@@ -5,6 +5,7 @@ import android.content.Intent;
import
android.support.annotation.NonNull
;
import
android.text.TextUtils
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.asyncs.MarkDownWindow
;
...
...
@@ -18,21 +19,21 @@ public class ManagerInstallDialog extends CustomAlertDialog {
super
(
activity
);
MagiskManager
mm
=
Utils
.
getMagiskManager
(
activity
);
String
filename
=
Utils
.
fmt
(
"MagiskManager-v%s(%d).apk"
,
mm
.
remoteManagerVersionString
,
mm
.
remoteManagerVersionCode
);
Global
.
remoteManagerVersionString
,
Global
.
remoteManagerVersionCode
);
setTitle
(
mm
.
getString
(
R
.
string
.
repo_install_title
,
mm
.
getString
(
R
.
string
.
app_name
)));
setMessage
(
mm
.
getString
(
R
.
string
.
repo_install_msg
,
filename
));
setCancelable
(
true
);
setPositiveButton
(
R
.
string
.
install
,
(
d
,
i
)
->
activity
.
runWithPermission
(
new
String
[]
{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
()
->
{
Intent
intent
=
new
Intent
(
mm
,
ManagerUpdate
.
class
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_SET_LINK
,
mm
.
managerLink
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_SET_LINK
,
Global
.
managerLink
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_SET_FILENAME
,
filename
);
mm
.
sendBroadcast
(
intent
);
}))
.
setNegativeButton
(
R
.
string
.
no_thanks
,
null
);
if
(!
TextUtils
.
isEmpty
(
mm
.
managerNoteLink
))
{
if
(!
TextUtils
.
isEmpty
(
Global
.
managerNoteLink
))
{
setNeutralButton
(
R
.
string
.
app_changelog
,
(
d
,
i
)
->
new
MarkDownWindow
(
activity
,
null
,
mm
.
managerNoteLink
).
exec
());
new
MarkDownWindow
(
activity
,
null
,
Global
.
managerNoteLink
).
exec
());
}
}
}
app/src/full/java/com/topjohnwu/magisk/components/UninstallDialog.java
View file @
914b7ee0
...
...
@@ -7,6 +7,7 @@ import android.net.Uri;
import
android.support.annotation.NonNull
;
import
android.text.TextUtils
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.FlashActivity
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
...
...
@@ -24,7 +25,7 @@ public class UninstallDialog extends CustomAlertDialog {
setTitle
(
R
.
string
.
uninstall_magisk_title
);
setMessage
(
R
.
string
.
uninstall_magisk_msg
);
setNeutralButton
(
R
.
string
.
restore_img
,
(
d
,
i
)
->
new
RestoreImages
(
activity
).
exec
());
if
(!
TextUtils
.
isEmpty
(
mm
.
uninstallerLink
))
{
if
(!
TextUtils
.
isEmpty
(
Global
.
uninstallerLink
))
{
setPositiveButton
(
R
.
string
.
complete_uninstall
,
(
d
,
i
)
->
Download
.
receive
(
activity
,
new
DownloadReceiver
()
{
@Override
...
...
@@ -35,7 +36,7 @@ public class UninstallDialog extends CustomAlertDialog {
.
putExtra
(
Const
.
Key
.
FLASH_ACTION
,
Const
.
Value
.
UNINSTALL
);
context
.
startActivity
(
intent
);
}
},
mm
.
uninstallerLink
,
"magisk-uninstaller.zip"
));
},
Global
.
uninstallerLink
,
"magisk-uninstaller.zip"
));
}
}
}
app/src/full/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java
View file @
914b7ee0
...
...
@@ -11,6 +11,7 @@ import android.support.annotation.NonNull;
import
android.text.TextUtils
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.container.Policy
;
...
...
@@ -72,13 +73,12 @@ public class MagiskDatabaseHelper {
// We don't want the app to crash, create a db and return
return
mm
.
openOrCreateDatabase
(
"su.db"
,
Context
.
MODE_PRIVATE
,
null
);
}
mm
.
loadMagiskInfo
();
// Cleanup
Shell
.
su
(
"db_clean "
+
Const
.
USER_ID
).
exec
();
if
(
mm
.
magiskVersionCode
<
Const
.
MAGISK_VER
.
FBE_AWARE
)
{
if
(
Global
.
magiskVersionCode
<
Const
.
MAGISK_VER
.
FBE_AWARE
)
{
// Super old legacy mode
return
mm
.
openOrCreateDatabase
(
"su.db"
,
Context
.
MODE_PRIVATE
,
null
);
}
else
if
(
mm
.
magiskVersionCode
<
Const
.
MAGISK_VER
.
HIDDEN_PATH
)
{
}
else
if
(
Global
.
magiskVersionCode
<
Const
.
MAGISK_VER
.
HIDDEN_PATH
)
{
// Legacy mode with FBE aware
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N
)
{
de
.
moveDatabaseFrom
(
mm
,
"su.db"
);
...
...
@@ -89,7 +89,7 @@ public class MagiskDatabaseHelper {
final
SuFile
GLOBAL_DB
=
new
SuFile
(
"/data/adb/magisk.db"
);
mm
.
deleteDatabase
(
"su.db"
);
de
.
deleteDatabase
(
"su.db"
);
if
(
mm
.
magiskVersionCode
<
Const
.
MAGISK_VER
.
SEPOL_REFACTOR
)
{
if
(
Global
.
magiskVersionCode
<
Const
.
MAGISK_VER
.
SEPOL_REFACTOR
)
{
// We need some additional policies on old versions
Shell
.
su
(
"db_sepatch"
).
exec
();
}
...
...
@@ -123,7 +123,7 @@ public class MagiskDatabaseHelper {
POLICY_TABLE
,
POLICY_TABLE
));
db
.
execSQL
(
Utils
.
fmt
(
"DROP TABLE %s_old"
,
POLICY_TABLE
));
MagiskManager
.
get
().
deleteDatabase
(
"sulog.db"
);
Global
.
MM
().
deleteDatabase
(
"sulog.db"
);
++
oldVersion
;
}
if
(
oldVersion
==
2
)
{
...
...
@@ -142,7 +142,7 @@ public class MagiskDatabaseHelper {
// Remove everything, we do not support downgrade
public
void
onDowngrade
(
SQLiteDatabase
db
)
{
MagiskManager
.
toast
(
R
.
string
.
su_db_corrupt
,
Toast
.
LENGTH_LONG
);
Global
.
toast
(
R
.
string
.
su_db_corrupt
,
Toast
.
LENGTH_LONG
);
db
.
execSQL
(
"DROP TABLE IF EXISTS "
+
POLICY_TABLE
);
db
.
execSQL
(
"DROP TABLE IF EXISTS "
+
LOG_TABLE
);
db
.
execSQL
(
"DROP TABLE IF EXISTS "
+
SETTINGS_TABLE
);
...
...
@@ -174,7 +174,7 @@ public class MagiskDatabaseHelper {
// Clear outdated policies
db
.
delete
(
POLICY_TABLE
,
Utils
.
fmt
(
"until > 0 AND until < %d"
,
System
.
currentTimeMillis
()
/
1000
),
null
);
// Clear outdated logs
db
.
delete
(
LOG_TABLE
,
Utils
.
fmt
(
"time < %d"
,
System
.
currentTimeMillis
()
-
MagiskManager
.
get
().
suLogTimeout
*
86400000
),
null
);
db
.
delete
(
LOG_TABLE
,
Utils
.
fmt
(
"time < %d"
,
System
.
currentTimeMillis
()
-
Global
.
MM
().
suLogTimeout
*
86400000
),
null
);
}
public
void
deletePolicy
(
Policy
policy
)
{
...
...
app/src/full/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java
View file @
914b7ee0
...
...
@@ -5,6 +5,7 @@ import android.database.Cursor;
import
android.database.sqlite.SQLiteDatabase
;
import
android.database.sqlite.SQLiteOpenHelper
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.container.Repo
;
import
com.topjohnwu.magisk.utils.Const
;
...
...
@@ -108,7 +109,7 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
orderBy
=
"last_update DESC"
;
}
return
mDb
.
query
(
TABLE_NAME
,
null
,
"minMagisk<=? AND minMagisk>=?"
,
new
String
[]
{
String
.
valueOf
(
mm
.
magiskVersionCode
),
String
.
valueOf
(
Const
.
MIN_MODULE_VER
())
},
new
String
[]
{
String
.
valueOf
(
Global
.
magiskVersionCode
),
String
.
valueOf
(
Const
.
MIN_MODULE_VER
())
},
null
,
null
,
orderBy
);
}
...
...
app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java
View file @
914b7ee0
...
...
@@ -8,8 +8,8 @@ import android.content.pm.ShortcutManager;
import
android.graphics.drawable.Icon
;
import
android.os.Build
;
import
android.support.annotation.RequiresApi
;
import
android.text.TextUtils
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.SplashActivity
;
...
...
@@ -25,10 +25,6 @@ public class ShortcutReceiver extends BroadcastReceiver {
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N_MR1
)
{
MagiskManager
mm
=
Utils
.
getMagiskManager
(
context
);
ShortcutManager
manager
=
context
.
getSystemService
(
ShortcutManager
.
class
);
if
(
TextUtils
.
equals
(
intent
.
getAction
(),
Intent
.
ACTION_LOCALE_CHANGED
))
{
// It is triggered with locale change, manual load Magisk info
mm
.
loadMagiskInfo
();
}
manager
.
setDynamicShortcuts
(
getShortCuts
(
mm
));
}
}
...
...
@@ -36,8 +32,8 @@ public class ShortcutReceiver extends BroadcastReceiver {
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
N_MR1
)
private
ArrayList
<
ShortcutInfo
>
getShortCuts
(
MagiskManager
mm
)
{
ArrayList
<
ShortcutInfo
>
shortCuts
=
new
ArrayList
<>();
if
(
Shell
.
rootAccess
()
&&
!(
Const
.
USER_ID
>
0
&&
boolean
root
=
Shell
.
rootAccess
();
if
(
root
&&
!(
Const
.
USER_ID
>
0
&&
mm
.
multiuserMode
==
Const
.
Value
.
MULTIUSER_MODE_OWNER_MANAGED
))
{
shortCuts
.
add
(
new
ShortcutInfo
.
Builder
(
mm
,
"superuser"
)
.
setShortLabel
(
mm
.
getString
(
R
.
string
.
superuser
))
...
...
@@ -49,7 +45,7 @@ public class ShortcutReceiver extends BroadcastReceiver {
.
setRank
(
0
)
.
build
());
}
if
(
Shell
.
rootAccess
()
&&
mm
.
magiskVersionCode
>=
Const
.
MAGISK_VER
.
UNIFIED
if
(
root
&&
Global
.
magiskVersionCode
>=
Const
.
MAGISK_VER
.
UNIFIED
&&
mm
.
prefs
.
getBoolean
(
Const
.
Key
.
MAGISKHIDE
,
false
))
{
shortCuts
.
add
(
new
ShortcutInfo
.
Builder
(
mm
,
"magiskhide"
)
.
setShortLabel
(
mm
.
getString
(
R
.
string
.
magiskhide
))
...
...
@@ -61,8 +57,7 @@ public class ShortcutReceiver extends BroadcastReceiver {
.
setRank
(
1
)
.
build
());
}
if
(!
mm
.
prefs
.
getBoolean
(
Const
.
Key
.
COREONLY
,
false
)
&&
Shell
.
rootAccess
()
&&
mm
.
magiskVersionCode
>=
0
)
{
if
(!
mm
.
prefs
.
getBoolean
(
Const
.
Key
.
COREONLY
,
false
)
&&
root
&&
Global
.
magiskVersionCode
>=
0
)
{
shortCuts
.
add
(
new
ShortcutInfo
.
Builder
(
mm
,
"modules"
)
.
setShortLabel
(
mm
.
getString
(
R
.
string
.
modules
))
.
setIntent
(
new
Intent
(
mm
,
SplashActivity
.
class
)
...
...
app/src/full/java/com/topjohnwu/magisk/services/UpdateCheckService.java
View file @
914b7ee0
...
...
@@ -4,15 +4,14 @@ import android.app.job.JobParameters;
import
android.app.job.JobService
;
import
com.topjohnwu.magisk.asyncs.CheckUpdates
;
import
com.topjohnwu.
magisk.utils.Utils
;
import
com.topjohnwu.
superuser.Shell
;
public
class
UpdateCheckService
extends
JobService
{
@Override
public
boolean
onStartJob
(
JobParameters
params
)
{
Utils
.
getMagiskManager
(
this
).
loadMagiskInfo
();
new
CheckUpdates
(
true
)
.
setCallBack
(()
->
jobFinished
(
params
,
false
)).
exec
();
Shell
.
getShell
();
new
CheckUpdates
(
true
).
setCallBack
(()
->
jobFinished
(
params
,
false
)).
exec
();
return
true
;
}
...
...
app/src/full/java/com/topjohnwu/magisk/superuser/SuReceiver.java
View file @
914b7ee0
...
...
@@ -7,6 +7,7 @@ import android.content.pm.PackageManager;
import
android.os.Process
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.container.Policy
;
...
...
@@ -32,7 +33,7 @@ public class SuReceiver extends BroadcastReceiver {
if
(
mode
<
0
)
return
;
if
(
mode
==
Const
.
Value
.
NOTIFY_USER_TO_OWNER
)
{
MagiskManager
.
toast
(
R
.
string
.
multiuser_hint_owner_request
,
Toast
.
LENGTH_LONG
);
Global
.
toast
(
R
.
string
.
multiuser_hint_owner_request
,
Toast
.
LENGTH_LONG
);
return
;
}
...
...
@@ -70,7 +71,7 @@ public class SuReceiver extends BroadcastReceiver {
}
if
(
policy
.
notification
&&
mm
.
suNotificationType
==
Const
.
Value
.
NOTIFICATION_TOAST
)
{
MagiskManager
.
toast
(
message
,
Toast
.
LENGTH_SHORT
);
Global
.
toast
(
message
,
Toast
.
LENGTH_SHORT
);
}
if
(
mode
==
Const
.
Value
.
NOTIFY_NORMAL_LOG
&&
policy
.
logging
)
{
...
...
app/src/full/java/com/topjohnwu/magisk/utils/Const.java
View file @
914b7ee0
...
...
@@ -3,7 +3,7 @@ package com.topjohnwu.magisk.utils;
import
android.os.Process
;
import
com.topjohnwu.magisk.BuildConfig
;
import
com.topjohnwu.magisk.
MagiskManager
;
import
com.topjohnwu.magisk.
Global
;
import
java.io.File
;
import
java.util.Arrays
;
...
...
@@ -40,13 +40,13 @@ public class Const {
public
static
final
int
SNET_VER
=
10
;
public
static
int
MIN_MODULE_VER
()
{
return
MagiskManager
.
get
()
.
magiskVersionCode
>=
MAGISK_VER
.
REMOVE_LEGACY_LINK
?
1500
:
1400
;
return
Global
.
magiskVersionCode
>=
MAGISK_VER
.
REMOVE_LEGACY_LINK
?
1500
:
1400
;
}
/* A list of apps that should not be shown as hide-able */
public
static
final
List
<
String
>
HIDE_BLACKLIST
=
Arrays
.
asList
(
"android"
,
MagiskManager
.
get
().
getPackageName
(),
Global
.
MM
().
getPackageName
(),
"com.google.android.gms"
);
...
...
app/src/full/java/com/topjohnwu/magisk/utils/FingerprintHelper.java
View file @
914b7ee0
...
...
@@ -9,6 +9,7 @@ import android.security.keystore.KeyGenParameterSpec;
import
android.security.keystore.KeyPermanentlyInvalidatedException
;
import
android.security.keystore.KeyProperties
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
java.security.KeyStore
;
...
...
@@ -27,14 +28,14 @@ public abstract class FingerprintHelper {
public
static
boolean
canUseFingerprint
()
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
M
)
return
false
;
MagiskManager
mm
=
MagiskManager
.
get
();
MagiskManager
mm
=
Global
.
MM
();
KeyguardManager
km
=
mm
.
getSystemService
(
KeyguardManager
.
class
);
FingerprintManager
fm
=
mm
.
getSystemService
(
FingerprintManager
.
class
);
return
km
.
isKeyguardSecure
()
&&
fm
!=
null
&&
fm
.
isHardwareDetected
()
&&
fm
.
hasEnrolledFingerprints
();
}
protected
FingerprintHelper
()
throws
Exception
{
MagiskManager
mm
=
MagiskManager
.
get
();
MagiskManager
mm
=
Global
.
MM
();
KeyStore
keyStore
=
KeyStore
.
getInstance
(
"AndroidKeyStore"
);
manager
=
mm
.
getSystemService
(
FingerprintManager
.
class
);
cipher
=
Cipher
.
getInstance
(
KeyProperties
.
KEY_ALGORITHM_AES
+
"/"
...
...
app/src/full/java/com/topjohnwu/magisk/utils/NotificationMgr.java
View file @
914b7ee0
...
...
@@ -7,6 +7,7 @@ import android.content.Intent;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.TaskStackBuilder
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.SplashActivity
;
...
...
@@ -16,7 +17,7 @@ import com.topjohnwu.magisk.receivers.RebootReceiver;
public
class
NotificationMgr
{
public
static
void
magiskUpdate
()
{
MagiskManager
mm
=
MagiskManager
.
get
();
MagiskManager
mm
=
Global
.
MM
();
Intent
intent
=
new
Intent
(
mm
,
SplashActivity
.
class
);
intent
.
putExtra
(
Const
.
Key
.
OPEN_SECTION
,
"magisk"
);
...
...
@@ -29,7 +30,7 @@ public class NotificationMgr {
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
mm
,
Const
.
ID
.
NOTIFICATION_CHANNEL
);
builder
.
setSmallIcon
(
R
.
drawable
.
ic_magisk_outline
)
.
setContentTitle
(
mm
.
getString
(
R
.
string
.
magisk_update_title
))
.
setContentText
(
mm
.
getString
(
R
.
string
.
magisk_update_available
,
mm
.
remoteMagiskVersionString
))
.
setContentText
(
mm
.
getString
(
R
.
string
.
magisk_update_available
,
Global
.
remoteMagiskVersionString
))
.
setVibrate
(
new
long
[]{
0
,
100
,
100
,
100
})
.
setAutoCancel
(
true
)
.
setContentIntent
(
pendingIntent
);
...
...
@@ -40,12 +41,12 @@ public class NotificationMgr {
}
public
static
void
managerUpdate
()
{
MagiskManager
mm
=
MagiskManager
.
get
();
MagiskManager
mm
=
Global
.
MM
();
String
filename
=
Utils
.
fmt
(
"MagiskManager-v%s(%d).apk"
,
mm
.
remoteManagerVersionString
,
mm
.
remoteManagerVersionCode
);
Global
.
remoteManagerVersionString
,
Global
.
remoteManagerVersionCode
);
Intent
intent
=
new
Intent
(
mm
,
ManagerUpdate
.
class
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_SET_LINK
,
mm
.
managerLink
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_SET_LINK
,
Global
.
managerLink
);
intent
.
putExtra
(
Const
.
Key
.
INTENT_SET_FILENAME
,
filename
);
PendingIntent
pendingIntent
=
PendingIntent
.
getBroadcast
(
mm
,
Const
.
ID
.
APK_UPDATE_NOTIFICATION_ID
,
intent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
...
...
@@ -64,7 +65,7 @@ public class NotificationMgr {
}
public
static
void
dtboPatched
()
{
MagiskManager
mm
=
MagiskManager
.
get
();
MagiskManager
mm
=
Global
.
MM
();
Intent
intent
=
new
Intent
(
mm
,
RebootReceiver
.
class
);
PendingIntent
pendingIntent
=
PendingIntent
.
getBroadcast
(
mm
,
...
...
app/src/full/java/com/topjohnwu/magisk/utils/RootUtils.java
View file @
914b7ee0
...
...
@@ -3,9 +3,11 @@ package com.topjohnwu.magisk.utils;
import
android.content.Context
;
import
android.support.annotation.NonNull
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.superuser.BusyBox
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.ShellUtils
;
import
com.topjohnwu.superuser.io.SuFile
;
import
java.io.File
;
...
...
@@ -18,26 +20,10 @@ public class RootUtils extends Shell.Initializer {
BusyBox
.
BB_PATH
=
new
File
(
Const
.
BUSYBOX_PATH
);
}
private
static
boolean
fileInit
=
false
;
public
static
void
uninstallPkg
(
String
pkg
)
{
Shell
.
su
(
"db_clean "
+
Const
.
USER_ID
,
"pm uninstall "
+
pkg
).
exec
();
}
private
void
initConsts
()
{
Const
.
MAGISK_DISABLE_FILE
=
new
SuFile
(
"/cache/.disable_magisk"
);
SuFile
file
=
new
SuFile
(
"/sbin/.core/img"
);
if
(
file
.
exists
())
{
Const
.
MAGISK_PATH
=
file
;
}
else
if
((
file
=
new
SuFile
(
"/dev/magisk/img"
)).
exists
())
{
Const
.
MAGISK_PATH
=
file
;
}
else
{
Const
.
MAGISK_PATH
=
new
SuFile
(
"/magisk"
);
}
Const
.
MAGISK_HOST_FILE
=
new
SuFile
(
Const
.
MAGISK_PATH
+
"/.core/hosts"
);
fileInit
=
true
;
}
@Override
public
boolean
onInit
(
Context
context
,
@NonNull
Shell
shell
)
{
if
(
shell
.
isRoot
())
{
...
...
@@ -51,8 +37,22 @@ public class RootUtils extends Shell.Initializer {
}
catch
(
IOException
e
)
{
return
false
;
}
if
(!
fileInit
)
initConsts
();
Const
.
MAGISK_DISABLE_FILE
=
new
SuFile
(
"/cache/.disable_magisk"
);
SuFile
file
=
new
SuFile
(
"/sbin/.core/img"
);
if
(
file
.
exists
())
{
Const
.
MAGISK_PATH
=
file
;
}
else
if
((
file
=
new
SuFile
(
"/dev/magisk/img"
)).
exists
())
{
Const
.
MAGISK_PATH
=
file
;
}
else
{
Const
.
MAGISK_PATH
=
new
SuFile
(
"/magisk"
);
}
Const
.
MAGISK_HOST_FILE
=
new
SuFile
(
Const
.
MAGISK_PATH
+
"/.core/hosts"
);
Global
.
loadMagiskInfo
();
Global
.
keepVerity
=
Boolean
.
parseBoolean
(
ShellUtils
.
fastCmd
(
"echo $KEEPVERITY"
));
Global
.
keepEnc
=
Boolean
.
parseBoolean
(
ShellUtils
.
fastCmd
(
"echo $KEEPFORCEENCRYPT"
));
}
return
true
;
}
...
...
app/src/full/java/com/topjohnwu/magisk/utils/Utils.java
View file @
914b7ee0
package
com
.
topjohnwu
.
magisk
.
utils
;
import
android.app.job.JobInfo
;
import
android.app.job.JobScheduler
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.content.res.Configuration
;
...
...
@@ -8,8 +11,10 @@ import android.net.Uri;
import
android.provider.OpenableColumns
;
import
android.support.annotation.StringRes
;
import
com.topjohnwu.magisk.Global
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.services.UpdateCheckService
;
import
java.util.ArrayList
;
import
java.util.Collections
;
...
...
@@ -50,7 +55,7 @@ public class Utils {
}
public
static
String
getLocaleString
(
Locale
locale
,
@StringRes
int
id
)
{
Context
context
=
MagiskManager
.
get
();
Context
context
=
Global
.
MM
();
Configuration
config
=
context
.
getResources
().
getConfiguration
();
config
.
setLocale
(
locale
);
Context
localizedContext
=
context
.
createConfigurationContext
(
config
);
...
...
@@ -76,7 +81,7 @@ public class Utils {
set
.
add
(
getLocaleString
(
locale
,
compareId
));
// Other locales
for
(
String
s
:
MagiskManager
.
get
().
getAssets
().
getLocales
())
{
for
(
String
s
:
Global
.
MM
().
getAssets
().
getLocales
())
{
locale
=
Locale
.
forLanguageTag
(
s
);
if
(
set
.
add
(
getLocaleString
(
locale
,
compareId
)))
{
locales
.
add
(
locale
);
...
...
@@ -89,7 +94,7 @@ public class Utils {
}
public
static
int
dpInPx
(
int
dp
)
{
Context
context
=
MagiskManager
.
get
();
Context
context
=
Global
.
MM
();
float
scale
=
context
.
getResources
().
getDisplayMetrics
().
density
;
return
(
int
)
(
dp
*
scale
+
0.5
);
}
...
...
@@ -106,4 +111,24 @@ public class Utils {
return
newString
;
}
}
public
static
void
setupUpdateCheck
()
{
MagiskManager
mm
=
Global
.
MM
();
JobScheduler
scheduler
=
(
JobScheduler
)
mm
.
getSystemService
(
Context
.
JOB_SCHEDULER_SERVICE
);
if
(
mm
.
prefs
.
getBoolean
(
Const
.
Key
.
CHECK_UPDATES
,
true
))
{
if
(
scheduler
.
getAllPendingJobs
().
isEmpty
()
||
Const
.
UPDATE_SERVICE_VER
>
mm
.
prefs
.
getInt
(
Const
.
Key
.
UPDATE_SERVICE_VER
,
-
1
))
{
ComponentName
service
=
new
ComponentName
(
mm
,
UpdateCheckService
.
class
);
JobInfo
info
=
new
JobInfo
.
Builder
(
Const
.
ID
.
UPDATE_SERVICE_ID
,
service
)
.
setRequiredNetworkType
(
JobInfo
.
NETWORK_TYPE_ANY
)
.
setPersisted
(
true
)
.
setPeriodic
(
8
*
60
*
60
*
1000
)
.
build
();
scheduler
.
schedule
(
info
);
}
}
else
{
scheduler
.
cancel
(
Const
.
UPDATE_SERVICE_VER
);
}
}
}
\ No newline at end of file
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