cmeng-git / atalk-android

xmpp/jabber client for android
Apache License 2.0
155 stars 56 forks source link

Incompatible xml:lang value #206

Closed sfPlayer1 closed 8 months ago

sfPlayer1 commented 8 months ago

Recently atalk started failing to connect to my server (ejabberd 21.12-1) with the stream error quoted below. It happened around the time I upgraded to Android 14 and a general apps update, I don't even think atalk itself was updated but yet stopped working. The server side didn't see any changes when it broke, although it might have been an automatic security update.

It looks like atalk sends a long form for the xml:lang attribute en-US-#u-fw-mon-mu-celsius which isn't supported by the server. This might be non-compliance on ejabberd's side.

D/SMACK   (31073): SENT (4): 
D/SMACK   (31073): <stream:stream xmlns='jabber:client' to='<myhost>' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en-US-#u-fw-mon-mu-celsius'>
D/SMACK   (31073): RECV (4): ?xml version='1.0'?>
D/SMACK   (31073): <stream:stream id='8616778772398523505' version='1.0' xml:lang='en' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client'>
D/SMACK   (31073): <stream:error>
D/SMACK   (31073):   <invalid-xml xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>
D/SMACK   (31073):   <text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>
D/SMACK   (31073):     Bad value of attribute &apos;xml:lang&apos; in tag &lt;stream:stream/&gt; qualified by namespace &apos;jabber:client&apos;
D/SMACK   (31073):   </text>
D/SMACK   (31073): </stream:error>
D/SMACK   (31073): </stream:stream>
cmeng-git commented 8 months ago

From your sent stanza info, the problem lies in

xml:lang='en-US-#u-fw-mon-mu-celsius'

Which is not correct, and should never be sent by aTalk; hence it is rejected by the server. The correct value should only be

xml:lang='en-US'

The following are the correct stanza exchanges between the client and the server

2023-11-04 08:10:10.385 5032-5199/org.atalk.hmos D/SMACK: SENT (0): 
    <stream:stream xmlns='jabber:client' to='myserver' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' id='8035541613338344702' xml:lang='en-US'>
2023-11-04 08:10:10.388 5032-5200/org.atalk.hmos D/SMACK: RECV (0): ?xml version='1.0'?>
    <stream:stream id='7431384739205787355' version='1.0' xml:lang='en-US' xmlns:stream='http://etherx.jabber.org/streams' from='myserver' xmlns='jabber:client'>

I suspect your aTalk app is corrupted during your android OS upgrade.

sfPlayer1 commented 8 months ago

I don't think it's corruption but the Android 14 changes. I never set any related property so it's most likely being pulled from the OS. I did some digging and found that the xml:lang content aTalk sends looks a lot like the output of https://developer.android.com/reference/java/util/Locale#toString() while replacing _ with -.

This relevant new functionality is detailed at https://developer.android.com/about/versions/14/features#regional-preferences

I suspect aTalk passes the above modified toString output or a similar source to smack without accounting for the extra data in Android 14.

cmeng-git commented 8 months ago

May I know what is your device system language used.

I just tested aTalk on AVD Pixel_6_API_34 (android-14) with device system Locale US. It is working normally. Below is the captured Locale.getDefault() and it returns correct values.

image

Just realise that your previous send stanza indicates that your system language is also en-US.

By the way please note, aTalk has not being tested on android-14; there may exist other problems due to android API_34 requirement changes.

sfPlayer1 commented 8 months ago

Did you set any of the regional preferences to non-default? Settings - System - Languages - Regional preferences - temp Celsius and first day of week Monday. I'm using the Pixel 7 pro with Google supplied Android 14, maybe there's a bit more to it than the AVD instance exposes. Also is Locale.getDefault() representative? You are using https://github.com/cmeng-git/atalk-android/blob/a821544edc644fdb3f63402340051dc1e86c1c59/aTalk/src/main/java/org/atalk/android/gui/util/LocaleHelper.java#L78 for example, not sure how closely that's related to what Locale does by itself.

I may have to figure out how to get a debugger in there, or use a custom build with extra logging if you tell me where it grabs the data. Don't worry about Android 14 apparently having some issues, I'm specifically reporting this so it can be improved.

sfPlayer1 commented 8 months ago

I can confirm that it only breaks with above regional preferences set to anything other than "app default".

cmeng-git commented 8 months ago

