Search code examples
androidandroid-permissionslive-wallpaper

How to get information about current live wallpaper app, without using QUERY_ALL_PACKAGES permission?


If you vote to close this, please explain why.

Background

For my tiny live wallpaper app (here), I offer to import previous wallpaper. I've noticed an issue of targeting API 33 that will cause me to use a more broad storage permission (written here and here).

The problem

In addition to the problematic storage permission, I've noticed that even getting the current live wallpaper is problematic.

What I've found is that without QUERY_ALL_PACKAGES , I can't find the current live wallpaper using getWallpaperInfo:

val wallpaperManager: WallpaperManager =...
val wallpaperInfo = wallpaperManager.wallpaperInfo

And I know that if I use this, I might have trouble publishing the app on the Play Store. I already have such an issue for the storage permission...

What I've tried

I know of the queries tag in the manifest, so I tried this, but it didn't work:

   <queries>
        <intent >
            <action android:name="android.service.wallpaper.WallpaperService"/>
        </intent>
    </queries>

The logic behind trying this, is that live wallpaper apps have to have this:

        <service
            android:name="..."
            android:exported="true"
            android:label="..."
            android:permission="android.permission.BIND_WALLPAPER">
            <intent-filter>
                <action android:name="android.service.wallpaper.WallpaperService" />
            </intent-filter>

            <meta-data
                android:name="android.service.wallpaper" android:resource="..." />
        </service>

The question

Is there any way to avoid using QUERY_ALL_PACKAGES permission, and still reliably be able to reach this API of getting the current live wallpaper?


Solution

  • It seems Google has noticed this issue, and made some adjustments so that at least on Android 14 the query I've mentioned would work:

    Returns the information about the home screen wallpaper if its current wallpaper is a live wallpaper component. Otherwise, if the wallpaper is a static image, this returns null.

    In order to use this, apps should declare a tag with the action "android.service.wallpaper.WallpaperService". Otherwise, this method will return null if the caller doesn't otherwise have visibility of the wallpaper package.

    So, if your app is supposed to run on Android 13 and below, QUERY_ALL_PACKAGES is required, but on Android 14 and above, you should be fine with just a query.

    For once, the Play policy team also approves this kind of thing. This is as opposed to fetching the wallpaper image, which requires MANAGE_EXTERNAL_STORAGE permission:

    https://issuetracker.google.com/issues/237124750

    In any case, the solution is:

    <uses-permission
        android:name="android.permission.QUERY_ALL_PACKAGES" android:maxSdkVersion="33"
        tools:ignore="QueryAllPackagesPermission" />
    
    <queries>
        <intent>
            <action android:name="android.service.wallpaper.WallpaperService"/>
        </intent>
    </queries>