Compare commits

...

16 Commits

Author SHA1 Message Date
2dust
2d5351ec9e Merge pull request #1218 from yuhan6665/fix-sniffing2
Fix sniffing default value again
2021-09-07 20:02:52 +08:00
yuhan6665
d9fb121d67 Fix sniffing default value again
I made a mistake, thought it would return null when key is not in storage,
But it is found default "true" must be specified
2021-09-03 18:15:06 -04:00
2dust
62d0951a24 Merge pull request #1208 from yuhan6665/fix-viewpager
Fix an issue with ViewPage2 and menu bar
2021-08-28 17:06:21 +08:00
2dust
d6605cc866 Merge pull request #1204 from douo/master
Add support in subscription url for http basic authentication.
2021-08-28 17:06:10 +08:00
yuhan6665
1fc493d879 Fix an issue with ViewPage2 and menu bar 2021-08-27 17:48:45 -04:00
tiou
bdc27dd180 Use built-in urlDecode. 2021-08-23 16:58:48 +08:00
tiou
e257c4cb56 Subscription support http basic authentication in url. 2021-08-23 16:49:35 +08:00
2dust
e9d2ed98af Merge pull request #1198 from yuhan6665/user-agent
Set user agent to v2rayNG/version when update subscription
2021-08-21 19:19:20 +08:00
yuhan6665
901a82eb54 Set user agent to v2rayNG/version when update subscription 2021-08-20 18:29:34 -04:00
2dust
26cc29944b Merge pull request #1183 from yuhan6665/fix-drag
Fix a bug when user delete item right after drag it
2021-08-17 20:20:56 +08:00
yuhan6665
7052546f2b Fix a bug when user delete item right after drag it 2021-08-13 18:04:43 -04:00
2dust
ae2b10ede7 Merge pull request #1177 from yuhan6665/fix-base64
Fix parsing for some loosely formatted base64
2021-08-10 13:09:35 +08:00
2dust
0df051e640 Merge pull request #1175 from jiuqianyuan/master
Add prompts for update subscription error
2021-08-10 13:06:14 +08:00
jiuqianyuan
79aa86a402 Update MainActivity.kt 2021-08-09 17:22:49 +08:00
yuhan6665
7bf32c2b30 Fix parsing for some loosely formatted base64 2021-08-07 17:35:09 -04:00
jiuqianyuan
ceb1c55e49 Fix missing prompts for update subscription error 2021-08-07 08:08:45 +08:00
5 changed files with 39 additions and 6 deletions

View File

