dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.28k stars 1.76k forks source link

When using SMS permission on Android ReceiveSms is always requested while it shouldn't #13446

Closed ertandk closed 1 year ago

ertandk commented 1 year ago

Description

Hello,

I'm moving my application that I wrote on a different platform to .NET MAUI and while installing this application, SEND_SMS permission was obtained and my application was published.

But I finished my application and in the background I added SMS.SEND to AndroidManifest on android, but when I try to send SMS it asks me to add android.permission.RECEIVE_SMS permission to AndroidManifest.

But my app is not doing any reading.

My app update was denied by PLAY STORE because it requested android.permission.RECEIVE_SMS as an additional permission.

image

What should I do so that it doesn't ask for the RECEIVE_SMS permission?

public void sendSMS(String phoneNumber, String message)
    {
        // Get the SMS manager
        SmsManager smsManager = SmsManager.Default;
        // Split text message content (SMS length limit)
        IList<string> divideContents = smsManager.DivideMessage(message);
        foreach (string text in divideContents)
        {
            smsManager.SendTextMessage(phoneNumber, null, text, null, null);
        }
    }
{Microsoft.Maui.ApplicationModel.PermissionException: You need to declare using the permission: `android.permission.RECEIVE_SMS` in your AndroidManifest.xml
   at Microsoft.Maui.ApplicationModel.Permissions.BasePlatformPermission.CheckStatusAsync() in D:\a\_work\1\s\src\Essentials\src\Permissions\Permissions.android.cs:line 62
   at Microsoft.Maui.ApplicationModel.Permissions.CheckStatusAsync[Sms]() in D:\a\_work\1\s\src\Essentials\src\Permissions\Permissions.shared.cs:line 10
   at App.MainPage.SMS_Send_Check() in C:\Users\App\Desktop\App\App\App\MainPage.xaml.cs:line 110}

Steps to Reproduce

When sending sms without any listening, sms listening permission is required by androidmanifest.

public void sendSMS(String phoneNumber, String message)
    {
        // Get the SMS manager
        SmsManager smsManager = SmsManager.Default;
        // Split text message content (SMS length limit)
        IList<string> divideContents = smsManager.DivideMessage(message);
        foreach (string text in divideContents)
        {
            smsManager.SendTextMessage(phoneNumber, null, text, null, null);
        }
    }

Link to public reproduction project repository

maui sample

Version with bug

6.0.312

Last version that worked well

6.0.312

Affected platforms

iOS, Android

Affected platform versions

All

Did you find any workaround?

If I'm only sending SMS, the SMS.SEND permission should be sufficient.

Relevant log output

{Microsoft.Maui.ApplicationModel.PermissionException: You need to declare using the permission: `android.permission.RECEIVE_SMS` in your AndroidManifest.xml
   at Microsoft.Maui.ApplicationModel.Permissions.BasePlatformPermission.CheckStatusAsync() in D:\a\_work\1\s\src\Essentials\src\Permissions\Permissions.android.cs:line 62
   at Microsoft.Maui.ApplicationModel.Permissions.CheckStatusAsync[Sms]() in D:\a\_work\1\s\src\Essentials\src\Permissions\Permissions.shared.cs:line 10
   at App.MainPage.SMS_Send_Check() in C:\Users\App\Desktop\App\App\App\MainPage.xaml.cs:line 110}
NonameMissingNo commented 1 year ago

Do you have \<uses-permission android:name="android.permission.RECEIVE_SMS"\/> in your Platforms/Android/AndroidManifest.xml? (It would appear that both those permissions do the same thing?)

Otherwise it won't work.

Also see this SO link: https://stackoverflow.com/questions/48634766/why-does-receive-sms-and-read-sms-permission-do-not-have-different-prompt-boxes

ertandk commented 1 year ago

Do you have in your Platforms/Android/AndroidManifest.xml? (It would appear that both those permissions do the same thing?)

Otherwise it won't work.

Also see this SO link: https://stackoverflow.com/questions/48634766/why-does-receive-sms-and-read-sms-permission-do-not-have-different-prompt-boxes

Thank you for the response.

