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
87bec70d
Commit
87bec70d
authored
Aug 25, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Setup notification on app init
Close #6216
parent
3668b28f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
51 deletions
+56
-51
App.kt
app/src/main/java/com/topjohnwu/magisk/core/App.kt
+2
-0
JobService.kt
app/src/main/java/com/topjohnwu/magisk/core/JobService.kt
+1
-1
Receiver.kt
app/src/main/java/com/topjohnwu/magisk/core/Receiver.kt
+1
-1
NotificationService.kt
...com/topjohnwu/magisk/core/download/NotificationService.kt
+1
-1
SplashActivity.kt
app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt
+0
-2
Notifications.kt
app/src/main/java/com/topjohnwu/magisk/view/Notifications.kt
+51
-46
No files found.
app/src/main/java/com/topjohnwu/magisk/core/App.kt
View file @
87bec70d
...
@@ -9,6 +9,7 @@ import com.topjohnwu.magisk.StubApk
...
@@ -9,6 +9,7 @@ import com.topjohnwu.magisk.StubApk
import
com.topjohnwu.magisk.core.di.ServiceLocator
import
com.topjohnwu.magisk.core.di.ServiceLocator
import
com.topjohnwu.magisk.core.utils.*
import
com.topjohnwu.magisk.core.utils.*
import
com.topjohnwu.magisk.ui.surequest.SuRequestActivity
import
com.topjohnwu.magisk.ui.surequest.SuRequestActivity
import
com.topjohnwu.magisk.view.Notifications
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.internal.UiThreadHandler
import
com.topjohnwu.superuser.internal.UiThreadHandler
import
com.topjohnwu.superuser.ipc.RootService
import
com.topjohnwu.superuser.ipc.RootService
...
@@ -70,6 +71,7 @@ open class App() : Application() {
...
@@ -70,6 +71,7 @@ open class App() : Application() {
refreshLocale
()
refreshLocale
()
resources
.
patch
()
resources
.
patch
()
Notifications
.
setup
()
}
}
override
fun
onConfigurationChanged
(
newConfig
:
Configuration
)
{
override
fun
onConfigurationChanged
(
newConfig
:
Configuration
)
{
...
...
app/src/main/java/com/topjohnwu/magisk/core/JobService.kt
View file @
87bec70d
...
@@ -33,7 +33,7 @@ class JobService : BaseJobService() {
...
@@ -33,7 +33,7 @@ class JobService : BaseJobService() {
svc
.
fetchUpdate
()
?.
let
{
svc
.
fetchUpdate
()
?.
let
{
Info
.
remote
=
it
Info
.
remote
=
it
if
(
Info
.
env
.
isActive
&&
BuildConfig
.
VERSION_CODE
<
it
.
magisk
.
versionCode
)
if
(
Info
.
env
.
isActive
&&
BuildConfig
.
VERSION_CODE
<
it
.
magisk
.
versionCode
)
Notifications
.
updateAvailable
(
this
)
Notifications
.
updateAvailable
()
}
}
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/core/Receiver.kt
View file @
87bec70d
...
@@ -51,7 +51,7 @@ open class Receiver : BaseReceiver() {
...
@@ -51,7 +51,7 @@ open class Receiver : BaseReceiver() {
@Suppress
(
"DEPRECATION"
)
@Suppress
(
"DEPRECATION"
)
val
installer
=
context
.
packageManager
.
getInstallerPackageName
(
context
.
packageName
)
val
installer
=
context
.
packageManager
.
getInstallerPackageName
(
context
.
packageName
)
if
(
installer
==
context
.
packageName
)
{
if
(
installer
==
context
.
packageName
)
{
Notifications
.
updateDone
(
context
)
Notifications
.
updateDone
()
}
}
}
}
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/core/download/NotificationService.kt
View file @
87bec70d
...
@@ -87,7 +87,7 @@ open class NotificationService : BaseService() {
...
@@ -87,7 +87,7 @@ open class NotificationService : BaseService() {
}
}
protected
fun
notifyUpdate
(
id
:
Int
,
editor
:
(
Notification
.
Builder
)
->
Unit
=
{})
{
protected
fun
notifyUpdate
(
id
:
Int
,
editor
:
(
Notification
.
Builder
)
->
Unit
=
{})
{
fun
create
()
=
Notifications
.
startProgress
(
this
,
""
)
fun
create
()
=
Notifications
.
startProgress
(
""
)
val
wasEmpty
=
!
hasNotifications
val
wasEmpty
=
!
hasNotifications
val
notification
=
notifications
.
getOrPut
(
id
,
::
create
).
also
(
editor
)
val
notification
=
notifications
.
getOrPut
(
id
,
::
create
).
also
(
editor
)
...
...
app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt
View file @
87bec70d
...
@@ -21,7 +21,6 @@ import com.topjohnwu.magisk.core.utils.RootUtils
...
@@ -21,7 +21,6 @@ import com.topjohnwu.magisk.core.utils.RootUtils
import
com.topjohnwu.magisk.ui.theme.Theme
import
com.topjohnwu.magisk.ui.theme.Theme
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.view.MagiskDialog
import
com.topjohnwu.magisk.view.MagiskDialog
import
com.topjohnwu.magisk.view.Notifications
import
com.topjohnwu.magisk.view.Shortcuts
import
com.topjohnwu.magisk.view.Shortcuts
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
...
@@ -107,7 +106,6 @@ abstract class SplashActivity<Binding : ViewDataBinding> : NavigationActivity<Bi
...
@@ -107,7 +106,6 @@ abstract class SplashActivity<Binding : ViewDataBinding> : NavigationActivity<Bi
return
return
}
}
Notifications
.
setup
(
this
)
JobService
.
schedule
(
this
)
JobService
.
schedule
(
this
)
Shortcuts
.
setupDynamic
(
this
)
Shortcuts
.
setupDynamic
(
this
)
...
...
app/src/main/java/com/topjohnwu/magisk/view/Notifications.kt
View file @
87bec70d
...
@@ -5,7 +5,6 @@ import android.app.Notification
...
@@ -5,7 +5,6 @@ import android.app.Notification
import
android.app.NotificationChannel
import
android.app.NotificationChannel
import
android.app.NotificationManager
import
android.app.NotificationManager
import
android.app.PendingIntent
import
android.app.PendingIntent
import
android.content.Context
import
android.os.Build
import
android.os.Build
import
android.os.Build.VERSION.SDK_INT
import
android.os.Build.VERSION.SDK_INT
import
androidx.core.content.getSystemService
import
androidx.core.content.getSystemService
...
@@ -23,69 +22,75 @@ object Notifications {
...
@@ -23,69 +22,75 @@ object Notifications {
val
mgr
by
lazy
{
AppContext
.
getSystemService
<
NotificationManager
>()
!!
}
val
mgr
by
lazy
{
AppContext
.
getSystemService
<
NotificationManager
>()
!!
}
private
const
val
APP_UPDATED_
NOTIFICATION_
ID
=
4
private
const
val
APP_UPDATED_ID
=
4
private
const
val
APP_UPDATE_
NOTIFICATION
_ID
=
5
private
const
val
APP_UPDATE_
AVAILABLE
_ID
=
5
private
const
val
UPDATE_CHANNEL
=
"update"
private
const
val
UPDATE_CHANNEL
=
"update"
private
const
val
PROGRESS_CHANNEL
=
"progress"
private
const
val
PROGRESS_CHANNEL
=
"progress"
private
const
val
UPDATED_CHANNEL
=
"updated"
private
const
val
UPDATED_CHANNEL
=
"updated"
private
val
nextId
=
AtomicInteger
(
APP_UPDATE_
NOTIFICATION
_ID
)
private
val
nextId
=
AtomicInteger
(
APP_UPDATE_
AVAILABLE
_ID
)
fun
setup
(
context
:
Context
)
{
fun
setup
()
{
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
AppContext
.
apply
{
val
channel
=
NotificationChannel
(
UPDATE_CHANNEL
,
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
context
.
getString
(
R
.
string
.
update_channel
),
NotificationManager
.
IMPORTANCE_DEFAULT
)
val
channel
=
NotificationChannel
(
UPDATE_CHANNEL
,
val
channel2
=
NotificationChannel
(
PROGRESS_CHANNEL
,
getString
(
R
.
string
.
update_channel
),
NotificationManager
.
IMPORTANCE_DEFAULT
)
context
.
getString
(
R
.
string
.
progress_channel
),
NotificationManager
.
IMPORTANCE_LOW
)
val
channel2
=
NotificationChannel
(
PROGRESS_CHANNEL
,
val
channel3
=
NotificationChannel
(
UPDATED_CHANNEL
,
getString
(
R
.
string
.
progress_channel
),
NotificationManager
.
IMPORTANCE_LOW
)
context
.
getString
(
R
.
string
.
updated_channel
),
NotificationManager
.
IMPORTANCE_HIGH
)
val
channel3
=
NotificationChannel
(
UPDATED_CHANNEL
,
mgr
.
createNotificationChannels
(
listOf
(
channel
,
channel2
,
channel3
))
getString
(
R
.
string
.
updated_channel
),
NotificationManager
.
IMPORTANCE_HIGH
)
mgr
.
createNotificationChannels
(
listOf
(
channel
,
channel2
,
channel3
))
}
}
}
}
}
@SuppressLint
(
"InlinedApi"
)
@SuppressLint
(
"InlinedApi"
)
fun
updateDone
(
context
:
Context
)
{
fun
updateDone
()
{
val
flag
=
PendingIntent
.
FLAG_IMMUTABLE
or
PendingIntent
.
FLAG_UPDATE_CURRENT
AppContext
.
apply
{
val
pending
=
PendingIntent
.
getActivity
(
context
,
0
,
context
.
selfLaunchIntent
(),
flag
)
val
flag
=
PendingIntent
.
FLAG_IMMUTABLE
or
PendingIntent
.
FLAG_UPDATE_CURRENT
val
builder
=
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
val
pending
=
PendingIntent
.
getActivity
(
this
,
0
,
selfLaunchIntent
(),
flag
)
Notification
.
Builder
(
context
,
UPDATED_CHANNEL
)
val
builder
=
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
.
setSmallIcon
(
context
.
getBitmap
(
R
.
drawable
.
ic_magisk_outline
).
toIcon
())
Notification
.
Builder
(
this
,
UPDATED_CHANNEL
)
}
else
{
.
setSmallIcon
(
getBitmap
(
R
.
drawable
.
ic_magisk_outline
).
toIcon
())
Notification
.
Builder
(
context
).
setPriority
(
Notification
.
PRIORITY_HIGH
)
}
else
{
.
setSmallIcon
(
R
.
drawable
.
ic_magisk_outline
)
Notification
.
Builder
(
this
).
setPriority
(
Notification
.
PRIORITY_HIGH
)
.
setSmallIcon
(
R
.
drawable
.
ic_magisk_outline
)
}
.
setContentIntent
(
pending
)
.
setContentTitle
(
getText
(
R
.
string
.
updated_title
))
.
setContentText
(
getText
(
R
.
string
.
updated_text
))
.
setAutoCancel
(
true
)
mgr
.
notify
(
APP_UPDATED_ID
,
builder
.
build
())
}
}
.
setContentIntent
(
pending
)
.
setContentTitle
(
context
.
getText
(
R
.
string
.
updated_title
))
.
setContentText
(
context
.
getText
(
R
.
string
.
updated_text
))
.
setAutoCancel
(
true
)
mgr
.
notify
(
APP_UPDATED_NOTIFICATION_ID
,
builder
.
build
())
}
}
fun
updateAvailable
(
context
:
Context
)
{
fun
updateAvailable
()
{
val
intent
=
DownloadService
.
getPendingIntent
(
context
,
Subject
.
App
())
AppContext
.
apply
{
val
bitmap
=
context
.
getBitmap
(
R
.
drawable
.
ic_magisk_outline
)
val
intent
=
DownloadService
.
getPendingIntent
(
this
,
Subject
.
App
())
val
builder
=
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
val
bitmap
=
getBitmap
(
R
.
drawable
.
ic_magisk_outline
)
Notification
.
Builder
(
context
,
UPDATE_CHANNEL
)
val
builder
=
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
.
setSmallIcon
(
bitmap
.
toIcon
())
Notification
.
Builder
(
this
,
UPDATE_CHANNEL
)
}
else
{
.
setSmallIcon
(
bitmap
.
toIcon
())
Notification
.
Builder
(
context
)
}
else
{
.
setSmallIcon
(
R
.
drawable
.
ic_magisk_outline
)
Notification
.
Builder
(
this
)
}
.
setSmallIcon
(
R
.
drawable
.
ic_magisk_outline
)
.
setLargeIcon
(
bitmap
)
}
.
setContentTitle
(
context
.
getString
(
R
.
string
.
magisk_update_title
))
.
setLargeIcon
(
bitmap
)
.
setContentText
(
context
.
getString
(
R
.
string
.
manager_download_install
))
.
setContentTitle
(
getString
(
R
.
string
.
magisk_update_title
))
.
setAutoCancel
(
true
)
.
setContentText
(
getString
(
R
.
string
.
manager_download_install
))
.
setContentIntent
(
intent
)
.
setAutoCancel
(
true
)
.
setContentIntent
(
intent
)
mgr
.
notify
(
APP_UPDATE_NOTIFICATION_ID
,
builder
.
build
())
mgr
.
notify
(
APP_UPDATE_AVAILABLE_ID
,
builder
.
build
())
}
}
}
fun
startProgress
(
context
:
Context
,
title
:
CharSequence
):
Notification
.
Builder
{
fun
startProgress
(
title
:
CharSequence
):
Notification
.
Builder
{
val
builder
=
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
val
builder
=
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
Notification
.
Builder
(
c
ontext
,
PROGRESS_CHANNEL
)
Notification
.
Builder
(
AppC
ontext
,
PROGRESS_CHANNEL
)
}
else
{
}
else
{
Notification
.
Builder
(
c
ontext
).
setPriority
(
Notification
.
PRIORITY_LOW
)
Notification
.
Builder
(
AppC
ontext
).
setPriority
(
Notification
.
PRIORITY_LOW
)
}
}
.
setSmallIcon
(
android
.
R
.
drawable
.
stat_sys_download
)
.
setSmallIcon
(
android
.
R
.
drawable
.
stat_sys_download
)
.
setContentTitle
(
title
)
.
setContentTitle
(
title
)
...
...
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