Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bannedbook committed May 31, 2020
1 parent 59688cf commit 479cc74
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 17 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ buildscript {
junitVersion = '4.13'
androidTestVersion = '1.2.0'
androidEspressoVersion = '3.2.0'
versionCode = 5000808
versionName = '5.1.4-nightly'
versionCode = 5000818
versionName = '5.1.5-nightly'
resConfigs = ['ar', 'es', 'fa', 'fr', 'ja', 'ko', 'ru', 'tr', 'zh-rCN', 'zh-rTW']
}

Expand Down
24 changes: 22 additions & 2 deletions core/src/main/java/com/github/shadowsocks/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,28 @@ object Core {
return ProfileManager.expand(theOne ?: return null)
}

fun switchProfile(id: Long): Profile {
fun switchProfile(id: Long, canStop:Boolean): Profile {
val oldProfileId=DataStore.profileId
Log.e("oldProfileId",oldProfileId.toString())
val result = ProfileManager.getProfile(id) ?: ProfileManager.createProfile()
DataStore.profileId = result.id
if (id==oldProfileId)return result

val profileTypeChanged = result.profileType != ProfileManager.getProfile(oldProfileId)?.profileType

if(!canStop)
DataStore.profileId = result.id
else if(canStop && profileTypeChanged) {
stopService()
while (BaseService.State.values()[DataStore.connection!!.service!!.state]!=BaseService.State.Stopped)Thread.sleep(100)
DataStore.profileId = result.id
startService()
}
else if (canStop && !profileTypeChanged){
DataStore.profileId = result.id
app.sendBroadcast(Intent(Action.RELOAD).setPackage(app.packageName))
}

Log.e("profileId",DataStore.profileId.toString())
return result
}

Expand All @@ -112,6 +131,7 @@ object Core {
var builtinSub=SSRSubManager.createBuiltInSub(builtinSubUrls.get(i))
if (builtinSub != null) break
}
if (DataStore.is_get_free_servers)importFreeSubs()
}
}
/**
Expand Down
13 changes: 11 additions & 2 deletions core/src/main/java/com/github/shadowsocks/preference/DataStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.util.Log
import androidx.preference.PreferenceDataStore
import com.github.shadowsocks.BootReceiver
import com.github.shadowsocks.Core
import com.github.shadowsocks.aidl.ShadowsocksConnection
import com.github.shadowsocks.database.PrivateDatabase
import com.github.shadowsocks.database.ProfileManager
import com.github.shadowsocks.database.PublicDatabase
Expand Down Expand Up @@ -59,10 +60,18 @@ object DataStore : OnPreferenceDataStoreChangeListener {
value
} else parsePort(publicStore.getString(key), default + userIndex)
}

var connection: ShadowsocksConnection? =null
var oldProfileId: Long
get() = publicStore.getLong(Key.oldId) ?: 0
set(value) = publicStore.putLong(Key.oldId, value)
var profileId: Long
get() = publicStore.getLong(Key.id) ?: 0
set(value) = publicStore.putLong(Key.id, value)
set(value) {
oldProfileId=profileId
publicStore.putLong(Key.id, value)
if (oldProfileId==0L || ProfileManager.getProfile(profileId)?.profileType != ProfileManager.getProfile(oldProfileId)?.profileType)
connection?.binderDied()
}
val persistAcrossReboot get() = publicStore.getBoolean(Key.persistAcrossReboot)
?: BootReceiver.enabled.also { publicStore.putBoolean(Key.persistAcrossReboot, it) }
val canToggleLocked: Boolean get() = publicStore.getBoolean(Key.directBootAware) == true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object Key {
const val DB_PROFILE = "profile.db"

const val id = "profileId"
const val oldId = "oldProfileId"
const val name = "profileName"
const val group = "groupName"

Expand Down
2 changes: 1 addition & 1 deletion gitupdate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ git pull origin master
git add -A
git commit -m "update"
git push origin master
git tag -a v5.1.4 -m "release v5.1.4"
git tag -a v5.1.5 -m "release v5.1.5"
git push origin --tags
pause
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref

changeState(BaseService.State.Idle) // reset everything to init state
connection.connect(this, this)
DataStore.connection=connection
DataStore.publicStore.registerChangeListener(this)
//updateBuiltinServers
if(DataStore.isAutoUpdateServers){
Core.updateBuiltinServers()
if (DataStore.is_get_free_servers)Core.importFreeSubs()
}
//Log.e("user-country", Locale.getDefault().country)
}
Expand Down
18 changes: 10 additions & 8 deletions mobile/src/main/java/com/github/shadowsocks/ProfilesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
}
text1.text = item.formattedName
text2.text = ArrayList<String>().apply {
if (item.url_group.isNotEmpty()) this += item.url_group
if (item.isBuiltin())this += "SSVPN Builtin"
else if (item.isBuiltin2()) this += "3rd-party free server"
else if (item.url_group.isNotEmpty()) this += item.url_group
else if (!item.name.isNullOrEmpty()) this += item.formattedAddress
val id = PluginConfiguration(item.plugin ?: "").selected
if (id.isNotEmpty() && !item.isBuiltin()) this += getString(R.string.profile_plugin, id)
Expand Down Expand Up @@ -356,14 +358,14 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
if (isEnabled) {
val activity = activity as MainActivity
val old = DataStore.profileId
Core.switchProfile(item.id)
if (item.id!=old)Core.switchProfile(item.id,activity.state.canStop)
profilesAdapter.refreshId(old)
itemView.isSelected = true
if (activity.state.canStop)
Core.reloadService(old,activity.getShadowsocksConnection())
else if (ProfileManager.getProfile(old)?.profileType != ProfileManager.getProfile(item.id)?.profileType) {
activity.getShadowsocksConnection().binderDied()
}
// if (activity.state.canStop)
// Core.reloadService(old,activity.getShadowsocksConnection())
// else if (ProfileManager.getProfile(old)?.profileType != ProfileManager.getProfile(item.id)?.profileType) {
// activity.getShadowsocksConnection().binderDied()
// }
}
}

Expand Down Expand Up @@ -715,7 +717,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
Log.e("real_ping_all",k.toString())
profilesAdapter.profiles[k].elapsed=-2
val old = DataStore.profileId
Core.switchProfile(profilesAdapter.profiles[k].id)
Core.switchProfile(profilesAdapter.profiles[k].id,false)
activity?.runOnUiThread() {
try {activity.window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)}catch (e:Exception){}
layoutManager.scrollToPositionWithOffset(k, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ActionListener : BroadcastReceiver() {
val settings = Settings.fromIntent(intent)
var changed = false
if (ProfileManager.getProfile(settings.profileId) != null) {
Core.switchProfile(settings.profileId)
Core.switchProfile(settings.profileId,false)
changed = true
}
if (settings.switchOn) {
Expand Down

0 comments on commit 479cc74

Please sign in to comment.