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
29c51169
Commit
29c51169
authored
Feb 20, 2014
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delay the startup when screen locked
parent
a17f12d3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
15 deletions
+38
-15
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
...la/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
+38
-15
No files found.
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
View file @
29c51169
...
@@ -39,10 +39,10 @@
...
@@ -39,10 +39,10 @@
package
com.github.shadowsocks
package
com.github.shadowsocks
import
android.app.
Activity
import
android.app.
{
Activity
,
KeyguardManager
}
import
android.os.
{
IBinder
,
Bundle
}
import
android.os.
{
IBinder
,
Bundle
,
Handler
}
import
android.net.VpnService
import
android.net.VpnService
import
android.content.
{
Context
,
ComponentName
,
ServiceConnection
,
Intent
}
import
android.content.
_
import
android.util.Log
import
android.util.Log
import
android.preference.PreferenceManager
import
android.preference.PreferenceManager
import
com.github.shadowsocks.utils._
import
com.github.shadowsocks.utils._
...
@@ -53,28 +53,43 @@ class ShadowsocksRunnerActivity extends Activity {
...
@@ -53,28 +53,43 @@ class ShadowsocksRunnerActivity extends Activity {
lazy
val
settings
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
)
lazy
val
settings
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
)
lazy
val
isRoot
=
Utils
.
getRoot
lazy
val
isRoot
=
Utils
.
getRoot
val
handler
=
new
Handler
()
val
receiver
=
new
BroadcastReceiver
()
{
override
def
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
if
(
intent
.
getAction
==
Intent
.
ACTION_USER_PRESENT
)
{
attachService
()
}
}
}
// Services
// Services
var
bgService
:
IShadowsocksService
=
null
var
bgService
:
IShadowsocksService
=
null
val
connection
=
new
ServiceConnection
{
val
connection
=
new
ServiceConnection
{
override
def
onServiceConnected
(
name
:
ComponentName
,
service
:
IBinder
)
{
override
def
onServiceConnected
(
name
:
ComponentName
,
service
:
IBinder
)
{
bgService
=
IShadowsocksService
.
Stub
.
asInterface
(
service
)
bgService
=
IShadowsocksService
.
Stub
.
asInterface
(
service
)
if
(!
isRoot
)
{
handler
.
postDelayed
(
new
Runnable
()
{
val
intent
=
VpnService
.
prepare
(
ShadowsocksRunnerActivity
.
this
)
override
def
run
()
=
startBackgroundService
()
if
(
intent
!=
null
)
{
},
1000
)
startActivityForResult
(
intent
,
Shadowsocks
.
REQUEST_CONNECT
)
}
else
{
onActivityResult
(
Shadowsocks
.
REQUEST_CONNECT
,
Activity
.
RESULT_OK
,
null
)
}
}
else
{
bgService
.
start
(
ConfigUtils
.
load
(
settings
))
finish
()
}
}
}
override
def
onServiceDisconnected
(
name
:
ComponentName
)
{
override
def
onServiceDisconnected
(
name
:
ComponentName
)
{
bgService
=
null
bgService
=
null
}
}
}
}
def
startBackgroundService
()
{
if
(!
isRoot
)
{
val
intent
=
VpnService
.
prepare
(
ShadowsocksRunnerActivity
.
this
)
if
(
intent
!=
null
)
{
startActivityForResult
(
intent
,
Shadowsocks
.
REQUEST_CONNECT
)
}
else
{
onActivityResult
(
Shadowsocks
.
REQUEST_CONNECT
,
Activity
.
RESULT_OK
,
null
)
}
}
else
{
bgService
.
start
(
ConfigUtils
.
load
(
settings
))
finish
()
}
}
def
attachService
()
{
def
attachService
()
{
if
(
bgService
==
null
)
{
if
(
bgService
==
null
)
{
val
s
=
if
(
isRoot
)
classOf
[
ShadowsocksNatService
]
else
classOf
[
ShadowsocksVpnService
]
val
s
=
if
(
isRoot
)
classOf
[
ShadowsocksNatService
]
else
classOf
[
ShadowsocksVpnService
]
...
@@ -94,12 +109,20 @@ class ShadowsocksRunnerActivity extends Activity {
...
@@ -94,12 +109,20 @@ class ShadowsocksRunnerActivity extends Activity {
override
def
onCreate
(
savedInstanceState
:
Bundle
)
{
override
def
onCreate
(
savedInstanceState
:
Bundle
)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
attachService
()
val
km
=
getSystemService
(
Context
.
KEYGUARD_SERVICE
).
asInstanceOf
[
KeyguardManager
]
val
locked
=
km
.
inKeyguardRestrictedInputMode
if
(
locked
)
{
val
filter
=
new
IntentFilter
(
Intent
.
ACTION_USER_PRESENT
)
registerReceiver
(
receiver
,
filter
)
}
else
{
attachService
()
}
}
}
override
def
onDestroy
()
{
override
def
onDestroy
()
{
super
.
onDestroy
()
super
.
onDestroy
()
deattachService
()
deattachService
()
unregisterReceiver
(
receiver
)
}
}
override
def
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
)
{
override
def
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
)
{
...
...
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