Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up ForegroundService.ToString() #8412

Merged
merged 2 commits into from
Oct 11, 2023
Merged

Conversation

dellis1972
Copy link
Contributor

@dellis1972 dellis1972 commented Oct 10, 2023

Fixes #8409

There were a number of missing ForegroundService types missing in the last few releases. As a result users were not able to make use of them via the Service attribute. If they tried it would result in an empty foregroundService attribute.

<service android:foregroundServiceType="" android:name="crc64cd18cf298594e84d.MyService " />

Lets fill in the missing types. We should address this in the future by using some form of code generation as outlined in #8272

@jonpryor
Copy link
Member

Related: #8272

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good if CI is green. 👍

@dellis1972
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jonpryor jonpryor merged commit 58a81eb into xamarin:main Oct 11, 2023
41 of 47 checks passed
@dellis1972 dellis1972 deleted the Issue8409 branch October 11, 2023 22:10
grendello added a commit to grendello/xamarin-android that referenced this pull request Oct 12, 2023
* main:
  [Xamarin.Android.Build.Tasks] Fix up ForegroundService.ToString() (xamarin#8412)
  [monodroid] Hush some messages logged by default on startup (xamarin#8414)
jonathanpeppers pushed a commit that referenced this pull request Oct 13, 2023
)

Fixes: #8409

Context: #8272

The [`//service/@android:foregroundServiceType`][0] attribute can be
generated based on the value of the
`Android.App.ServiceAttribute.ForegroundServiceType` property:

	[Service(ForegroundServiceType=ForegroundService.TypeCamera)]
	partial class MyService : Service {
	}

which will result in an `AndroidManifest.xml` fragment such as:

	<service android:foregroundServiceType="camera" android:name="crc64….MyService" />

However, a number of `ForegroundService` enum values have been added
without corresponding updates to `ServiceAttribute` XML generation.
Consequently, using "recently added" values such as
`ForegroundService.TypeHealth` would result in those values *not*
being added to the generated `//service/@android:foregroundServiceType`.

Update `ManifestDocumentElement.cs` to update
`ToString(ForegroundService)` so that all current `ForegroundService`
enum values are supported.  This will allow:

	[Service(ForegroundServiceType=
	    ForegroundService.TypeCamera |      // previously supported
	    ForegroundService.TypeMicrophone)]  // new hawtness
	partial class MyService : Service {
	}

to properly emit:

	<service android:foregroundServiceType="camera|microphone" android:name="crc64….MyService" />

[0]: https://developer.android.com/guide/topics/manifest/service-element#foregroundservicetype
jonathanpeppers pushed a commit that referenced this pull request Oct 17, 2023
)

Fixes: #8409

Context: #8272

The [`//service/@android:foregroundServiceType`][0] attribute can be
generated based on the value of the
`Android.App.ServiceAttribute.ForegroundServiceType` property:

	[Service(ForegroundServiceType=ForegroundService.TypeCamera)]
	partial class MyService : Service {
	}

which will result in an `AndroidManifest.xml` fragment such as:

	<service android:foregroundServiceType="camera" android:name="crc64….MyService" />

However, a number of `ForegroundService` enum values have been added
without corresponding updates to `ServiceAttribute` XML generation.
Consequently, using "recently added" values such as
`ForegroundService.TypeHealth` would result in those values *not*
being added to the generated `//service/@android:foregroundServiceType`.

Update `ManifestDocumentElement.cs` to update
`ToString(ForegroundService)` so that all current `ForegroundService`
enum values are supported.  This will allow:

	[Service(ForegroundServiceType=
	    ForegroundService.TypeCamera |      // previously supported
	    ForegroundService.TypeMicrophone)]  // new hawtness
	partial class MyService : Service {
	}

to properly emit:

	<service android:foregroundServiceType="camera|microphone" android:name="crc64….MyService" />

[0]: https://developer.android.com/guide/topics/manifest/service-element#foregroundservicetype
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to set up "special use" foreground service via ServiceAttribute
3 participants