@@ -6,11 +6,13 @@ platformTarget in Android := "android-23"
|
||||
|
||||
name := "shadowsocks"
|
||||
|
||||
scalaVersion := "2.11.7"
|
||||
|
||||
compileOrder in Compile := CompileOrder.JavaThenScala
|
||||
|
||||
javacOptions ++= Seq("-source", "1.6", "-target", "1.6")
|
||||
|
||||
scalacOptions += "-target:jvm-1.6"
|
||||
scalacOptions ++= Seq("-target:jvm-1.6", "-Xexperimental")
|
||||
|
||||
ndkJavah in Android := List()
|
||||
|
||||
@@ -24,26 +26,20 @@ resolvers += "JRAF" at "http://JRAF.org/static/maven/2"
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"dnsjava" % "dnsjava" % "2.1.7",
|
||||
"com.github.kevinsawicki" % "http-request" % "5.6",
|
||||
"com.github.kevinsawicki" % "http-request" % "6.0",
|
||||
"commons-net" % "commons-net" % "3.3",
|
||||
"com.google.zxing" % "android-integration" % "3.1.0"
|
||||
)
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"com.joanzapata.android" % "android-iconify" % "1.0.9",
|
||||
"com.google.zxing" % "android-integration" % "3.1.0",
|
||||
"com.joanzapata.android" % "android-iconify" % "1.0.11",
|
||||
"net.glxn.qrgen" % "android" % "2.0",
|
||||
"net.simonvt.menudrawer" % "menudrawer" % "3.0.6",
|
||||
"com.google.android.gms" % "play-services-base" % "8.1.0",
|
||||
"com.google.android.gms" % "play-services-ads" % "8.1.0",
|
||||
"com.google.android.gms" % "play-services-analytics" % "8.1.0",
|
||||
"com.android.support" % "support-v4" % "23.0.1"
|
||||
)
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"com.android.support" % "support-v4" % "23.0.1",
|
||||
"com.github.mrengineer13" % "snackbar" % "0.5.0",
|
||||
"com.nostra13.universalimageloader" % "universal-image-loader" % "1.8.4",
|
||||
"com.j256.ormlite" % "ormlite-core" % "4.47",
|
||||
"com.j256.ormlite" % "ormlite-android" % "4.47"
|
||||
"com.j256.ormlite" % "ormlite-core" % "4.48",
|
||||
"com.j256.ormlite" % "ormlite-android" % "4.48"
|
||||
)
|
||||
|
||||
proguardOptions in Android ++= Seq("-keep class android.support.v4.app.** { *; }",
|
||||
|
||||
@@ -65,7 +65,8 @@ import com.nostra13.universalimageloader.core.{DisplayImageOptions, ImageLoader,
|
||||
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer
|
||||
import com.github.shadowsocks.utils.{Utils, Scheme, Key}
|
||||
|
||||
import scala.concurrent.ops._
|
||||
import scala.concurrent.ExecutionContext.Implicits.global
|
||||
import scala.concurrent.Future
|
||||
import scala.language.implicitConversions
|
||||
|
||||
case class ProxiedApp(uid: Int, name: String, packageName: String, var proxied: Boolean)
|
||||
@@ -267,9 +268,8 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
|
||||
}
|
||||
|
||||
protected override def onCreateOptionsMenu(menu: Menu): Boolean = {
|
||||
val inflater = getMenuInflater()
|
||||
inflater.inflate(R.menu.app_manager_menu, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
getMenuInflater.inflate(R.menu.app_manager_menu, menu)
|
||||
super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
protected override def onCreate(savedInstanceState: Bundle) {
|
||||
@@ -277,7 +277,7 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
|
||||
|
||||
handler = new Handler()
|
||||
|
||||
val actionBar = getActionBar()
|
||||
val actionBar = getActionBar
|
||||
actionBar.setTitle(R.string.proxied_help)
|
||||
actionBar.setDisplayHomeAsUpEnabled(true)
|
||||
actionBar.setDisplayShowHomeEnabled(false)
|
||||
@@ -297,11 +297,8 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
|
||||
|
||||
val bypassSwitch = findViewById(R.id.bypassSwitch).asInstanceOf[Switch]
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext)
|
||||
bypassSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener {
|
||||
def onCheckedChanged(button: CompoundButton, checked: Boolean) {
|
||||
prefs.edit().putBoolean(Key.isBypassApps, checked).commit()
|
||||
}
|
||||
})
|
||||
bypassSwitch.setOnCheckedChangeListener((button: CompoundButton, checked: Boolean) =>
|
||||
prefs.edit().putBoolean(Key.isBypassApps, checked).commit())
|
||||
bypassSwitch.setChecked(prefs.getBoolean(Key.isBypassApps, false))
|
||||
|
||||
appListView = findViewById(R.id.applistview).asInstanceOf[ListView]
|
||||
@@ -309,7 +306,7 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
|
||||
|
||||
protected override def onResume() {
|
||||
super.onResume()
|
||||
spawn {
|
||||
Future {
|
||||
handler.post(loadStartRunnable)
|
||||
if (!appsLoaded) loadApps()
|
||||
handler.post(loadFinishRunnable)
|
||||
|
||||
@@ -39,13 +39,11 @@
|
||||
|
||||
package com.github.shadowsocks
|
||||
|
||||
import android.os.{Handler, RemoteCallbackList}
|
||||
import com.github.shadowsocks.aidl.{Config, IShadowsocksService, IShadowsocksServiceCallback}
|
||||
import com.github.shadowsocks.utils.{Path, State}
|
||||
import java.io.{IOException, FileNotFoundException, FileReader, BufferedReader}
|
||||
import android.util.Log
|
||||
import android.app.Notification
|
||||
import android.content.Context
|
||||
import android.os.{Handler, RemoteCallbackList}
|
||||
import com.github.shadowsocks.aidl.{Config, IShadowsocksService, IShadowsocksServiceCallback}
|
||||
import com.github.shadowsocks.utils.State
|
||||
|
||||
trait BaseService {
|
||||
|
||||
@@ -100,10 +98,10 @@ trait BaseService {
|
||||
def getTag: String
|
||||
def getContext: Context
|
||||
|
||||
def getCallbackCount(): Int = {
|
||||
def getCallbackCount: Int = {
|
||||
callbackCount
|
||||
}
|
||||
def getState(): Int = {
|
||||
def getState: Int = {
|
||||
state
|
||||
}
|
||||
def changeState(s: Int) {
|
||||
@@ -112,23 +110,19 @@ trait BaseService {
|
||||
|
||||
protected def changeState(s: Int, msg: String) {
|
||||
val handler = new Handler(getContext.getMainLooper)
|
||||
handler.post(new Runnable {
|
||||
override def run() {
|
||||
if (state != s) {
|
||||
if (callbackCount > 0) {
|
||||
val n = callbacks.beginBroadcast()
|
||||
for (i <- 0 to n - 1) {
|
||||
try {
|
||||
callbacks.getBroadcastItem(i).stateChanged(s, msg)
|
||||
} catch {
|
||||
case _: Exception => // Ignore
|
||||
}
|
||||
}
|
||||
callbacks.finishBroadcast()
|
||||
handler.post(() => if (state != s) {
|
||||
if (callbackCount > 0) {
|
||||
val n = callbacks.beginBroadcast()
|
||||
for (i <- 0 to n - 1) {
|
||||
try {
|
||||
callbacks.getBroadcastItem(i).stateChanged(s, msg)
|
||||
} catch {
|
||||
case _: Exception => // Ignore
|
||||
}
|
||||
state = s
|
||||
}
|
||||
callbacks.finishBroadcast()
|
||||
}
|
||||
state = s
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -39,15 +39,15 @@
|
||||
|
||||
package com.github.shadowsocks
|
||||
|
||||
import android.os.{Message, Handler, Bundle}
|
||||
import android.app.{ProgressDialog, AlertDialog, Activity}
|
||||
import android.content.{Intent, DialogInterface}
|
||||
import com.github.shadowsocks.database.{ProfileManager, Profile}
|
||||
import com.github.shadowsocks.utils.{Parser, Action}
|
||||
import android.preference.PreferenceManager
|
||||
import android.view.WindowManager
|
||||
import android.app.{Activity, AlertDialog, ProgressDialog}
|
||||
import android.content.DialogInterface
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.{Bundle, Handler, Message}
|
||||
import android.preference.PreferenceManager
|
||||
import android.view.WindowManager
|
||||
import com.github.shadowsocks.database.{Profile, ProfileManager}
|
||||
import com.github.shadowsocks.utils.Parser
|
||||
|
||||
class ParserActivity extends Activity {
|
||||
override def onCreate(savedInstanceState: Bundle) {
|
||||
@@ -57,21 +57,17 @@ class ParserActivity extends Activity {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.add_profile_dialog)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
override def onClick(dialog: DialogInterface, id: Int) {
|
||||
.setPositiveButton(R.string.yes, ((dialog: DialogInterface, id: Int) => {
|
||||
Parser.parse(data) match {
|
||||
case Some(profile) => addProfile(profile)
|
||||
case _ => // ignore
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
override def onClick(dialog: DialogInterface, id: Int) {
|
||||
}): DialogInterface.OnClickListener)
|
||||
.setNegativeButton(R.string.no, ((dialog: DialogInterface, id: Int) => {
|
||||
dialog.dismiss()
|
||||
finish()
|
||||
}
|
||||
})
|
||||
}): DialogInterface.OnClickListener)
|
||||
.setMessage(data)
|
||||
.create()
|
||||
.show()
|
||||
@@ -91,15 +87,13 @@ class ParserActivity extends Activity {
|
||||
|
||||
val h = showProgress(getString(R.string.loading))
|
||||
|
||||
h.postDelayed(new Runnable {
|
||||
def run() {
|
||||
val profileManager =
|
||||
new ProfileManager(PreferenceManager.getDefaultSharedPreferences(getBaseContext),
|
||||
getApplication.asInstanceOf[ShadowsocksApplication].dbHelper)
|
||||
profileManager.createOrUpdateProfile(profile)
|
||||
profileManager.reload(profile.id)
|
||||
h.sendEmptyMessage(0)
|
||||
}
|
||||
h.postDelayed(() => {
|
||||
val profileManager =
|
||||
new ProfileManager(PreferenceManager.getDefaultSharedPreferences(getBaseContext),
|
||||
getApplication.asInstanceOf[ShadowsocksApplication].dbHelper)
|
||||
profileManager.createOrUpdateProfile(profile)
|
||||
profileManager.reload(profile.id)
|
||||
h.sendEmptyMessage(0)
|
||||
}, 600)
|
||||
}
|
||||
|
||||
|
||||
@@ -38,10 +38,9 @@
|
||||
*/
|
||||
package com.github.shadowsocks
|
||||
|
||||
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, FileOutputStream, IOException, InputStream, OutputStream}
|
||||
import java.util
|
||||
import java.io.{OutputStream, InputStream, ByteArrayInputStream, ByteArrayOutputStream, IOException, FileOutputStream}
|
||||
import java.util.Locale
|
||||
import java.lang.Math
|
||||
|
||||
import android.app.backup.BackupManager
|
||||
import android.app.{Activity, AlertDialog, ProgressDialog}
|
||||
@@ -52,8 +51,8 @@ import android.graphics.{Bitmap, Color, Typeface}
|
||||
import android.net.{Uri, VpnService}
|
||||
import android.os._
|
||||
import android.preference._
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.util.{DisplayMetrics, Log}
|
||||
import android.view.View.OnLongClickListener
|
||||
import android.view._
|
||||
import android.webkit.{WebView, WebViewClient}
|
||||
import android.widget._
|
||||
@@ -65,15 +64,15 @@ import com.github.shadowsocks.utils._
|
||||
import com.google.android.gms.ads.{AdRequest, AdSize, AdView}
|
||||
import com.google.android.gms.analytics.HitBuilders
|
||||
import com.google.zxing.integration.android.IntentIntegrator
|
||||
import com.nostra13.universalimageloader.core.download.BaseImageDownloader
|
||||
import net.simonvt.menudrawer.MenuDrawer
|
||||
import com.joanzapata.android.iconify.Iconify
|
||||
import com.joanzapata.android.iconify.Iconify.IconValue
|
||||
import com.joanzapata.android.iconify.IconDrawable
|
||||
import com.joanzapata.android.iconify.Iconify.IconValue
|
||||
import com.nostra13.universalimageloader.core.download.BaseImageDownloader
|
||||
import net.glxn.qrgen.android.QRCode
|
||||
import net.simonvt.menudrawer.MenuDrawer
|
||||
|
||||
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
|
||||
import scala.concurrent.ops._
|
||||
import scala.concurrent.ExecutionContext.Implicits.global
|
||||
import scala.concurrent.Future
|
||||
|
||||
class ProfileIconDownloader(context: Context, connectTimeout: Int, readTimeout: Int)
|
||||
extends BaseImageDownloader(context, connectTimeout, readTimeout) {
|
||||
@@ -224,7 +223,7 @@ class Shadowsocks
|
||||
|
||||
if (!status.getBoolean(getVersionName, false)) {
|
||||
status.edit.putBoolean(getVersionName, true).commit()
|
||||
recovery();
|
||||
recovery()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,11 +269,7 @@ class Shadowsocks
|
||||
switchButton.setChecked(checked)
|
||||
if (switchButton.isEnabled) {
|
||||
switchButton.setEnabled(false)
|
||||
handler.postDelayed(new Runnable {
|
||||
override def run() {
|
||||
switchButton.setEnabled(true)
|
||||
}
|
||||
}, 1000)
|
||||
handler.postDelayed(() => switchButton.setEnabled(true), 1000)
|
||||
}
|
||||
switchButton.setOnCheckedChangeListener(this)
|
||||
}
|
||||
@@ -396,7 +391,7 @@ class Shadowsocks
|
||||
changeSwitch(checked = false)
|
||||
}
|
||||
|
||||
def isReady(): Boolean = {
|
||||
def isReady: Boolean = {
|
||||
if (!checkText(Key.proxy)) return false
|
||||
if (!checkText(Key.sitekey)) return false
|
||||
if (!checkNumber(Key.localPort, low = false)) return false
|
||||
@@ -407,7 +402,7 @@ class Shadowsocks
|
||||
|
||||
def prepareStartService() {
|
||||
showProgress(R.string.connecting)
|
||||
spawn {
|
||||
Future {
|
||||
if (isVpnEnabled) {
|
||||
val intent = VpnService.prepare(this)
|
||||
if (intent != null) {
|
||||
@@ -434,11 +429,7 @@ class Shadowsocks
|
||||
}
|
||||
if (switchButton.isEnabled) {
|
||||
switchButton.setEnabled(false)
|
||||
handler.postDelayed(new Runnable {
|
||||
override def run() {
|
||||
switchButton.setEnabled(true)
|
||||
}
|
||||
}, 1000)
|
||||
handler.postDelayed(() => switchButton.setEnabled(true), 1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -522,28 +513,26 @@ class Shadowsocks
|
||||
getActionBar.setDisplayShowTitleEnabled(false)
|
||||
getActionBar.setDisplayShowCustomEnabled(true)
|
||||
if (Utils.isLollipopOrAbove) {
|
||||
getWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
getWindow.setStatusBarColor(getResources().getColor(R.color.grey3));
|
||||
getWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||
getWindow.setStatusBarColor(ContextCompat.getColor(this, R.color.grey3))
|
||||
getActionBar.setDisplayHomeAsUpEnabled(true)
|
||||
getActionBar.setHomeAsUpIndicator(R.drawable.ic_drawer)
|
||||
} else {
|
||||
getActionBar.setIcon(R.drawable.ic_stat_shadowsocks)
|
||||
}
|
||||
title.setOnLongClickListener(new OnLongClickListener {
|
||||
override def onLongClick(v: View): Boolean = {
|
||||
if (Utils.isLollipopOrAbove && bgService != null
|
||||
&& (bgService.getState == State.INIT || bgService.getState == State.STOPPED)) {
|
||||
val natEnabled = status.getBoolean(Key.isNAT, false)
|
||||
status.edit().putBoolean(Key.isNAT, !natEnabled).commit()
|
||||
if (!natEnabled) {
|
||||
Toast.makeText(getBaseContext, R.string.enable_nat, Toast.LENGTH_LONG).show()
|
||||
} else {
|
||||
Toast.makeText(getBaseContext, R.string.disable_nat, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
true
|
||||
title.setOnLongClickListener((v: View) => {
|
||||
if (Utils.isLollipopOrAbove && bgService != null
|
||||
&& (bgService.getState == State.INIT || bgService.getState == State.STOPPED)) {
|
||||
val natEnabled = status.getBoolean(Key.isNAT, false)
|
||||
status.edit().putBoolean(Key.isNAT, !natEnabled).commit()
|
||||
if (!natEnabled) {
|
||||
Toast.makeText(getBaseContext, R.string.enable_nat, Toast.LENGTH_LONG).show()
|
||||
} else {
|
||||
false
|
||||
Toast.makeText(getBaseContext, R.string.disable_nat, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
|
||||
@@ -551,13 +540,11 @@ class Shadowsocks
|
||||
registerReceiver(preferenceReceiver, new IntentFilter(Action.UPDATE_PREFS))
|
||||
|
||||
// Bind to the service
|
||||
spawn {
|
||||
Future {
|
||||
val isRoot = (!Utils.isLollipopOrAbove || status.getBoolean(Key.isNAT, false)) && Console.isRoot
|
||||
handler.post(new Runnable {
|
||||
override def run() {
|
||||
status.edit.putBoolean(Key.isRoot, isRoot).commit()
|
||||
attachService()
|
||||
}
|
||||
handler.post(() => {
|
||||
status.edit.putBoolean(Key.isRoot, isRoot).commit()
|
||||
attachService()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -613,29 +600,23 @@ class Shadowsocks
|
||||
val builder = new AlertDialog.Builder(this)
|
||||
builder
|
||||
.setTitle(R.string.add_profile)
|
||||
.setItems(R.array.add_profile_methods, new DialogInterface.OnClickListener() {
|
||||
def onClick(dialog: DialogInterface, which: Int) {
|
||||
which match {
|
||||
case 0 =>
|
||||
dialog.dismiss()
|
||||
val h = showProgress(R.string.loading)
|
||||
h.postDelayed(new Runnable() {
|
||||
def run() {
|
||||
val integrator = new IntentIntegrator(Shadowsocks.this)
|
||||
val list = new java.util.ArrayList(IntentIntegrator.TARGET_ALL_KNOWN)
|
||||
list.add("tw.com.quickmark")
|
||||
integrator.setTargetApplications(list)
|
||||
integrator.initiateScan()
|
||||
h.sendEmptyMessage(0)
|
||||
}
|
||||
}, 600)
|
||||
case 1 =>
|
||||
dialog.dismiss()
|
||||
addProfile(id)
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
})
|
||||
.setItems(R.array.add_profile_methods, ((dialog: DialogInterface, which: Int) => which match {
|
||||
case 0 =>
|
||||
dialog.dismiss()
|
||||
val h = showProgress(R.string.loading)
|
||||
h.postDelayed(() => {
|
||||
val integrator = new IntentIntegrator(Shadowsocks.this)
|
||||
val list = new java.util.ArrayList(IntentIntegrator.TARGET_ALL_KNOWN)
|
||||
list.add("tw.com.quickmark")
|
||||
integrator.setTargetApplications(list)
|
||||
integrator.initiateScan()
|
||||
h.sendEmptyMessage(0)
|
||||
}, 600)
|
||||
case 1 =>
|
||||
dialog.dismiss()
|
||||
addProfile(id)
|
||||
case _ =>
|
||||
}): DialogInterface.OnClickListener)
|
||||
builder.create().show()
|
||||
}
|
||||
|
||||
@@ -644,17 +625,15 @@ class Shadowsocks
|
||||
|
||||
val h = showProgress(R.string.loading)
|
||||
|
||||
handler.postDelayed(new Runnable {
|
||||
def run() {
|
||||
currentProfile = {
|
||||
profileManager.getProfile(settings.getInt(Key.profileId, -1)) getOrElse currentProfile
|
||||
}
|
||||
menuAdapter.updateList(getMenuList, currentProfile.id)
|
||||
|
||||
updatePreferenceScreen()
|
||||
|
||||
h.sendEmptyMessage(0)
|
||||
handler.postDelayed(() => {
|
||||
currentProfile = {
|
||||
profileManager.getProfile(settings.getInt(Key.profileId, -1)) getOrElse currentProfile
|
||||
}
|
||||
menuAdapter.updateList(getMenuList, currentProfile.id)
|
||||
|
||||
updatePreferenceScreen()
|
||||
|
||||
h.sendEmptyMessage(0)
|
||||
}, 600)
|
||||
}
|
||||
|
||||
@@ -663,17 +642,15 @@ class Shadowsocks
|
||||
|
||||
val h = showProgress(R.string.loading)
|
||||
|
||||
handler.postDelayed(new Runnable {
|
||||
def run() {
|
||||
currentProfile = profile
|
||||
profileManager.createOrUpdateProfile(currentProfile)
|
||||
profileManager.reload(currentProfile.id)
|
||||
menuAdapter.updateList(getMenuList, currentProfile.id)
|
||||
handler.postDelayed(() => {
|
||||
currentProfile = profile
|
||||
profileManager.createOrUpdateProfile(currentProfile)
|
||||
profileManager.reload(currentProfile.id)
|
||||
menuAdapter.updateList(getMenuList, currentProfile.id)
|
||||
|
||||
updatePreferenceScreen()
|
||||
updatePreferenceScreen()
|
||||
|
||||
h.sendEmptyMessage(0)
|
||||
}
|
||||
h.sendEmptyMessage(0)
|
||||
}, 600)
|
||||
}
|
||||
|
||||
@@ -682,16 +659,14 @@ class Shadowsocks
|
||||
|
||||
val h = showProgress(R.string.loading)
|
||||
|
||||
handler.postDelayed(new Runnable {
|
||||
def run() {
|
||||
currentProfile = profileManager.reload(id)
|
||||
profileManager.save()
|
||||
menuAdapter.updateList(getMenuList, currentProfile.id)
|
||||
handler.postDelayed(() => {
|
||||
currentProfile = profileManager.reload(id)
|
||||
profileManager.save()
|
||||
menuAdapter.updateList(getMenuList, currentProfile.id)
|
||||
|
||||
updatePreferenceScreen()
|
||||
updatePreferenceScreen()
|
||||
|
||||
h.sendEmptyMessage(0)
|
||||
}
|
||||
h.sendEmptyMessage(0)
|
||||
}, 600)
|
||||
}
|
||||
|
||||
@@ -700,16 +675,14 @@ class Shadowsocks
|
||||
|
||||
val h = showProgress(R.string.loading)
|
||||
|
||||
handler.postDelayed(new Runnable {
|
||||
def run() {
|
||||
currentProfile = profileManager.reload(id)
|
||||
menuAdapter.setActiveId(id)
|
||||
menuAdapter.notifyDataSetChanged()
|
||||
handler.postDelayed(() => {
|
||||
currentProfile = profileManager.reload(id)
|
||||
menuAdapter.setActiveId(id)
|
||||
menuAdapter.notifyDataSetChanged()
|
||||
|
||||
updatePreferenceScreen()
|
||||
updatePreferenceScreen()
|
||||
|
||||
h.sendEmptyMessage(0)
|
||||
}
|
||||
h.sendEmptyMessage(0)
|
||||
}, 600)
|
||||
}
|
||||
|
||||
@@ -718,20 +691,18 @@ class Shadowsocks
|
||||
|
||||
val profile = profileManager.getProfile(id)
|
||||
|
||||
if (!profile.isDefined) return false
|
||||
if (profile.isEmpty) return false
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(String.format(Locale.ENGLISH, getString(R.string.remove_profile), profile.get.name))
|
||||
.setCancelable(false)
|
||||
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
override def onClick(dialog: DialogInterface, i: Int) = dialog.cancel()
|
||||
})
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
override def onClick(dialog: DialogInterface, i: Int) {
|
||||
.setNegativeButton(R.string.no,
|
||||
((dialog: DialogInterface, i: Int) => dialog.cancel()): DialogInterface.OnClickListener)
|
||||
.setPositiveButton(R.string.yes, ((dialog: DialogInterface, i: Int) => {
|
||||
profileManager.delProfile(id)
|
||||
val profileId = {
|
||||
val profiles = profileManager.getAllProfiles.getOrElse(List[Profile]())
|
||||
if (profiles.isEmpty) -1 else profiles(0).id
|
||||
if (profiles.isEmpty) -1 else profiles.head.id
|
||||
}
|
||||
currentProfile = profileManager.load(profileId)
|
||||
menuAdapter.updateList(getMenuList, currentProfile.id)
|
||||
@@ -739,8 +710,7 @@ class Shadowsocks
|
||||
updatePreferenceScreen()
|
||||
|
||||
dialog.dismiss()
|
||||
}
|
||||
})
|
||||
}): DialogInterface.OnClickListener)
|
||||
.create()
|
||||
.show()
|
||||
|
||||
@@ -934,16 +904,14 @@ class Shadowsocks
|
||||
private def recovery() {
|
||||
serviceStop()
|
||||
val h = showProgress(R.string.recovering)
|
||||
spawn {
|
||||
Future {
|
||||
reset()
|
||||
h.sendEmptyMessage(0)
|
||||
}
|
||||
}
|
||||
|
||||
private def dp2px(dp: Int): Int = {
|
||||
val displayMetrics = getBaseContext.getResources.getDisplayMetrics()
|
||||
Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT))
|
||||
}
|
||||
private def dp2px(dp: Int): Int =
|
||||
Math.round(dp * (getBaseContext.getResources.getDisplayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT))
|
||||
|
||||
private def showQrCode() {
|
||||
val image = new ImageView(this)
|
||||
@@ -955,11 +923,8 @@ class Shadowsocks
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setCancelable(true)
|
||||
.setNegativeButton(getString(R.string.close), new DialogInterface.OnClickListener() {
|
||||
override def onClick(dialog: DialogInterface, id: Int) {
|
||||
dialog.cancel()
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getString(R.string.close),
|
||||
((dialog: DialogInterface, id: Int) => dialog.cancel()): DialogInterface.OnClickListener)
|
||||
.setView(image)
|
||||
.create()
|
||||
.show()
|
||||
@@ -967,7 +932,7 @@ class Shadowsocks
|
||||
|
||||
private def flushDnsCache() {
|
||||
val h = showProgress(R.string.flushing)
|
||||
spawn {
|
||||
Future {
|
||||
Utils.toggleAirplaneMode(getBaseContext)
|
||||
h.sendEmptyMessage(0)
|
||||
}
|
||||
@@ -1070,11 +1035,8 @@ class Shadowsocks
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.about_title).formatLocal(Locale.ENGLISH, versionName))
|
||||
.setCancelable(false)
|
||||
.setNegativeButton(getString(R.string.ok_iknow), new DialogInterface.OnClickListener() {
|
||||
override def onClick(dialog: DialogInterface, id: Int) {
|
||||
dialog.cancel()
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getString(R.string.ok_iknow),
|
||||
((dialog: DialogInterface, id: Int) => dialog.cancel()): DialogInterface.OnClickListener)
|
||||
.setView(web)
|
||||
.create()
|
||||
.show()
|
||||
@@ -1089,46 +1051,42 @@ class Shadowsocks
|
||||
}
|
||||
|
||||
def onStateChanged(s: Int, m: String) {
|
||||
handler.post(new Runnable {
|
||||
override def run() {
|
||||
if (state != s) {
|
||||
state = s
|
||||
state match {
|
||||
case State.CONNECTING =>
|
||||
if (progressDialog == null) {
|
||||
progressDialog = ProgressDialog
|
||||
.show(Shadowsocks.this, "", getString(R.string.connecting), true, true)
|
||||
progressTag = R.string.connecting
|
||||
}
|
||||
setPreferenceEnabled(enabled = false)
|
||||
case State.CONNECTED =>
|
||||
if (progressTag == R.string.connecting) {
|
||||
clearDialog()
|
||||
}
|
||||
changeSwitch(checked = true)
|
||||
setPreferenceEnabled(enabled = false)
|
||||
case State.STOPPED =>
|
||||
if (progressTag == R.string.stopping || progressTag == R.string.connecting) {
|
||||
clearDialog()
|
||||
}
|
||||
changeSwitch(checked = false)
|
||||
if (m != null) {
|
||||
new SnackBar.Builder(Shadowsocks.this)
|
||||
.withMessage(getString(R.string.vpn_error).formatLocal(Locale.ENGLISH, m))
|
||||
.withActionMessageId(R.string.error)
|
||||
.withStyle(SnackBar.Style.ALERT)
|
||||
.withDuration(SnackBar.LONG_SNACK)
|
||||
.show()
|
||||
}
|
||||
setPreferenceEnabled(enabled = true)
|
||||
case State.STOPPING =>
|
||||
if (progressDialog == null) {
|
||||
progressDialog = ProgressDialog
|
||||
.show(Shadowsocks.this, "", getString(R.string.stopping), true, true)
|
||||
progressTag = R.string.stopping
|
||||
}
|
||||
handler.post(() => if (state != s) {
|
||||
state = s
|
||||
state match {
|
||||
case State.CONNECTING =>
|
||||
if (progressDialog == null) {
|
||||
progressDialog = ProgressDialog
|
||||
.show(Shadowsocks.this, "", getString(R.string.connecting), true, true)
|
||||
progressTag = R.string.connecting
|
||||
}
|
||||
setPreferenceEnabled(enabled = false)
|
||||
case State.CONNECTED =>
|
||||
if (progressTag == R.string.connecting) {
|
||||
clearDialog()
|
||||
}
|
||||
changeSwitch(checked = true)
|
||||
setPreferenceEnabled(enabled = false)
|
||||
case State.STOPPED =>
|
||||
if (progressTag == R.string.stopping || progressTag == R.string.connecting) {
|
||||
clearDialog()
|
||||
}
|
||||
changeSwitch(checked = false)
|
||||
if (m != null) {
|
||||
new SnackBar.Builder(Shadowsocks.this)
|
||||
.withMessage(getString(R.string.vpn_error).formatLocal(Locale.ENGLISH, m))
|
||||
.withActionMessageId(R.string.error)
|
||||
.withStyle(SnackBar.Style.ALERT)
|
||||
.withDuration(SnackBar.LONG_SNACK)
|
||||
.show()
|
||||
}
|
||||
setPreferenceEnabled(enabled = true)
|
||||
case State.STOPPING =>
|
||||
if (progressDialog == null) {
|
||||
progressDialog = ProgressDialog
|
||||
.show(Shadowsocks.this, "", getString(R.string.stopping), true, true)
|
||||
progressTag = R.string.stopping
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -47,7 +47,6 @@ import com.github.shadowsocks.database.DBHelper
|
||||
import com.github.shadowsocks.utils.Utils
|
||||
import com.google.android.gms.analytics.GoogleAnalytics
|
||||
import com.google.android.gms.common.api.ResultCallback
|
||||
import com.google.android.gms.tagmanager.Container.FunctionCallMacroCallback
|
||||
import com.google.android.gms.tagmanager.{ContainerHolder, TagManager}
|
||||
|
||||
class ShadowsocksApplication extends Application {
|
||||
@@ -66,14 +65,13 @@ class ShadowsocksApplication extends Application {
|
||||
}
|
||||
containerHolder = holder
|
||||
val container = holder.getContainer
|
||||
container.registerFunctionCallMacroCallback(SIG_FUNC, new FunctionCallMacroCallback {
|
||||
override def getValue(functionName: String, parameters: util.Map[String, AnyRef]): AnyRef = {
|
||||
container.registerFunctionCallMacroCallback(SIG_FUNC,
|
||||
(functionName: String, parameters: util.Map[String, AnyRef]) => {
|
||||
if (functionName == SIG_FUNC) {
|
||||
Utils.getSignature(getApplicationContext)
|
||||
}
|
||||
null
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
pending.setResultCallback(callback, 2, TimeUnit.SECONDS)
|
||||
|
||||
@@ -58,7 +58,8 @@ import com.google.android.gms.analytics.HitBuilders
|
||||
|
||||
import scala.collection._
|
||||
import scala.collection.mutable.ArrayBuffer
|
||||
import scala.concurrent.ops._
|
||||
import scala.concurrent.ExecutionContext.Implicits.global
|
||||
import scala.concurrent.Future
|
||||
|
||||
class ShadowsocksNatService extends Service with BaseService {
|
||||
|
||||
@@ -172,11 +173,7 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
|
||||
def initConnectionReceiver() {
|
||||
val filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
|
||||
connReceiver = new BroadcastReceiver {
|
||||
override def onReceive(context: Context, intent: Intent) = {
|
||||
setupDns()
|
||||
}
|
||||
}
|
||||
connReceiver = (context: Context, intent: Intent) => setupDns()
|
||||
registerReceiver(connReceiver, filter)
|
||||
}
|
||||
|
||||
@@ -511,11 +508,9 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
val filter = new IntentFilter()
|
||||
filter.addAction(Intent.ACTION_SHUTDOWN)
|
||||
filter.addAction(Action.CLOSE)
|
||||
closeReceiver = new BroadcastReceiver() {
|
||||
def onReceive(context: Context, intent: Intent) {
|
||||
Toast.makeText(context, R.string.stopping, Toast.LENGTH_SHORT).show()
|
||||
stopRunner()
|
||||
}
|
||||
closeReceiver = (context: Context, intent: Intent) => {
|
||||
Toast.makeText(context, R.string.stopping, Toast.LENGTH_SHORT).show()
|
||||
stopRunner()
|
||||
}
|
||||
registerReceiver(closeReceiver, filter)
|
||||
|
||||
@@ -524,26 +519,22 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
screenFilter.addAction(Intent.ACTION_SCREEN_ON)
|
||||
screenFilter.addAction(Intent.ACTION_SCREEN_OFF)
|
||||
screenFilter.addAction(Intent.ACTION_USER_PRESENT)
|
||||
lockReceiver = new BroadcastReceiver() {
|
||||
def onReceive(context: Context, intent: Intent) {
|
||||
if (getState == State.CONNECTED) {
|
||||
val action = intent.getAction
|
||||
if (action == Intent.ACTION_SCREEN_OFF) {
|
||||
notifyForegroundAlert(getString(R.string.forward_success),
|
||||
getString(R.string.service_running).formatLocal(Locale.ENGLISH, config.profileName), false)
|
||||
} else if (action == Intent.ACTION_SCREEN_ON) {
|
||||
val keyGuard = getSystemService(Context.KEYGUARD_SERVICE).asInstanceOf[KeyguardManager]
|
||||
if (!keyGuard.inKeyguardRestrictedInputMode) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
lockReceiver = (context: Context, intent: Intent) => if (getState == State.CONNECTED) {
|
||||
val action = intent.getAction
|
||||
if (action == Intent.ACTION_SCREEN_OFF) {
|
||||
notifyForegroundAlert(getString(R.string.forward_success),
|
||||
getString(R.string.service_running).formatLocal(Locale.ENGLISH, config.profileName), false)
|
||||
} else if (action == Intent.ACTION_SCREEN_ON) {
|
||||
val keyGuard = getSystemService(Context.KEYGUARD_SERVICE).asInstanceOf[KeyguardManager]
|
||||
if (!keyGuard.inKeyguardRestrictedInputMode) {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -556,7 +547,7 @@ class ShadowsocksNatService extends Service with BaseService {
|
||||
|
||||
changeState(State.CONNECTING)
|
||||
|
||||
spawn {
|
||||
Future {
|
||||
|
||||
if (config.proxy == "198.199.101.152") {
|
||||
val holder = application.containerHolder
|
||||
|
||||
@@ -57,11 +57,7 @@ class ShadowsocksRunnerActivity extends Activity {
|
||||
val connection = new ServiceConnection {
|
||||
override def onServiceConnected(name: ComponentName, service: IBinder) {
|
||||
bgService = IShadowsocksService.Stub.asInterface(service)
|
||||
handler.postDelayed(new Runnable() {
|
||||
override def run() {
|
||||
if (bgService != null) startBackgroundService()
|
||||
}
|
||||
}, 1000)
|
||||
handler.postDelayed(() => if (bgService != null) startBackgroundService(), 1000)
|
||||
}
|
||||
override def onServiceDisconnected(name: ComponentName) {
|
||||
bgService = null
|
||||
@@ -122,11 +118,9 @@ class ShadowsocksRunnerActivity extends Activity {
|
||||
val locked = km.inKeyguardRestrictedInputMode
|
||||
if (locked) {
|
||||
val filter = new IntentFilter(Intent.ACTION_USER_PRESENT)
|
||||
receiver = new BroadcastReceiver() {
|
||||
override def onReceive(context: Context, intent: Intent) {
|
||||
if (intent.getAction == Intent.ACTION_USER_PRESENT) {
|
||||
attachService()
|
||||
}
|
||||
receiver = (context: Context, intent: Intent) => {
|
||||
if (intent.getAction == Intent.ACTION_USER_PRESENT) {
|
||||
attachService()
|
||||
}
|
||||
}
|
||||
registerReceiver(receiver, filter)
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
package com.github.shadowsocks
|
||||
|
||||
import java.io.File
|
||||
import java.net.InetAddress
|
||||
import java.util.Locale
|
||||
|
||||
import android.app._
|
||||
@@ -57,7 +56,8 @@ import org.apache.commons.net.util.SubnetUtils
|
||||
|
||||
import scala.collection.mutable
|
||||
import scala.collection.mutable.ArrayBuffer
|
||||
import scala.concurrent.ops._
|
||||
import scala.concurrent.ExecutionContext.Implicits.global
|
||||
import scala.concurrent.Future
|
||||
|
||||
class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
|
||||
@@ -208,17 +208,15 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
// register close receiver
|
||||
val filter = new IntentFilter()
|
||||
filter.addAction(Intent.ACTION_SHUTDOWN)
|
||||
receiver = new BroadcastReceiver {
|
||||
def onReceive(p1: Context, p2: Intent) {
|
||||
Toast.makeText(p1, R.string.stopping, Toast.LENGTH_SHORT)
|
||||
stopRunner()
|
||||
}
|
||||
receiver = (p1: Context, p2: Intent) => {
|
||||
Toast.makeText(p1, R.string.stopping, Toast.LENGTH_SHORT)
|
||||
stopRunner()
|
||||
}
|
||||
registerReceiver(receiver, filter)
|
||||
|
||||
changeState(State.CONNECTING)
|
||||
|
||||
spawn {
|
||||
Future {
|
||||
if (config.proxy == "198.199.101.152") {
|
||||
val holder = getApplication.asInstanceOf[ShadowsocksApplication].containerHolder
|
||||
try {
|
||||
@@ -453,7 +451,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
|
||||
Console.runCommand(cmd)
|
||||
|
||||
return fd
|
||||
fd
|
||||
}
|
||||
|
||||
override def stopBackgroundService() {
|
||||
|
||||
@@ -93,35 +93,34 @@ class ShadowsocksVpnThread(vpnService: ShadowsocksVpnService) extends Thread {
|
||||
try {
|
||||
val socket = serverSocket.accept()
|
||||
|
||||
pool.execute(new Runnable {
|
||||
override def run() {
|
||||
try {
|
||||
val input = socket.getInputStream
|
||||
val output = socket.getOutputStream
|
||||
pool.execute(() => {
|
||||
try {
|
||||
val input = socket.getInputStream
|
||||
val output = socket.getOutputStream
|
||||
|
||||
input.read()
|
||||
input.read()
|
||||
|
||||
val fds = socket.getAncillaryFileDescriptors
|
||||
val fds = socket.getAncillaryFileDescriptors
|
||||
|
||||
if (fds.length > 0) {
|
||||
var ret = false
|
||||
if (fds.nonEmpty) {
|
||||
var ret = false
|
||||
|
||||
val getInt = classOf[FileDescriptor].getDeclaredMethod("getInt$")
|
||||
val fd = getInt.invoke(fds(0)).asInstanceOf[Int]
|
||||
ret = vpnService.protect(fd)
|
||||
val getInt = classOf[FileDescriptor].getDeclaredMethod("getInt$")
|
||||
val fd = getInt.invoke(fds(0)).asInstanceOf[Int]
|
||||
ret = vpnService.protect(fd)
|
||||
|
||||
// Trick to close file decriptor
|
||||
System.jniclose(fd)
|
||||
// Trick to close file decriptor
|
||||
System.jniclose(fd)
|
||||
|
||||
if (ret) {
|
||||
output.write(0)
|
||||
} else {
|
||||
output.write(1)
|
||||
}
|
||||
|
||||
input.close()
|
||||
output.close()
|
||||
if (ret) {
|
||||
output.write(0)
|
||||
} else {
|
||||
output.write(1)
|
||||
}
|
||||
|
||||
input.close()
|
||||
output.close()
|
||||
}
|
||||
} catch {
|
||||
case e: Exception =>
|
||||
Log.e(TAG, "Error when protect socket", e)
|
||||
@@ -134,12 +133,11 @@ class ShadowsocksVpnThread(vpnService: ShadowsocksVpnService) extends Thread {
|
||||
case _: Exception => // ignore
|
||||
}
|
||||
|
||||
}})
|
||||
})
|
||||
} catch {
|
||||
case e: IOException => {
|
||||
case e: IOException =>
|
||||
Log.e(TAG, "Error when accept socket", e)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,14 +40,10 @@
|
||||
package com.github.shadowsocks.database
|
||||
|
||||
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 com.github.shadowsocks.{R}
|
||||
import android.view.View.{OnLongClickListener, OnClickListener}
|
||||
import android.view.{LayoutInflater, View, ViewGroup}
|
||||
import android.widget.{BaseAdapter, TextView}
|
||||
import com.github.shadowsocks.R
|
||||
|
||||
abstract class Item {
|
||||
def id: Int
|
||||
@@ -147,17 +143,13 @@ class MenuAdapter(context: Context, var items: List[Any]) extends BaseAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
tv.setOnClickListener(new OnClickListener {
|
||||
def onClick(view: View) {
|
||||
val item = view.getTag(R.id.mdItem).asInstanceOf[Item]
|
||||
item.click(item.id)
|
||||
}
|
||||
tv.setOnClickListener((view: View) => {
|
||||
val item = view.getTag(R.id.mdItem).asInstanceOf[Item]
|
||||
item.click(item.id)
|
||||
})
|
||||
tv.setOnLongClickListener(new OnLongClickListener {
|
||||
def onLongClick(view: View): Boolean = {
|
||||
val item = view.getTag(R.id.mdItem).asInstanceOf[Item]
|
||||
item.longClick(item.id)
|
||||
}
|
||||
tv.setOnLongClickListener((view: View) => {
|
||||
val item = view.getTag(R.id.mdItem).asInstanceOf[Item]
|
||||
item.longClick(item.id)
|
||||
})
|
||||
|
||||
v.setTag(R.id.mdItem, value)
|
||||
|
||||
@@ -39,9 +39,9 @@
|
||||
|
||||
package com.github.shadowsocks.database
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import com.github.shadowsocks._
|
||||
import android.content.{SharedPreferences, Context}
|
||||
import com.github.shadowsocks.utils.Key
|
||||
|
||||
class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
|
||||
|
||||
@@ -233,8 +233,8 @@ object ConfigUtils {
|
||||
.readTimeout(2000)
|
||||
.send("sig="+sig)
|
||||
.body
|
||||
val proxies = util.Random.shuffle(list.split('|').toSeq).toSeq
|
||||
val proxy = proxies(0).split(':')
|
||||
val proxies = util.Random.shuffle(list.split('|').toSeq)
|
||||
val proxy = proxies.head.split(':')
|
||||
|
||||
val host = proxy(0).trim
|
||||
val port = proxy(1).trim.toInt
|
||||
|
||||
@@ -39,10 +39,11 @@
|
||||
|
||||
package com.github.shadowsocks.utils
|
||||
|
||||
import eu.chainfire.libsuperuser.Shell
|
||||
import eu.chainfire.libsuperuser.Shell.{OnCommandResultListener, SU, Builder}
|
||||
import java.util
|
||||
|
||||
import eu.chainfire.libsuperuser.Shell
|
||||
import eu.chainfire.libsuperuser.Shell.{Builder, SU}
|
||||
|
||||
object Console {
|
||||
|
||||
private def openShell(): Shell.Interactive = {
|
||||
@@ -68,14 +69,8 @@ object Console {
|
||||
|
||||
def runCommand(commands: Array[String]) {
|
||||
val shell = openShell()
|
||||
shell.addCommand(commands, 0, new OnCommandResultListener {
|
||||
override def onCommandResult(commandCode: Int, exitCode: Int,
|
||||
output: util.List[String]) {
|
||||
if (exitCode < 0) {
|
||||
shell.close()
|
||||
}
|
||||
}
|
||||
})
|
||||
shell.addCommand(commands, 0, ((commandCode: Int, exitCode: Int, output: util.List[String]) =>
|
||||
if (exitCode < 0) shell.close()): Shell.OnCommandResultListener)
|
||||
shell.waitForIdle()
|
||||
shell.close()
|
||||
}
|
||||
@@ -90,17 +85,14 @@ object Console {
|
||||
}
|
||||
val shell = openRootShell(context)
|
||||
val sb = new StringBuilder
|
||||
shell.addCommand(commands, 0, new OnCommandResultListener {
|
||||
override def onCommandResult(commandCode: Int, exitCode: Int,
|
||||
output: util.List[String]) {
|
||||
if (exitCode < 0) {
|
||||
shell.close()
|
||||
} else {
|
||||
import scala.collection.JavaConversions._
|
||||
output.foreach(line => sb.append(line).append('\n'))
|
||||
}
|
||||
shell.addCommand(commands, 0, ((commandCode: Int, exitCode: Int, output: util.List[String]) => {
|
||||
if (exitCode < 0) {
|
||||
shell.close()
|
||||
} else {
|
||||
import scala.collection.JavaConversions._
|
||||
output.foreach(line => sb.append(line).append('\n'))
|
||||
}
|
||||
})
|
||||
}): Shell.OnCommandResultListener)
|
||||
if (shell.waitForIdle()) {
|
||||
shell.close()
|
||||
sb.toString()
|
||||
|
||||
@@ -47,11 +47,8 @@ import android.util.{Log, Base64}
|
||||
object Parser {
|
||||
val TAG = "ShadowParser"
|
||||
|
||||
def generate (profile: Profile): String = {
|
||||
val path = "%s:%s@%s:%d".formatLocal(Locale.ENGLISH,
|
||||
profile.method, profile.password, profile.host, profile.remotePort)
|
||||
return "ss://" + Base64.encodeToString(path.getBytes, Base64.NO_PADDING)
|
||||
}
|
||||
def generate (profile: Profile): String = "ss://" + Base64.encodeToString("%s:%s@%s:%d".formatLocal(Locale.ENGLISH,
|
||||
profile.method, profile.password, profile.host, profile.remotePort).getBytes, Base64.NO_PADDING)
|
||||
|
||||
def parse (data: String): Option[Profile] = {
|
||||
try {
|
||||
|
||||
@@ -38,21 +38,21 @@
|
||||
*/
|
||||
package com.github.shadowsocks.utils
|
||||
|
||||
import android.content.{Intent, Context}
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.drawable.{BitmapDrawable, Drawable}
|
||||
import android.util.{Base64, Log}
|
||||
import java.io._
|
||||
import java.net._
|
||||
import org.xbill.DNS._
|
||||
import android.graphics._
|
||||
import java.security.MessageDigest
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.content.pm.{ApplicationInfo, PackageManager}
|
||||
import android.content.{Context, Intent}
|
||||
import android.graphics._
|
||||
import android.graphics.drawable.{BitmapDrawable, Drawable}
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import scala.Some
|
||||
import java.security.MessageDigest
|
||||
import com.github.shadowsocks.{BuildConfig}
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.util.{Base64, Log}
|
||||
import com.github.shadowsocks.BuildConfig
|
||||
import org.xbill.DNS._
|
||||
|
||||
|
||||
object Utils {
|
||||
@@ -146,6 +146,7 @@ object Utils {
|
||||
// + "am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false\n")
|
||||
}
|
||||
|
||||
//noinspection ScalaDeprecation
|
||||
private def toggleBelowApiLevel17(context: Context) {
|
||||
// Android 4.2 below
|
||||
Settings.System.putInt(context.getContentResolver, Settings.System.AIRPLANE_MODE_ON, 1)
|
||||
@@ -197,7 +198,7 @@ object Utils {
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
case e: Exception => None
|
||||
case e: Exception =>
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -232,7 +233,7 @@ object Utils {
|
||||
None
|
||||
}
|
||||
|
||||
lazy val isNumericMethod = classOf[InetAddress].getMethod("isNumeric", classOf[String])
|
||||
private lazy val isNumericMethod = classOf[InetAddress].getMethod("isNumeric", classOf[String])
|
||||
def isNumeric(address: String): Boolean = isNumericMethod.invoke(null, address).asInstanceOf[Boolean]
|
||||
|
||||
/**
|
||||
@@ -338,7 +339,7 @@ object Utils {
|
||||
|
||||
def getAppIcon(c: Context, packageName: String): Drawable = {
|
||||
val pm: PackageManager = c.getPackageManager
|
||||
val icon: Drawable = c.getResources.getDrawable(android.R.drawable.sym_def_app_icon)
|
||||
val icon: Drawable = ContextCompat.getDrawable(c, android.R.drawable.sym_def_app_icon)
|
||||
try {
|
||||
pm.getApplicationIcon(packageName)
|
||||
} catch {
|
||||
@@ -348,7 +349,7 @@ object Utils {
|
||||
|
||||
def getAppIcon(c: Context, uid: Int): Drawable = {
|
||||
val pm: PackageManager = c.getPackageManager
|
||||
val icon: Drawable = c.getResources.getDrawable(android.R.drawable.sym_def_app_icon)
|
||||
val icon: Drawable = ContextCompat.getDrawable(c, android.R.drawable.sym_def_app_icon)
|
||||
val packages: Array[String] = pm.getPackagesForUid(uid)
|
||||
if (packages != null) {
|
||||
if (packages.length >= 1) {
|
||||
|
||||
Reference in New Issue
Block a user