element-hq / element-android

A Matrix collaboration client for Android.
https://element.io/
GNU Affero General Public License v3.0
3.36k stars 713 forks source link

No menu entry to add shortcut to home screen #4423

Open opk12 opened 2 years ago

opk12 commented 2 years ago

Steps to reproduce

On my phone, the room settings screen and the app's long-tap context menu have no option to add a shortcut on the home screen. Shortcuts do work in other apps on the same phone.

element_bug_shortcut

Intended result and actual result

What did you expect?

To see options to add a shortcut to the home.

What happened instead?

There are no options to add a shortcut to the home.

Your phone model

Samsung

Operating system version

Android 7

Application version and app store

Element Android 1.3.3 (40103030) from F-Droid

Homeserver

matrix.org

Will you send logs?

No

bmarty commented 2 years ago

The app is checking here the returned value of [isRequestPinShortcutSupported()](https://developer.android.com/reference/android/content/pm/ShortcutManager#isRequestPinShortcutSupported()) before displaying this action item. There is maybe a missing permission, can you check on the device app settings?

opk12 commented 2 years ago

Install shortcuts and uninstall shortcuts are in the list for other apps, but not for Element. Do I report to F-droid?

tutti all1 all2
ouchadam commented 2 years ago

which version of android 7 is the device running? from my understanding android added shortcut support in 7.1.1, so if this device is running 7.0 then unfortunately we won't be able to add shortcuts

https://developer.android.com/reference/android/content/pm/ShortcutManager.html (Api 25) https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels

opk12 commented 2 years ago

Version 7.1.1. As said above, the other apps have working shortcuts and have install shortcuts/remove shortcuts in the "All permissions" list, Element does not.

ouchadam commented 2 years ago

@bmarty this might actually be a simple case of using the ShorcutManagerCompat instead

By default the system version seems to support android 8.0+ but the compat version can go lower

Note: See also the support library counterpart ShortcutManagerCompat.isRequestPinShortcutSupported(Context), which supports Android versions lower than VERSION_CODES#O using the legacy private intent com.android.launcher.action.INSTALL_SHORTCUT.

bmarty commented 2 years ago

Yes, this is the current imple : https://github.com/vector-im/element-android/blob/main/vector/src/main/java/im/vector/app/features/home/ShortcutCreator.kt#L57. Is there something else you are thinking about?

ouchadam commented 2 years ago

ah :facepalm: I confused the ShortcutCreator for the system version

opk12 commented 2 years ago

The X-Needs-Info label is still present - is there other info I can provide about the phone?

ouchadam commented 2 years ago

nope, only needed to confirm the exact android 7 version, have removed

opk12 commented 2 years ago

Ok. I have not experience in Android development, but where do the install shortcuts / remove shortcuts in the "All permissions" list come from for the other apps? I mean, the app has a hard-coded manifest with the permissions list? Or a build tool generates the list based on the invoked system library's methods?

ouchadam commented 2 years ago

ideally the permission should come through via the ShortcutCompat library but there's something strange going on...

I'm also able to reproduce the issue on a 7.1.1 emulator and fix it by manually adding the com.android.launcher.permission.INSTALL_SHORTCUT permission

7.1.1 10 7.1.1 WITH PERMISSION 7.1.1 LAUNCHER (WP)
2021-11-17T17:53:47,088292286+00:00 Screenshot_20211117_175523 2021-11-17T17:59:18,282005910+00:00 2021-11-17T18:03:21,888363673+00:00

For some reason the shortcut permission is being commented by the ShortcutBadger library out during the manifest merging process

2021-11-17T18:05:37,932070832+00:00

ouchadam commented 2 years ago

it seems the workaround is to long press the element icon from the launcher which will show shortcut options and then long press those to add to the homescreen

opk12 commented 2 years ago

it seems the workaround is to long press the element icon from the launcher which will show shortcut options and then long press those to add to the homescreen

How? When I long-press the Element icon on the home (Samsung builtin home screen), I have Select multiple items - Remove shortcut - Sleep - Uninstall - App info. Long-pressing them has the effect of a short press.

bmarty commented 2 years ago

For some reason the shortcut permission is being commented by the ShortcutBadger library out during the manifest merging process

It was commented 7 years ago...

Maybe just add

<uses-permission
        android:name="com.android.launcher.permission.INSTALL_SHORTCUT"
        android:maxSdkVersion="25" />

in our Manifest as a workaround, WDYT @ouchadam ?

ouchadam commented 2 years ago

How? When I long-press the Element icon on the home (Samsung builtin home screen), I have Select multiple items - Remove shortcut - Sleep - Uninstall - App info. Long-pressing them has the effect of a short press.

I see, this must be launcher dependant, using the Pixel launcher on 7.1.1 I'm able to long press the launcher icon which reveals the launcher shortcuts which I can then long press to add to the home screen


<uses-permission
        android:name="com.android.launcher.permission.INSTALL_SHORTCUT"
        android:maxSdkVersion="25" />

in our Manifest as a workaround, WDYT @ouchadam ?

sounds reasonable to me