Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any Android app I compile asks for some permissions, even for a Hello World app

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.");
    }
}
like image 1000
Luc Avatar asked Oct 19 '22 07:10

Luc


1 Answers

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.

like image 67
Luc Avatar answered Oct 21 '22 06:10

Luc