Skip to content

WIP: Support Android R #2507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ val Project.currentFlavor get() = gradle.startParameter.taskRequests.toString().

fun Project.setupCommon() {
android.apply {
compileSdkVersion(29)
compileSdkVersion(30)
defaultConfig {
minSdkVersion(21)
targetSdkVersion(29)
targetSdkVersion(30)
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
val javaVersion = JavaVersion.VERSION_1_8
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@
<uses-feature android:name="android.software.leanback"
android:required="false"/>

<queries>
<intent>
<action android:name="com.github.shadowsocks.plugin.ACTION_NATIVE_PLUGIN" />
</intent>
</queries>

<application
android:icon="@mipmap/ic_launcher"
android:allowBackup="true"
android:autoRevokePermissions="allowed"
android:backupAgent="com.github.shadowsocks.ConfigBackupHelper"
android:extractNativeLibs="true"
android:fullBackupContent="@xml/backup_descriptor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import android.content.Intent
import android.content.ServiceConnection
import android.os.Handler
import android.os.IBinder
import android.os.Looper
import android.os.RemoteException
import com.github.shadowsocks.bg.BaseService
import com.github.shadowsocks.bg.ProxyService
Expand All @@ -38,7 +39,7 @@ import com.github.shadowsocks.utils.Key
/**
* This object should be compact as it will not get GC-ed.
*/
class ShadowsocksConnection(private val handler: Handler = Handler(),
class ShadowsocksConnection(private val handler: Handler = Handler(Looper.getMainLooper()),
private var listenForDeath: Boolean = false) :
ServiceConnection, IBinder.DeathRecipient {
companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ object DefaultNetworkListener {
// NB: this runs in ConnectivityThread, and this behavior cannot be changed until API 26
private object Callback : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) = runBlocking { networkActor.send(NetworkMessage.Put(network)) }
override fun onCapabilitiesChanged(network: Network, networkCapabilities: NetworkCapabilities?) {
override fun onCapabilitiesChanged(network: Network, networkCapabilities: NetworkCapabilities) {
// it's a good idea to refresh capabilities
runBlocking { networkActor.send(NetworkMessage.Update(network)) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ sealed class DnsResolverCompat {
"bindSocketToNetwork", Int::class.java, Int::class.java)
}
private val netId by lazy { Network::class.java.getDeclaredField("netId") }
@SuppressLint("NewApi")
override fun bindSocket(network: Network, socket: FileDescriptor) {
val netId = netId.get(network)!!
val err = bindSocketToNetwork.invoke(null, socket.int, netId) as Int
if (err == 0) return
val message = "Binding socket to network $netId"
throw IOException(message, ErrnoException(message, -err))
throw ErrnoException(message, -err).rethrowAsSocketException()
}

/**
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/com/github/shadowsocks/net/HttpsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import android.os.Build
import android.os.SystemClock
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.github.shadowsocks.Core
import com.github.shadowsocks.Core.app
import com.github.shadowsocks.acl.Acl
import com.github.shadowsocks.core.R
import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.utils.Key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package com.github.shadowsocks.net

import android.annotation.SuppressLint
import android.net.LocalServerSocket
import android.net.LocalSocket
import android.net.LocalSocketAddress
Expand Down Expand Up @@ -63,6 +64,7 @@ abstract class LocalSocketListener(name: String, socketFile: File) : Thread(name
closeChannel.sendBlocking(Unit)
}

@SuppressLint("NewApi")
open fun shutdown(scope: CoroutineScope) {
running = false
localSocket.fileDescriptor?.apply {
Expand All @@ -71,7 +73,7 @@ abstract class LocalSocketListener(name: String, socketFile: File) : Thread(name
Os.shutdown(this, OsConstants.SHUT_RDWR)
} catch (e: ErrnoException) {
// suppress fd inactive or already closed
if (e.errno != OsConstants.EBADF && e.errno != OsConstants.ENOTCONN) throw IOException(e)
if (e.errno != OsConstants.EBADF && e.errno != OsConstants.ENOTCONN) throw e.rethrowAsSocketException()
}
}
scope.launch { closeChannel.receive() }
Expand Down
5 changes: 5 additions & 0 deletions mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package="com.github.shadowsocks"
tools:ignore="MissingLeanbackSupport">

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<uses-permission-sdk-23 android:name="android.permission.CAMERA" />

<uses-feature android:name="android.hardware.touchscreen"
Expand Down Expand Up @@ -85,6 +87,9 @@
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
<meta-data
android:name="android.service.quicksettings.TOGGLEABLE_TILE"
android:value="true" />
</service>

<receiver android:name=".tasker.ActionListener"
Expand Down
3 changes: 2 additions & 1 deletion mobile/src/main/java/com/github/shadowsocks/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import android.content.Intent
import android.net.VpnService
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.RemoteException
import android.view.*
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -130,7 +131,7 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
else -> Core.startService()
}

private val handler = Handler()
private val handler = Handler(Looper.getMainLooper())
private val connection = ShadowsocksConnection(handler, true)
override fun onServiceConnected(service: IShadowsocksService) = changeState(try {
BaseService.State.values()[service.state]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class ScannerActivity : AppCompatActivity(), BarcodeRetriever {
menuInflater.inflate(R.menu.scanner_menu, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem?) = when (item?.itemId) {
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
R.id.action_import_clipboard -> {
startImport(true)
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import android.content.Intent
import android.net.VpnService
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.RemoteException
import android.text.format.Formatter
import android.widget.Toast
Expand Down Expand Up @@ -117,7 +118,7 @@ class MainPreferenceFragment : LeanbackPreferenceFragmentCompat(), ShadowsocksCo
}
}

private val handler = Handler()
private val handler = Handler(Looper.getMainLooper())
private val connection = ShadowsocksConnection(handler, true)
override fun onServiceConnected(service: IShadowsocksService) = changeState(try {
BaseService.State.values()[service.state]
Expand Down