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
14ac37e8
Commit
14ac37e8
authored
Dec 08, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix and optimize APK installations
parent
1fae89cb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
15 deletions
+23
-15
PatchAPK.java
app/src/full/java/com/topjohnwu/magisk/asyncs/PatchAPK.java
+11
-11
DlInstallManager.java
...ull/java/com/topjohnwu/magisk/utils/DlInstallManager.java
+12
-4
No files found.
app/src/full/java/com/topjohnwu/magisk/asyncs/PatchAPK.java
View file @
14ac37e8
...
...
@@ -12,11 +12,12 @@ import com.topjohnwu.magisk.components.Notifications;
import
com.topjohnwu.magisk.utils.RootUtils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.ShellUtils
;
import
com.topjohnwu.superuser.io.SuFile
;
import
com.topjohnwu.superuser.io.SuFileOutputStream
;
import
com.topjohnwu.utils.JarMap
;
import
com.topjohnwu.utils.SignAPK
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteOrder
;
import
java.nio.CharBuffer
;
...
...
@@ -97,23 +98,22 @@ public class PatchAPK {
MagiskManager
mm
=
Data
.
MM
();
// Generate a new app with random package name
SuFile
repack
=
new
SuFile
(
"/data/local/tmp/repack
.apk"
);
File
repack
=
new
File
(
mm
.
getFilesDir
(),
"patched
.apk"
);
String
pkg
=
genPackageName
(
"com."
,
BuildConfig
.
APPLICATION_ID
.
length
());
try
{
JarMap
apk
=
new
JarMap
(
mm
.
getPackageCodePath
());
if
(!
patch
PackageID
(
apk
,
BuildConfig
.
APPLICATION_ID
,
pkg
))
if
(!
patch
(
apk
,
pkg
))
return
false
;
SignAPK
.
sign
(
apk
,
new
SuFileOutputStream
(
repack
));
SignAPK
.
sign
(
apk
,
new
BufferedOutputStream
(
new
FileOutputStream
(
repack
)
));
}
catch
(
Exception
e
)
{
return
false
;
}
// Install the application
repack
.
setReadable
(
true
,
false
);
if
(!
ShellUtils
.
fastCmdResult
(
"pm install "
+
repack
))
return
false
;
repack
.
delete
();
return
false
;;
mm
.
mDB
.
setStrings
(
Const
.
Key
.
SU_MANAGER
,
pkg
);
Data
.
exportPrefs
();
...
...
@@ -122,13 +122,13 @@ public class PatchAPK {
return
true
;
}
public
static
boolean
patch
PackageID
(
JarMap
apk
,
String
from
,
String
to
)
{
public
static
boolean
patch
(
JarMap
apk
,
String
pkg
)
{
try
{
JarEntry
je
=
apk
.
getJarEntry
(
Const
.
ANDROID_MANIFEST
);
byte
xml
[]
=
apk
.
getRawData
(
je
);
if
(!
findAndPatch
(
xml
,
from
,
to
)
||
!
findAndPatch
(
xml
,
from
+
".provider"
,
to
+
".provider"
)
||
if
(!
findAndPatch
(
xml
,
BuildConfig
.
APPLICATION_ID
,
pkg
)
||
!
findAndPatch
(
xml
,
BuildConfig
.
APPLICATION_ID
+
".provider"
,
pkg
+
".provider"
)
||
!
findAndPatch
(
xml
,
R
.
string
.
app_name
,
R
.
string
.
re_app_name
))
return
false
;
...
...
app/src/full/java/com/topjohnwu/magisk/utils/DlInstallManager.java
View file @
14ac37e8
...
...
@@ -81,14 +81,14 @@ public class DlInstallManager {
patched
=
new
File
(
apk
.
getParent
(),
"patched.apk"
);
try
{
JarMap
jarMap
=
new
JarMap
(
apk
);
PatchAPK
.
patch
PackageID
(
jarMap
,
BuildConfig
.
APPLICATION_ID
,
mm
.
getPackageName
());
PatchAPK
.
patch
(
jarMap
,
mm
.
getPackageName
());
SignAPK
.
sign
(
jarMap
,
new
BufferedOutputStream
(
new
FileOutputStream
(
patched
)));
}
catch
(
Exception
e
)
{
return
;
}
}
progress
.
dismiss
();
APKInstall
.
install
(
mm
,
patched
);
progress
.
dismiss
();
}
}
...
...
@@ -96,10 +96,18 @@ public class DlInstallManager {
@Override
public
void
onDownloadComplete
(
File
apk
,
ProgressNotification
progress
)
{
progress
.
dismiss
();
MagiskManager
mm
=
Data
.
MM
();
progress
.
getNotification
()
.
setProgress
(
0
,
0
,
true
)
.
setContentTitle
(
mm
.
getString
(
R
.
string
.
restore_img_msg
))
.
setContentText
(
""
);
progress
.
update
();
Data
.
exportPrefs
();
// Make it world readable
apk
.
setReadable
(
true
,
false
);
if
(
ShellUtils
.
fastCmdResult
(
"pm install "
+
apk
))
RootUtils
.
rmAndLaunch
(
Data
.
MM
().
getPackageName
(),
BuildConfig
.
APPLICATION_ID
);
RootUtils
.
rmAndLaunch
(
mm
.
getPackageName
(),
BuildConfig
.
APPLICATION_ID
);
progress
.
dismiss
();
}
}
}
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