Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
PublicAndroidApps
Nebulo
Commits
f333f830
Commit
f333f830
authored
Dec 25, 2020
by
Daniel Wolf
Browse files
Do not show battery optimization notification when battery optimization is already disabled
parent
44345f1e
Pipeline
#7673
passed with stage
in 4 minutes and 26 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/frostnerd/smokescreen/service/DnsVpnService.kt
View file @
f333f830
...
@@ -177,48 +177,50 @@ class DnsVpnService : VpnService(), Runnable, CoroutineScope {
...
@@ -177,48 +177,50 @@ class DnsVpnService : VpnService(), Runnable, CoroutineScope {
!
getPreferences
().
ignoreServiceKilled
&&
!
getPreferences
().
ignoreServiceKilled
&&
getPreferences
().
vpnLaunchLastVersion
==
BuildConfig
.
VERSION_CODE
getPreferences
().
vpnLaunchLastVersion
==
BuildConfig
.
VERSION_CODE
)
{
// The app didn't stop properly
)
{
// The app didn't stop properly
val
ignoreIntent
=
Intent
(
this
,
DnsVpnService
::
class
.
java
).
putExtra
(
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
M
||
!(
getSystemService
(
POWER_SERVICE
)
as
PowerManager
).
isIgnoringBatteryOptimizations
(
packageName
))
{
"command"
,
val
ignoreIntent
=
Intent
(
this
,
DnsVpnService
::
class
.
java
).
putExtra
(
Command
.
IGNORE_SERVICE_KILLED
"command"
,
)
Command
.
IGNORE_SERVICE_KILLED
val
ignorePendingIntent
=
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
PendingIntent
.
getForegroundService
(
this
@DnsVpnService
,
RequestCodes
.
REQUEST_CODE_IGNORE_SERVICE_KILLED
,
ignoreIntent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
)
}
else
{
PendingIntent
.
getService
(
this
@DnsVpnService
,
RequestCodes
.
REQUEST_CODE_IGNORE_SERVICE_KILLED
,
ignoreIntent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
)
)
}
val
ignorePendingIntent
=
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
NotificationCompat
.
Builder
(
this
,
Notifications
.
getDefaultNotificationChannelId
(
this
))
PendingIntent
.
getForegroundService
(
.
apply
{
this
@DnsVpnService
,
setContentTitle
(
getString
(
R
.
string
.
notification_service_killed_title
))
RequestCodes
.
REQUEST_CODE_IGNORE_SERVICE_KILLED
,
setStyle
(
NotificationCompat
.
BigTextStyle
().
bigText
(
getString
(
R
.
string
.
notification_service_killed_message
)))
ignoreIntent
,
setSmallIcon
(
R
.
drawable
.
ic_cloud_warn
)
PendingIntent
.
FLAG_UPDATE_CURRENT
setAutoCancel
(
true
)
setOngoing
(
false
)
setContentIntent
(
DeepActionState
.
BATTERY_OPTIMIZATION_DIALOG
.
pendingIntentTo
(
this
@DnsVpnService
)
)
addAction
(
R
.
drawable
.
ic_eye
,
getString
(
R
.
string
.
notification_service_killed_ignore
),
ignorePendingIntent
)
)
}.
build
().
also
{
}
else
{
(
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
).
notify
(
PendingIntent
.
getService
(
Notifications
.
ID_SERVICE_KILLED
,
this
@DnsVpnService
,
it
RequestCodes
.
REQUEST_CODE_IGNORE_SERVICE_KILLED
,
ignoreIntent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
)
)
}
}
NotificationCompat
.
Builder
(
this
,
Notifications
.
getDefaultNotificationChannelId
(
this
))
.
apply
{
setContentTitle
(
getString
(
R
.
string
.
notification_service_killed_title
))
setStyle
(
NotificationCompat
.
BigTextStyle
().
bigText
(
getString
(
R
.
string
.
notification_service_killed_message
)))
setSmallIcon
(
R
.
drawable
.
ic_cloud_warn
)
setAutoCancel
(
true
)
setOngoing
(
false
)
setContentIntent
(
DeepActionState
.
BATTERY_OPTIMIZATION_DIALOG
.
pendingIntentTo
(
this
@DnsVpnService
)
)
addAction
(
R
.
drawable
.
ic_eye
,
getString
(
R
.
string
.
notification_service_killed_ignore
),
ignorePendingIntent
)
}.
build
().
also
{
(
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
).
notify
(
Notifications
.
ID_SERVICE_KILLED
,
it
)
}
}
}
}
getPreferences
().
vpnServiceState
=
VpnServiceState
.
STARTED
getPreferences
().
vpnServiceState
=
VpnServiceState
.
STARTED
getPreferences
().
vpnLaunchLastVersion
=
BuildConfig
.
VERSION_CODE
getPreferences
().
vpnLaunchLastVersion
=
BuildConfig
.
VERSION_CODE
...
...
Write
Preview
Supports
Markdown
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