It appears we're getting a crash specific to Samsung devices with Android 8.
The relevant bits of the stack trace:
Fatal Exception: java.lang.IndexOutOfBoundsException: 51, -49
at android.text.PackedIntVector.deleteAt(PackedIntVector.java:222)
at android.text.DynamicLayout.reflow(DynamicLayout.java:317)
at android.text.DynamicLayout.-wrap0(Unknown Source)
at android.text.DynamicLayout$ChangeWatcher.reflow(DynamicLayout.java:750)
at android.text.DynamicLayout$ChangeWatcher.onSpanChanged(DynamicLayout.java:779)
at android.text.SpannableStringBuilder.sendSpanChanged(SpannableStringBuilder.java:1292)
at android.text.SpannableStringBuilder.sendToSpanWatchers(SpannableStringBuilder.java:647)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:577)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:504)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:502)
at android.widget.TextView.pasteClipBoardData(TextView.java:673)
at android.widget.TextView.-wrap8(Unknown Source)
at android.widget.TextView$TextViewClipboardEventListener$1.run(TextView.java:581)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
The android.widget.TextView.pasteClipBoardData part seems like the main issue AFAICT.
reference: 5a8aafe48cb3c2fa635d5605-fabric
marked as high priority as it's happening ~40 times/day and affecting ~1000 users
Steps to reproduce:
Result : App will crash
Tested with: Galaxy Tab A (2016), Android 8.1
App version : alpha: 144
cc: @hypest @rachelmcr @daniloercoli @jkmassel
Update :
Also reproduced on Samsung Galaxy S9, Android 8.0 from browserstack.com account
App version : alpha: 144
This seems to be a duplicate of https://github.com/wordpress-mobile/WordPress-Android/issues/7790
@marecar3 Would you mind to close the other ticket (if both report the same error - I think yes)?
Thanks @daniloercoli ! I have closed that one.
As I need to get back to gb-mobile, I will leave the summary of my work here.
Bug summary:
Samsung devices has an option to paste the text from CLIPBAORD ListView which is unique functionallity comparing to other products. We have a line of code here : https://github.com/wordpress-mobile/AztecEditor-Android/blob/d570acad6c7d9eed029bb324aa1b78a94a82dce6/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt#L1378
which will detect copy/paste/cut from Android devices, but it WON'T detect the paste action from CLIPBOARD List view on Samsung devices.
Test Case:
If user creates a new post and paste the text which has <br> on the end of the text, app will crash.
Problem
How to detect PASTE action on Samsung devices.
Here are the notes which I have written while trying to solve above problem.
Notes:
If we change this line of code https://github.com/wordpress-mobile/AztecEditor-Android/blob/d570acad6c7d9eed029bb324aa1b78a94a82dce6/aztec/src/main/kotlin/org/wordpress/aztec/watchers/EndOfBufferMarkerAdder.kt#L62
to any character ->e.g. text.append("*") app won't crash, but of course, it's not solution.
Samsung is using their own ClipboardManage https://github.com/fonix232/SCoverRE/blob/master/Reversed/framework/com/samsung/android/content/clipboard/SemClipboardManager.java
There was idea to use reflection and to see if Paste Listener can be set, but there is inly one Paste Listener.
There is a way to avoid showing Clipboard ListView : 16908874 -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && Build.MANUFACTURER.equals("samsung")) {
// Nope
return true
} else return super.onTextContextMenuItem(id)
} Thanks to @daniloercoli
As there were a problems to build the WPAndroid with local version of Aztec Editor, I created a branch : https://github.com/wordpress-mobile/WordPress-Android/tree/try/aztec_editor_next_to_wp_main_app
which has ugly changes, but didn't find better way at that point.
Final thought is to maybe we take a look at how they actually paste the content?
Let me know if you have some questions while working on this one.
reference: 5a8aafe48cb3c2fa635d5605-fabric marked as high priority as it's happening ~40 times/day and affecting ~1000 users
Noting that this crash is still happening in 11.9 and happened overall 1189 times (~40 times a day) for 440 users from Feb 14 - Mar 14, 2019.
This seems a bit similar to https://github.com/wordpress-mobile/WordPress-Android/issues/8828.
Since we are able to replicate this issue, I'd suggest trying to disable the HardwareAcceleration ->if it fixes the crash, I believe we can merge these two tickets together. Simply add android:hardwareAccelerated="false" to application tag in AndroidManifest.xml. cc @daniloercoli
This issue is happening when you use the Samsung custom clipboard. Not happening if you use the standard Paste action. It could be the same issue, but we've a way to intercept the custom paste and stop the action before the crash.
Setting android:hardwareAccelerated="false" in the manifest is a no go, since it will slow down the editor for all users. We've already investigated this way with @hypest and decided to not follow that path. We may need to release a custom version of the app for those Samsung devices / Android versions only, but this will mean we need to release the app twice on the store.
I'm sorry for not being clear - I wasn't suggesting we should disable the hardwareAcceleration in the manifest in production. I suggested it only to test whether it fixes the crash so we can decide whether to merge the issues or not.
I just want to make sure we won't release two fixes for both issues even though one fix would be enough. However, since it seems the fix for 8828 won't be merged any time soon if ever, fixing this issue makes sense.
Fixed in https://github.com/wordpress-mobile/AztecEditor-Android/pull/795!
(Or we tried to fix it :))
A user running WP 13.0.1 on a Samsung SM-A520F device with Android 8 is reporting seeing the following message when they try to paste content into the visual editor (they checked both Aztec and the block editor).
Sorry, this feature is disabled on Android 8. Please use the Paste action instead.

To double check, is this the expected behavior? If so, I think the best advice for the user will be to paste in HTML Mode or upgrade to the latest version of Android if at all possible. Do you agree?
(internal reference: 2291211-zen)
To double check, is this the expected behavior?
They should see both options "Clipboard and Paste". It seems they see only "Clipboard", which doesn't work as expected and hence is disabled. I'm not sure why they don't see regular "Paste" 馃し鈥嶁檪.
If so, I think the best advice for the user
Tbh I'm not sure:D. I think the feature is disabled in both visual and html editors. Newer version of Android isn't officially supported :(.
@daniloercoli any ideas?
Sentry issue: WORDPRESS-ANDROID-8W
@jd-alexander Good find on the related issue ;). Since the new crash in Sentry seems to be happening only on Android 7, I'd consider creating a brand new issue with a link to this issue. Another option is to re-open this issue and update its title, but a lot of the comments might be confusing since they are explicitly mentioning Android 8. Wdyt?
I will opt for creating the new issue and linking it to this one :)
Most helpful comment
Steps to reproduce:
Result : App will crash
Tested with: Galaxy Tab A (2016), Android 8.1
App version : alpha: 144
cc: @hypest @rachelmcr @daniloercoli @jkmassel