-
Notifications
You must be signed in to change notification settings - Fork 6k
Avoid clipboard permissions prompt #24021
Conversation
bee9c60 to
4923268
Compare
|
|
||
| clipboardManager.clearPrimaryClip(); | ||
| // TODO(justinmc): This fails too. Also, directly running | ||
| // clipboardManager.hasPrimaryClip() here returns true too! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anyone know why clipboardHasStrings and hasPrimaryClip are always returning true? Is something being mocked here that I'm missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving to hasText fixed this, so I'm going with that.
…main Android ClipboardManager class.
8aef272 to
69da37f
Compare
|
Maybe the permission will be prompt here if the clipboard data is URI :
|
| private boolean clipboardHasText() { | ||
| ClipboardManager clipboard = | ||
| (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); | ||
| return clipboard.hasText(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the documentation says hasText is deprecated: https://developer.android.com/reference/android/content/ClipboardManager#hasPrimaryClip()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried hasPrimaryClip but it completely wasn't working for me in the tests. It seemed to always return true, even if I setPrimaryClip to null or did clearPrimaryClip. You can see how I had it before in 72c32b8. CC @blasten who was helping me with this on Discord. Is that a robolectric problem?
|
@justinmc Can you please clarify how hastext make the permission bypassed. |
|
@hamdikahloun It seemed to stop the Xiaomi permission prompt (see flutter/flutter#74139), but it was hard to verify. Are you sure this won't help if an image has been copied? We didn't try that I guess. This is just for starting the app, where the framework checks the clipboard to decide if it should display the Paste button. If you actually paste, then the prompt will still show, which is what it should do. Edit: The general idea is that previously, Android was always calling getPrimaryClip just to check if there was a string on the clipboard to paste, which triggered the prompt. With this PR, it would only call hasText. |
|
Can you check this please : #21290 & flutter/flutter#66108 (comment) |
@justinmc there is a hint here to check whether the clipboard data is a text or not: It seems that the current implementation is not working flutter/flutter#74139 (comment). Can we build an release apk with |
|
@justinmc Any updates? If this issue is stalled, can we mark it WIP or close it till we can resume work it? |
|
Closing it as stale. Feel free to re-open when progress can be made. |
|
Sorry I missed the notifications from this PR. It was the right decision to close for now. The problems are:
I'm having trouble building an example with this using hasPrimaryClip due to engine compilation failing. Hopefully it's a temporary problem with the engine or my setup. |
Currently, some Xiaomi devices show a permissions prompt when the clipboard is accessed. This is similar to iOS14, where we added the
hasStringsmethod to not trigger this prompt (see flutter/flutter#60145). This uses native Android's hasText method to do the same sort of workaround in Android's hasStrings.For flutter/flutter#74139, but probably needs a small framework change too.