@@ -219,11 +219,6 @@ object V2rayConfigManager {
219219 resolveOutboundDomainsToHosts(v2rayConfig)
220220 }
221221
222- // apply fragment
223- for (outbound in v2rayConfig.outbounds) {
224- updateOutboundFragment(outbound)
225- }
226-
227222 result.status = true
228223 result.content = JsonUtil .toJsonPretty(v2rayConfig) ? : " "
229224 result.guid = guid
@@ -283,11 +278,6 @@ object V2rayConfigManager {
283278 resolveOutboundDomainsToHosts(v2rayConfig)
284279 }
285280
286- // apply fragment
287- for (outbound in v2rayConfig.outbounds) {
288- updateOutboundFragment(outbound)
289- }
290-
291281 return v2rayConfig
292282 }
293283
@@ -963,37 +953,30 @@ object V2rayConfigManager {
963953 *
964954 * Configures packet fragmentation for TLS and REALITY protocols if enabled.
965955 *
966- * @param outbound The outbound object to be modified
956+ * @param streamSettings The streamSettings object to be modified
967957 * @return true if fragment configuration was successful, false otherwise
968958 */
969- private fun updateOutboundFragment (outbound : OutboundBean ): Boolean {
959+ private fun updateOutboundFragment (streamSettings : StreamSettingsBean ): Boolean {
970960 try {
971961 if (MmkvManager .decodeSettingsBool(AppConfig .PREF_FRAGMENT_ENABLED , false ) == false ) {
972962 return true
973963 }
974- if (outbound. streamSettings? .security != AppConfig .TLS
975- && outbound. streamSettings? .security != AppConfig .REALITY
964+ if (streamSettings.security != AppConfig .TLS
965+ && streamSettings.security != AppConfig .REALITY
976966 ) {
977967 return true
978968 }
979- if (outbound. streamSettings? .sockopt?.dialerProxy.isNotNullEmpty()) {
969+ if (streamSettings.sockopt?.dialerProxy.isNotNullEmpty()) {
980970 return true
981971 }
982972
983- val fragmentOutbound =
984- OutboundBean (
985- protocol = AppConfig .PROTOCOL_FREEDOM ,
986- tag = AppConfig .TAG_FRAGMENT ,
987- mux = null
988- )
989-
990973 var packets =
991974 MmkvManager .decodeSettingsString(AppConfig .PREF_FRAGMENT_PACKETS ) ? : " tlshello"
992- if (outbound. streamSettings? .security == AppConfig .REALITY
975+ if (streamSettings.security == AppConfig .REALITY
993976 && packets == " tlshello"
994977 ) {
995978 packets = " 1-3"
996- } else if (outbound. streamSettings? .security == AppConfig .TLS
979+ } else if (streamSettings.security == AppConfig .TLS
997980 && packets != " tlshello"
998981 ) {
999982 packets = " tlshello"
@@ -1021,15 +1004,20 @@ object V2rayConfigManager {
10211004 )
10221005 )
10231006
1024- val finalMaskObj = JsonUtil .parseString(JsonUtil .toJson(outbound.streamSettings?.finalmask))
1025- ? : com.google.gson.JsonObject ()
1007+ val finalMaskObj = streamSettings.finalmask?.let { existingFinalMask ->
1008+ JsonUtil .parseString(JsonUtil .toJson(existingFinalMask))
1009+ } ? : com.google.gson.JsonObject ()
10261010
10271011 // finalmask.tcp / finalmask.udp are arrays; prepend mask at index 0.
10281012 fun prependMask (scope : String , mask : StreamSettingsBean .FinalMaskBean .MaskBean ) {
1013+ val current = finalMaskObj.get(scope)
1014+ if (current != null && current.isJsonArray && current.asJsonArray.size() > 0 ) {
1015+ return
1016+ }
1017+
10291018 val newArray = JsonArray ()
10301019 newArray.add(JsonUtil .parseString(JsonUtil .toJson(mask)))
10311020
1032- val current = finalMaskObj.get(scope)
10331021 if (current != null && current.isJsonArray) {
10341022 current.asJsonArray.forEach { newArray.add(it) }
10351023 }
@@ -1038,7 +1026,7 @@ object V2rayConfigManager {
10381026
10391027 prependMask(" tcp" , fragmentMask)
10401028 prependMask(" udp" , noiseMask)
1041- outbound. streamSettings? .finalmask = finalMaskObj
1029+ streamSettings.finalmask = finalMaskObj
10421030 } catch (e: Exception ) {
10431031 Log .e(AppConfig .TAG , " Failed to update outbound fragment" , e)
10441032 return false
@@ -1424,6 +1412,10 @@ object V2rayConfigManager {
14241412 streamSettings.tlsSettings = null
14251413 streamSettings.realitySettings = tlsSetting
14261414 }
1415+
1416+ if (profileItem.finalMask.isNullOrEmpty()) {
1417+ updateOutboundFragment(streamSettings)
1418+ }
14271419 }
14281420
14291421 // endregion
0 commit comments