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
026d1ecb
Commit
026d1ecb
authored
Feb 15, 2018
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix receiver leaking
parent
7461d3bf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
10 deletions
+26
-10
mobile/src/main/java/com/github/shadowsocks/App.kt
mobile/src/main/java/com/github/shadowsocks/App.kt
+7
-3
mobile/src/main/java/com/github/shadowsocks/AppManager.kt
mobile/src/main/java/com/github/shadowsocks/AppManager.kt
+7
-4
mobile/src/main/java/com/github/shadowsocks/ProfileConfigFragment.kt
...main/java/com/github/shadowsocks/ProfileConfigFragment.kt
+4
-1
mobile/src/main/java/com/github/shadowsocks/plugin/PluginManager.kt
.../main/java/com/github/shadowsocks/plugin/PluginManager.kt
+8
-2
No files found.
mobile/src/main/java/com/github/shadowsocks/App.kt
View file @
026d1ecb
...
@@ -174,12 +174,16 @@ class App : Application() {
...
@@ -174,12 +174,16 @@ class App : Application() {
}
}
}
}
fun
listenForPackageChanges
(
callback
:
()
->
Unit
):
BroadcastReceiver
{
fun
listenForPackageChanges
(
onetime
:
Boolean
=
true
,
callback
:
()
->
Unit
):
BroadcastReceiver
{
val
filter
=
IntentFilter
(
Intent
.
ACTION_PACKAGE_ADDED
)
val
filter
=
IntentFilter
(
Intent
.
ACTION_PACKAGE_ADDED
)
filter
.
addAction
(
Intent
.
ACTION_PACKAGE_REMOVED
)
filter
.
addAction
(
Intent
.
ACTION_PACKAGE_REMOVED
)
filter
.
addDataScheme
(
"package"
)
filter
.
addDataScheme
(
"package"
)
val
result
=
broadcastReceiver
{
_
,
intent
->
val
result
=
object
:
BroadcastReceiver
()
{
if
(!
intent
.
getBooleanExtra
(
Intent
.
EXTRA_REPLACING
,
false
))
callback
()
override
fun
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
if
(
intent
.
getBooleanExtra
(
Intent
.
EXTRA_REPLACING
,
false
))
return
callback
()
if
(
onetime
)
app
.
unregisterReceiver
(
this
)
}
}
}
app
.
registerReceiver
(
result
,
filter
)
app
.
registerReceiver
(
result
,
filter
)
return
result
return
result
...
...
mobile/src/main/java/com/github/shadowsocks/AppManager.kt
View file @
026d1ecb
...
@@ -63,11 +63,14 @@ class AppManager : AppCompatActivity(), Toolbar.OnMenuItemClickListener {
...
@@ -63,11 +63,14 @@ class AppManager : AppCompatActivity(), Toolbar.OnMenuItemClickListener {
private
var
receiver
:
BroadcastReceiver
?
=
null
private
var
receiver
:
BroadcastReceiver
?
=
null
private
var
cachedApps
:
List
<
PackageInfo
>?
=
null
private
var
cachedApps
:
List
<
PackageInfo
>?
=
null
private
fun
getApps
(
pm
:
PackageManager
):
List
<
ProxiedApp
>
{
private
fun
getApps
(
pm
:
PackageManager
):
List
<
ProxiedApp
>
{
if
(
receiver
==
null
)
receiver
=
app
.
listenForPackageChanges
{
synchronized
(
AppManager
)
{
cachedApps
=
null
}
AppManager
.
instance
?.
reloadApps
()
}
return
synchronized
(
AppManager
)
{
return
synchronized
(
AppManager
)
{
if
(
receiver
==
null
)
receiver
=
app
.
listenForPackageChanges
{
synchronized
(
AppManager
)
{
receiver
=
null
cachedApps
=
null
}
AppManager
.
instance
?.
reloadApps
()
}
// Labels and icons can change on configuration (locale, etc.) changes, therefore they are not cached.
// Labels and icons can change on configuration (locale, etc.) changes, therefore they are not cached.
val
cachedApps
=
cachedApps
?:
pm
.
getInstalledPackages
(
PackageManager
.
GET_PERMISSIONS
)
val
cachedApps
=
cachedApps
?:
pm
.
getInstalledPackages
(
PackageManager
.
GET_PERMISSIONS
)
.
filter
{
it
.
packageName
!=
app
.
packageName
&&
.
filter
{
it
.
packageName
!=
app
.
packageName
&&
...
...
mobile/src/main/java/com/github/shadowsocks/ProfileConfigFragment.kt
View file @
026d1ecb
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
package
com.github.shadowsocks
package
com.github.shadowsocks
import
android.app.Activity
import
android.app.Activity
import
android.content.BroadcastReceiver
import
android.content.Intent
import
android.content.Intent
import
android.os.Build
import
android.os.Build
import
android.os.Bundle
import
android.os.Bundle
...
@@ -60,6 +61,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
...
@@ -60,6 +61,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
private
lateinit
var
plugin
:
IconListPreference
private
lateinit
var
plugin
:
IconListPreference
private
lateinit
var
pluginConfigure
:
EditTextPreference
private
lateinit
var
pluginConfigure
:
EditTextPreference
private
lateinit
var
pluginConfiguration
:
PluginConfiguration
private
lateinit
var
pluginConfiguration
:
PluginConfiguration
private
lateinit
var
receiver
:
BroadcastReceiver
override
fun
onCreatePreferencesFix
(
savedInstanceState
:
Bundle
?,
rootKey
:
String
?)
{
override
fun
onCreatePreferencesFix
(
savedInstanceState
:
Bundle
?,
rootKey
:
String
?)
{
preferenceManager
.
preferenceDataStore
=
DataStore
.
privateStore
preferenceManager
.
preferenceDataStore
=
DataStore
.
privateStore
...
@@ -102,7 +104,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
...
@@ -102,7 +104,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
}
}
pluginConfigure
.
onPreferenceChangeListener
=
this
pluginConfigure
.
onPreferenceChangeListener
=
this
initPlugins
()
initPlugins
()
app
.
listenForPackageChanges
{
initPlugins
()
}
receiver
=
app
.
listenForPackageChanges
(
false
)
{
initPlugins
()
}
DataStore
.
privateStore
.
registerChangeListener
(
this
)
DataStore
.
privateStore
.
registerChangeListener
(
this
)
}
}
...
@@ -202,6 +204,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
...
@@ -202,6 +204,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
override
fun
onDestroy
()
{
override
fun
onDestroy
()
{
DataStore
.
privateStore
.
unregisterChangeListener
(
this
)
DataStore
.
privateStore
.
unregisterChangeListener
(
this
)
app
.
unregisterReceiver
(
receiver
)
super
.
onDestroy
()
super
.
onDestroy
()
}
}
}
}
mobile/src/main/java/com/github/shadowsocks/plugin/PluginManager.kt
View file @
026d1ecb
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
package
com.github.shadowsocks.plugin
package
com.github.shadowsocks.plugin
import
android.annotation.SuppressLint
import
android.annotation.SuppressLint
import
android.content.BroadcastReceiver
import
android.content.ContentResolver
import
android.content.ContentResolver
import
android.content.Intent
import
android.content.Intent
import
android.content.pm.PackageManager
import
android.content.pm.PackageManager
...
@@ -84,11 +85,16 @@ object PluginManager {
...
@@ -84,11 +85,16 @@ object PluginManager {
"""
,
Base64
.
DEFAULT
))
"""
,
Base64
.
DEFAULT
))
}
}
private
va
l
receiver
by
lazy
{
app
.
listenForPackageChanges
{
synchronized
(
this
)
{
cachedPlugins
=
null
}
}
}
private
va
r
receiver
:
BroadcastReceiver
?
=
null
private
var
cachedPlugins
:
Map
<
String
,
Plugin
>?
=
null
private
var
cachedPlugins
:
Map
<
String
,
Plugin
>?
=
null
fun
fetchPlugins
():
Map
<
String
,
Plugin
>
{
fun
fetchPlugins
():
Map
<
String
,
Plugin
>
{
receiver
return
synchronized
(
this
)
{
return
synchronized
(
this
)
{
if
(
receiver
==
null
)
receiver
=
app
.
listenForPackageChanges
{
synchronized
(
this
)
{
receiver
=
null
cachedPlugins
=
null
}
}
if
(
cachedPlugins
==
null
)
{
if
(
cachedPlugins
==
null
)
{
val
pm
=
app
.
packageManager
val
pm
=
app
.
packageManager
cachedPlugins
=
(
pm
.
queryIntentContentProviders
(
Intent
(
PluginContract
.
ACTION_NATIVE_PLUGIN
),
cachedPlugins
=
(
pm
.
queryIntentContentProviders
(
Intent
(
PluginContract
.
ACTION_NATIVE_PLUGIN
),
...
...
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