Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
fd01712b
Commit
fd01712b
authored
Dec 26, 2015
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce battery usage - use notify instead of startForeground
parent
92c8e085
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala
...cala/com/github/shadowsocks/ShadowsocksNotification.scala
+7
-3
No files found.
src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala
View file @
fd01712b
...
...
@@ -2,7 +2,7 @@ package com.github.shadowsocks
import
java.util.Locale
import
android.app.
{
KeyguardManager
,
PendingIntent
}
import
android.app.
{
KeyguardManager
,
NotificationManager
,
PendingIntent
}
import
android.content.
{
BroadcastReceiver
,
Context
,
Intent
,
IntentFilter
}
import
android.os.PowerManager
import
android.support.v4.app.NotificationCompat
...
...
@@ -16,6 +16,7 @@ import com.github.shadowsocks.utils.{Action, State, Utils}
*/
class
ShadowsocksNotification
(
private
val
service
:
BaseService
,
profileName
:
String
,
visible
:
Boolean
=
false
)
{
private
lazy
val
keyGuard
=
service
.
getSystemService
(
Context
.
KEYGUARD_SERVICE
).
asInstanceOf
[
KeyguardManager
]
private
lazy
val
nm
=
service
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
).
asInstanceOf
[
NotificationManager
]
private
lazy
val
callback
=
new
Stub
{
override
def
stateChanged
(
state
:
Int
,
msg
:
String
)
=
()
// ignore
override
def
trafficUpdated
(
txRate
:
String
,
rxRate
:
String
,
txTotal
:
String
,
rxTotal
:
String
)
{
...
...
@@ -27,6 +28,7 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str
}
private
var
lockReceiver
:
BroadcastReceiver
=
_
private
var
callbackRegistered
:
Boolean
=
_
private
var
started
:
Boolean
=
_
private
val
builder
=
new
NotificationCompat
.
Builder
(
service
)
.
setWhen
(
0
)
...
...
@@ -73,8 +75,10 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str
show
()
}
else
if
(
forceShow
)
show
()
def
notification
=
builder
.
build
()
def
show
()
=
service
.
startForeground
(
1
,
notification
)
def
show
()
=
if
(
started
)
nm
.
notify
(
1
,
builder
.
build
)
else
{
service
.
startForeground
(
1
,
builder
.
build
)
started
=
true
}
def
destroy
()
{
if
(
lockReceiver
!=
null
)
{
...
...
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