Search Unity

Resolved FOREGROUND_SERVICE permission added automatically

Discussion in 'Android' started by Haze-Games, Sep 21, 2020.

  1. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    189
    Hello,

    We have upgraded our project to Unity 2020.1.6f1. We are using Google Play Games Services with the official GPG plugin from Google. We are also using Google Play Billing library package that requires Unity IAP to be enabled (thus enables automatically Unity Analytics only to gain access to IAPs, requiring us to add the DataPrivacy plugin and display the opt out button in the privacy policy).

    We are also requiring CAMERA permission for specific points in the game (to display camera feed using WebCamTexture, not actually recording data of photos / videos capture to the device).

    In addition, we are also using Google's license check system.

    After upgrading and adding all this, strangely, our APK now automatically ads
    android.permission.FOREGROUND_SERVICE
    to the final manifest file. It's not present in our custom manifest in the Unity Project.

    Disabling Unity IAP and disabling Google Play Billing library (removed from project) still keeps this permission in the final manifest.

    We are now targeting latest Android 10 (API level 29) in Player Settings.

    I am lost right now as to why this is added. Any ideas what would be causing this suspicious FOREGROUND_SERVICE to be automatically added?

    We aren't knowingly doing any kind of foreground service / notification stuff. Could it be that Google Play Games requires this for Cloud Save or Achievements? Seems strange that it wasn't needed before (maybe only from API 28/29?).

    It could also be that CAMERA permission requires this from Android API 28/29?

    If it's automatically added because of other permissions, it might be good to update this page.

    I'm a bit worried because the only examples Google documentation provides are about background notifications and music players continuing to play music and such; since we're doing none of that, could potentially a violation for suspension, to have this permission and doing nothing that justifies its presence...

    Thank you in advance for your help!
    Charles
     
    Last edited: Sep 22, 2020
  2. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
    If you have a manual AndroidManifest file, you can add
    Code (CSharp):
    1. <uses-permission android:name="android.permission.FOREGROUND_SERVICE" tools:node="remove" />
    and see if that removes it.
     
    skullthug and Haze-Games like this.
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    So you know, the Google Billing Library does not require Unity IAP, you can do native IAP coding with the library without Unity IAP or Analytics. So it's actually the other way around, Unity IAP requires the Google billing library. It's likely not the cause of your issue, but I wanted to clarify.
     
    Haze-Games likes this.
  4. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    189
    @kaarloew Thank you so much for the quick reply and solution! It did indeed remove the FOREGROUND_SERVICE! Excellent. The game seems to still work perfectly without it.

    @JeffDUnity3D Thank you for the clarification. That's great to know, and good news! I might remove DataPrivacy plugin then and go this way and disable Unity IAP as I won't really need it.

    However I'm very surprised; Google explicitly says that Unity IAP is required:

    The first step described on Google's documentation is: 1. Enable the Unity IAP abstraction layer.

    From that page:
    The Google Play Billing plugin is built on an abstraction layer included with Unity IAP, so you need to enable this abstraction layer before you download and import the plugin. To enable the Unity IAP abstraction layer, do the following:

    Then, all the examples are using Unity IAP calls.

    Did I misunderstood it? Maybe there a different version of the Google IAB library that should be used to avoid the necessity of Unity IAP? I'm using the one from the Google Registry of the Package Manager.

    I will give it a try to remove Unity IAP and see if it results in errors.

    Thank you,
    Charles
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Are you selling virtual products in your game? Why are you including the library? I am referring to this link, which does not need Unity https://developer.android.com/google/play/billing/integrate but you look to be using this https://developer.android.com/google/play/billing/unity
     
  6. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    189
    Indeed, you are right; I'm using the one on your second link, as it was in the Package Manager - and it shows a dependency for Google Play Billing Library on In-App Purchases:

    upload_2020-9-22_14-47-10.png

    I am selling in-app-purchases to unlock game content only. Maybe this is the wrong way to go and I shouldn't use the library from the package manager? You just replied in between, I will investigate more :)

    Yes, basically, from your first link, I clicked the "Use the Billing Library with Unity" link and it brings to your second link with steps to enable Unity IAP. That's why I ended up using this ;)

    Thanks!
    Charles
     

    Attached Files:

  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, Unity IAP requires the Google billing library. But you can install IAP through the Services window, and it will import all necessary dependencies. But if it's working for you now, no need to change anything!
     
    Haze-Games likes this.
  8. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    189
    Thank you for the info. Yes, it is working right now because I implemented it using Google Play Billing Library via Unity IAP.

    However, if there was a way to bypass Unity IAP to simply use the Google Play Billing Library natively, without the requirement of Unity IAP + Unity Analytics enabled, I would have preferred that (to avoid requiring DataPrivacyPlugin and such since I'm not using Analytics nor Cloud Diagnostics specifically to avoid GDPR issues and collect no data at all).

    I think that to in order to achieve this, I would need to call java code from C# and probably do my own library? Which I wouldn't be able to do, so I'll just remain using Unity IAP, since I already added the DataPrivacyPlugin & stuff the past few days :)

    Thanks again,
    Charles
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    So you know, we plan to decouple IAP and Analytics in an upcoming release in a few months.
     
    Haze-Games likes this.
  10. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    189
    Wow, that's excellent news; I've been avoiding Unity IAP since its release for that reason:
    - I've been using other third party plugins for IAPs to avoid using Unity IAP because of the enabling of Analytics and requirements of Privacy Policy / Unity Policy Button / Data Privacy settings "simply" to add IAPs
    - It's been working fine for years, but the plugin I've been using doesn't work well with latest Unity versions, so I decided to scrap it and use Unity IAP regardless of the additional privacy / changes it required to ensure future versions of Unity won't break the game
    - Now that it's implemented, it's working and I've added the DataPrivacy button + Unity Privacy Policy link + mention that the game collects data to process IAPs and non-identifiable data for Analytics, and I hope it's enough to respect Google's policies...

    If you indeed decouple both, you will be saving a lot of headaches for a lot of people in my situation. The hardest part here, is that it's hard to be 100% sure nothing is missing in texts / buttons and that the app won't get suspended / banned for a mistake in the privacy policy, even though I'm not collecting anything with Analytics.

    I did read all the documentation I could on this, but didn't find a good example of "what the privacy policy should look like when you are using Analytics because Unity IAP is enabled". I understand it's hard because it depends on the game, but it does leave a gray area and doubts, when you can't afford a legal team to do it for you.

    Thanks for the info, will keep an eye for an update that would decouple the two! I'll have to cross fingers until then :)
     
  11. unity_grJWwPgd0nddEA

    unity_grJWwPgd0nddEA

    Joined:
    Feb 4, 2020
    Posts:
    16
    I ended up with the same `FOREGROUND_SERVICE` that I don't know where it came from!

    The only things changed was:
    - Added the Play Core Package
    - Bumped the minimum API Version to 28.

    And I can't use the solution @kaarloew proposed here: Sep 22, 2020

    I always end up with a Manifest Merge error when I add that to my custom AndroidManifest.xml .


    Any helps?
     
  12. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
    That manifest merge error should say which parts are conflicting.
     
  13. unity_grJWwPgd0nddEA

    unity_grJWwPgd0nddEA

    Joined:
    Feb 4, 2020
    Posts:
    16
    This is what I get after adding the line you mentioned earlier:

    Code (CSharp):
    1. XmlException: 'tools' is an undeclared prefix. Line 8, position 73.
    2. System.Xml.XmlTextReaderImpl.Throw (System.Exception e) (at <1d98d70bb7d8453b80c25aa561fdecd1>:0)
    3. System.Xml.XmlTextReaderImpl.Throw (System.String res, System.String arg, System.Int32 lineNo, System.Int32 linePos) (at <1d98d70bb7d8453b80c25aa561fdecd1>:0)
    4. System.Xml.XmlTextReaderImpl.LookupNamespace (System.Xml.XmlTextReaderImpl+NodeData node) (at <1d98d70bb7d8453b80c25aa561fdecd1>:0)
    5. System.Xml.XmlTextReaderImpl.AttributeNamespaceLookup () (at <1d98d70bb7d8453b80c25aa561fdecd1>:0)
    6. System.Xml.XmlTextReaderImpl.ParseAttributes () (at <1d98d70bb7d8453b80c25aa561fdecd1>:0)
    7. System.Xml.XmlTextReaderImpl.ParseElement () (at <1d98d70bb7d8453b80c25aa561fdecd1>:0)
    8. System.Xml.XmlTextReaderImpl.ParseElementContent () (at <1d98d70bb7d8453b80c25aa561fdecd1>:0)
    9. System.Xml.XmlTextReaderImpl.Read () (at <1d98d70bb7d8453b80c25aa561fdecd1>:0)
    10. System.Xml.XmlLoader.LoadNode (System.Boolean skipOverWhitespace) (at <1d98d70bb7d8453b80c25aa561fdecd1>:0)
    11. System.Xml.XmlLoader.LoadDocSequence (System.Xml.XmlDocument parentDoc) (at <1d98d70bb7d8453b80c25aa561fdecd1>:0)
    12. System.Xml.XmlLoader.Load (System.Xml.XmlDocument doc, System.Xml.XmlReader reader, System.Boolean preserveWhitespace) (at <1d98d70bb7d8453b80c25aa561fdecd1>:0)
    13. System.Xml.XmlDocument.Load (System.Xml.XmlReader reader) (at <1d98d70bb7d8453b80c25aa561fdecd1>:0)
    14. System.Xml.XmlDocument.Load (System.IO.TextReader txtReader) (at <1d98d70bb7d8453b80c25aa561fdecd1>:0)
    15. GooglePlayServices.PlayServicesResolver.ReplaceVariablesInAndroidManifest (System.String androidManifestPath, System.String bundleId, System.Collections.Generic.Dictionary`2[TKey,TValue] attributeValueReplacements) (at Z:/tmp/tmp.glyoHcYR53/third_party/unity/unity_jar_resolver/source/AndroidResolver/src/PlayServicesResolver.cs:1288)
    16. GooglePlayServices.PlayServicesResolver.PatchAndroidManifest (System.String bundleId, System.String previousBundleId) (at Z:/tmp/tmp.glyoHcYR53/third_party/unity/unity_jar_resolver/source/AndroidResolver/src/PlayServicesResolver.cs:1335)
    17. GooglePlayServices.PlayServicesResolver.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths) (at Z:/tmp/tmp.glyoHcYR53/third_party/unity/unity_jar_resolver/source/AndroidResolver/src/PlayServicesResolver.cs:1049)
    18. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <fb001e01371b4adca20013e0ac763896>:0)
    19. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    20. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <fb001e01371b4adca20013e0ac763896>:0)
    21. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <fb001e01371b4adca20013e0ac763896>:0)
    22. UnityEditor.AssetPostprocessingInternal.InvokeMethod (System.Reflection.MethodInfo method, System.Object[] args) (at /Users/builduser/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:744)
    23. UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets) (at /Users/builduser/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:165)
    24. UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorApplication.cs:442)
    25.  
    Nvm, after adding the
    Code (CSharp):
    1. xmlns:tools="http://schemas.android.com/tools"
    and properly resetting Unity, looks like things are correct now
     
    Last edited: Nov 25, 2020
    niirirgomel likes this.
  14. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    589
    I'm running into the same problem and I don't have a manual Android Manifest file, or at least I don't know where to find it. I'm not publishing through Android Studio, I just use the Unity Build screen to build and install the android SDK's as needed.

    To be honest, I don't know exactly what Google is asking for. They accepted the bundle, but if I don't fix my declaration they won't accept any updates. I've never seen any of this before, they asked for a video demonstrating how "Foreground Services" is used in the app.

    The only things I would think this is referencing is the use of the camera (for AR), and I allow people to save the AR screenshots to their photo album.

    I uploaded a video of the app asking permission to use the camera under the 'Other' checkbox, because none of the other options made sense to me and it was rejected or incorrect. Here are the two issues I need to fix:
    Screenshot 2023-12-19 at 10.30.42 AM.png Screenshot 2023-12-19 at 10.30.29 AM.png

    Can someone please explain how to declare this properly when only using the Unity Editor to build?
     
  15. rousseleva1

    rousseleva1

    Joined:
    Dec 8, 2020
    Posts:
    1

    It looks like you need to check "Custom Main Manifest" in the Android player settings
    There is a tutorial over here on how to get the main manifest : https://docs.unity3d.com/Manual/overriding-android-manifest.html

    It will be inside the Assets/Plugins/Android folder

    All of this is inside Unity :)
     
    Voronoi likes this.