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
fd6cbb13
Commit
fd6cbb13
authored
Dec 11, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change new magisk database
parent
aa75c8e5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
152 additions
and
181 deletions
+152
-181
LogFragment.java
src/main/java/com/topjohnwu/magisk/LogFragment.java
+4
-1
MagiskManager.java
src/main/java/com/topjohnwu/magisk/MagiskManager.java
+11
-11
MainActivity.java
src/main/java/com/topjohnwu/magisk/MainActivity.java
+5
-5
SettingsActivity.java
src/main/java/com/topjohnwu/magisk/SettingsActivity.java
+8
-4
SplashActivity.java
src/main/java/com/topjohnwu/magisk/SplashActivity.java
+0
-4
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
-2
RestoreImages.java
src/main/java/com/topjohnwu/magisk/asyncs/RestoreImages.java
+1
-1
Policy.java
src/main/java/com/topjohnwu/magisk/container/Policy.java
+1
-1
SuDatabaseHelper.java
.../java/com/topjohnwu/magisk/database/SuDatabaseHelper.java
+68
-109
Const.java
src/main/java/com/topjohnwu/magisk/utils/Const.java
+3
-0
ShowUI.java
src/main/java/com/topjohnwu/magisk/utils/ShowUI.java
+28
-35
Utils.java
src/main/java/com/topjohnwu/magisk/utils/Utils.java
+19
-7
strings.xml
src/main/res/values/strings.xml
+2
-0
No files found.
src/main/java/com/topjohnwu/magisk/LogFragment.java
View file @
fd6cbb13
...
@@ -10,6 +10,7 @@ import android.view.ViewGroup;
...
@@ -10,6 +10,7 @@ import android.view.ViewGroup;
import
com.topjohnwu.magisk.adapters.TabFragmentAdapter
;
import
com.topjohnwu.magisk.adapters.TabFragmentAdapter
;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.utils.Const
;
import
butterknife.BindView
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
import
butterknife.ButterKnife
;
...
@@ -33,7 +34,9 @@ public class LogFragment extends Fragment {
...
@@ -33,7 +34,9 @@ public class LogFragment extends Fragment {
TabFragmentAdapter
adapter
=
new
TabFragmentAdapter
(
getChildFragmentManager
());
TabFragmentAdapter
adapter
=
new
TabFragmentAdapter
(
getChildFragmentManager
());
if
(!(
Const
.
USER_ID
>
0
&&
getApplication
().
multiuserMode
==
Const
.
Value
.
MULTIUSER_MODE_OWNER_MANAGED
))
{
adapter
.
addTab
(
new
SuLogFragment
(),
getString
(
R
.
string
.
superuser
));
adapter
.
addTab
(
new
SuLogFragment
(),
getString
(
R
.
string
.
superuser
));
}
adapter
.
addTab
(
new
MagiskLogFragment
(),
getString
(
R
.
string
.
magisk
));
adapter
.
addTab
(
new
MagiskLogFragment
(),
getString
(
R
.
string
.
magisk
));
tab
.
setupWithViewPager
(
viewPager
);
tab
.
setupWithViewPager
(
viewPager
);
tab
.
setVisibility
(
View
.
VISIBLE
);
tab
.
setVisibility
(
View
.
VISIBLE
);
...
...
src/main/java/com/topjohnwu/magisk/MagiskManager.java
View file @
fd6cbb13
...
@@ -39,7 +39,6 @@ public class MagiskManager extends Application {
...
@@ -39,7 +39,6 @@ public class MagiskManager extends Application {
// Info
// Info
public
boolean
hasInit
=
false
;
public
boolean
hasInit
=
false
;
public
int
userId
;
public
String
magiskVersionString
;
public
String
magiskVersionString
;
public
int
magiskVersionCode
=
-
1
;
public
int
magiskVersionCode
=
-
1
;
public
String
remoteMagiskVersionString
;
public
String
remoteMagiskVersionString
;
...
@@ -95,14 +94,6 @@ public class MagiskManager extends Application {
...
@@ -95,14 +94,6 @@ public class MagiskManager extends Application {
public
void
onCreate
()
{
public
void
onCreate
()
{
super
.
onCreate
();
super
.
onCreate
();
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
);
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
);
userId
=
getApplicationInfo
().
uid
/
100000
;
if
(
Utils
.
getDatabasePath
(
this
,
SuDatabaseHelper
.
DB_NAME
).
exists
())
{
// Don't migrate yet, wait and check Magisk version
suDB
=
new
SuDatabaseHelper
(
this
);
}
else
{
suDB
=
new
SuDatabaseHelper
();
}
// Handle duplicate package
// Handle duplicate package
if
(!
getPackageName
().
equals
(
Const
.
ORIG_PKG_NAME
))
{
if
(!
getPackageName
().
equals
(
Const
.
ORIG_PKG_NAME
))
{
...
@@ -113,11 +104,15 @@ public class MagiskManager extends Application {
...
@@ -113,11 +104,15 @@ public class MagiskManager extends Application {
startActivity
(
intent
);
startActivity
(
intent
);
return
;
return
;
}
catch
(
PackageManager
.
NameNotFoundException
ignored
)
{
/* Expected */
}
}
catch
(
PackageManager
.
NameNotFoundException
ignored
)
{
/* Expected */
}
}
else
{
}
suDB
=
new
SuDatabaseHelper
(
true
);
if
(
getPackageName
().
equals
(
Const
.
ORIG_PKG_NAME
))
{
String
pkg
=
suDB
.
getStrings
(
Const
.
Key
.
SU_REQUESTER
,
null
);
String
pkg
=
suDB
.
getStrings
(
Const
.
Key
.
SU_REQUESTER
,
null
);
if
(
pkg
!=
null
)
{
if
(
pkg
!=
null
)
{
suDB
.
setStrings
(
Const
.
Key
.
SU_REQUESTER
,
null
);
suDB
.
setStrings
(
Const
.
Key
.
SU_REQUESTER
,
null
);
Shell
.
su_raw
(
"pm uninstall "
+
pkg
);
Utils
.
uninstallPkg
(
pkg
);
}
}
}
}
...
@@ -216,6 +211,11 @@ public class MagiskManager extends Application {
...
@@ -216,6 +211,11 @@ public class MagiskManager extends Application {
}
catch
(
NumberFormatException
e
)
{
}
catch
(
NumberFormatException
e
)
{
keepEnc
=
false
;
keepEnc
=
false
;
}
}
if
(
suDB
!=
null
)
{
suDB
.
close
();
suDB
=
new
SuDatabaseHelper
();
}
}
}
public
void
setPermissionGrantCallback
(
Runnable
callback
)
{
public
void
setPermissionGrantCallback
(
Runnable
callback
)
{
...
...
src/main/java/com/topjohnwu/magisk/MainActivity.java
View file @
fd6cbb13
...
@@ -149,13 +149,13 @@ public class MainActivity extends Activity
...
@@ -149,13 +149,13 @@ public class MainActivity extends Activity
menu
.
findItem
(
R
.
id
.
magiskhide
).
setVisible
(
menu
.
findItem
(
R
.
id
.
magiskhide
).
setVisible
(
Shell
.
rootAccess
()
&&
mm
.
magiskVersionCode
>=
1300
Shell
.
rootAccess
()
&&
mm
.
magiskVersionCode
>=
1300
&&
prefs
.
getBoolean
(
Const
.
Key
.
MAGISKHIDE
,
false
));
&&
prefs
.
getBoolean
(
Const
.
Key
.
MAGISKHIDE
,
false
));
menu
.
findItem
(
R
.
id
.
modules
).
setVisible
(
menu
.
findItem
(
R
.
id
.
modules
).
setVisible
(
!
mm
.
prefs
.
getBoolean
(
Const
.
Key
.
COREONLY
,
false
)
&&
Shell
.
rootAccess
()
&&
mm
.
magiskVersionCode
>=
0
);
Shell
.
rootAccess
()
&&
mm
.
magiskVersionCode
>=
0
);
menu
.
findItem
(
R
.
id
.
downloads
).
setVisible
(
Utils
.
checkNetworkStatus
()
&&
menu
.
findItem
(
R
.
id
.
downloads
).
setVisible
(!
mm
.
prefs
.
getBoolean
(
Const
.
Key
.
COREONLY
,
false
)
Shell
.
rootAccess
()
&&
mm
.
magiskVersionCode
>=
0
);
&&
Utils
.
checkNetworkStatus
()
&&
Shell
.
rootAccess
()
&&
mm
.
magiskVersionCode
>=
0
);
menu
.
setGroupVisible
(
R
.
id
.
second_group
,
!
mm
.
prefs
.
getBoolean
(
Const
.
Key
.
COREONLY
,
false
));
menu
.
findItem
(
R
.
id
.
log
).
setVisible
(
Shell
.
rootAccess
());
menu
.
findItem
(
R
.
id
.
log
).
setVisible
(
Shell
.
rootAccess
());
menu
.
findItem
(
R
.
id
.
superuser
).
setVisible
(
Shell
.
rootAccess
());
menu
.
findItem
(
R
.
id
.
superuser
).
setVisible
(
Shell
.
rootAccess
()
&&
!(
Const
.
USER_ID
>
0
&&
mm
.
multiuserMode
==
Const
.
Value
.
MULTIUSER_MODE_OWNER_MANAGED
));
}
}
public
void
navigate
(
String
item
)
{
public
void
navigate
(
String
item
)
{
...
...
src/main/java/com/topjohnwu/magisk/SettingsActivity.java
View file @
fd6cbb13
...
@@ -133,12 +133,12 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
...
@@ -133,12 +133,12 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
setSummary
();
setSummary
();
// Disable dangerous settings in
user mode if selected owner manage
// Disable dangerous settings in
secondary user
if
(
mm
.
userId
>
0
)
{
if
(
Const
.
USER_ID
>
0
)
{
suCategory
.
removePreference
(
multiuserMode
);
suCategory
.
removePreference
(
multiuserMode
);
}
}
//
Remov
e re-authentication option on Android O, it will not work
//
Disabl
e re-authentication option on Android O, it will not work
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
reauth
.
setEnabled
(
false
);
reauth
.
setEnabled
(
false
);
reauth
.
setSummary
(
R
.
string
.
android_o_not_support
);
reauth
.
setSummary
(
R
.
string
.
android_o_not_support
);
...
@@ -155,9 +155,13 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
...
@@ -155,9 +155,13 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
generalCatagory
.
removePreference
(
hideManager
);
generalCatagory
.
removePreference
(
hideManager
);
}
}
if
(!
Shell
.
rootAccess
()
||
(
Const
.
USER_ID
>
0
&&
mm
.
multiuserMode
==
Const
.
Value
.
MULTIUSER_MODE_OWNER_MANAGED
))
{
prefScreen
.
removePreference
(
suCategory
);
}
if
(!
Shell
.
rootAccess
())
{
if
(!
Shell
.
rootAccess
())
{
prefScreen
.
removePreference
(
magiskCategory
);
prefScreen
.
removePreference
(
magiskCategory
);
prefScreen
.
removePreference
(
suCategory
);
generalCatagory
.
removePreference
(
hideManager
);
generalCatagory
.
removePreference
(
hideManager
);
}
else
if
(
mm
.
magiskVersionCode
<
1300
)
{
}
else
if
(
mm
.
magiskVersionCode
<
1300
)
{
prefScreen
.
removePreference
(
magiskCategory
);
prefScreen
.
removePreference
(
magiskCategory
);
...
...
src/main/java/com/topjohnwu/magisk/SplashActivity.java
View file @
fd6cbb13
...
@@ -15,7 +15,6 @@ import com.topjohnwu.magisk.asyncs.LoadModules;
...
@@ -15,7 +15,6 @@ import com.topjohnwu.magisk.asyncs.LoadModules;
import
com.topjohnwu.magisk.asyncs.ParallelTask
;
import
com.topjohnwu.magisk.asyncs.ParallelTask
;
import
com.topjohnwu.magisk.asyncs.UpdateRepos
;
import
com.topjohnwu.magisk.asyncs.UpdateRepos
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.database.SuDatabaseHelper
;
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.Shell
;
...
@@ -68,9 +67,6 @@ public class SplashActivity extends Activity {
...
@@ -68,9 +67,6 @@ public class SplashActivity extends Activity {
mm
.
bootBlock
=
ret
.
get
(
0
);
mm
.
bootBlock
=
ret
.
get
(
0
);
}
}
// Setup suDB
SuDatabaseHelper
.
setupSuDB
();
// Add update checking service
// Add update checking service
if
(
Const
.
Value
.
UPDATE_SERVICE_VER
>
mm
.
prefs
.
getInt
(
Const
.
Key
.
UPDATE_SERVICE_VER
,
-
1
))
{
if
(
Const
.
Value
.
UPDATE_SERVICE_VER
>
mm
.
prefs
.
getInt
(
Const
.
Key
.
UPDATE_SERVICE_VER
,
-
1
))
{
ComponentName
service
=
new
ComponentName
(
this
,
UpdateCheckService
.
class
);
ComponentName
service
=
new
ComponentName
(
this
,
UpdateCheckService
.
class
);
...
...
src/main/java/com/topjohnwu/magisk/asyncs/FlashZip.java
View file @
fd6cbb13
...
@@ -38,7 +38,7 @@ public class FlashZip extends ParallelTask<Void, Void, Integer> {
...
@@ -38,7 +38,7 @@ public class FlashZip extends ParallelTask<Void, Void, Integer> {
private
boolean
unzipAndCheck
()
throws
Exception
{
private
boolean
unzipAndCheck
()
throws
Exception
{
ZipUtils
.
unzip
(
mCachedFile
,
mCachedFile
.
getParentFile
(),
"META-INF/com/google/android"
,
true
);
ZipUtils
.
unzip
(
mCachedFile
,
mCachedFile
.
getParentFile
(),
"META-INF/com/google/android"
,
true
);
List
<
String
>
ret
=
Utils
.
readFile
(
new
File
(
mCachedFile
.
getParentFile
(),
"updater-script"
)
.
getPath
()
);
List
<
String
>
ret
=
Utils
.
readFile
(
new
File
(
mCachedFile
.
getParentFile
(),
"updater-script"
));
return
Utils
.
isValidShellResponse
(
ret
)
&&
ret
.
get
(
0
).
contains
(
"#MAGISK"
);
return
Utils
.
isValidShellResponse
(
ret
)
&&
ret
.
get
(
0
).
contains
(
"#MAGISK"
);
}
}
...
...
src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java
View file @
fd6cbb13
...
@@ -14,7 +14,6 @@ import java.io.File;
...
@@ -14,7 +14,6 @@ import java.io.File;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
import
java.security.SecureRandom
;
import
java.security.SecureRandom
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarEntry
;
public
class
HideManager
extends
ParallelTask
<
Void
,
Void
,
Boolean
>
{
public
class
HideManager
extends
ParallelTask
<
Void
,
Void
,
Boolean
>
{
...
@@ -130,7 +129,7 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
...
@@ -130,7 +129,7 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
mm
.
suDB
.
setStrings
(
Const
.
Key
.
SU_REQUESTER
,
pkg
);
mm
.
suDB
.
setStrings
(
Const
.
Key
.
SU_REQUESTER
,
pkg
);
Utils
.
dumpPrefs
();
Utils
.
dumpPrefs
();
Shell
.
su_raw
(
"pm uninstall "
+
Const
.
ORIG_PKG_NAME
);
Utils
.
uninstallPkg
(
Const
.
ORIG_PKG_NAME
);
return
true
;
return
true
;
}
}
...
...
src/main/java/com/topjohnwu/magisk/asyncs/Restore
StockBoot
.java
→
src/main/java/com/topjohnwu/magisk/asyncs/Restore
Images
.java
View file @
fd6cbb13
...
@@ -9,7 +9,7 @@ import com.topjohnwu.magisk.utils.Utils;
...
@@ -9,7 +9,7 @@ import com.topjohnwu.magisk.utils.Utils;
import
java.util.List
;
import
java.util.List
;
public
class
Restore
StockBoot
extends
ParallelTask
<
Void
,
Void
,
Boolean
>
{
public
class
Restore
Images
extends
ParallelTask
<
Void
,
Void
,
Boolean
>
{
@Override
@Override
protected
Boolean
doInBackground
(
Void
...
voids
)
{
protected
Boolean
doInBackground
(
Void
...
voids
)
{
...
...
src/main/java/com/topjohnwu/magisk/container/Policy.java
View file @
fd6cbb13
...
@@ -21,7 +21,7 @@ public class Policy implements Comparable<Policy>{
...
@@ -21,7 +21,7 @@ public class Policy implements Comparable<Policy>{
public
Policy
(
int
uid
,
PackageManager
pm
)
throws
PackageManager
.
NameNotFoundException
{
public
Policy
(
int
uid
,
PackageManager
pm
)
throws
PackageManager
.
NameNotFoundException
{
String
[]
pkgs
=
pm
.
getPackagesForUid
(
uid
);
String
[]
pkgs
=
pm
.
getPackagesForUid
(
uid
);
if
(
pkgs
==
null
||
pkgs
.
length
==
0
)
throw
new
PackageManager
.
NameNotFoundException
();
if
(
pkgs
==
null
||
pkgs
.
length
==
0
)
throw
new
PackageManager
.
NameNotFoundException
();
this
.
uid
=
uid
%
100000
;
this
.
uid
=
uid
;
packageName
=
pkgs
[
0
];
packageName
=
pkgs
[
0
];
info
=
pm
.
getApplicationInfo
(
packageName
,
0
);
info
=
pm
.
getApplicationInfo
(
packageName
,
0
);
appName
=
info
.
loadLabel
(
pm
).
toString
();
appName
=
info
.
loadLabel
(
pm
).
toString
();
...
...
src/main/java/com/topjohnwu/magisk/database/SuDatabaseHelper.java
View file @
fd6cbb13
This diff is collapsed.
Click to expand it.
src/main/java/com/topjohnwu/magisk/utils/Const.java
View file @
fd6cbb13
package
com
.
topjohnwu
.
magisk
.
utils
;
package
com
.
topjohnwu
.
magisk
.
utils
;
import
android.os.Environment
;
import
android.os.Environment
;
import
android.os.Process
;
import
java.io.File
;
import
java.io.File
;
import
java.util.Arrays
;
import
java.util.Arrays
;
...
@@ -63,6 +64,8 @@ public class Const {
...
@@ -63,6 +64,8 @@ public class Const {
"com.nianticlabs.pokemongo"
"com.nianticlabs.pokemongo"
);
);
public
static
final
int
USER_ID
=
Process
.
myUid
()
/
100000
;
public
static
class
ID
{
public
static
class
ID
{
public
static
final
int
UPDATE_SERVICE_ID
=
1
;
public
static
final
int
UPDATE_SERVICE_ID
=
1
;
public
static
final
int
FETCH_ZIP
=
2
;
public
static
final
int
FETCH_ZIP
=
2
;
...
...
src/main/java/com/topjohnwu/magisk/utils/ShowUI.java
View file @
fd6cbb13
...
@@ -7,6 +7,7 @@ import android.app.PendingIntent;
...
@@ -7,6 +7,7 @@ import android.app.PendingIntent;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.os.Handler
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.TaskStackBuilder
;
import
android.support.v4.app.TaskStackBuilder
;
import
android.support.v7.app.AlertDialog
;
import
android.support.v7.app.AlertDialog
;
...
@@ -16,14 +17,13 @@ import com.topjohnwu.magisk.FlashActivity;
...
@@ -16,14 +17,13 @@ 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.SplashActivity
;
import
com.topjohnwu.magisk.SplashActivity
;
import
com.topjohnwu.magisk.asyncs.Restore
StockBoot
;
import
com.topjohnwu.magisk.asyncs.Restore
Images
;
import
com.topjohnwu.magisk.components.AlertDialogBuilder
;
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
java.io.File
;
import
java.io.ByteArrayOutputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -258,42 +258,35 @@ public class ShowUI {
...
@@ -258,42 +258,35 @@ public class ShowUI {
.
setTitle
(
R
.
string
.
uninstall_magisk_title
)
.
setTitle
(
R
.
string
.
uninstall_magisk_title
)
.
setMessage
(
R
.
string
.
uninstall_magisk_msg
)
.
setMessage
(
R
.
string
.
uninstall_magisk_msg
)
.
setPositiveButton
(
R
.
string
.
complete_uninstall
,
(
d
,
i
)
->
{
.
setPositiveButton
(
R
.
string
.
complete_uninstall
,
(
d
,
i
)
->
{
try
{
ByteArrayOutputStream
uninstaller
=
new
ByteArrayOutputStream
();
InputStream
in
=
mm
.
getAssets
().
open
(
Const
.
UNINSTALLER
);
try
(
InputStream
in
=
mm
.
getAssets
().
open
(
Const
.
UNINSTALLER
))
{
File
uninstaller
=
new
File
(
mm
.
getCacheDir
(),
Const
.
UNINSTALLER
);
Utils
.
inToOut
(
in
,
uninstaller
);
FileOutputStream
out
=
new
FileOutputStream
(
uninstaller
);
}
catch
(
IOException
e
)
{
byte
[]
bytes
=
new
byte
[
1024
];
e
.
printStackTrace
();
int
read
;
return
;
while
((
read
=
in
.
read
(
bytes
))
!=
-
1
)
{
out
.
write
(
bytes
,
0
,
read
);
}
}
in
.
close
();
ByteArrayOutputStream
utils
=
new
ByteArrayOutputStream
();
out
.
close
();
try
(
InputStream
in
=
mm
.
getAssets
().
open
(
Const
.
UTIL_FUNCTIONS
))
{
in
=
mm
.
getAssets
().
open
(
Const
.
UTIL_FUNCTIONS
);
Utils
.
inToOut
(
in
,
utils
);
File
utils
=
new
File
(
mm
.
getCacheDir
(),
Const
.
UTIL_FUNCTIONS
);
}
catch
(
IOException
e
)
{
out
=
new
FileOutputStream
(
utils
);
e
.
printStackTrace
();
while
((
read
=
in
.
read
(
bytes
))
!=
-
1
)
{
return
;
out
.
write
(
bytes
,
0
,
read
);
}
}
in
.
close
();
out
.
close
();
Shell
.
su
(
Shell
.
su
(
"cat "
+
uninstaller
+
" > /cache/"
+
Const
.
UNINSTALLER
,
Utils
.
fmt
(
"echo '%s' > /cache/%s"
,
uninstaller
.
toString
().
replace
(
"'"
,
"'\\''"
),
Const
.
UNINSTALLER
)
,
"cat "
+
utils
+
" > /data/magisk/"
+
Const
.
UTIL_FUNCTIONS
Utils
.
fmt
(
"echo '%s' > /data/magisk/%s"
,
utils
.
toString
().
replace
(
"'"
,
"'\\''"
),
Const
.
UTIL_FUNCTIONS
)
);
);
try
{
uninstaller
.
close
();
utils
.
close
();
}
catch
(
IOException
ignored
)
{}
MagiskManager
.
toast
(
R
.
string
.
uninstall_toast
,
Toast
.
LENGTH_LONG
);
MagiskManager
.
toast
(
R
.
string
.
uninstall_toast
,
Toast
.
LENGTH_LONG
);
Shell
.
su_raw
(
new
Handler
().
postDelayed
(()
->
Utils
.
uninstallPkg
(
mm
.
getPackageName
()),
5000
);
"sleep 5"
,
"pm uninstall "
+
mm
.
getApplicationInfo
().
packageName
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
})
})
.
setNeutralButton
(
R
.
string
.
restore_stock_boot
,
(
d
,
i
)
->
{
.
setNeutralButton
(
R
.
string
.
restore_img
,
(
d
,
i
)
->
new
RestoreImages
().
exec
())
new
RestoreStockBoot
().
exec
();
.
setNegativeButton
(
R
.
string
.
uninstall_app
,
(
d
,
i
)
->
Utils
.
uninstallPkg
(
mm
.
getPackageName
()))
})
.
setNegativeButton
(
R
.
string
.
no_thanks
,
null
)
.
show
();
.
show
();
}
}
}
}
src/main/java/com/topjohnwu/magisk/utils/Utils.java
View file @
fd6cbb13
...
@@ -45,24 +45,32 @@ public class Utils {
...
@@ -45,24 +45,32 @@ public class Utils {
public
static
boolean
isDownloading
=
false
;
public
static
boolean
isDownloading
=
false
;
public
static
boolean
itemExist
(
String
path
)
{
public
static
boolean
itemExist
(
Object
path
)
{
List
<
String
>
ret
=
Shell
.
su
(
fmt
(
"[ -e %s ] && echo true || echo false"
,
path
));
List
<
String
>
ret
=
Shell
.
su
(
fmt
(
"[ -e %s ] && echo true || echo false"
,
path
));
return
isValidShellResponse
(
ret
)
&&
Boolean
.
parseBoolean
(
ret
.
get
(
0
));
return
isValidShellResponse
(
ret
)
&&
Boolean
.
parseBoolean
(
ret
.
get
(
0
));
}
}
public
static
void
createFile
(
String
path
)
{
public
static
void
createFile
(
Object
path
)
{
String
folder
=
path
.
substring
(
0
,
path
.
lastIndexOf
(
'/'
));
Shell
.
su_raw
(
fmt
(
"mkdir -p `dirname '%s'` 2>/dev/null; touch '%s' 2>/dev/null"
,
path
,
path
));
Shell
.
su_raw
(
fmt
(
"mkdir -p %s 2>/dev/null; touch %s 2>/dev/null"
,
folder
,
path
));
}
}
public
static
void
removeItem
(
String
path
)
{
public
static
void
removeItem
(
Object
path
)
{
Shell
.
su_raw
(
fmt
(
"rm -rf %s 2>/dev/null"
,
path
));
Shell
.
su_raw
(
fmt
(
"rm -rf %s 2>/dev/null"
,
path
));
}
}
public
static
List
<
String
>
readFile
(
String
path
)
{
public
static
List
<
String
>
readFile
(
Object
path
)
{
return
Shell
.
su
(
fmt
(
"cat %s | sed '$a\\ ' | sed '$d'"
,
path
));
return
Shell
.
su
(
fmt
(
"cat %s | sed '$a\\ ' | sed '$d'"
,
path
));
}
}
public
static
String
checkMD5
(
Object
path
)
{
List
<
String
>
ret
=
Shell
.
su
(
fmt
(
"md5sum %s"
,
path
));
return
isValidShellResponse
(
ret
)
?
ret
.
get
(
0
).
split
(
"\\s+"
)[
0
]
:
null
;
}
public
static
void
uninstallPkg
(
String
pkg
)
{
Shell
.
su_raw
(
fmt
(
"find /data/user*/*/%s -exec umount -l {} 2>/dev/null \\;; pm uninstall %s"
,
pkg
,
pkg
));
}
public
static
void
dlAndReceive
(
Context
context
,
DownloadReceiver
receiver
,
String
link
,
String
filename
)
{
public
static
void
dlAndReceive
(
Context
context
,
DownloadReceiver
receiver
,
String
link
,
String
filename
)
{
if
(
isDownloading
)
if
(
isDownloading
)
return
;
return
;
...
@@ -209,6 +217,10 @@ public class Utils {
...
@@ -209,6 +217,10 @@ public class Utils {
}
}
}
}
public
static
File
getDatabasePath
(
String
dbName
)
{
return
getDatabasePath
(
MagiskManager
.
get
(),
dbName
);
}
public
static
File
getDatabasePath
(
Context
context
,
String
dbName
)
{
public
static
File
getDatabasePath
(
Context
context
,
String
dbName
)
{
return
new
File
(
context
.
getFilesDir
().
getParent
()
+
"/databases"
,
dbName
);
return
new
File
(
context
.
getFilesDir
().
getParent
()
+
"/databases"
,
dbName
);
}
}
...
@@ -258,7 +270,7 @@ public class Utils {
...
@@ -258,7 +270,7 @@ public class Utils {
}
}
public
static
void
loadPrefs
()
{
public
static
void
loadPrefs
()
{
String
config
=
fmt
(
"/data/user/%d/%s"
,
MagiskManager
.
get
().
userId
,
Const
.
MANAGER_CONFIGS
);
String
config
=
fmt
(
"/data/user/%d/%s"
,
Const
.
USER_ID
,
Const
.
MANAGER_CONFIGS
);
List
<
String
>
ret
=
readFile
(
config
);
List
<
String
>
ret
=
readFile
(
config
);
if
(
isValidShellResponse
(
ret
))
{
if
(
isValidShellResponse
(
ret
))
{
removeItem
(
config
);
removeItem
(
config
);
...
...
src/main/res/values/strings.xml
View file @
fd6cbb13
...
@@ -115,6 +115,8 @@
...
@@ -115,6 +115,8 @@
<string
name=
"boot_file_patch_msg"
>
Select stock boot image dump in .img or .img.tar format
</string>
<string
name=
"boot_file_patch_msg"
>
Select stock boot image dump in .img or .img.tar format
</string>
<string
name=
"complete_uninstall"
>
Complete Uninstall
</string>
<string
name=
"complete_uninstall"
>
Complete Uninstall
</string>
<string
name=
"restore_stock_boot"
>
Restore Stock Boot
</string>
<string
name=
"restore_stock_boot"
>
Restore Stock Boot
</string>
<string
name=
"restore_img"
>
Restore Images
</string>
<string
name=
"uninstall_app"
>
Uninstall App
</string>
<string
name=
"restore_done"
>
Restoration done!
</string>
<string
name=
"restore_done"
>
Restoration done!
</string>
<string
name=
"restore_fail"
>
Stock backup does not exist!
</string>
<string
name=
"restore_fail"
>
Stock backup does not exist!
</string>
<string
name=
"uninstall_toast"
>
Uninstalling Magisk Manager in 5 seconds, please manually reboot afterwards
</string>
<string
name=
"uninstall_toast"
>
Uninstalling Magisk Manager in 5 seconds, please manually reboot afterwards
</string>
...
...
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