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
6df42a4b
Commit
6df42a4b
authored
Feb 17, 2022
by
vvb2060
Committed by
John Wu
Mar 02, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle install failure
parent
7fd111b9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
15 deletions
+30
-15
APKInstall.java
.../src/main/java/com/topjohnwu/magisk/utils/APKInstall.java
+11
-4
HideAPK.kt
app/src/main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt
+19
-11
No files found.
app/shared/src/main/java/com/topjohnwu/magisk/utils/APKInstall.java
View file @
6df42a4b
...
@@ -40,11 +40,12 @@ public final class APKInstall {
...
@@ -40,11 +40,12 @@ public final class APKInstall {
}
}
public
static
Session
startSession
(
Context
context
)
{
public
static
Session
startSession
(
Context
context
)
{
return
startSession
(
context
,
null
,
null
);
return
startSession
(
context
,
null
,
null
,
null
);
}
}
public
static
Session
startSession
(
Context
context
,
String
pkg
,
Runnable
onSuccess
)
{
public
static
Session
startSession
(
Context
context
,
String
pkg
,
var
receiver
=
new
InstallReceiver
(
pkg
,
onSuccess
);
Runnable
onFailure
,
Runnable
onSuccess
)
{
var
receiver
=
new
InstallReceiver
(
pkg
,
onSuccess
,
onFailure
);
context
=
context
.
getApplicationContext
();
context
=
context
.
getApplicationContext
();
if
(
pkg
!=
null
)
{
if
(
pkg
!=
null
)
{
// If pkg is not null, look for package added event
// If pkg is not null, look for package added event
...
@@ -68,14 +69,16 @@ public final class APKInstall {
...
@@ -68,14 +69,16 @@ public final class APKInstall {
private
static
class
InstallReceiver
extends
BroadcastReceiver
implements
Session
{
private
static
class
InstallReceiver
extends
BroadcastReceiver
implements
Session
{
private
final
String
packageName
;
private
final
String
packageName
;
private
final
Runnable
onSuccess
;
private
final
Runnable
onSuccess
;
private
final
Runnable
onFailure
;
private
final
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
private
final
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
private
Intent
userAction
=
null
;
private
Intent
userAction
=
null
;
final
String
sessionId
=
UUID
.
randomUUID
().
toString
();
final
String
sessionId
=
UUID
.
randomUUID
().
toString
();
private
InstallReceiver
(
String
packageName
,
Runnable
onSuccess
)
{
private
InstallReceiver
(
String
packageName
,
Runnable
onSuccess
,
Runnable
onFailure
)
{
this
.
packageName
=
packageName
;
this
.
packageName
=
packageName
;
this
.
onSuccess
=
onSuccess
;
this
.
onSuccess
=
onSuccess
;
this
.
onFailure
=
onFailure
;
}
}
@Override
@Override
...
@@ -108,6 +111,10 @@ public final class APKInstall {
...
@@ -108,6 +111,10 @@ public final class APKInstall {
installer
.
abandonSession
(
info
.
getSessionId
());
installer
.
abandonSession
(
info
.
getSessionId
());
}
}
}
}
if
(
onFailure
!=
null
)
{
onFailure
.
run
();
}
context
.
getApplicationContext
().
unregisterReceiver
(
this
);
}
}
latch
.
countDown
();
latch
.
countDown
();
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt
View file @
6df42a4b
...
@@ -22,6 +22,7 @@ import com.topjohnwu.magisk.utils.APKInstall
...
@@ -22,6 +22,7 @@ import com.topjohnwu.magisk.utils.APKInstall
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Runnable
import
kotlinx.coroutines.withContext
import
kotlinx.coroutines.withContext
import
timber.log.Timber
import
timber.log.Timber
import
java.io.File
import
java.io.File
...
@@ -102,7 +103,7 @@ object HideAPK {
...
@@ -102,7 +103,7 @@ object HideAPK {
activity
.
finish
()
activity
.
finish
()
}
}
private
suspend
fun
patchAndHide
(
activity
:
Activity
,
label
:
String
):
Boolean
{
private
suspend
fun
patchAndHide
(
activity
:
Activity
,
label
:
String
,
onFailure
:
Runnable
):
Boolean
{
val
stub
=
File
(
activity
.
cacheDir
,
"stub.apk"
)
val
stub
=
File
(
activity
.
cacheDir
,
"stub.apk"
)
try
{
try
{
svc
.
fetchFile
(
Info
.
remote
.
stub
.
link
).
byteStream
().
writeTo
(
stub
)
svc
.
fetchFile
(
Info
.
remote
.
stub
.
link
).
byteStream
().
writeTo
(
stub
)
...
@@ -123,7 +124,7 @@ object HideAPK {
...
@@ -123,7 +124,7 @@ object HideAPK {
return
false
return
false
// Install and auto launch app
// Install and auto launch app
val
session
=
APKInstall
.
startSession
(
activity
,
pkg
)
{
val
session
=
APKInstall
.
startSession
(
activity
,
pkg
,
onFailure
)
{
launchApp
(
activity
,
pkg
)
launchApp
(
activity
,
pkg
)
}
}
try
{
try
{
...
@@ -132,7 +133,7 @@ object HideAPK {
...
@@ -132,7 +133,7 @@ object HideAPK {
Timber
.
e
(
e
)
Timber
.
e
(
e
)
return
false
return
false
}
}
session
.
waitIntent
()
?.
let
{
activity
.
startActivity
(
it
)
}
session
.
waitIntent
()
?.
let
{
activity
.
startActivity
(
it
)
}
?:
return
false
return
true
return
true
}
}
...
@@ -144,13 +145,14 @@ object HideAPK {
...
@@ -144,13 +145,14 @@ object HideAPK {
setCancelable
(
false
)
setCancelable
(
false
)
show
()
show
()
}
}
val
result
=
withContext
(
Dispatchers
.
IO
)
{
val
onFailure
=
Runnable
{
patchAndHide
(
activity
,
label
)
}
if
(!
result
)
{
dialog
.
dismiss
()
dialog
.
dismiss
()
Utils
.
toast
(
R
.
string
.
failure
,
Toast
.
LENGTH_LONG
)
Utils
.
toast
(
R
.
string
.
failure
,
Toast
.
LENGTH_LONG
)
}
}
val
success
=
withContext
(
Dispatchers
.
IO
)
{
patchAndHide
(
activity
,
label
,
onFailure
)
}
if
(!
success
)
onFailure
.
run
()
}
}
@Suppress
(
"DEPRECATION"
)
@Suppress
(
"DEPRECATION"
)
...
@@ -161,19 +163,25 @@ object HideAPK {
...
@@ -161,19 +163,25 @@ object HideAPK {
setCancelable
(
false
)
setCancelable
(
false
)
show
()
show
()
}
}
val
onFailure
=
Runnable
{
dialog
.
dismiss
()
Utils
.
toast
(
R
.
string
.
failure
,
Toast
.
LENGTH_LONG
)
}
val
apk
=
StubApk
.
current
(
activity
)
val
apk
=
StubApk
.
current
(
activity
)
val
session
=
APKInstall
.
startSession
(
activity
,
APPLICATION_ID
)
{
val
session
=
APKInstall
.
startSession
(
activity
,
APPLICATION_ID
,
onFailure
)
{
launchApp
(
activity
,
APPLICATION_ID
)
launchApp
(
activity
,
APPLICATION_ID
)
dialog
.
dismiss
()
dialog
.
dismiss
()
}
}
withContext
(
Dispatchers
.
IO
)
{
val
success
=
withContext
(
Dispatchers
.
IO
)
{
try
{
try
{
session
.
install
(
activity
,
apk
)
session
.
install
(
activity
,
apk
)
}
catch
(
e
:
IOException
)
{
}
catch
(
e
:
IOException
)
{
Timber
.
e
(
e
)
Timber
.
e
(
e
)
return
@withContext
return
@withContext
false
}
}
session
.
waitIntent
()
?.
let
{
activity
.
startActivity
(
it
)
}
session
.
waitIntent
()
?.
let
{
activity
.
startActivity
(
it
)
}
?:
return
@withContext
false
return
@withContext
true
}
}
if
(!
success
)
onFailure
.
run
()
}
}
}
}
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