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

Unable to request android.permission.RECEIVE_SMS #19658

Closed
tarasverq opened this issue Jan 2, 2024 · 1 comment · Fixed by #19659
Closed

Unable to request android.permission.RECEIVE_SMS #19658

tarasverq opened this issue Jan 2, 2024 · 1 comment · Fixed by #19659
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info fixed-in-8.0.7 fixed-in-9.0.100-preview.1.9973 platform/android 🤖 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@tarasverq
Copy link
Contributor

tarasverq commented Jan 2, 2024

Description

Hi.

Looks like after merging PR #14203 - Remove ReceiveSms added by default it's impossible to request android.permission.RECEIVE_SMS permission at all. It's not in the list anymore.

The problem is in the file Microsoft.Maui.ApplicationModel.Permissions.android.cs
I think it should look like this:

public partial class Sms : BasePlatformPermission
{
	public override (string androidPermission, bool isRuntime)[] RequiredPermissions
	{
		get
		{
			var permissions = new List<(string, bool)>
			{
			};

			if (IsDeclaredInManifest(Manifest.Permission.SendSms))
				permissions.Add((Manifest.Permission.SendSms, true));
			if (IsDeclaredInManifest(Manifest.Permission.ReadSms))
				permissions.Add((Manifest.Permission.ReadSms, true));
			if (IsDeclaredInManifest(Manifest.Permission.ReceiveWapPush))
				permissions.Add((Manifest.Permission.ReceiveWapPush, true));
			if (IsDeclaredInManifest(Manifest.Permission.ReceiveMms))
				permissions.Add((Manifest.Permission.ReceiveMms, true));


			--> if (IsDeclaredInManifest(Manifest.Permission.ReceiveSms))
			-->	 permissions.Add((Manifest.Permission.ReceiveSms, true));

			return permissions.ToArray();
		}
	}
}

My app needs this permission to process messages in background using BroadcastReceiver, but I'm unable to request it :(
I have a proper line in my Manifest file, but anyway it doesn't work:

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

Giving this permission manually through settings

Relevant log output

No response

@tarasverq tarasverq added the t/bug Something isn't working label Jan 2, 2024
Redth added a commit that referenced this issue Jan 2, 2024
#14203 Removed the permission for `ReceiveSms` that was added by default if you tried to use the `Sms` permission on Android, which was only partially correct.

We still want to add the `ReceiveSms` permission to the request if you have also defined it in your android manifest file, just like the other permissions optionally added.

This fixes #19658
@Redth
Copy link
Member

Redth commented Jan 2, 2024

Good catch, I agree, we should be still adding it to the list of requested permissions if it's defined in the manifest, just like the others.

For now you could always implement your own Sms permission class with the correct code until this fix gets merged and released.

@Redth Redth added this to the .NET 8 SR2 milestone Jan 2, 2024
@Redth Redth added platform/android 🤖 area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info s/verified Verified / Reproducible Issue ready for Engineering Triage labels Jan 2, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info fixed-in-8.0.7 fixed-in-9.0.100-preview.1.9973 platform/android 🤖 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
Status: Done
3 participants