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
6128c24f
Commit
6128c24f
authored
Apr 10, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Drastically improve module download service
parent
d9c58f30
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
29 deletions
+80
-29
App.java
app/src/main/java/com/topjohnwu/magisk/App.java
+7
-3
DownloadModuleService.java
...om/topjohnwu/magisk/components/DownloadModuleService.java
+62
-24
UpdateCheckService.java
...a/com/topjohnwu/magisk/components/UpdateCheckService.java
+1
-1
ProgressNotification.java
...m/topjohnwu/magisk/uicomponents/ProgressNotification.java
+10
-1
No files found.
app/src/main/java/com/topjohnwu/magisk/App.java
View file @
6128c24f
...
@@ -33,7 +33,7 @@ public class App extends Application implements Application.ActivityLifecycleCal
...
@@ -33,7 +33,7 @@ public class App extends Application implements Application.ActivityLifecycleCal
public
SharedPreferences
prefs
;
public
SharedPreferences
prefs
;
public
MagiskDB
mDB
;
public
MagiskDB
mDB
;
public
RepoDatabaseHelper
repoDB
;
public
RepoDatabaseHelper
repoDB
;
p
ublic
BaseActivity
foreground
;
p
rivate
volatile
BaseActivity
foreground
;
static
{
static
{
Shell
.
Config
.
setFlags
(
Shell
.
FLAG_MOUNT_MASTER
|
Shell
.
FLAG_USE_MAGISK_BUSYBOX
);
Shell
.
Config
.
setFlags
(
Shell
.
FLAG_MOUNT_MASTER
|
Shell
.
FLAG_USE_MAGISK_BUSYBOX
);
...
@@ -68,6 +68,10 @@ public class App extends Application implements Application.ActivityLifecycleCal
...
@@ -68,6 +68,10 @@ public class App extends Application implements Application.ActivityLifecycleCal
LocaleManager
.
setLocale
(
this
);
LocaleManager
.
setLocale
(
this
);
}
}
public
static
BaseActivity
foreground
()
{
return
self
.
foreground
;
}
@Override
@Override
public
void
onActivityCreated
(
@NonNull
Activity
activity
,
@Nullable
Bundle
bundle
)
{}
public
void
onActivityCreated
(
@NonNull
Activity
activity
,
@Nullable
Bundle
bundle
)
{}
...
@@ -75,12 +79,12 @@ public class App extends Application implements Application.ActivityLifecycleCal
...
@@ -75,12 +79,12 @@ public class App extends Application implements Application.ActivityLifecycleCal
public
void
onActivityStarted
(
@NonNull
Activity
activity
)
{}
public
void
onActivityStarted
(
@NonNull
Activity
activity
)
{}
@Override
@Override
public
void
onActivityResumed
(
@NonNull
Activity
activity
)
{
public
synchronized
void
onActivityResumed
(
@NonNull
Activity
activity
)
{
foreground
=
(
BaseActivity
)
activity
;
foreground
=
(
BaseActivity
)
activity
;
}
}
@Override
@Override
public
void
onActivityPaused
(
@NonNull
Activity
activity
)
{
public
synchronized
void
onActivityPaused
(
@NonNull
Activity
activity
)
{
foreground
=
null
;
foreground
=
null
;
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/components/DownloadModuleService.java
View file @
6128c24f
package
com
.
topjohnwu
.
magisk
.
components
;
package
com
.
topjohnwu
.
magisk
.
components
;
import
android.app.PendingIntent
;
import
android.app.Service
;
import
android.app.Service
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.os.IBinder
;
import
android.os.IBinder
;
import
android.widget.Toast
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
import
com.topjohnwu.magisk.App
;
import
com.topjohnwu.magisk.ClassMap
;
import
com.topjohnwu.magisk.ClassMap
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.FlashActivity
;
import
com.topjohnwu.magisk.FlashActivity
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.container.Repo
;
import
com.topjohnwu.magisk.container.Repo
;
import
com.topjohnwu.magisk.uicomponents.Notifications
;
import
com.topjohnwu.magisk.uicomponents.ProgressNotification
;
import
com.topjohnwu.magisk.uicomponents.ProgressNotification
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.net.Networking
;
import
com.topjohnwu.net.Networking
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.ShellUtils
;
import
com.topjohnwu.superuser.ShellUtils
;
...
@@ -25,13 +25,15 @@ import java.io.FileOutputStream;
...
@@ -25,13 +25,15 @@ import java.io.FileOutputStream;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipInputStream
;
import
java.util.zip.ZipInputStream
;
import
java.util.zip.ZipOutputStream
;
import
java.util.zip.ZipOutputStream
;
public
class
DownloadModuleService
extends
Service
{
public
class
DownloadModuleService
extends
Service
{
private
boolean
running
=
false
;
private
List
<
ProgressNotification
>
notifications
;
@Nullable
@Nullable
@Override
@Override
...
@@ -39,46 +41,82 @@ public class DownloadModuleService extends Service {
...
@@ -39,46 +41,82 @@ public class DownloadModuleService extends Service {
return
null
;
return
null
;
}
}
@Override
public
void
onCreate
()
{
notifications
=
new
ArrayList
<>();
}
@Override
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
if
(
flags
==
0
&&
running
)
{
Shell
.
EXECUTOR
.
execute
(()
->
{
Utils
.
toast
(
R
.
string
.
dl_one_module
,
Toast
.
LENGTH_LONG
);
Repo
repo
=
intent
.
getParcelableExtra
(
"repo"
);
boolean
install
=
intent
.
getBooleanExtra
(
"install"
,
false
);
dlProcessInstall
(
repo
,
install
);
});
return
START_REDELIVER_INTENT
;
}
@Override
public
synchronized
void
onTaskRemoved
(
Intent
rootIntent
)
{
for
(
ProgressNotification
n
:
notifications
)
{
Notifications
.
mgr
.
cancel
(
n
.
hashCode
());
}
notifications
.
clear
();
}
private
synchronized
void
addNotification
(
ProgressNotification
n
)
{
if
(
notifications
.
isEmpty
())
{
// Start foreground
startForeground
(
n
.
hashCode
(),
n
.
getNotification
());
}
notifications
.
add
(
n
);
}
private
synchronized
void
removeNotification
(
ProgressNotification
n
)
{
notifications
.
remove
(
n
);
if
(
notifications
.
isEmpty
())
{
// No more tasks, stop service
stopForeground
(
true
);
stopSelf
();
}
else
{
}
else
{
running
=
true
;
// Pick another notification as our foreground notification
Shell
.
EXECUTOR
.
execute
(()
->
{
n
=
notifications
.
get
(
0
);
Repo
repo
=
intent
.
getParcelableExtra
(
"repo"
);
startForeground
(
n
.
hashCode
(),
n
.
getNotification
());
boolean
install
=
intent
.
getBooleanExtra
(
"install"
,
false
);
dlProcessInstall
(
repo
,
install
);
stopSelf
();
});
}
}
return
START_REDELIVER_INTENT
;
}
}
private
void
dlProcessInstall
(
Repo
repo
,
boolean
install
)
{
private
void
dlProcessInstall
(
Repo
repo
,
boolean
install
)
{
File
output
=
new
File
(
Const
.
EXTERNAL_PATH
,
repo
.
getDownloadFilename
());
File
output
=
new
File
(
Const
.
EXTERNAL_PATH
,
repo
.
getDownloadFilename
());
ProgressNotification
progress
=
new
ProgressNotification
(
output
.
getName
());
ProgressNotification
progress
=
new
ProgressNotification
(
output
.
getName
());
startForeground
(
progress
.
hashCode
(),
progress
.
getNotification
()
);
addNotification
(
progress
);
try
{
try
{
InputStream
in
=
Networking
.
get
(
repo
.
getZipUrl
())
InputStream
in
=
Networking
.
get
(
repo
.
getZipUrl
())
.
setDownloadProgressListener
(
progress
)
.
setDownloadProgressListener
(
progress
)
.
execForInputStream
().
getResult
();
.
execForInputStream
().
getResult
();
OutputStream
out
=
new
BufferedOutputStream
(
new
FileOutputStream
(
output
));
OutputStream
out
=
new
BufferedOutputStream
(
new
FileOutputStream
(
output
));
processZip
(
in
,
out
,
repo
.
isNewInstaller
());
processZip
(
in
,
out
,
repo
.
isNewInstaller
());
if
(
install
)
{
Intent
intent
=
new
Intent
(
this
,
ClassMap
.
get
(
FlashActivity
.
class
));
progress
.
dismiss
();
intent
.
setData
(
Uri
.
fromFile
(
output
))
Intent
intent
=
new
Intent
(
this
,
ClassMap
.
get
(
FlashActivity
.
class
));
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
)
intent
.
setData
(
Uri
.
fromFile
(
output
))
.
putExtra
(
Const
.
Key
.
FLASH_ACTION
,
Const
.
Value
.
FLASH_ZIP
);
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
)
synchronized
(
getApplication
())
{
.
putExtra
(
Const
.
Key
.
FLASH_ACTION
,
Const
.
Value
.
FLASH_ZIP
);
if
(
install
&&
App
.
foreground
()
!=
null
&&
startActivity
(
intent
);
!(
App
.
foreground
()
instanceof
FlashActivity
))
{
}
else
{
/* Only start flashing if there is a foreground activity and the
progress
.
dlDone
();
* user is not also flashing another module at the same time */
App
.
foreground
().
startActivity
(
intent
);
}
else
{
/* Or else we preset a notification notifying that we are done */
PendingIntent
pi
=
PendingIntent
.
getActivity
(
this
,
progress
.
hashCode
(),
intent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
progress
.
dlDone
(
pi
);
}
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
progress
.
dlFail
();
progress
.
dlFail
();
}
}
removeNotification
(
progress
);
}
}
private
void
processZip
(
InputStream
in
,
OutputStream
out
,
boolean
inject
)
private
void
processZip
(
InputStream
in
,
OutputStream
out
,
boolean
inject
)
...
...
app/src/main/java/com/topjohnwu/magisk/components/UpdateCheckService.java
View file @
6128c24f
...
@@ -15,7 +15,7 @@ public class UpdateCheckService extends DelegateWorker {
...
@@ -15,7 +15,7 @@ public class UpdateCheckService extends DelegateWorker {
@NonNull
@NonNull
@Override
@Override
public
ListenableWorker
.
Result
doWork
()
{
public
ListenableWorker
.
Result
doWork
()
{
if
(
App
.
self
.
foreground
==
null
)
{
if
(
App
.
foreground
()
==
null
)
{
Shell
.
getShell
();
Shell
.
getShell
();
CheckUpdates
.
check
(
this
::
onCheckDone
);
CheckUpdates
.
check
(
this
::
onCheckDone
);
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/uicomponents/ProgressNotification.java
View file @
6128c24f
package
com
.
topjohnwu
.
magisk
.
uicomponents
;
package
com
.
topjohnwu
.
magisk
.
uicomponents
;
import
android.app.Notification
;
import
android.app.Notification
;
import
android.app.PendingIntent
;
import
android.content.Intent
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
androidx.core.app.NotificationCompat
;
import
androidx.core.app.NotificationCompat
;
...
@@ -55,10 +57,17 @@ public class ProgressNotification implements DownloadProgressListener {
...
@@ -55,10 +57,17 @@ public class ProgressNotification implements DownloadProgressListener {
}
}
public
void
dlDone
()
{
public
void
dlDone
()
{
dlDone
(
PendingIntent
.
getActivity
(
App
.
self
,
hashCode
(),
new
Intent
(),
PendingIntent
.
FLAG_UPDATE_CURRENT
));
}
public
void
dlDone
(
PendingIntent
intent
)
{
builder
.
setProgress
(
0
,
0
,
false
)
builder
.
setProgress
(
0
,
0
,
false
)
.
setContentText
(
App
.
self
.
getString
(
R
.
string
.
download_complete
))
.
setContentText
(
App
.
self
.
getString
(
R
.
string
.
download_complete
))
.
setSmallIcon
(
android
.
R
.
drawable
.
stat_sys_download_done
)
.
setSmallIcon
(
android
.
R
.
drawable
.
stat_sys_download_done
)
.
setOngoing
(
false
);
.
setContentIntent
(
intent
)
.
setOngoing
(
false
)
.
setAutoCancel
(
true
);
lastUpdate
();
lastUpdate
();
}
}
...
...
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