I had written the application on a different platform before, when I wrote it there, we only added the SMS.SEND permission to the Platforms/Android/AndroidManifest.xml section and sent it, and the play store verified it by asking us for evidence and accepted the application.

I just finished the project with .NET MAUI, I had to add android.permission.RECEIVE_SMS because "Relevant log output" was giving an error.

so android.permission.RECEIVE_SMS should not be written in "Platforms/Android/AndroidManifest.xml". Because PLAY STORE does not accept it. It rejects my app.

NonameMissingNo commented 1 year ago

Ah, now I see the issue. When you're sending an SMS, it asks you to also have Receive permissions, but because you're not an sms application, it gets rejected.

NonameMissingNo commented 1 year ago

https://github.com/dotnet/maui/blob/main/src/Essentials/src/Permissions/Permissions.android.cs#L450

It would appear that Receive SMS is a must to have?

ertandk commented 1 year ago

https://github.com/dotnet/maui/blob/main/src/Essentials/src/Permissions/Permissions.android.cs#L450

It would appear that Receive SMS is a must to have?

I don't know why, but I think it shouldn't be necessary. Can I fix this value somehow?

NonameMissingNo commented 1 year ago

https://github.com/dotnet/maui/blob/main/src/Essentials/src/Permissions/Permissions.android.cs#L450 It would appear that Receive SMS is a must to have?

I don't know why, but I think it shouldn't be necessary. Can I fix this value somehow?

Wait for tomorrow, see if a dev responds.

jfversluis commented 1 year ago

Hm yeah that seems a bit weird. I think you should be able to use send SMS without read SMS.

For a short-term solution you can declare your own permission and use that to unblock yourself. Learn more about that in our docs: https://learn.microsoft.com/dotnet/maui/platform-integration/appmodel/permissions?view=net-maui-7.0&tabs=windows#extending-permissions

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

jonpryor commented 1 year ago

@NonameMissingNo: Indeed, Manifest.Permission.ReceiveSms appears to be required.

@Redth: do you remember why commit 152284f0af813f46b271044277b7df5b61128995 requires that the Manifest.Permission.ReceiveSms permission be present in order to use SMS? Is there some reason to not just remove the requirement for Manifest.Permission.ReceiveSms?

moljac commented 1 year ago

Added repro sample.

Sample.Issue_13446.SMS_Perimisions.zip

Emulator test did not crash with just android.permission.SEND_SMS and nothing was added during builds.

Preparing to Test on devices right now.

find . -type f -iname "AndroidManifest.xml" -exec grep -Hni "android.permission." {} \;  
./obj/Debug/net7.0-android/android/manifest/AndroidManifest.xml:11:  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
./obj/Debug/net7.0-android/android/manifest/AndroidManifest.xml:12:  <uses-permission android:name="android.permission.INTERNET" />
./obj/Debug/net7.0-android/android/manifest/AndroidManifest.xml:13:  <uses-permission android:name="android.permission.SEND_SMS" />
./obj/Debug/net7.0-android/android/AndroidManifest.xml:11:  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
./obj/Debug/net7.0-android/android/AndroidManifest.xml:12:  <uses-permission android:name="android.permission.INTERNET" />
./obj/Debug/net7.0-android/android/AndroidManifest.xml:13:  <uses-permission android:name="android.permission.SEND_SMS" />
./obj/Debug/net7.0-android/AndroidManifest.xml:9:  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
./obj/Debug/net7.0-android/AndroidManifest.xml:10:  <uses-permission android:name="android.permission.INTERNET" />
./obj/Debug/net7.0-android/AndroidManifest.xml:11:  <uses-permission android:name="android.permission.SEND_SMS" />
./Platforms/Android/AndroidManifest.xml:4:  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
./Platforms/Android/AndroidManifest.xml:5:  <uses-permission android:name="android.permission.INTERNET" />
./Platforms/Android/AndroidManifest.xml:6:  <uses-permission android:name="android.permission.SEND_SMS" />
moljac commented 1 year ago

I was able to sens SMS from sidelaoaded app on a real device, i.e only with android.permission.SEND_SMS permission.

So, no need to add android.permission.RECEIVE_SMS.

Improved sample. Sample.Issue_13446.SMS_Perimisions.zip

Note: Logging in UI needs refactoring to use MVVM.