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
646a10d9
Commit
646a10d9
authored
Dec 29, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use foreground service for downloading modules
parent
52137fd6
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
160 additions
and
31 deletions
+160
-31
AndroidManifest.xml
app/src/full/AndroidManifest.xml
+3
-1
j.java
app/src/full/java/a/j.java
+3
-1
ClassMap.java
app/src/full/java/com/topjohnwu/magisk/ClassMap.java
+2
-0
ReposAdapter.java
...full/java/com/topjohnwu/magisk/adapters/ReposAdapter.java
+18
-3
ProgressNotification.java
...com/topjohnwu/magisk/components/ProgressNotification.java
+17
-4
DownloadModuleService.java
.../com/topjohnwu/magisk/services/DownloadModuleService.java
+38
-14
DownloadApp.java
...src/full/java/com/topjohnwu/magisk/utils/DownloadApp.java
+2
-2
strings.xml
app/src/full/res/values/strings.xml
+1
-0
BaseModule.java
...rc/main/java/com/topjohnwu/core/container/BaseModule.java
+34
-6
Module.java
core/src/main/java/com/topjohnwu/core/container/Module.java
+16
-0
Repo.java
core/src/main/java/com/topjohnwu/core/container/Repo.java
+26
-0
No files found.
app/src/full/AndroidManifest.xml
View file @
646a10d9
...
...
@@ -6,7 +6,7 @@
<uses-permission
android:name=
"android.permission.VIBRATE"
/>
<uses-permission
android:name=
"android.permission.FOREGROUND_SERVICE"
/>
<uses-permission
android:name=
"android.permission.USE_FINGERPRINT"
/>
<uses-permission
android:name=
"android.permission.
WAKE_LOCK
"
/>
<uses-permission
android:name=
"android.permission.
FOREGROUND_SERVICE
"
/>
<application
android:name=
"a.q"
...
...
@@ -71,6 +71,8 @@
<!-- Service -->
<service
android:name=
"a.j"
/>
<!-- Hardcode GMS version -->
<meta-data
android:name=
"com.google.android.gms.version"
...
...
app/src/full/java/a/j.java
View file @
646a10d9
package
a
;
public
class
j
{
import
com.topjohnwu.magisk.services.DownloadModuleService
;
public
class
j
extends
DownloadModuleService
{
/* stub */
}
app/src/full/java/com/topjohnwu/magisk/ClassMap.java
View file @
646a10d9
...
...
@@ -4,6 +4,7 @@ import com.topjohnwu.core.App;
import
com.topjohnwu.magisk.components.AboutCardRow
;
import
com.topjohnwu.magisk.receivers.GeneralReceiver
;
import
com.topjohnwu.magisk.receivers.ShortcutReceiver
;
import
com.topjohnwu.magisk.services.DownloadModuleService
;
import
com.topjohnwu.magisk.services.UpdateCheckService
;
import
java.util.HashMap
;
...
...
@@ -22,6 +23,7 @@ public class ClassMap {
classMap
.
put
(
UpdateCheckService
.
class
,
a
.
g
.
class
);
classMap
.
put
(
GeneralReceiver
.
class
,
a
.
h
.
class
);
classMap
.
put
(
ShortcutReceiver
.
class
,
a
.
i
.
class
);
classMap
.
put
(
DownloadModuleService
.
class
,
a
.
j
.
class
);
classMap
.
put
(
AboutCardRow
.
class
,
a
.
l
.
class
);
classMap
.
put
(
SuRequestActivity
.
class
,
a
.
m
.
class
);
}
...
...
app/src/full/java/com/topjohnwu/magisk/adapters/ReposAdapter.java
View file @
646a10d9
package
com
.
topjohnwu
.
magisk
.
adapters
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.database.Cursor
;
import
android.os.Build
;
import
android.text.TextUtils
;
import
android.util.Pair
;
import
android.view.LayoutInflater
;
...
...
@@ -14,11 +16,12 @@ import android.widget.TextView;
import
com.topjohnwu.core.container.Module
;
import
com.topjohnwu.core.container.Repo
;
import
com.topjohnwu.core.database.RepoDatabaseHelper
;
import
com.topjohnwu.magisk.ClassMap
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.components.BaseActivity
;
import
com.topjohnwu.magisk.components.CustomAlertDialog
;
import
com.topjohnwu.magisk.components.MarkDownWindow
;
import
com.topjohnwu.magisk.
utils.DownloadModul
e
;
import
com.topjohnwu.magisk.
services.DownloadModuleServic
e
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -109,14 +112,26 @@ public class ReposAdapter extends SectionedAdapter<ReposAdapter.SectionHolder, R
.
setMessage
(
context
.
getString
(
R
.
string
.
repo_install_msg
,
repo
.
getDownloadFilename
()))
.
setCancelable
(
true
)
.
setPositiveButton
(
R
.
string
.
install
,
(
d
,
i
)
->
DownloadModule
.
exec
((
BaseActivity
)
context
,
repo
,
true
))
startDownload
((
BaseActivity
)
context
,
repo
,
true
))
.
setNeutralButton
(
R
.
string
.
download
,
(
d
,
i
)
->
DownloadModule
.
exec
((
BaseActivity
)
context
,
repo
,
false
))
startDownload
((
BaseActivity
)
context
,
repo
,
false
))
.
setNegativeButton
(
R
.
string
.
no_thanks
,
null
)
.
show
();
});
}
private
void
startDownload
(
BaseActivity
activity
,
Repo
repo
,
Boolean
install
)
{
activity
.
runWithExternalRW
(()
->
{
Intent
intent
=
new
Intent
(
activity
,
ClassMap
.
get
(
DownloadModuleService
.
class
))
.
putExtra
(
"repo"
,
repo
).
putExtra
(
"install"
,
install
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
activity
.
startForegroundService
(
intent
);
}
else
{
activity
.
startService
(
intent
);
}
});
}
public
void
notifyDBChanged
()
{
if
(
repoCursor
!=
null
)
repoCursor
.
close
();
...
...
app/src/full/java/com/topjohnwu/magisk/components/ProgressNotification.java
View file @
646a10d9
package
com
.
topjohnwu
.
magisk
.
components
;
import
android.app.Notification
;
import
android.widget.Toast
;
import
com.topjohnwu.core.App
;
...
...
@@ -13,6 +14,7 @@ import androidx.core.app.NotificationManagerCompat;
public
class
ProgressNotification
implements
DownloadProgressListener
{
private
NotificationManagerCompat
mgr
;
private
NotificationCompat
.
Builder
builder
;
private
Notification
notification
;
private
long
prevTime
;
public
ProgressNotification
(
String
title
)
{
...
...
@@ -35,12 +37,23 @@ public class ProgressNotification implements DownloadProgressListener {
}
}
public
NotificationCompat
.
Builder
getNotification
()
{
public
NotificationCompat
.
Builder
getNotification
Builder
()
{
return
builder
;
}
public
Notification
getNotification
()
{
return
notification
;
}
public
void
update
()
{
mgr
.
notify
(
hashCode
(),
builder
.
build
());
notification
=
builder
.
build
();
mgr
.
notify
(
hashCode
(),
notification
);
}
private
void
lastUpdate
()
{
notification
=
builder
.
build
();
mgr
.
cancel
(
hashCode
());
mgr
.
notify
(
notification
.
hashCode
(),
notification
);
}
public
void
dlDone
()
{
...
...
@@ -48,7 +61,7 @@ public class ProgressNotification implements DownloadProgressListener {
.
setContentText
(
App
.
self
.
getString
(
R
.
string
.
download_complete
))
.
setSmallIcon
(
R
.
drawable
.
ic_check_circle
)
.
setOngoing
(
false
);
u
pdate
();
lastU
pdate
();
}
public
void
dlFail
()
{
...
...
@@ -56,7 +69,7 @@ public class ProgressNotification implements DownloadProgressListener {
.
setContentText
(
App
.
self
.
getString
(
R
.
string
.
download_file_error
))
.
setSmallIcon
(
R
.
drawable
.
ic_cancel
)
.
setOngoing
(
false
);
u
pdate
();
lastU
pdate
();
}
public
void
dismiss
()
{
...
...
app/src/full/java/com/topjohnwu/magisk/
utils/DownloadModul
e.java
→
app/src/full/java/com/topjohnwu/magisk/
services/DownloadModuleServic
e.java
View file @
646a10d9
package
com
.
topjohnwu
.
magisk
.
util
s
;
package
com
.
topjohnwu
.
magisk
.
service
s
;
import
android.app.Service
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.AsyncTask
;
import
android.os.IBinder
;
import
android.widget.Toast
;
import
com.topjohnwu.core.App
;
import
com.topjohnwu.core.Const
;
import
com.topjohnwu.core.container.Repo
;
import
com.topjohnwu.core.utils.Utils
;
import
com.topjohnwu.magisk.ClassMap
;
import
com.topjohnwu.magisk.FlashActivity
;
import
com.topjohnwu.magisk.
components.BaseActivity
;
import
com.topjohnwu.magisk.
R
;
import
com.topjohnwu.magisk.components.ProgressNotification
;
import
com.topjohnwu.net.Networking
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.ShellUtils
;
import
java.io.BufferedOutputStream
;
...
...
@@ -24,16 +27,38 @@ import java.util.zip.ZipEntry;
import
java.util.zip.ZipInputStream
;
import
java.util.zip.ZipOutputStream
;
public
class
DownloadModule
{
import
androidx.annotation.Nullable
;
public
static
void
exec
(
BaseActivity
activity
,
Repo
repo
,
boolean
install
)
{
activity
.
runWithExternalRW
(()
->
AsyncTask
.
THREAD_POOL_EXECUTOR
.
execute
(
()
->
dlProcessInstall
(
repo
,
install
)));
public
class
DownloadModuleService
extends
Service
{
private
boolean
running
=
false
;
@Nullable
@Override
public
IBinder
onBind
(
Intent
intent
)
{
return
null
;
}
private
static
void
dlProcessInstall
(
Repo
repo
,
boolean
install
)
{
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
if
(
flags
==
0
&&
running
)
{
Utils
.
toast
(
R
.
string
.
dl_one_module
,
Toast
.
LENGTH_LONG
);
}
else
{
running
=
true
;
Shell
.
EXECUTOR
.
execute
(()
->
{
Repo
repo
=
intent
.
getParcelableExtra
(
"repo"
);
boolean
install
=
intent
.
getBooleanExtra
(
"install"
,
false
);
dlProcessInstall
(
repo
,
install
);
stopSelf
();
});
}
return
START_REDELIVER_INTENT
;
}
private
void
dlProcessInstall
(
Repo
repo
,
boolean
install
)
{
File
output
=
new
File
(
Const
.
EXTERNAL_PATH
,
repo
.
getDownloadFilename
());
ProgressNotification
progress
=
new
ProgressNotification
(
output
.
getName
());
startForeground
(
progress
.
hashCode
(),
progress
.
getNotification
());
try
{
InputStream
in
=
Networking
.
get
(
repo
.
getZipUrl
())
.
setDownloadProgressListener
(
progress
)
...
...
@@ -41,13 +66,13 @@ public class DownloadModule {
removeTopFolder
(
in
,
new
BufferedOutputStream
(
new
FileOutputStream
(
output
)));
if
(
install
)
{
progress
.
dismiss
();
Intent
intent
=
new
Intent
(
App
.
self
,
ClassMap
.
get
(
FlashActivity
.
class
));
Intent
intent
=
new
Intent
(
this
,
ClassMap
.
get
(
FlashActivity
.
class
));
intent
.
setData
(
Uri
.
fromFile
(
output
))
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
)
.
putExtra
(
Const
.
Key
.
FLASH_ACTION
,
Const
.
Value
.
FLASH_ZIP
);
App
.
self
.
startActivity
(
intent
);
startActivity
(
intent
);
}
else
{
progress
.
getNotification
().
setContentTitle
(
output
.
getName
());
progress
.
getNotification
Builder
().
setContentTitle
(
output
.
getName
());
progress
.
dlDone
();
}
}
catch
(
Exception
e
)
{
...
...
@@ -56,7 +81,7 @@ public class DownloadModule {
}
}
private
static
void
removeTopFolder
(
InputStream
in
,
OutputStream
out
)
throws
IOException
{
private
void
removeTopFolder
(
InputStream
in
,
OutputStream
out
)
throws
IOException
{
try
(
ZipInputStream
zin
=
new
ZipInputStream
(
in
);
ZipOutputStream
zout
=
new
ZipOutputStream
(
out
))
{
ZipEntry
entry
;
...
...
@@ -73,5 +98,4 @@ public class DownloadModule {
}
}
}
}
app/src/full/java/com/topjohnwu/magisk/utils/DownloadApp.java
View file @
646a10d9
...
...
@@ -65,7 +65,7 @@ public class DownloadApp {
File
patched
=
apk
;
App
app
=
App
.
self
;
if
(!
App
.
self
.
getPackageName
().
equals
(
BuildConfig
.
APPLICATION_ID
))
{
progress
.
getNotification
()
progress
.
getNotification
Builder
()
.
setProgress
(
0
,
0
,
true
)
.
setContentTitle
(
app
.
getString
(
R
.
string
.
hide_manager_title
))
.
setContentText
(
""
);
...
...
@@ -89,7 +89,7 @@ public class DownloadApp {
@Override
public
void
onDownloadComplete
(
File
apk
,
ProgressNotification
progress
)
{
App
app
=
App
.
self
;
progress
.
getNotification
()
progress
.
getNotification
Builder
()
.
setProgress
(
0
,
0
,
true
)
.
setContentTitle
(
app
.
getString
(
R
.
string
.
restore_img_msg
))
.
setContentText
(
""
);
...
...
app/src/full/res/values/strings.xml
View file @
646a10d9
...
...
@@ -126,6 +126,7 @@
<string
name=
"setup_msg"
>
Running environment setup…
</string>
<string
name=
"downloading_toast"
>
Downloading %1$s
</string>
<string
name=
"no_rw_storage"
>
This feature will not work without permission to write external storage.
</string>
<string
name=
"dl_one_module"
>
Download one module at a time.
</string>
<!--Settings Activity -->
<string
name=
"settings_general_category"
>
General
</string>
...
...
core/src/main/java/com/topjohnwu/core/container/BaseModule.java
View file @
646a10d9
...
...
@@ -2,12 +2,14 @@ package com.topjohnwu.core.container;
import
android.content.ContentValues
;
import
android.database.Cursor
;
import
android.os.Parcel
;
import
android.os.Parcelable
;
import
java.util.List
;
import
androidx.annotation.NonNull
;
public
abstract
class
BaseModule
implements
Comparable
<
BaseModule
>
{
public
abstract
class
BaseModule
implements
Comparable
<
BaseModule
>
,
Parcelable
{
private
String
mId
,
mName
,
mVersion
,
mAuthor
,
mDescription
;
private
int
mVersionCode
=
-
1
,
minMagiskVersion
=
-
1
;
...
...
@@ -26,6 +28,37 @@ public abstract class BaseModule implements Comparable<BaseModule> {
minMagiskVersion
=
c
.
getInt
(
c
.
getColumnIndex
(
"minMagisk"
));
}
protected
BaseModule
(
Parcel
p
)
{
mId
=
p
.
readString
();
mName
=
p
.
readString
();
mVersion
=
p
.
readString
();
mAuthor
=
p
.
readString
();
mDescription
=
p
.
readString
();
mVersionCode
=
p
.
readInt
();
minMagiskVersion
=
p
.
readInt
();
}
@Override
public
int
compareTo
(
@NonNull
BaseModule
module
)
{
return
this
.
getName
().
toLowerCase
().
compareTo
(
module
.
getName
().
toLowerCase
());
}
@Override
public
int
describeContents
()
{
return
0
;
}
@Override
public
void
writeToParcel
(
Parcel
dest
,
int
flags
)
{
dest
.
writeString
(
mId
);
dest
.
writeString
(
mName
);
dest
.
writeString
(
mVersion
);
dest
.
writeString
(
mAuthor
);
dest
.
writeString
(
mDescription
);
dest
.
writeInt
(
mVersionCode
);
dest
.
writeInt
(
minMagiskVersion
);
}
private
String
nonNull
(
String
s
)
{
return
s
==
null
?
""
:
s
;
}
...
...
@@ -119,9 +152,4 @@ public abstract class BaseModule implements Comparable<BaseModule> {
public
int
getMinMagiskVersion
()
{
return
minMagiskVersion
;
}
@Override
public
int
compareTo
(
@NonNull
BaseModule
module
)
{
return
this
.
getName
().
toLowerCase
().
compareTo
(
module
.
getName
().
toLowerCase
());
}
}
core/src/main/java/com/topjohnwu/core/container/Module.java
View file @
646a10d9
package
com
.
topjohnwu
.
core
.
container
;
import
android.os.Parcel
;
import
android.os.Parcelable
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.io.SuFile
;
...
...
@@ -32,6 +35,19 @@ public class Module extends BaseModule {
mUpdated
=
mUpdateFile
.
exists
();
}
public
static
final
Parcelable
.
Creator
<
Module
>
CREATOR
=
new
Creator
<
Module
>()
{
/* It won't be used at any place */
@Override
public
Module
createFromParcel
(
Parcel
source
)
{
return
null
;
}
@Override
public
Module
[]
newArray
(
int
size
)
{
return
null
;
}
};
public
void
createDisableFile
()
{
mEnable
=
!
mDisableFile
.
createNewFile
();
}
...
...
core/src/main/java/com/topjohnwu/core/container/Repo.java
View file @
646a10d9
...
...
@@ -2,6 +2,8 @@ package com.topjohnwu.core.container;
import
android.content.ContentValues
;
import
android.database.Cursor
;
import
android.os.Parcel
;
import
android.os.Parcelable
;
import
com.topjohnwu.core.Const
;
import
com.topjohnwu.core.utils.Logger
;
...
...
@@ -23,6 +25,30 @@ public class Repo extends BaseModule {
mLastUpdate
=
new
Date
(
c
.
getLong
(
c
.
getColumnIndex
(
"last_update"
)));
}
public
Repo
(
Parcel
p
)
{
super
(
p
);
mLastUpdate
=
new
Date
(
p
.
readLong
());
}
public
static
final
Parcelable
.
Creator
<
Repo
>
CREATOR
=
new
Parcelable
.
Creator
<
Repo
>()
{
@Override
public
Repo
createFromParcel
(
Parcel
source
)
{
return
new
Repo
(
source
);
}
@Override
public
Repo
[]
newArray
(
int
size
)
{
return
new
Repo
[
size
];
}
};
@Override
public
void
writeToParcel
(
Parcel
dest
,
int
flags
)
{
super
.
writeToParcel
(
dest
,
flags
);
dest
.
writeLong
(
mLastUpdate
.
getTime
());
}
public
void
update
()
throws
IllegalRepoException
{
String
props
[]
=
Utils
.
dlString
(
getPropUrl
()).
split
(
"\\n"
);
try
{
...
...
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