Game crashes when permission READ_PHONE_STATE is removed (SOLVED)

Hi all!

I have been trying to remove all the unnecessary things in the AndroidManifest.xml. When I remove the permission READ_PHONE_STATE, the game crashes on my phone (Samsung Galaxy Grand, GT-I9082, running Android 4.1.2) on startup after the main page loads. I tried the game (download from Google Play) on another phone (Samsung Galaxy Note 4, SM-N910G, running Android 6.0.1) and it does not crash. Below is the version of the AndroidManifest.xml with the READ_PHONE_STATE permission that does not crash on either phones. Help is much appreciated! Thank you!

Update: Tried the game (download from Google Play) on Galaxy S7 (SM-G930FD, Android 6.0.1) and it doesnā€™t crash too

Anyways, I have also released my game on Google Play (https://play.google.com/store/apps/details?id=com.jiax.blocks&hl=en), but with an earlier AndroidManifest.xml and without the READ_PHONE_STATE permission, which means it probably will crash on some phones (I am thinking the older Android versions). Nevertheless, support is very much appreciated too! Thank you too!

<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.jiax.blocks"
        android:versionCode="1"
        android:versionName="1"
        android:installLocation="auto">

    <uses-feature android:required="true" android:glEsVersion="0x00020000" />
    <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" />
    <application
        
        android:icon="@drawable/icon"
        
        android:label="jiax.Blocks" android:hasCode="true" android:debuggable="false">


        <!-- For GCM (push) -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />


        <!-- For Facebook -->
        <meta-data android:name="com.facebook.sdk.ApplicationName"
            android:value="jiax.Blocks" />

        <activity android:name="com.dynamo.android.DefoldActivity"
                android:label="jiax.Blocks"
                android:configChanges="orientation|screenSize|keyboardHidden"
                android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                android:screenOrientation="portrait"
                android:launchMode="singleTask">
            <meta-data android:name="android.app.lib_name"
                    android:value="jiax.Blocks" />
            
            
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.dynamo.android.DispatcherActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
        <activity android:name="com.facebook.FacebookActivity"
          android:theme="@android:style/Theme.Translucent.NoTitleBar"
          android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
          android:label="jiax.Blocks" />
        <activity android:name="com.defold.iap.IapGooglePlayActivity"
          android:theme="@android:style/Theme.Translucent.NoTitleBar"
          android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
          android:label="IAP">
        </activity>

    </application>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

</manifest>
<!-- END_INCLUDE(manifest) -->
1 Like

Do you have any logs from the crash?

In the meantime maybe this thread has some useful info: Google requires a privacy policy

1 Like

Hi, thank you for your fast reply!

Using logcat, here are what Iā€™ve gotten, which arenā€™t really helpful I suppose? Because they are the sameā€¦

Without READ_PHONE_STATE:

Grand (game crashes):

W/defold (10245): WARNING:DLIB: Unable to start profile http-server (-1)
E/defold (10245): ERROR:ENGINE: Unable to create engine web-server (-1)
I/defold (10245): INFO:ENGINE: Defold Engine 1.2.119 (2406775)
I/defold (10245): INFO:ENGINE: Loading data from: dmanif:game.dmanifest
I/defold (10245): INFO:ENGINE: Initialised sound device 'defaultā€™
I/defold (10245):

Note 4 (game does not crash):

01-05 23:26:05.398 30797 30811 W defold : WARNING:CRASH: Number of modules exceeds capacity
01-05 23:26:05.398 30797 30811 W defold : WARNING:DLIB: Unable to start profile http-server (-1)
01-05 23:26:05.458 30797 30811 E defold : ERROR:ENGINE: Unable to create engine web-server (-1)
01-05 23:26:05.458 30797 30811 I defold : INFO:ENGINE: Defold Engine 1.2.119 (2406775)
01-05 23:26:05.468 30797 30811 I defold : INFO:ENGINE: Loading data from: dmanif:game.dmanifest
01-05 23:26:05.538 30797 30811 I defold : INFO:ENGINE: Initialised sound device 'defaultā€™
01-05 23:26:05.538 30797 30811 I defold :

With READ_PHONE_STATE

Grand (game does not crash):

W/defold (10640): WARNING:DLIB: Unable to start profile http-server (-1)
E/defold (10640): ERROR:ENGINE: Unable to create engine web-server (-1)
I/defold (10640): INFO:ENGINE: Defold Engine 1.2.119 (2406775)
I/defold (10640): INFO:ENGINE: Loading data from: dmanif:game.dmanifest
I/defold (10640): INFO:ENGINE: Initialised sound device 'defaultā€™
I/defold (10640):

Note 4 (game does not crash):

01-05 23:23:52.498 30247 30274 W defold : WARNING:CRASH: Number of modules exceeds capacity
01-05 23:23:52.498 30247 30274 W defold : WARNING:DLIB: Unable to start profile http-server (-1)
01-05 23:23:52.558 30247 30274 E defold : ERROR:ENGINE: Unable to create engine web-server (-1)
01-05 23:23:52.558 30247 30274 I defold : INFO:ENGINE: Defold Engine 1.2.119 (2406775)
01-05 23:23:52.558 30247 30274 I defold : INFO:ENGINE: Loading data from: dmanif:game.dmanifest
01-05 23:23:52.608 30247 30274 I defold : INFO:ENGINE: Initialised sound device 'defaultā€™
01-05 23:23:52.608 30247 30274 I defold :

But one thing Iā€™ve noticed, if I use ā€œBuild and Launchā€ from Defold Editor (WIndows) to dmengine on Android, the game does not crash (on my Grand without READ_PHONE_STATE)

INFO:ENGINE: Defold Engine 1.2.119 (2406775)
INFO:ENGINE: Loading data from: http://192.168.1.6:8080/build/default
INFO:ENGINE: Initialised sound device ā€˜defaultā€™

Regarding the link, are you referring to creating a privacy policy or the mention of push notifications? I am trying to avoid the privacy policy because my game does not require those permissions, and it does not use push notifications too.

Thank you!

Off topic:
I found out that another kind of error is thrown when running the game on Android (on both phones) (Below is just an example, but basically, the error appears for any thing I press on the main screen). This error doesnā€™t appear when I run on Windows. This isnā€™t really important since the game still runs as intended, but itā€™s kind of weird for this to happen.

ERROR:GAMESYS: The collection /main/game.collectionc could not be loaded since it was already. Message ā€˜loadā€™ sent from main:/main#script to main:/main#gameproxy.

1 Like

We keep a minimal set of permissions in the Android manifest. You should not remove any of the permissions unless youā€™ll cripple the engine. I canā€™t remember if itā€™s required for push, facebook or iap.

2 Likes

my game does not use any of those functions, and it appears to work as intended on note 4 and s7, both running android 6.0.1.

do you have any suggestions on how else i can try to debug?

Ok, and in that case have you also removed all other references in the manifest to these systems? There should be other references to facebook, iap etc that probably also needs to be removed if you mess with the permissions.

This is the current state of the AndroidManifest.xml with the permission READ_PHONE_STATE that does not crash on any of the phones. Is there anything else that I can/should remove?

<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.jiax.blocks"
        android:versionCode="2"
        android:versionName="1.01"
        android:installLocation="auto">

    <uses-feature android:required="true" android:glEsVersion="0x00020000" />
    <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" />
    <application
        
        android:icon="@drawable/icon"
        
        android:label="jiax.Blocks" android:hasCode="true" android:debuggable="false">

        <!-- For GCM (push) -->
        <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity android:name="com.dynamo.android.DefoldActivity"
                android:label="jiax.Blocks"
                android:configChanges="orientation|screenSize|keyboardHidden"
                android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                android:screenOrientation="portrait"
                android:launchMode="singleTask">
            <meta-data android:name="android.app.lib_name"
                    android:value="jiax.Blocks" />
            
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

	
</manifest>
<!-- END_INCLUDE(manifest) -->

This is required for sys.get_sys_info() and specifically to read android.id used for the device_ident field. According to the code it should emit a warning message (ā€œUnable to get ā€˜android.idā€™. Is permission android.permission.READ_PHONE_STATE set?ā€) but not crash. The permission could potentially be used for other things as well. What does logcat show when it crashes?

3 Likes

sorry i have pasted the logcat in the previous reply, and thatā€™s all i could get from logcat. the main screen loads up, i canā€™t press anything, and few seconds later android returns the game has stopped.

Where did you post the Android log (ie the result of running adb logcat)? All I see is the content of the editor console.

Sorry my mistakeā€¦ I have run logcat again and came across this section (hope this is where the problem lies). This error did not appear when I install and run the exact same apk on Note 4.

E/AndroidRuntime(13773): FATAL EXCEPTION: main
E/AndroidRuntime(13773): java.lang.SecurityException: Neither user 10037 nor current process has android.permission.READ_PHONE_STATE.
E/AndroidRuntime(13773):        at android.os.Parcel.readException(Parcel.java:1425)
E/AndroidRuntime(13773):        at android.os.Parcel.readException(Parcel.java:1379)
E/AndroidRuntime(13773):        at com.android.internal.telephony.ITelephonyRegistry$Stub$Proxy.listen(ITelephonyRegistry.java:238)
E/AndroidRuntime(13773):        at android.telephony.MultiSimTelephonyManager.listen(MultiSimTelephonyManager.java:120)
E/AndroidRuntime(13773):        at com.defold.sound.SoundManager$1.run(SoundManager.java:68)
E/AndroidRuntime(13773):        at android.os.Handler.handleCallback(Handler.java:615)
E/AndroidRuntime(13773):        at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(13773):        at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(13773):        at android.app.ActivityThread.main(ActivityThread.java:4935)
E/AndroidRuntime(13773):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(13773):        at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(13773):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
E/AndroidRuntime(13773):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
E/AndroidRuntime(13773):        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
E/AndroidRuntime(13773):        at dalvik.system.NativeStart.main(Native Method)
1 Like

Ah, there we go. Line #68 does this:

SoundManager.this.telephonyManager.listen(new CustomPhoneCallListener(SoundManager.this), PhoneStateListener.LISTEN_CALL_STATE);

It deals with how sounds are played in Defold when you have an incoming phone call. @sicher perhaps we should document the required Android permissions in the Android manual and explain why they are needed?

2 Likes

I see, thank you!

But is there any workaround for this issue? Like perhaps not load sounds at all if necessary?

Also, do you have an explanation as to why this error occurred on the Grand and not the Note 4 (and S7)?

Not sure if itā€™s possible to remove sounds completely using an App Manifest. @Mathias_Westerdahl?

Android OS version?

You should be able to disable all sound altogether by using an app manifest.

Save the file below in ā€œgame.appmanifestā€ next to your project, and add these lines to your game.project:

[native_extension]
app_manifest = /game.appmanifest

game.appmanifest:

# Disables all sound
platforms:
    x86_64-linux:
        context:
            excludeSymbols: ["AudioDecoderStbVorbis", "AudioDecoderTremolo", "AudioDecoderWav","DefaultSoundDevice"]
            excludeLibs: ["sound"]
            libs: ["sound_null"]

    x86_64-osx:
        context:
            excludeSymbols: ["AudioDecoderStbVorbis", "AudioDecoderTremolo", "AudioDecoderWav","DefaultSoundDevice"]
            excludeLibs: ["sound"]
            libs: ["sound_null"]

    js-web:
        context:
            excludeSymbols: ["AudioDecoderStbVorbis", "AudioDecoderTremolo", "AudioDecoderWav","DefaultSoundDevice"]
            excludeLibs: ["sound"]
            libs: ["sound_null"]

    x86-win32:
        context:
            excludeSymbols: ["AudioDecoderStbVorbis", "AudioDecoderTremolo", "AudioDecoderWav","DefaultSoundDevice"]
            excludeLibs: ["libsound"]
            libs: ["libsound_null.lib"]

    x86_64-win32:
        context:
            excludeSymbols: ["AudioDecoderStbVorbis", "AudioDecoderTremolo", "AudioDecoderWav","DefaultSoundDevice"]
            excludeLibs: ["libsound"] 
            libs: ["libsound_null.lib"]

    armv7-android:
        context:
            excludeSymbols: ["AudioDecoderStbVorbis", "AudioDecoderTremolo", "AudioDecoderWav","DefaultSoundDevice"]
            excludeLibs: ["sound"]
            libs: ["sound_null"]

    armv7-ios:
        context:
            excludeSymbols: ["AudioDecoderStbVorbis", "AudioDecoderTremolo", "AudioDecoderWav","DefaultSoundDevice"]
            excludeLibs: ["sound"]
            libs: ["sound_null"]
            
    arm64-ios:
        context:
            excludeSymbols: ["AudioDecoderStbVorbis", "AudioDecoderTremolo", "AudioDecoderWav","DefaultSoundDevice"]
            excludeLibs: ["sound"]
            libs: ["sound_null"]
6 Likes

Grand is running on Android 4.1.2, Note 4 and S7 are running on 6.0.1.
But oh I just saw this line somewhere in the logcat (just a few lines before the error, in between are some lines about sensors)

W/defold.sound(29825): Android version < 17. Unable to determine hardware sample rate.

Thank you!! Iā€™ve done as instructed, tested and the game no longer crashes! Though it is a workaround, sound is currently not important so all is well. But just wondering if itā€™s an OS issue or is it something that you guys can perhaps to look into?

Thank you all so much once again!! :slight_smile:

1 Like

The Defold sound manager on mobile phones is designed to mute the music/sfx during an incoming phone call. This is the pretty much the expected behaviour of any Android app, and the way to detect an incoming call is to use the TelephonyManager. On older Android OS versions the READ_PHONE_STATE permission is required for LISTEN_CALL_STATE. On newer Android devices this permission requirement has been removed. And thatā€™s why itā€™s crashing on the Grand and not your other devices.

5 Likes

I see! Thank you very much for your explanation! :slight_smile:

1 Like

Hello, i think bug here Missing READ_PHONE_STATE permission