@@ -83,7 +83,7 @@ dependencies {
implementation "androidx.preference:preference:1.0.0" implementation "androidx.preference:preference:1.0.0"
implementation "androidx.recyclerview:recyclerview:1.2.1" implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.viewpager2:viewpager2:1.0.0' implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01'
// Androidx ktx // Androidx ktx
implementation 'androidx.activity:activity-ktx:1.2.4' implementation 'androidx.activity:activity-ktx:1.2.4'

View File

@@ -371,7 +371,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
} }
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
val configText = try { val configText = try {
URL(url).readText() Utils.getUrlContentWithCustomUserAgent(url)
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
"" ""
@@ -408,9 +408,12 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
Log.d(ANG_PACKAGE, url) Log.d(ANG_PACKAGE, url)
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
val configText = try { val configText = try {
URL(url).readText() Utils.getUrlContentWithCustomUserAgent(url)
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
launch(Dispatchers.Main) {
toast("\"" + it.second.remarks + "\" " + getString(R.string.toast_failure))
}
return@launch return@launch
} }
launch(Dispatchers.Main) { launch(Dispatchers.Main) {

View File

@@ -213,7 +213,11 @@ class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter<Mai
override fun onItemMove(fromPosition: Int, toPosition: Int): Boolean { override fun onItemMove(fromPosition: Int, toPosition: Int): Boolean {
mActivity.mainViewModel.swapServer(fromPosition, toPosition) mActivity.mainViewModel.swapServer(fromPosition, toPosition)
notifyItemMoved(fromPosition, toPosition) notifyItemMoved(fromPosition, toPosition)
//notifyItemRangeChanged(fromPosition, toPosition - fromPosition + 1) // position is changed, since position is used by click callbacks, need to update range
if (toPosition > fromPosition)
notifyItemRangeChanged(fromPosition, toPosition - fromPosition + 1)
else
notifyItemRangeChanged(toPosition, fromPosition - toPosition + 1)
return true return true
} }

View File

@@ -20,6 +20,7 @@ import android.util.Patterns
import android.webkit.URLUtil import android.webkit.URLUtil
import com.tencent.mmkv.MMKV import com.tencent.mmkv.MMKV
import com.v2ray.ang.AppConfig import com.v2ray.ang.AppConfig
import com.v2ray.ang.BuildConfig
import com.v2ray.ang.R import com.v2ray.ang.R
import com.v2ray.ang.extension.responseLength import com.v2ray.ang.extension.responseLength
import com.v2ray.ang.extension.toast import com.v2ray.ang.extension.toast
@@ -99,6 +100,15 @@ object Utils {
* base64 decode * base64 decode
*/ */
fun decode(text: String): String { fun decode(text: String): String {
tryDecodeBase64(text)?.let { return it }
if (text.endsWith('=')) {
// try again for some loosely formatted base64
tryDecodeBase64(text.trimEnd('='))?.let { return it }
}
return ""
}
fun tryDecodeBase64(text: String): String? {
try { try {
return Base64.decode(text, Base64.NO_WRAP).toString(charset("UTF-8")) return Base64.decode(text, Base64.NO_WRAP).toString(charset("UTF-8"))
} catch (e: Exception) { } catch (e: Exception) {
@@ -109,7 +119,7 @@ object Utils {
} catch (e: Exception) { } catch (e: Exception) {
Log.i(AppConfig.ANG_PACKAGE, "Parse base64 url safe failed $e") Log.i(AppConfig.ANG_PACKAGE, "Parse base64 url safe failed $e")
} }
return "" return null
} }
/** /**
@@ -447,5 +457,21 @@ object Utils {
tcpTestingSockets.clear() tcpTestingSockets.clear()
} }
} }
@Throws(IOException::class)
fun getUrlContentWithCustomUserAgent(urlStr: String?): String {
val url = URL(urlStr)
val conn = url.openConnection()
conn.setRequestProperty("Connection", "close")
conn.setRequestProperty("User-agent", "v2rayNG/${BuildConfig.VERSION_NAME}")
url.userInfo?.let {
conn.setRequestProperty("Authorization",
"Basic ${encode(urlDecode(it))}")
}
conn.useCaches = false
return conn.inputStream.use {
it.bufferedReader().readText()
}
}
} }

View File

@@ -101,7 +101,7 @@ object V2rayConfigUtil {
v2rayConfig.inbounds[0].port = 10808 v2rayConfig.inbounds[0].port = 10808
val fakedns = settingsStorage?.decodeBool(AppConfig.PREF_FAKE_DNS_ENABLED) val fakedns = settingsStorage?.decodeBool(AppConfig.PREF_FAKE_DNS_ENABLED)
?: false ?: false
val sniffAllTlsAndHttp = settingsStorage?.decodeBool(AppConfig.PREF_SNIFFING_ENABLED) val sniffAllTlsAndHttp = settingsStorage?.decodeBool(AppConfig.PREF_SNIFFING_ENABLED, true)
?: true ?: true
v2rayConfig.inbounds[0].sniffing?.enabled = fakedns || sniffAllTlsAndHttp v2rayConfig.inbounds[0].sniffing?.enabled = fakedns || sniffAllTlsAndHttp
if (!sniffAllTlsAndHttp) { if (!sniffAllTlsAndHttp) {