Adobe-Runtime-Support icon indicating copy to clipboard operation
Adobe-Runtime-Support copied to clipboard

About FOREGROUND_SERVICE

Open yvant opened this issue 1 year ago • 12 comments

Recent updates within the AIR ecosystem now require that we upgrade the targetSDKVersion to 34. Apparently, it comes with using android.permission.FOREGROUND_SERVICE, which wasn't require before.

With this new requirement, Google Play asks for a video and a description on how the app uses that requirement. Since I didn't know how to answer, I just said that it was a requirement because of the SDK upgrade + added a regular video of my game. The app update was rejected, here's an excerpt of the mail rejection:

Issue found: Play Console declaration and/or app description in Google Play Store does not sufficiently demonstrate the use of permission.
We are unable to approve your app’s use of [FOREGROUND_SERVICE] permission because we found the following information provided to be insufficient in evaluating compliance with [foreground service permission requirements]:
The video link you provided in the Play Console declaration and/or
The app description in the Google Play store.

What can I do to make it pass Google Play review? Is there a way to remove the FOREGROUND_SERVICE permission?

yvant avatar May 30 '24 13:05 yvant

That FOREGROUND_SERVICE permission isn't required (or included) by just the AIR runtimes; but we have come across it when using the Play Asset Delivery functionality. It was required in the manifest file and is probably added for you if using APM. There may be other ANEs that could be using this, so the first step may be to find out where this is coming from..

Re the use from Play Asset Delivery .. I can't actually see the documentation now that specifies that this was required, so let me check with the developer who'd put this together to find out the reason for its inclusion and whether it may be excluded now. But if it is still a requirement, then Google/Android should accept that this is required for using Play Asset Delivery and installing the asset packs etc.

thanks

ajwfrost avatar May 30 '24 15:05 ajwfrost

Thanks for the quick answer. Indeed, I am not sure what requires that. I'll be waiting for your feedback!

yvant avatar May 30 '24 16:05 yvant

What extensions are you using?

It is required by the android play core lib "to launch foreground extraction service for targetSdkVersion 28+" (ExtractionForegroundService) which is related to the PlayAssetDelivery extension.

We also have a few extensions that use it for other purposes.

marchbold avatar May 30 '24 23:05 marchbold

I'm using these libraries: ├──[email protected] ├──[email protected] ├──[email protected] ├──[email protected] ├──[email protected] ├──[email protected] ├──[email protected] ├──[email protected] ├──[email protected] ├──[email protected] ├──[email protected] ├──[email protected] └──[email protected]

If I have to use it, what kind of message can I send to Google Play? What about the video?

Here's the screenshot they want me to fill. image

yvant avatar May 30 '24 23:05 yvant

Any news on that matter?

yvant avatar Jun 03 '24 23:06 yvant

The FOREGROUND_SERVICE/FOREGROUND_SERVICE_DATA_SYNC permissions should fall in the local importing / exporting category I believe for extracting resources.

marchbold avatar Jun 04 '24 01:06 marchbold

How can I present that information to Google so they validate the build? As you can see on the screenshot, they need a video and a description to validate the addition of that permission.

yvant avatar Jun 04 '24 15:06 yvant

FYI we've been looking at the Play Asset Delivery requirements, a lot of that has been updated and their documentation doesn't now talk about that permission.. although, it does still seem that it only works if we do have the ExtractionForegroundService service defined in the manifest. But even with this service, and omitting the FOREGROUND_SERVICE permission, the application does manage to download/extract the asset packs when tested with the Play console 'internal app testing' approach..

So it might be you could omit that permission too? Worth just testing everything carefully (and on different versions of Android -> we're just starting to do this part too) to ensure it doesn't cause problems on particular older or newer devices. Would be nice if the Android documentation was clearer on all this :-(

thanks

ajwfrost avatar Jun 04 '24 15:06 ajwfrost

What lines should I try to remove from the manifest? I have several lines mentionning "foreground":

1 - <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
2 - <!-- Is required to launch foreground extraction service for targetSdkVersion 34+. -->
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>
3 - <service android:name="androidx.work.impl.foreground.SystemForegroundService" android:directBootAware="false" android:enabled="@bool/enable_system_foreground_service_default" android:exported="false"/>
4 - <service android:name="com.google.android.play.core.assetpacks.ExtractionForegroundService" android:enabled="false" android:exported="false" android:foregroundServiceType="dataSync"/>

yvant avatar Jun 04 '24 16:06 yvant

I would just try removing the permissions if you don't plan to use the functionality.

marchbold avatar Jun 05 '24 02:06 marchbold

Just to be sure I understand well: I should try removing 1 & 2, right? Another question: what ANEs or features use those permissions? I've seen your message regarding local importing / exporting resources but I didn't really understand it.

yvant avatar Jun 05 '24 21:06 yvant

I'll try to push a new version by removing 1 & 2. 1 - Should I expect some new ANR from these changes? 2 - Would it deactivate some functionalities these are related to? I am still having a hard time trying to figure out what these refer to.

yvant avatar Jun 20 '24 13:06 yvant

@ajwfrost When using just install-time assets packets you can ommit implementation of play-asset-delivery library on the ANE and also the service permissions. If you plan to use fast-follow | on-demand you will need to request aproval of google using the form submition when targeting android 14+

https://developer.android.com/about/versions/14/changes/fgs-types-required?hl=pt-br

bobaoapae avatar Jul 11 '24 17:07 bobaoapae

Hi @bobaoapae - thanks for that; the link is about Foreground Services which we'd already reviewed, but we've not actually been able to find the details on what requirements there are with the different play asset delivery types. Do you have any reference for that i.e. something that says you don't need the play asset delivery library or service permissions if just using install-time? And it seems crazy that you would need to request Google's permission just to use their own play asset delivery functionality for fast-follow/on-demand..?!

thanks

ajwfrost avatar Jul 12 '24 06:07 ajwfrost

Hi @bobaoapae - thanks for that; the link is about Foreground Services which we'd already reviewed, but we've not actually been able to find the details on what requirements there are with the different play asset delivery types. Do you have any reference for that i.e. something that says you don't need the play asset delivery library or service permissions if just using install-time? And it seems crazy that you would need to request Google's permission just to use their own play asset delivery functionality for fast-follow/on-demand..?!

thanks

If you check play asset delivery notification you will see that to use install time assets you just need the plug-in and configure assets folders on grade. And on the next section it's show the need of de library to use on demand and fast follow

Check here: https://developer.android.com/guide/playcore/asset-delivery/integrate-java

Now about the permissions, when you add dependency to the play asset delivery this automatically add the request for permission of foreground service etc, and those permission now on Android 14+ will need the form submission questing approval.

I agree that this is not ideal, and also not very documented. But for use of play asset delivery library each user will need to use the form validation provided by Google.

To Harman the unique alternative it's to just handle that to don't implement the library of using install time assets. Here I'm using my own ane to handle that, I use the assets resource on the application descriptor but I use my own ane to get those files, avoiding for complete the use of the play asset delivery and everything works like a charm without need of the form approval

bobaoapae avatar Jul 12 '24 10:07 bobaoapae

public static class MyAneExtensionNativeLoaderFunction implements FREFunction {
        @Override
        public FREObject call(FREContext freContext, FREObject[] freObjects) {
            try {
                try (InputStream inputStream = context.getAssetManager().open(freObjects[1].getAsString())) {
                    Log.d(TAG, "loadNative: " + freObjects[1].getAsString() + " " + inputStream.available());
                    FREByteArray freByteArray = FREByteArray.newByteArray(inputStream.available());
                    freByteArray.acquire();
                    ByteBuffer buffer = freByteArray.getBytes();
                    byte[] bufferRead = new byte[1024];
                    int bytesRead;
                    while ((bytesRead = inputStream.read(bufferRead)) != -1) {
                        buffer.put(bufferRead, 0, bytesRead);
                    }
                    freByteArray.release();
                    return freByteArray;
                } catch (FileNotFoundException e) {
                    //if file not found just return null
                    Log.d(TAG, "File not found: ", e);
                    return null;
                }
            } catch (Exception e) {
                Log.e(TAG, "Error: ", e);
            }

            return null;
        }
    }

I use that code on my ANE to open assets packed using install-time, without any dependency

bobaoapae avatar Jul 12 '24 14:07 bobaoapae

I'll try to push a new version by removing 1 & 2.

@yvant were you able to push a new build ?

believe for extracting resources. @marchbold I am using Zip ane, do they need this permission ?

Shaunmax avatar Jul 16 '24 13:07 Shaunmax

Yes, I was able to push the new build without said requirements. I can see some new ANR, but nothing critical: globally, my ANRs are a bit lower now.

yvant avatar Jul 16 '24 13:07 yvant

FOREGROUND_SERVICE_DATA_SYNC

so remove these two lines ?

  <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>

Shaunmax avatar Jul 16 '24 14:07 Shaunmax

This one is not a problem for Google Play and is required for notifications I think. <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

Just remove the other one.

yvant avatar Jul 16 '24 14:07 yvant

Hi! I have the same problem. Here is the solution I found:

First add (xmlns:tools="http://schemas.android.com/tools") to the manifest: <manifest android:installLocation="auto" xmlns:tools="http://schemas.android.com/tools">

Second add: <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" tools:node="remove" />

SergeevRV avatar Feb 22 '25 22:02 SergeevRV

This should be resolved in the latest ANE updates. the android play core lib dependency has been broken up into components so only adds this permission if you are using that certain service.

marchbold avatar Feb 23 '25 00:02 marchbold