Commit 4e5c67e8 authored by Mygod's avatar Mygod

Move port default value to OrmLitePreferenceDataStore

parent 8c33345a
......@@ -28,7 +28,7 @@ import android.app.{Application, NotificationChannel, NotificationManager}
import android.content._
import android.content.pm.{PackageInfo, PackageManager}
import android.content.res.Configuration
import android.os.{Binder, Build, LocaleList}
import android.os.{Build, LocaleList}
import android.support.v7.app.AppCompatDelegate
import android.util.Log
import com.evernote.android.job.JobManager
......@@ -163,11 +163,7 @@ class ShadowsocksApplication extends Application {
TcpFastOpen.enabled(dataStore.getBoolean(Key.tfo, TcpFastOpen.sendEnabled))
if (dataStore.getLong(Key.assetUpdateTime, -1) != info.lastUpdateTime) copyAssets()
// hopefully hashCode = mHandle doesn't change, currently this is true from KitKat to Nougat
lazy val userIndex = Binder.getCallingUserHandle.hashCode
if (!(1025 to 65535 contains dataStore.portProxy)) dataStore.putInt(Key.portProxy, 1080 + userIndex)
if (!(1025 to 65535 contains dataStore.portLocalDns)) dataStore.putInt(Key.portLocalDns, 5450 + userIndex)
if (!(1025 to 65535 contains dataStore.portTransproxy)) dataStore.putInt(Key.portTransproxy, 8200 + userIndex)
(dataStore.portProxy, dataStore.portLocalDns, dataStore.portTransproxy) // initialize ports for UI
if (Build.VERSION.SDK_INT >= 26) {
val nm = getSystemService(classOf[NotificationManager])
......
......@@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream
import java.nio.ByteBuffer
import java.util
import android.os.Binder
import android.support.v7.preference.PreferenceDataStore
import com.github.shadowsocks.database.{DBHelper, KeyValuePair}
import com.github.shadowsocks.utils.{Key, Utils}
......@@ -98,8 +99,10 @@ final class OrmLitePreferenceDataStore(dbHelper: DBHelper) extends PreferenceDat
def registerChangeListener(listener: OnPreferenceDataStoreChangeListener): Unit = listeners += listener
def unregisterChangeListener(listener: OnPreferenceDataStoreChangeListener): Unit = listeners -= listener
private def getLocalPort(key: String) = getInt(key, 0) match {
case 0 => Utils.parsePort(getString(key), 0)
// hopefully hashCode = mHandle doesn't change, currently this is true from KitKat to Nougat
private lazy val userIndex = Binder.getCallingUserHandle.hashCode
private def getLocalPort(key: String, default: Int) = getInt(key, 0) match {
case 0 => Utils.parsePort(getString(key), default + userIndex)
case value =>
putString(key, value.toString)
value
......@@ -108,9 +111,9 @@ final class OrmLitePreferenceDataStore(dbHelper: DBHelper) extends PreferenceDat
def profileId: Int = getInt(Key.id, 0)
def profileId_=(i: Int): Unit = putInt(Key.id, i)
def serviceMode: String = getString(Key.serviceMode, Key.modeVpn)
def portProxy: Int = getLocalPort(Key.portProxy)
def portLocalDns: Int = getLocalPort(Key.portLocalDns)
def portTransproxy: Int = getLocalPort(Key.portTransproxy)
def portProxy: Int = getLocalPort(Key.portProxy, 1080)
def portLocalDns: Int = getLocalPort(Key.portLocalDns, 5450)
def portTransproxy: Int = getLocalPort(Key.portTransproxy, 8200)
def proxyApps: Boolean = getBoolean(Key.proxyApps)
def proxyApps_=(value: Boolean): Unit = putBoolean(Key.proxyApps, value)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment