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
d111bc82
Commit
d111bc82
authored
Oct 04, 2015
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using SAM
parent
a57c06e3
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
195 additions
and
281 deletions
+195
-281
src/main/scala/com/github/shadowsocks/AppManager.scala
src/main/scala/com/github/shadowsocks/AppManager.scala
+2
-5
src/main/scala/com/github/shadowsocks/BaseService.scala
src/main/scala/com/github/shadowsocks/BaseService.scala
+10
-14
src/main/scala/com/github/shadowsocks/ParserActivity.scala
src/main/scala/com/github/shadowsocks/ParserActivity.scala
+11
-17
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+102
-138
src/main/scala/com/github/shadowsocks/ShadowsocksApplication.scala
...scala/com/github/shadowsocks/ShadowsocksApplication.scala
+3
-5
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
.../scala/com/github/shadowsocks/ShadowsocksNatService.scala
+18
-28
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
...la/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
+4
-10
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
.../scala/com/github/shadowsocks/ShadowsocksVpnService.scala
+3
-5
src/main/scala/com/github/shadowsocks/ShadowsocksVpnThread.scala
...n/scala/com/github/shadowsocks/ShadowsocksVpnThread.scala
+22
-23
src/main/scala/com/github/shadowsocks/database/MenuAdapter.scala
...n/scala/com/github/shadowsocks/database/MenuAdapter.scala
+8
-16
src/main/scala/com/github/shadowsocks/utils/Console.scala
src/main/scala/com/github/shadowsocks/utils/Console.scala
+12
-20
No files found.
src/main/scala/com/github/shadowsocks/AppManager.scala
View file @
d111bc82
...
@@ -297,11 +297,8 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
...
@@ -297,11 +297,8 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
val
bypassSwitch
=
findViewById
(
R
.
id
.
bypassSwitch
).
asInstanceOf
[
Switch
]
val
bypassSwitch
=
findViewById
(
R
.
id
.
bypassSwitch
).
asInstanceOf
[
Switch
]
val
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
getBaseContext
)
val
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
getBaseContext
)
bypassSwitch
.
setOnCheckedChangeListener
(
new
OnCheckedChangeListener
{
bypassSwitch
.
setOnCheckedChangeListener
((
button
:
CompoundButton
,
checked
:
Boolean
)
=>
def
onCheckedChanged
(
button
:
CompoundButton
,
checked
:
Boolean
)
{
prefs
.
edit
().
putBoolean
(
Key
.
isBypassApps
,
checked
).
commit
())
prefs
.
edit
().
putBoolean
(
Key
.
isBypassApps
,
checked
).
commit
()
}
})
bypassSwitch
.
setChecked
(
prefs
.
getBoolean
(
Key
.
isBypassApps
,
false
))
bypassSwitch
.
setChecked
(
prefs
.
getBoolean
(
Key
.
isBypassApps
,
false
))
appListView
=
findViewById
(
R
.
id
.
applistview
).
asInstanceOf
[
ListView
]
appListView
=
findViewById
(
R
.
id
.
applistview
).
asInstanceOf
[
ListView
]
...
...
src/main/scala/com/github/shadowsocks/BaseService.scala
View file @
d111bc82
...
@@ -110,23 +110,19 @@ trait BaseService {
...
@@ -110,23 +110,19 @@ trait BaseService {
protected
def
changeState
(
s
:
Int
,
msg
:
String
)
{
protected
def
changeState
(
s
:
Int
,
msg
:
String
)
{
val
handler
=
new
Handler
(
getContext
.
getMainLooper
)
val
handler
=
new
Handler
(
getContext
.
getMainLooper
)
handler
.
post
(
new
Runnable
{
handler
.
post
(()
=>
if
(
state
!=
s
)
{
override
def
run
()
{
if
(
callbackCount
>
0
)
{
if
(
state
!=
s
)
{
val
n
=
callbacks
.
beginBroadcast
()
if
(
callbackCount
>
0
)
{
for
(
i
<-
0
to
n
-
1
)
{
val
n
=
callbacks
.
beginBroadcast
()
try
{
for
(
i
<-
0
to
n
-
1
)
{
callbacks
.
getBroadcastItem
(
i
).
stateChanged
(
s
,
msg
)
try
{
}
catch
{
callbacks
.
getBroadcastItem
(
i
).
stateChanged
(
s
,
msg
)
case
_:
Exception
=>
// Ignore
}
catch
{
case
_:
Exception
=>
// Ignore
}
}
callbacks
.
finishBroadcast
()
}
}
state
=
s
}
}
callbacks
.
finishBroadcast
()
}
}
state
=
s
})
})
}
}
...
...
src/main/scala/com/github/shadowsocks/ParserActivity.scala
View file @
d111bc82
...
@@ -57,21 +57,17 @@ class ParserActivity extends Activity {
...
@@ -57,21 +57,17 @@ class ParserActivity extends Activity {
new
AlertDialog
.
Builder
(
this
)
new
AlertDialog
.
Builder
(
this
)
.
setTitle
(
R
.
string
.
add_profile_dialog
)
.
setTitle
(
R
.
string
.
add_profile_dialog
)
.
setCancelable
(
false
)
.
setCancelable
(
false
)
.
setPositiveButton
(
R
.
string
.
yes
,
new
DialogInterface
.
OnClickListener
()
{
.
setPositiveButton
(
R
.
string
.
yes
,
((
dialog
:
DialogInterface
,
id
:
Int
)
=>
{
override
def
onClick
(
dialog
:
DialogInterface
,
id
:
Int
)
{
Parser
.
parse
(
data
)
match
{
Parser
.
parse
(
data
)
match
{
case
Some
(
profile
)
=>
addProfile
(
profile
)
case
Some
(
profile
)
=>
addProfile
(
profile
)
case
_
=>
// ignore
case
_
=>
// ignore
}
}
dialog
.
dismiss
()
dialog
.
dismiss
()
}
})
:
DialogInterface.OnClickListener
)
})
.
setNegativeButton
(
R
.
string
.
no
,
((
dialog
:
DialogInterface
,
id
:
Int
)
=>
{
.
setNegativeButton
(
R
.
string
.
no
,
new
DialogInterface
.
OnClickListener
()
{
override
def
onClick
(
dialog
:
DialogInterface
,
id
:
Int
)
{
dialog
.
dismiss
()
dialog
.
dismiss
()
finish
()
finish
()
}
})
:
DialogInterface.OnClickListener
)
})
.
setMessage
(
data
)
.
setMessage
(
data
)
.
create
()
.
create
()
.
show
()
.
show
()
...
@@ -91,15 +87,13 @@ class ParserActivity extends Activity {
...
@@ -91,15 +87,13 @@ class ParserActivity extends Activity {
val
h
=
showProgress
(
getString
(
R
.
string
.
loading
))
val
h
=
showProgress
(
getString
(
R
.
string
.
loading
))
h
.
postDelayed
(
new
Runnable
{
h
.
postDelayed
(()
=>
{
def
run
()
{
val
profileManager
=
val
profileManager
=
new
ProfileManager
(
PreferenceManager
.
getDefaultSharedPreferences
(
getBaseContext
),
new
ProfileManager
(
PreferenceManager
.
getDefaultSharedPreferences
(
getBaseContext
),
getApplication
.
asInstanceOf
[
ShadowsocksApplication
].
dbHelper
)
getApplication
.
asInstanceOf
[
ShadowsocksApplication
].
dbHelper
)
profileManager
.
createOrUpdateProfile
(
profile
)
profileManager
.
createOrUpdateProfile
(
profile
)
profileManager
.
reload
(
profile
.
id
)
profileManager
.
reload
(
profile
.
id
)
h
.
sendEmptyMessage
(
0
)
h
.
sendEmptyMessage
(
0
)
}
},
600
)
},
600
)
}
}
...
...
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
d111bc82
This diff is collapsed.
Click to expand it.
src/main/scala/com/github/shadowsocks/ShadowsocksApplication.scala
View file @
d111bc82
...
@@ -47,7 +47,6 @@ import com.github.shadowsocks.database.DBHelper
...
@@ -47,7 +47,6 @@ import com.github.shadowsocks.database.DBHelper
import
com.github.shadowsocks.utils.Utils
import
com.github.shadowsocks.utils.Utils
import
com.google.android.gms.analytics.GoogleAnalytics
import
com.google.android.gms.analytics.GoogleAnalytics
import
com.google.android.gms.common.api.ResultCallback
import
com.google.android.gms.common.api.ResultCallback
import
com.google.android.gms.tagmanager.Container.FunctionCallMacroCallback
import
com.google.android.gms.tagmanager.
{
ContainerHolder
,
TagManager
}
import
com.google.android.gms.tagmanager.
{
ContainerHolder
,
TagManager
}
class
ShadowsocksApplication
extends
Application
{
class
ShadowsocksApplication
extends
Application
{
...
@@ -66,14 +65,13 @@ class ShadowsocksApplication extends Application {
...
@@ -66,14 +65,13 @@ class ShadowsocksApplication extends Application {
}
}
containerHolder
=
holder
containerHolder
=
holder
val
container
=
holder
.
getContainer
val
container
=
holder
.
getContainer
container
.
registerFunctionCallMacroCallback
(
SIG_FUNC
,
new
FunctionCallMacroCallback
{
container
.
registerFunctionCallMacroCallback
(
SIG_FUNC
,
override
def
getValue
(
functionName
:
String
,
parameters
:
util.Map
[
String
,
AnyRef
])
:
AnyRef
=
{
(
functionName
:
String
,
parameters
:
util.Map
[
String
,
AnyRef
])
=>
{
if
(
functionName
==
SIG_FUNC
)
{
if
(
functionName
==
SIG_FUNC
)
{
Utils
.
getSignature
(
getApplicationContext
)
Utils
.
getSignature
(
getApplicationContext
)
}
}
null
null
}
})
})
}
}
}
}
pending
.
setResultCallback
(
callback
,
2
,
TimeUnit
.
SECONDS
)
pending
.
setResultCallback
(
callback
,
2
,
TimeUnit
.
SECONDS
)
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
View file @
d111bc82
...
@@ -173,11 +173,7 @@ class ShadowsocksNatService extends Service with BaseService {
...
@@ -173,11 +173,7 @@ class ShadowsocksNatService extends Service with BaseService {
def
initConnectionReceiver
()
{
def
initConnectionReceiver
()
{
val
filter
=
new
IntentFilter
(
ConnectivityManager
.
CONNECTIVITY_ACTION
)
val
filter
=
new
IntentFilter
(
ConnectivityManager
.
CONNECTIVITY_ACTION
)
connReceiver
=
new
BroadcastReceiver
{
connReceiver
=
(
context
:
Context
,
intent
:
Intent
)
=>
setupDns
()
override
def
onReceive
(
context
:
Context
,
intent
:
Intent
)
=
{
setupDns
()
}
}
registerReceiver
(
connReceiver
,
filter
)
registerReceiver
(
connReceiver
,
filter
)
}
}
...
@@ -512,11 +508,9 @@ class ShadowsocksNatService extends Service with BaseService {
...
@@ -512,11 +508,9 @@ class ShadowsocksNatService extends Service with BaseService {
val
filter
=
new
IntentFilter
()
val
filter
=
new
IntentFilter
()
filter
.
addAction
(
Intent
.
ACTION_SHUTDOWN
)
filter
.
addAction
(
Intent
.
ACTION_SHUTDOWN
)
filter
.
addAction
(
Action
.
CLOSE
)
filter
.
addAction
(
Action
.
CLOSE
)
closeReceiver
=
new
BroadcastReceiver
()
{
closeReceiver
=
(
context
:
Context
,
intent
:
Intent
)
=>
{
def
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
Toast
.
makeText
(
context
,
R
.
string
.
stopping
,
Toast
.
LENGTH_SHORT
).
show
()
Toast
.
makeText
(
context
,
R
.
string
.
stopping
,
Toast
.
LENGTH_SHORT
).
show
()
stopRunner
()
stopRunner
()
}
}
}
registerReceiver
(
closeReceiver
,
filter
)
registerReceiver
(
closeReceiver
,
filter
)
...
@@ -525,26 +519,22 @@ class ShadowsocksNatService extends Service with BaseService {
...
@@ -525,26 +519,22 @@ class ShadowsocksNatService extends Service with BaseService {
screenFilter
.
addAction
(
Intent
.
ACTION_SCREEN_ON
)
screenFilter
.
addAction
(
Intent
.
ACTION_SCREEN_ON
)
screenFilter
.
addAction
(
Intent
.
ACTION_SCREEN_OFF
)
screenFilter
.
addAction
(
Intent
.
ACTION_SCREEN_OFF
)
screenFilter
.
addAction
(
Intent
.
ACTION_USER_PRESENT
)
screenFilter
.
addAction
(
Intent
.
ACTION_USER_PRESENT
)
lockReceiver
=
new
BroadcastReceiver
()
{
lockReceiver
=
(
context
:
Context
,
intent
:
Intent
)
=>
if
(
getState
==
State
.
CONNECTED
)
{
def
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
val
action
=
intent
.
getAction
if
(
getState
==
State
.
CONNECTED
)
{
if
(
action
==
Intent
.
ACTION_SCREEN_OFF
)
{
val
action
=
intent
.
getAction
notifyForegroundAlert
(
getString
(
R
.
string
.
forward_success
),
if
(
action
==
Intent
.
ACTION_SCREEN_OFF
)
{
getString
(
R
.
string
.
service_running
).
formatLocal
(
Locale
.
ENGLISH
,
config
.
profileName
),
false
)
notifyForegroundAlert
(
getString
(
R
.
string
.
forward_success
),
}
else
if
(
action
==
Intent
.
ACTION_SCREEN_ON
)
{
getString
(
R
.
string
.
service_running
).
formatLocal
(
Locale
.
ENGLISH
,
config
.
profileName
),
false
)
val
keyGuard
=
getSystemService
(
Context
.
KEYGUARD_SERVICE
).
asInstanceOf
[
KeyguardManager
]
}
else
if
(
action
==
Intent
.
ACTION_SCREEN_ON
)
{
if
(!
keyGuard
.
inKeyguardRestrictedInputMode
)
{
val
keyGuard
=
getSystemService
(
Context
.
KEYGUARD_SERVICE
).
asInstanceOf
[
KeyguardManager
]
notifyForegroundAlert
(
getString
(
R
.
string
.
forward_success
),
if
(!
keyGuard
.
inKeyguardRestrictedInputMode
)
{
getString
(
R
.
string
.
service_running
).
formatLocal
(
Locale
.
ENGLISH
,
config
.
profileName
),
true
)
notifyForegroundAlert
(
getString
(
R
.
string
.
forward_success
),
getString
(
R
.
string
.
service_running
).
formatLocal
(
Locale
.
ENGLISH
,
config
.
profileName
),
true
)
}
}
else
if
(
action
==
Intent
.
ACTION_USER_PRESENT
)
{
notifyForegroundAlert
(
getString
(
R
.
string
.
forward_success
),
getString
(
R
.
string
.
service_running
).
formatLocal
(
Locale
.
ENGLISH
,
config
.
profileName
),
true
)
}
}
}
}
}
else
if
(
action
==
Intent
.
ACTION_USER_PRESENT
)
{
notifyForegroundAlert
(
getString
(
R
.
string
.
forward_success
),
getString
(
R
.
string
.
service_running
).
formatLocal
(
Locale
.
ENGLISH
,
config
.
profileName
),
true
)
}
}
}
registerReceiver
(
lockReceiver
,
screenFilter
)
registerReceiver
(
lockReceiver
,
screenFilter
)
}
}
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
View file @
d111bc82
...
@@ -57,11 +57,7 @@ class ShadowsocksRunnerActivity extends Activity {
...
@@ -57,11 +57,7 @@ class ShadowsocksRunnerActivity extends Activity {
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
)
handler
.
postDelayed
(
new
Runnable
()
{
handler
.
postDelayed
(()
=>
if
(
bgService
!=
null
)
startBackgroundService
(),
1000
)
override
def
run
()
{
if
(
bgService
!=
null
)
startBackgroundService
()
}
},
1000
)
}
}
override
def
onServiceDisconnected
(
name
:
ComponentName
)
{
override
def
onServiceDisconnected
(
name
:
ComponentName
)
{
bgService
=
null
bgService
=
null
...
@@ -122,11 +118,9 @@ class ShadowsocksRunnerActivity extends Activity {
...
@@ -122,11 +118,9 @@ class ShadowsocksRunnerActivity extends Activity {
val
locked
=
km
.
inKeyguardRestrictedInputMode
val
locked
=
km
.
inKeyguardRestrictedInputMode
if
(
locked
)
{
if
(
locked
)
{
val
filter
=
new
IntentFilter
(
Intent
.
ACTION_USER_PRESENT
)
val
filter
=
new
IntentFilter
(
Intent
.
ACTION_USER_PRESENT
)
receiver
=
new
BroadcastReceiver
()
{
receiver
=
(
context
:
Context
,
intent
:
Intent
)
=>
{
override
def
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
if
(
intent
.
getAction
==
Intent
.
ACTION_USER_PRESENT
)
{
if
(
intent
.
getAction
==
Intent
.
ACTION_USER_PRESENT
)
{
attachService
()
attachService
()
}
}
}
}
}
registerReceiver
(
receiver
,
filter
)
registerReceiver
(
receiver
,
filter
)
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
View file @
d111bc82
...
@@ -208,11 +208,9 @@ class ShadowsocksVpnService extends VpnService with BaseService {
...
@@ -208,11 +208,9 @@ class ShadowsocksVpnService extends VpnService with BaseService {
// register close receiver
// register close receiver
val
filter
=
new
IntentFilter
()
val
filter
=
new
IntentFilter
()
filter
.
addAction
(
Intent
.
ACTION_SHUTDOWN
)
filter
.
addAction
(
Intent
.
ACTION_SHUTDOWN
)
receiver
=
new
BroadcastReceiver
{
receiver
=
(
p1
:
Context
,
p2
:
Intent
)
=>
{
def
onReceive
(
p1
:
Context
,
p2
:
Intent
)
{
Toast
.
makeText
(
p1
,
R
.
string
.
stopping
,
Toast
.
LENGTH_SHORT
)
Toast
.
makeText
(
p1
,
R
.
string
.
stopping
,
Toast
.
LENGTH_SHORT
)
stopRunner
()
stopRunner
()
}
}
}
registerReceiver
(
receiver
,
filter
)
registerReceiver
(
receiver
,
filter
)
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksVpnThread.scala
View file @
d111bc82
...
@@ -93,35 +93,34 @@ class ShadowsocksVpnThread(vpnService: ShadowsocksVpnService) extends Thread {
...
@@ -93,35 +93,34 @@ class ShadowsocksVpnThread(vpnService: ShadowsocksVpnService) extends Thread {
try
{
try
{
val
socket
=
serverSocket
.
accept
()
val
socket
=
serverSocket
.
accept
()
pool
.
execute
(
new
Runnable
{
pool
.
execute
(()
=>
{
override
def
run
()
{
try
{
try
{
val
input
=
socket
.
getInputStream
val
input
=
socket
.
getInputStream
val
output
=
socket
.
getOutputStream
val
output
=
socket
.
getOutputStream
input
.
read
()
val
fds
=
socket
.
getAncillaryFileDescriptors
input
.
read
()
if
(
fds
.
nonEmpty
)
{
val
fds
=
socket
.
getAncillaryFileDescriptors
var
ret
=
false
val
getInt
=
classOf
[
FileDescriptor
].
getDeclaredMethod
(
"getInt$"
)
if
(
fds
.
nonEmpty
)
{
val
fd
=
getInt
.
invoke
(
fds
(
0
)).
asInstanceOf
[
Int
]
var
ret
=
false
ret
=
vpnService
.
protect
(
fd
)
// Trick to close file decriptor
val
getInt
=
classOf
[
FileDescriptor
].
getDeclaredMethod
(
"getInt$"
)
System
.
jniclose
(
fd
)
val
fd
=
getInt
.
invoke
(
fds
(
0
)).
asInstanceOf
[
Int
]
ret
=
vpnService
.
protect
(
fd
)
if
(
ret
)
{
// Trick to close file decriptor
output
.
write
(
0
)
System
.
jniclose
(
fd
)
}
else
{
output
.
write
(
1
)
}
input
.
close
()
if
(
ret
)
{
output
.
close
()
output
.
write
(
0
)
}
else
{
output
.
write
(
1
)
}
}
input
.
close
()
output
.
close
()
}
}
catch
{
}
catch
{
case
e
:
Exception
=>
case
e
:
Exception
=>
Log
.
e
(
TAG
,
"Error when protect socket"
,
e
)
Log
.
e
(
TAG
,
"Error when protect socket"
,
e
)
...
@@ -134,7 +133,7 @@ class ShadowsocksVpnThread(vpnService: ShadowsocksVpnService) extends Thread {
...
@@ -134,7 +133,7 @@ class ShadowsocksVpnThread(vpnService: ShadowsocksVpnService) extends Thread {
case
_:
Exception
=>
// ignore
case
_:
Exception
=>
// ignore
}
}
}
}
)
})
}
catch
{
}
catch
{
case
e
:
IOException
=>
case
e
:
IOException
=>
Log
.
e
(
TAG
,
"Error when accept socket"
,
e
)
Log
.
e
(
TAG
,
"Error when accept socket"
,
e
)
...
...
src/main/scala/com/github/shadowsocks/database/MenuAdapter.scala
View file @
d111bc82
...
@@ -40,14 +40,10 @@
...
@@ -40,14 +40,10 @@
package
com.github.shadowsocks.database
package
com.github.shadowsocks.database
import
android.content.Context
import
android.content.Context
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.BaseAdapter
import
android.widget.TextView
import
android.graphics.drawable.Drawable
import
android.graphics.drawable.Drawable
import
android.view.
{
LayoutInflater
,
View
,
ViewGroup
}
import
android.widget.
{
BaseAdapter
,
TextView
}
import
com.github.shadowsocks.R
import
com.github.shadowsocks.R
import
android.view.View.
{
OnLongClickListener
,
OnClickListener
}
abstract
class
Item
{
abstract
class
Item
{
def
id
:
Int
def
id
:
Int
...
@@ -147,17 +143,13 @@ class MenuAdapter(context: Context, var items: List[Any]) extends BaseAdapter {
...
@@ -147,17 +143,13 @@ class MenuAdapter(context: Context, var items: List[Any]) extends BaseAdapter {
}
}
}
}
tv
.
setOnClickListener
(
new
OnClickListener
{
tv
.
setOnClickListener
((
view
:
View
)
=>
{
def
onClick
(
view
:
View
)
{
val
item
=
view
.
getTag
(
R
.
id
.
mdItem
).
asInstanceOf
[
Item
]
val
item
=
view
.
getTag
(
R
.
id
.
mdItem
).
asInstanceOf
[
Item
]
item
.
click
(
item
.
id
)
item
.
click
(
item
.
id
)
}
})
})
tv
.
setOnLongClickListener
(
new
OnLongClickListener
{
tv
.
setOnLongClickListener
((
view
:
View
)
=>
{
def
onLongClick
(
view
:
View
)
:
Boolean
=
{
val
item
=
view
.
getTag
(
R
.
id
.
mdItem
).
asInstanceOf
[
Item
]
val
item
=
view
.
getTag
(
R
.
id
.
mdItem
).
asInstanceOf
[
Item
]
item
.
longClick
(
item
.
id
)
item
.
longClick
(
item
.
id
)
}
})
})
v
.
setTag
(
R
.
id
.
mdItem
,
value
)
v
.
setTag
(
R
.
id
.
mdItem
,
value
)
...
...
src/main/scala/com/github/shadowsocks/utils/Console.scala
View file @
d111bc82
...
@@ -39,10 +39,11 @@
...
@@ -39,10 +39,11 @@
package
com.github.shadowsocks.utils
package
com.github.shadowsocks.utils
import
eu.chainfire.libsuperuser.Shell
import
eu.chainfire.libsuperuser.Shell.
{
OnCommandResultListener
,
SU
,
Builder
}
import
java.util
import
java.util
import
eu.chainfire.libsuperuser.Shell
import
eu.chainfire.libsuperuser.Shell.
{
Builder
,
SU
}
object
Console
{
object
Console
{
private
def
openShell
()
:
Shell.Interactive
=
{
private
def
openShell
()
:
Shell.Interactive
=
{
...
@@ -68,14 +69,8 @@ object Console {
...
@@ -68,14 +69,8 @@ object Console {
def
runCommand
(
commands
:
Array
[
String
])
{
def
runCommand
(
commands
:
Array
[
String
])
{
val
shell
=
openShell
()
val
shell
=
openShell
()
shell
.
addCommand
(
commands
,
0
,
new
OnCommandResultListener
{
shell
.
addCommand
(
commands
,
0
,
((
commandCode
:
Int
,
exitCode
:
Int
,
output
:
util.List
[
String
])
=>
override
def
onCommandResult
(
commandCode
:
Int
,
exitCode
:
Int
,
if
(
exitCode
<
0
)
shell
.
close
())
:
Shell.OnCommandResultListener
)
output
:
util.List
[
String
])
{
if
(
exitCode
<
0
)
{
shell
.
close
()
}
}
})
shell
.
waitForIdle
()
shell
.
waitForIdle
()
shell
.
close
()
shell
.
close
()
}
}
...
@@ -90,17 +85,14 @@ object Console {
...
@@ -90,17 +85,14 @@ object Console {
}
}
val
shell
=
openRootShell
(
context
)
val
shell
=
openRootShell
(
context
)
val
sb
=
new
StringBuilder
val
sb
=
new
StringBuilder
shell
.
addCommand
(
commands
,
0
,
new
OnCommandResultListener
{
shell
.
addCommand
(
commands
,
0
,
((
commandCode
:
Int
,
exitCode
:
Int
,
output
:
util.List
[
String
])
=>
{
override
def
onCommandResult
(
commandCode
:
Int
,
exitCode
:
Int
,
if
(
exitCode
<
0
)
{
output
:
util.List
[
String
])
{
shell
.
close
()
if
(
exitCode
<
0
)
{
}
else
{
shell
.
close
()
import
scala.collection.JavaConversions._
}
else
{
output
.
foreach
(
line
=>
sb
.
append
(
line
).
append
(
'\n'
))
import
scala.collection.JavaConversions._
output
.
foreach
(
line
=>
sb
.
append
(
line
).
append
(
'\n'
))
}
}
}
})
})
:
Shell.OnCommandResultListener
)
if
(
shell
.
waitForIdle
())
{
if
(
shell
.
waitForIdle
())
{
shell
.
close
()
shell
.
close
()
sb
.
toString
()
sb
.
toString
()
...
...
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