I have just tested with all the aTalk supported languages on AVD_API-34. aTalk works well with any of the language supported selection. Actually all the locale settings are stored in aTalk resource file. Looks like the stored values are corrupted. When you select system default, the value is set with the following and not taken from the resource file. Have you try to reinstall aTalk to see if it solves the problem.

        if (TextUtils.isEmpty(language)) {
            // System default
            locale = Resources.getSystem().getConfiguration().locale;
        }
    <string-array name="settings_language_values" translatable="false">
        <item></item>
        <item>af</item>
        <item>az</item>
        <item>in</item>
        <item>ms</item>
        <item>bm</item>
        <item>br</item>
        <item>ca</item>
        <item>cs</item>
        <item>cy</item>
        <item>da</item>
        <item>de</item>
        <item>et</item>
        <item>en</item>
        <item>es</item>
        <item>eo</item>
        <item>eu</item>
        <item>ee</item>
        <item>fr</item>
        <item>fr_CA</item>
        <item>ff</item>
        <item>ga</item>
        <item>gd</item>
        <item>gl</item>
        <item>ha</item>
        <item>hr</item>
        <item>xs</item>
        <item>zu</item>
        <item>is</item>
        <item>it</item>
        <item>rw</item>
        <item>rn</item>
        <item>sw</item>
        <item>lv</item>
        <item>lt</item>
        <item>hu</item>
        <item>mt</item>
        <item>nl</item>
        <item>no</item>
        <item>nb</item>
        <item>uz</item>
        <item>pl</item>
        <item>pt_PT</item>
        <item>pt_BR</item>
        <item>ru</item>
        <item>ro</item>
        <item>sq</item>
        <item>sk</item>
        <item>sl</item>
        <item>so</item>
        <item>fi</item>
        <item>sv</item>
        <item>vi</item>
        <item>tr</item>
        <item>wo</item>
        <item>yo</item>
        <item>el</item>
        <item>ab</item>
        <item>be</item>
        <item>bg</item>
        <item>ky</item>
        <item>kk</item>
        <item>mk</item>
        <item>sr</item>
        <item>uk</item>
        <item>hy</item>
        <item>iw</item>
        <item>ur</item>
        <item>ar</item>
        <item>ps</item>
        <item>fa</item>
        <item>am</item>
        <item>hi</item>
        <item>te</item>
        <item>kn</item>
        <item>th</item>
        <item>ko</item>
        <item>zh_CN</item>
        <item>zh_TW</item>
        <item>ja</item>
    </string-array>
/* === Chinese === */
2023-11-05 07:20:59.335 12169-12270/org.atalk.hmos D/SMACK: SENT (0): 
    <stream:stream xmlns='jabber:client' to='atalk.sytes.net' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' id='7342956805692872581' xml:lang='zh-CN'>
2023-11-05 07:20:59.343 12169-12271/org.atalk.hmos D/SMACK: RECV (0): ?xml version='1.0'?>
    <stream:stream id='2326520678171705326' version='1.0' xml:lang='zh-CN' xmlns:stream='http://etherx.jabber.org/streams' from='atalk.sytes.net' xmlns='jabber:client'>
/* === Portugese === */
2023-11-05 07:43:25.450 12849-12952/org.atalk.hmos D/SMACK: SENT (0): 
    <stream:stream xmlns='jabber:client' to='atalk.sytes.net' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='pt-BR'>
2023-11-05 07:43:25.456 12849-12953/org.atalk.hmos D/SMACK: RECV (0): ?xml version='1.0'?>
    <stream:stream id='769685307253291631' version='1.0' xml:lang='pt-BR' xmlns:stream='http://etherx.jabber.org/streams' from='atalk.sytes.net' xmlns='jabber:client'>
/* === Russia === */
2023-11-05 07:40:38.577 12667-12774/org.atalk.hmos D/SMACK: SENT (0): 
    <stream:stream xmlns='jabber:client' to='atalk.sytes.net' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' id='993327012630007410' xml:lang='ru'>
2023-11-05 07:40:38.581 12667-12775/org.atalk.hmos D/SMACK: RECV (0): ?xml version='1.0'?>
    <stream:stream id='1492847393068736128' version='1.0' xml:lang='ru' xmlns:stream='http://etherx.jabber.org/streams' from='atalk.sytes.net' xmlns='jabber:client'>
sfPlayer1 commented 8 months ago

Did you read my last message? It works fine if I don't use the regional preferences but break if I customize anything there. It's probably Android yielding a subclass of whatever Locale-related class you are using that has the different String representation.

cmeng-git commented 8 months ago

Has reported your finding to the smack development team for their comments:

https://discourse.igniterealtime.org/t/smack-4-4-6-invalid-xml-lang-attribute-in-stanza-sending-when-user-changes-android-language-regional-preference-settings/93311

Please note if you choose other UI language other than the System Default for aTalk e.g. English, then thing works OK.

cmeng-git commented 8 months ago

Problem fixed in v3.2.2 release.

sfPlayer1 commented 8 months ago

fix confirmed working, thanks!