codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.
https://www.codenameone.com/
Other
1.71k stars 405 forks source link

Playing a sound on Android requires Phone permissions. #1945

Closed mwarnett closed 7 years ago

mwarnett commented 7 years ago

I just added Media & MediaManager to play sound in my app. All I am doing is playing a beep to alert the user to an issue.

I did not change my android.xpermissions as there does not seem to be one related to sound.

When I installed the new version on a device running Android 4.4.2 I was told that my app needed new permissions to read phone status and identity.

When I installed the app on a device running Android 6.0.1 the install went normally but when the app went to play the sound I am asked if I want to allow the app to place phone calls.

All I am doing is playing a stupid beep (Why isn't that in CodenameOne?), I do not need phone access and don't want my app to require it. I asked about this on the forums. Shai responded:

This is something we might want to re-evaluate with Android 6. Can you file an issue on that?

Android has a major bug where it doesn't stop audio playback when a phone call comes in (seriously!). The workaround is to track incoming phone calls and pause the audio...

Naturally that's a horrible workaround that has gotten worse with Android 6.

chen-fishbein commented 7 years ago

fixed

mwarnett commented 7 years ago

I was not sure what to expect now as this was just marked fixed, but I don't consider this fixed.

On Android 6 it no loner asks me to allow phone access but the Phone permission is still there even though I did not include it. It seems to be OFF so I guess that is OK.

On Android 4.4.2 when I go to update my app which previously just had Storage I am told the app now also needs phone access. I did not request phone access. I cannot install the upgrade unless I allow the Phone permission.

This is a very sensitive issue for me. It seems that every time I go to update an Android app is needs more and more permissions. I often end up removing an app that demands permissions there is no logical reason for.

Now my own apps are doing it.

I do not use the phone, this should not be required.

codenameone commented 7 years ago

I think this might not be us but rather google play services. Try adding the build hint android.playService.ads=false which will disable all googleplay services. Unless you use location or in app purchase this shouldn't have an impact on your app.

mwarnett commented 7 years ago

I am still having this problem.

Here is a sample program:

`package com.mycompany.myapp;

import com.codename1.ui.AutoCompleteTextField; import com.codename1.ui.Button; import com.codename1.ui.Dialog; import com.codename1.ui.Display; import com.codename1.ui.Form; import com.codename1.ui.Toolbar; import com.codename1.ui.plaf.UIManager; import com.codename1.ui.util.Resources; import com.codename1.io.Log; import com.codename1.media.Media; import com.codename1.media.MediaManager; import com.codename1.ui.Command; import com.codename1.ui.events.ActionEvent; import com.codename1.ui.events.ActionListener; import com.codename1.ui.layouts.BorderLayout;

import java.util.Vector;

/**

I build the above with the following build hints:

android.min_sdk_version=9 android.playService.ads=false android.xpermissions=android.permission.INTERNET,android.permission.WRITE_EXTERNAL_STOR

When I install it on an Android device it needs:

Read phone status and identity Modify or delete the contents of your SD card. Read the contents of your CD card Full network access

If I comment out the two lines in actionPerformed it does not need the phone permission.

`

codenameone commented 7 years ago

It's possible that this is triggered because you are using Ant and not Gradle. We shifted all our effort to Gradle as Google deprecated ant quite a while back. I think Play allows you to submit different APK's for different OS/Device combinations. Maybe that could be a good strategy if you really want to support the users remaining on older devices.

mwarnett commented 7 years ago

I am not using Ant in this case, just the build hints mentioned above. This was built with the default Gradle build

codenameone commented 7 years ago

I'll try to reproduce this.

shannah commented 7 years ago

The AndroidGradleBuilder explicitly adds the phone permission if any classes in the com.codename1.media package are used.

Any idea why this is necessary? @chen-fishbein @codenameone

shannah commented 7 years ago

I have just removed this from the builder (now it won't add the phone permission simply because the media package is used). Seems to work ok on my Nexus 5 so far.

codenameone commented 7 years ago

@shannah this is necessary for the background sound playback mode. If a call comes in Android devices would keep playing sound during the phonecall unless you detect incoming calls and stop media playback (seriously). I think there is a build flag to disable that feature maybe it should be on by default.

chen-fishbein commented 7 years ago

This is an old behavior which was fixed, we are now responding to the media focus. (see Audio#onAudioFocusChange). We don't need this permission anymore, I am guessing I fixed the code without fixing the permission in the gradle script.