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
569f056a
Commit
569f056a
authored
Dec 26, 2015
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce battery usage - register broadcast at runtime
parent
971ea090
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
26 deletions
+19
-26
src/main/AndroidManifest.xml
src/main/AndroidManifest.xml
+0
-8
src/main/scala/com/github/shadowsocks/AppManager.scala
src/main/scala/com/github/shadowsocks/AppManager.scala
+19
-7
src/main/scala/com/github/shadowsocks/AppManagerReceiver.scala
...ain/scala/com/github/shadowsocks/AppManagerReceiver.scala
+0
-11
No files found.
src/main/AndroidManifest.xml
View file @
569f056a
...
...
@@ -108,14 +108,6 @@
</intent-filter>
</service>
<receiver
android:name=
".AppManagerReceiver"
>
<intent-filter>
<action
android:name=
"android.intent.action.PACKAGE_ADDED"
/>
<action
android:name=
"android.intent.action.PACKAGE_REMOVED"
/>
<data
android:scheme=
"package"
/>
</intent-filter>
</receiver>
<receiver
android:name=
".ShadowsocksReceiver"
>
<intent-filter>
<action
android:name=
"android.intent.action.BOOT_COMPLETED"
/>
...
...
src/main/scala/com/github/shadowsocks/AppManager.scala
View file @
569f056a
...
...
@@ -40,7 +40,7 @@
package
com.github.shadowsocks
import
android.content.pm.PackageManager
import
android.content.
{
ClipData
,
ClipboardManager
,
Context
}
import
android.content.
_
import
android.graphics.PixelFormat
import
android.graphics.drawable.Drawable
import
android.os.
{
Bundle
,
Handler
}
...
...
@@ -65,13 +65,25 @@ object AppManager {
case
class
ProxiedApp
(
name
:
String
,
packageName
:
String
,
icon
:
Drawable
)
private
case
class
ListEntry
(
switch
:
Switch
,
text
:
TextView
,
icon
:
ImageView
)
var
cachedApps
:
Array
[
ProxiedApp
]
=
_
private
var
receiverRegistered
:
Boolean
=
_
private
var
cachedApps
:
Array
[
ProxiedApp
]
=
_
private
def
getApps
(
pm
:
PackageManager
)
=
{
if
(
cachedApps
==
null
)
cachedApps
=
pm
.
getInstalledPackages
(
PackageManager
.
GET_PERMISSIONS
)
.
filter
(
p
=>
p
.
requestedPermissions
!=
null
&&
p
.
requestedPermissions
.
contains
(
permission
.
INTERNET
))
.
map
(
p
=>
new
ProxiedApp
(
pm
.
getApplicationLabel
(
p
.
applicationInfo
).
toString
,
p
.
packageName
,
p
.
applicationInfo
.
loadIcon
(
pm
))).
toArray
cachedApps
if
(!
receiverRegistered
)
{
val
filter
=
new
IntentFilter
(
Intent
.
ACTION_PACKAGE_ADDED
)
filter
.
addAction
(
Intent
.
ACTION_PACKAGE_REMOVED
)
filter
.
addDataScheme
(
"package"
)
ShadowsocksApplication
.
instance
.
registerReceiver
((
context
:
Context
,
intent
:
Intent
)
=>
if
(
intent
.
getAction
!=
Intent
.
ACTION_PACKAGE_REMOVED
||
!
intent
.
getBooleanExtra
(
Intent
.
EXTRA_REPLACING
,
false
))
synchronized
(
cachedApps
=
null
),
filter
)
receiverRegistered
=
true
}
synchronized
{
if
(
cachedApps
==
null
)
cachedApps
=
pm
.
getInstalledPackages
(
PackageManager
.
GET_PERMISSIONS
)
.
filter
(
p
=>
p
.
requestedPermissions
!=
null
&&
p
.
requestedPermissions
.
contains
(
permission
.
INTERNET
))
.
map
(
p
=>
new
ProxiedApp
(
pm
.
getApplicationLabel
(
p
.
applicationInfo
).
toString
,
p
.
packageName
,
p
.
applicationInfo
.
loadIcon
(
pm
))).
toArray
cachedApps
}
}
}
...
...
src/main/scala/com/github/shadowsocks/AppManagerReceiver.scala
deleted
100644 → 0
View file @
971ea090
package
com.github.shadowsocks
import
android.content.
{
Intent
,
Context
,
BroadcastReceiver
}
/**
* @author Mygod
*/
class
AppManagerReceiver
extends
BroadcastReceiver
{
override
def
onReceive
(
context
:
Context
,
intent
:
Intent
)
=
if
(
intent
.
getAction
!=
Intent
.
ACTION_PACKAGE_REMOVED
||
!
intent
.
getBooleanExtra
(
Intent
.
EXTRA_REPLACING
,
false
))
AppManager
.
synchronized
(
AppManager
.
cachedApps
=
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