5

When creating a Hello World app that only puts Hello World into a TextView element, the app asks for the permissions "Read phone status and identity" and "Modify and delete SD card contents". Nowhere can I find (even grepping recursively through the whole project folder) any references to either permission.

There are various threads where people complain about their app requesting random permissions, and it turns out a library dependency uses it. I do not use any libraries. My imports are android.app.Activity, android.widget.TextView and android.os.Bundle. My AndroidManifest.xml contains this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="helloworld.test"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:label="@string/app_name">
        <activity android:name="helloactivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

Note there are no <uses-permission .... The libs folder is empty; the res folder contains exactly two folders with an xml file each: one is the layout (containing a LinearLayout and TextView element); the other is values/strings.xml with the application's name.

Finally I also checked the .apk file and decoded the binary AndroidManifest.xml file (it gets compiled to some custom binary format), and it's the same as the original. It does not add anything during compile time either.

The permissions are requested on all devices I could test with: two Android 4.4 devices and a 5.1 device.

Edit: Looking around some more, it sounds like this: Why is my app asking for phone id permission?

I'm targeting API level 19. ~~Could that be something?~~ Edit 2: never mind, compiling against level 23 makes no difference /edit 2. I really hate apps asking permissions they shouldn't have (the famous flashlight app example), but of course I want it to run on older phones as well.

In response to the comment, the project does not use gradle but ant. This is the build.xml file, stripped of any comments:

<?xml version="1.0" encoding="UTF-8"?>
    <project name="helloworld" default="help">
    <property file="local.properties" />
    <property file="ant.properties" />
    <property environment="env" />
    <condition property="sdk.dir" value="${env.ANDROID_HOME}">
        <isset property="env.ANDROID_HOME" />
    </condition>
    <loadproperties srcFile="project.properties" />
    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable." unless="sdk.dir" />
    <import file="custom_rules.xml" optional="true" />
    <import file="${sdk.dir}/tools/ant/build.xml" />
</project>

And finally the java code:

package helloworld.test;

import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;

public class skeletonactivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView out = (TextView) findViewById(R.id.output);
        out.setText("Hello World.");
    }
}
Community
  • 1
  • 1
Luc
  • 5,339
  • 2
  • 48
  • 48
  • Post the code of your Activity and your build.gradle please. – earthw0rmjim Jun 21 '16 at 06:34
  • @user13 Done. Thanks – Luc Jun 21 '16 at 06:44
  • what are the permissions the app is asking for? Also, not sure why you need build.xml instead of build.gradle. Are you not using Android Studio? – Akshay Jun 21 '16 at 06:47
  • @Akshay Not using Android Studio. I posted `build.xml`, see the second code block. The app should ask for no permissions at all (see manifest file), but instead asks for phone identity and modifying files (see first paragraph of the question). – Luc Jun 21 '16 at 07:16
  • @Luc only logical thing in this case seems that either your build.xml or your code is telling your app to create file or directory, and that is why it is asking for permission – Akshay Jun 21 '16 at 07:23
  • @Akshay I'll say, but where is it? Nothing in build.xml nor my code (see the post) does either. It's a hello world application after all. Could I turn on debug output while building or something? – Luc Jun 21 '16 at 08:04
  • May I ask which ide you are using? It seems that it's trying to create directory by reading your build. xml. Most likely your build configuration might not have been setup correctly. Try creating same project in Android Studio. See if you still get same error. – Akshay Jun 21 '16 at 08:14
  • @Akshay I don't use an IDE, I'm using `vim` to edit the code. I build the apk with te command `ant release`. What directory are you talking about? I don't understand what you mean by "it's trying to create directory by reading your build.xml" -- which directory could erroneously be causing permission problems? – Luc Jun 21 '16 at 09:05

1 Answers1

3

It turned out to be the minimum sdk version that mattered, which was not even a property generated by android create project. It generated a project.properties file which contained, as only setting, target=android-19 (or whichever target I specified in the create project command).

In the AndroidManifest.xml you must have a line like this:

    <uses-sdk android:minSdkVersion="19"/>

Without minSdkVersion, it will silently default to version 1. This line comes right under <manifest ...>, so outside of your <application> tag.

For these specific permissions, API level 4 is required to get rid of them. When using minSdkVersion 3 it still asks for the permissions.

Luc
  • 5,339
  • 2
  • 48
  • 48
  • @barlop Ah yes, it told me "you can accept your own answer in 2 days", which made me forget it. – Luc Jun 25 '16 at 16:59