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
e3659647
Commit
e3659647
authored
Feb 14, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor adjustments
parent
668e5492
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
15 deletions
+27
-15
APKInstall.java
.../src/main/java/com/topjohnwu/magisk/utils/APKInstall.java
+4
-2
DownloadService.kt
...ava/com/topjohnwu/magisk/core/download/DownloadService.kt
+9
-4
Subject.kt
...c/main/java/com/topjohnwu/magisk/core/download/Subject.kt
+6
-5
Notifications.kt
app/src/main/java/com/topjohnwu/magisk/view/Notifications.kt
+8
-4
No files found.
app/shared/src/main/java/com/topjohnwu/magisk/utils/APKInstall.java
View file @
e3659647
...
@@ -56,8 +56,11 @@ public final class APKInstall {
...
@@ -56,8 +56,11 @@ public final class APKInstall {
}
}
public
interface
Session
{
public
interface
Session
{
// @WorkerThread
OutputStream
openStream
(
Context
context
)
throws
IOException
;
OutputStream
openStream
(
Context
context
)
throws
IOException
;
// @WorkerThread
void
install
(
Context
context
,
File
apk
)
throws
IOException
;
void
install
(
Context
context
,
File
apk
)
throws
IOException
;
// @WorkerThread @Nullable
Intent
waitIntent
();
Intent
waitIntent
();
}
}
...
@@ -106,11 +109,10 @@ public final class APKInstall {
...
@@ -106,11 +109,10 @@ public final class APKInstall {
context
.
getApplicationContext
().
unregisterReceiver
(
this
);
context
.
getApplicationContext
().
unregisterReceiver
(
this
);
}
}
// @WorkerThread @Nullable
@Override
@Override
public
Intent
waitIntent
()
{
public
Intent
waitIntent
()
{
try
{
try
{
//noinspection ResultOfMethodCallIgnored
//
noinspection ResultOfMethodCallIgnored
latch
.
await
(
5
,
TimeUnit
.
SECONDS
);
latch
.
await
(
5
,
TimeUnit
.
SECONDS
);
}
catch
(
Exception
ignored
)
{}
}
catch
(
Exception
ignored
)
{}
return
userAction
;
return
userAction
;
...
...
app/src/main/java/com/topjohnwu/magisk/core/download/DownloadService.kt
View file @
e3659647
...
@@ -13,12 +13,14 @@ import com.topjohnwu.magisk.R
...
@@ -13,12 +13,14 @@ import com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.StubApk
import
com.topjohnwu.magisk.StubApk
import
com.topjohnwu.magisk.core.*
import
com.topjohnwu.magisk.core.*
import
com.topjohnwu.magisk.core.tasks.HideAPK
import
com.topjohnwu.magisk.core.tasks.HideAPK
import
com.topjohnwu.magisk.core.utils.MediaStoreUtils
import
com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream
import
com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream
import
com.topjohnwu.magisk.ktx.copyAndClose
import
com.topjohnwu.magisk.ktx.copyAndClose
import
com.topjohnwu.magisk.ktx.forEach
import
com.topjohnwu.magisk.ktx.forEach
import
com.topjohnwu.magisk.ktx.withStreams
import
com.topjohnwu.magisk.ktx.withStreams
import
com.topjohnwu.magisk.ktx.writeTo
import
com.topjohnwu.magisk.ktx.writeTo
import
com.topjohnwu.magisk.utils.APKInstall
import
com.topjohnwu.magisk.utils.APKInstall
import
com.topjohnwu.magisk.view.Notifications
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Job
import
kotlinx.coroutines.Job
...
@@ -57,12 +59,13 @@ class DownloadService : NotificationService() {
...
@@ -57,12 +59,13 @@ class DownloadService : NotificationService() {
is
Subject
.
Module
->
handleModule
(
stream
,
subject
.
file
)
is
Subject
.
Module
->
handleModule
(
stream
,
subject
.
file
)
}
}
val
activity
=
ActivityTracker
.
foreground
val
activity
=
ActivityTracker
.
foreground
if
(
activity
!=
null
&&
subject
.
auto
Start
)
{
if
(
activity
!=
null
&&
subject
.
auto
Launch
)
{
remove
(
subject
.
notifyId
)
remove
(
subject
.
notifyId
)
subject
.
pendingIntent
(
activity
)
?.
send
()
subject
.
pendingIntent
(
activity
)
?.
send
()
}
else
{
}
else
{
notifyFinish
(
subject
)
notifyFinish
(
subject
)
}
}
subject
.
postDownload
?.
invoke
()
if
(!
hasNotifications
)
if
(!
hasNotifications
)
stopSelf
()
stopSelf
()
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
...
@@ -79,7 +82,8 @@ class DownloadService : NotificationService() {
...
@@ -79,7 +82,8 @@ class DownloadService : NotificationService() {
private
suspend
fun
handleApp
(
stream
:
InputStream
,
subject
:
Subject
.
App
)
{
private
suspend
fun
handleApp
(
stream
:
InputStream
,
subject
:
Subject
.
App
)
{
fun
writeTee
(
output
:
OutputStream
)
{
fun
writeTee
(
output
:
OutputStream
)
{
val
external
=
subject
.
externalFile
.
outputStream
()
val
uri
=
MediaStoreUtils
.
getFile
(
"${subject.title}.apk"
).
uri
val
external
=
uri
.
outputStream
()
stream
.
copyAndClose
(
TeeOutputStream
(
external
,
output
))
stream
.
copyAndClose
(
TeeOutputStream
(
external
,
output
))
}
}
...
@@ -120,8 +124,9 @@ class DownloadService : NotificationService() {
...
@@ -120,8 +124,9 @@ class DownloadService : NotificationService() {
// Relaunch the process if we are foreground
// Relaunch the process if we are foreground
StubApk
.
restartProcess
(
it
)
StubApk
.
restartProcess
(
it
)
}
?:
run
{
}
?:
run
{
// Or else simply kill the current process
// Or else kill the current process after posting notification
Runtime
.
getRuntime
().
exit
(
0
)
subject
.
intent
=
Notifications
.
selfLaunchIntent
(
this
)
subject
.
postDownload
=
{
Runtime
.
getRuntime
().
exit
(
0
)
}
}
}
return
return
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/core/download/Subject.kt
View file @
e3659647
...
@@ -32,7 +32,8 @@ sealed class Subject : Parcelable {
...
@@ -32,7 +32,8 @@ sealed class Subject : Parcelable {
abstract
val
file
:
Uri
abstract
val
file
:
Uri
abstract
val
title
:
String
abstract
val
title
:
String
abstract
val
notifyId
:
Int
abstract
val
notifyId
:
Int
open
val
autoStart
:
Boolean
get
()
=
true
open
val
autoLaunch
:
Boolean
get
()
=
true
open
val
postDownload
:
(()
->
Unit
)?
get
()
=
null
abstract
fun
pendingIntent
(
context
:
Context
):
PendingIntent
?
abstract
fun
pendingIntent
(
context
:
Context
):
PendingIntent
?
...
@@ -44,7 +45,7 @@ sealed class Subject : Parcelable {
...
@@ -44,7 +45,7 @@ sealed class Subject : Parcelable {
)
:
Subject
()
{
)
:
Subject
()
{
override
val
url
:
String
get
()
=
module
.
zipUrl
override
val
url
:
String
get
()
=
module
.
zipUrl
override
val
title
:
String
get
()
=
module
.
downloadFilename
override
val
title
:
String
get
()
=
module
.
downloadFilename
override
val
auto
Start
:
Boolean
get
()
=
action
==
Action
.
Flash
override
val
auto
Launch
:
Boolean
get
()
=
action
==
Action
.
Flash
@IgnoredOnParcel
@IgnoredOnParcel
override
val
file
by
lazy
{
override
val
file
by
lazy
{
...
@@ -70,10 +71,10 @@ sealed class Subject : Parcelable {
...
@@ -70,10 +71,10 @@ sealed class Subject : Parcelable {
}
}
@IgnoredOnParcel
@IgnoredOnParcel
var
intent
:
Intent
?
=
null
override
var
postDownload
:
(()
->
Unit
)?
=
null
val
externalFile
get
()
=
MediaStoreUtils
.
getFile
(
"$title.apk"
).
uri
@IgnoredOnParcel
var
intent
:
Intent
?
=
null
override
fun
pendingIntent
(
context
:
Context
)
=
intent
?.
toPending
(
context
)
override
fun
pendingIntent
(
context
:
Context
)
=
intent
?.
toPending
(
context
)
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/view/Notifications.kt
View file @
e3659647
...
@@ -43,13 +43,17 @@ object Notifications {
...
@@ -43,13 +43,17 @@ object Notifications {
}
}
}
}
@SuppressLint
(
"InlinedApi"
)
fun
selfLaunchIntent
(
context
:
Context
):
Intent
{
fun
updateDone
(
context
:
Context
)
{
val
pm
=
context
.
packageManager
val
pm
=
context
.
packageManager
val
intent
=
pm
.
getLaunchIntentForPackage
(
context
.
packageName
)
?:
return
val
intent
=
pm
.
getLaunchIntentForPackage
(
context
.
packageName
)
!!
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
or
Intent
.
FLAG_ACTIVITY_CLEAR_TASK
)
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
or
Intent
.
FLAG_ACTIVITY_CLEAR_TASK
)
return
intent
}
@SuppressLint
(
"InlinedApi"
)
fun
updateDone
(
context
:
Context
)
{
val
flag
=
PendingIntent
.
FLAG_IMMUTABLE
or
PendingIntent
.
FLAG_UPDATE_CURRENT
val
flag
=
PendingIntent
.
FLAG_IMMUTABLE
or
PendingIntent
.
FLAG_UPDATE_CURRENT
val
pending
=
PendingIntent
.
getActivity
(
context
,
0
,
intent
,
flag
)
val
pending
=
PendingIntent
.
getActivity
(
context
,
0
,
selfLaunchIntent
(
context
)
,
flag
)
val
builder
=
if
(
SDK_INT
>=
26
)
{
val
builder
=
if
(
SDK_INT
>=
26
)
{
Notification
.
Builder
(
context
,
UPDATED_CHANNEL
)
Notification
.
Builder
(
context
,
UPDATED_CHANNEL
)
.
setSmallIcon
(
context
.
getBitmap
(
R
.
drawable
.
ic_magisk_outline
).
toIcon
())
.
setSmallIcon
(
context
.
getBitmap
(
R
.
drawable
.
ic_magisk_outline
).
toIcon
())
...
...
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