Skip to content

Unable to specify PROPERTY_SPECIAL_USE_FGS_SUBTYPE via Service Attribute #8729

Description

@tipa

Android application type

.NET Android (net7.0-android, net8.0-android, etc.)

Affected platform version

VS2022, NET8

Description

The goal is to specify a FOREGROUND_SERVICE_SPECIAL_USE permission using a Service attribute.
This issue is a continuation of this issue: #8409, which was closed after fixing a problem that prevented the foregroundServiceType to be filled in the AndroidManifest.xml.
The issue that remains is that is isn't possible to declare the PROPERTY_SPECIAL_USE_FGS_SUBTYPE for "special use" via an attribute: https://developer.android.com/about/versions/14/changes/fgs-types-required#special-use

Did you find any workaround?

I was able to workaround the problem by manually adding the service tag in the AndroidManifex.xml and giving my Service an explicit name

<service android:foregroundServiceType="specialUse" android:name="my.app.MyService">
   <property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
             android:value="Explanation on why I am using this service type"/>
</service>
[Service(Name = "my.app.MyService")]
sealed class FocusSessionService : Service
{ 
}

Activity

  1. added
    Area: App+Library BuildIssues when building Library projects or Application projects.
    needs-triageIssues that need to be assigned.
    on Feb 16, 2024
  2. added this to the .NET 9 milestone on Feb 16, 2024
  3. jonpryor commented on Feb 16, 2024

    @jonpryor
    Contributor

    Related: https://developer.android.com/guide/topics/manifest/property-element

    We should probably introduce a PropertyAttribute, which emits <property/> within the appropriate scope:

    [AttributeUsage (AttributeTargets.Class, AllowMultiple=true)]
    public partial class PropertyAttribute : Attribute {
        public PropertyAttribute (string name);
        public string Resource {get; set;}
        public string Value {get; set;}
    }

    which would allow:

    [Service]
    [Property ("android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE", Value="Explanation")]
    partial class FocusSessionService : Service {
    }

    Open design question: from the <property/> docs:

    Note: A <property> tag should not contain both android:value and android:resource attributes. If that happens, android:resource is preferred.

    Given this, it might instead be better to have PropertyResourceAttribute and PropertyValueAttribute instead of a single PropertyAttribute.

  4. locked and limited conversation to collaborators on Aug 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area: App+Library BuildIssues when building Library projects or Application projects.Area: Mono.AndroidIssues with the Android API binding (Mono.Android.dll).enhancementProposed change to current functionality.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions