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
535561cf
Commit
535561cf
authored
May 24, 2016
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Manage auto connect via Android API
parent
505e40eb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
11 deletions
+27
-11
src/main/AndroidManifest.xml
src/main/AndroidManifest.xml
+1
-2
src/main/res/xml/pref_all.xml
src/main/res/xml/pref_all.xml
+1
-0
src/main/scala/com/github/shadowsocks/BootReceiver.scala
src/main/scala/com/github/shadowsocks/BootReceiver.scala
+13
-7
src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala
...in/scala/com/github/shadowsocks/ShadowsocksSettings.scala
+12
-2
No files found.
src/main/AndroidManifest.xml
View file @
535561cf
...
...
@@ -125,10 +125,9 @@
</intent-filter>
</service>
<receiver
android:name=
".
ShadowsocksReceiver
"
>
<receiver
android:name=
".
BootReceiver"
android:enabled=
"false
"
>
<intent-filter>
<action
android:name=
"android.intent.action.BOOT_COMPLETED"
/>
<action
android:name=
"com.github.shadowsocks.ACTION_UPDATE_STATE"
/>
</intent-filter>
</receiver>
...
...
src/main/res/xml/pref_all.xml
View file @
535561cf
...
...
@@ -70,6 +70,7 @@
<SwitchPreference
android:key=
"isAutoConnect"
android:persistent=
"false"
android:summary=
"@string/auto_connect_summary"
android:title=
"@string/auto_connect"
/>
...
...
src/main/scala/com/github/shadowsocks/
Shadowsocks
Receiver.scala
→
src/main/scala/com/github/shadowsocks/
Boot
Receiver.scala
View file @
535561cf
...
...
@@ -39,13 +39,19 @@
package
com.github.shadowsocks
import
android.content.
{
BroadcastReceiver
,
Context
,
Intent
}
import
android.content.pm.PackageManager
import
android.content.
{
BroadcastReceiver
,
ComponentName
,
Context
,
Intent
}
import
com.github.shadowsocks.utils._
class
ShadowsocksReceiver
extends
BroadcastReceiver
{
def
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
if
(
ShadowsocksApplication
.
settings
.
getBoolean
(
Key
.
isAutoConnect
,
false
))
{
Utils
.
startSsService
(
context
)
}
}
object
BootReceiver
{
def
getEnabled
(
context
:
Context
)
=
PackageManager
.
COMPONENT_ENABLED_STATE_ENABLED
==
context
.
getPackageManager
.
getComponentEnabledSetting
(
new
ComponentName
(
context
,
classOf
[
BootReceiver
]))
def
setEnabled
(
context
:
Context
,
enabled
:
Boolean
)
=
context
.
getPackageManager
.
setComponentEnabledSetting
(
new
ComponentName
(
context
,
classOf
[
BootReceiver
]),
if
(
enabled
)
PackageManager
.
COMPONENT_ENABLED_STATE_ENABLED
else
PackageManager
.
COMPONENT_ENABLED_STATE_DISABLED
,
PackageManager
.
DONT_KILL_APP
)
}
class
BootReceiver
extends
BroadcastReceiver
{
def
onReceive
(
context
:
Context
,
intent
:
Intent
)
=
Utils
.
startSsService
(
context
)
}
src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala
View file @
535561cf
...
...
@@ -16,7 +16,6 @@ import com.github.shadowsocks.utils.{Key, Utils}
object
ShadowsocksSettings
{
// Constants
private
final
val
TAG
=
"ShadowsocksSettings"
private
final
val
PREFS_NAME
=
"Shadowsocks"
private
val
PROXY_PREFS
=
Array
(
Key
.
profileName
,
Key
.
proxy
,
Key
.
remotePort
,
Key
.
localPort
,
Key
.
sitekey
,
Key
.
encMethod
,
Key
.
isAuth
)
private
val
FEATURE_PREFS
=
Array
(
Key
.
route
,
Key
.
isProxyApps
,
Key
.
isUdpDns
,
Key
.
isIpv6
)
...
...
@@ -81,6 +80,17 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
false
})
val
switch
=
findPreference
(
Key
.
isAutoConnect
).
asInstanceOf
[
SwitchPreference
]
switch
.
setOnPreferenceChangeListener
((
_
,
value
)
=>
{
BootReceiver
.
setEnabled
(
activity
,
value
.
asInstanceOf
[
Boolean
])
true
})
if
(
getPreferenceManager
.
getSharedPreferences
.
getBoolean
(
Key
.
isAutoConnect
,
false
))
{
BootReceiver
.
setEnabled
(
activity
,
true
)
getPreferenceManager
.
getSharedPreferences
.
edit
.
remove
(
Key
.
isAutoConnect
).
apply
}
switch
.
setChecked
(
BootReceiver
.
getEnabled
(
activity
))
findPreference
(
"recovery"
).
setOnPreferenceClickListener
((
preference
:
Preference
)
=>
{
ShadowsocksApplication
.
track
(
TAG
,
"reset"
)
activity
.
recovery
()
...
...
@@ -130,7 +140,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
ShadowsocksApplication
.
settings
.
unregisterOnSharedPreferenceChangeListener
(
this
)
}
def
onSharedPreferenceChanged
(
sharedPreferences
:
SharedPreferences
,
key
:
String
)
=
key
match
{
def
onSharedPreferenceChanged
(
pref
:
SharedPreferences
,
key
:
String
)
=
key
match
{
case
Key
.
isNAT
=>
activity
.
handler
.
post
(()
=>
{
activity
.
detachService
...
...
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