Disable dependency permissions - android

I'm facing the following problem at the moment:
I have developed app 'A' which uses permissions 1, 2, 3 and uses an 3rd party library 'B' as a dependency (added using maven & gradle).
Library 'B' uses the permissions 4 and 5. Now when building the app, the manifest merger adds the permissions 4 and 5 to app 'A'.
How can I prevent this and only have the permissions 1, 2 and 3 in the final manifest?
My first guess would be using one of the manifest merger markers as seen here: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-Markers

You need to use Selector
Each tools:node or tools:attr declaration can be augmented by a
tools:selector attribute which is contextual information on whether or
not the merging strategy should be applied to the current lower
priority XML description. For instance, this is useful when removing a
permission only if coming for one particular library as opposed to any
library:
<permission
android:name="permissionOne"
tools:node="remove"
tools:selector="com.example.lib1">
It would be next according your initial requirements
<!--suppress AndroidDomInspection -->
<uses-permission
tools:node="removeAll"/>
but keep in mind that all other <uses-permissions/> will be removed.

As you know all libraries have a manifest file and will merge together.
you can remove a permission that is in one of your libraries by this:
tools:node="remove"
for an example removing location permission:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" tools:node="remove" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" tools:node="remove" />

Related

What is the difference between different android permission name prefix?

In the android manifest, there are sometimes permissions named as:
com.google.android.gms.permission...
or android.permission....
Is this naming arbitrary or is there a reason for having different prefixes?
The reason I would like to know this is to be able to locate the right permissions I usually go to the https://developer.android.com/reference/android/Manifest.permission
This link contains only ones with "android.permission.*" I would like to know if there is a single reference somewhere for all the other permissions?
P.S. Below is an example of ACTIVITY_RECOGNITION being added to the manifest, trying to make sense of it.
<!-- Required for 28 and below. -->
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<!-- Required for 29+. -->
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
Is this naming arbitrary or is there a reason for having different prefixes?
android.permission is used for permissions in the Android Open Source Project.
com.google.android.gms.permission is used for permissions from what we think of as Play Services.
Other apps can define their own permissions, ideally in their own namespaces. But, they are just strings, so you or I could try defining a custom permission that starts with android.permission.
I would like to know if there is a single reference somewhere for all the other permissions?
Permissions are arbitrary strings from arbitrary developers. There is no way to know what all of them are. I am not aware of Google having documentation listing all of Play Services' permissions, but I cannot rule it out.
Below is an example of ACTIVITY_RECOGNITION being added to the manifest, trying to make sense of it.
This was tied to functionality that originally was supplied by Play Services and then moved into Android itself. So, the permission started with the Play Services namespace and then was cloned into the AOSP namespace.

Making the camera permission required by the library as not required

In my app i include a library that request camera. This limits my application for devices without camera and i need it specifically for a device with scanner but no camera. So i want to make the camera permission as not required in my app. How can i do this.
I added
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
in my apps manifest. Is that enough?
Or should i add tools:node="remove" or tools:node="replace" in my app like as below
<uses-permission android:name="android.permission.CAMERA" tools:node="replace" />
Yes it's enough. You set it to be a non-required feature, so it's non-required.
Just because you use the CAMERA permission doesn't mean the device has to have a camera. You could put in:
<uses-permission android:name="hue.com.derp" />
And it wouldn't restrict your compatibility base at all. If the host device doesn't recognize a permission, it ignores it.
The tools namespace has zero effect on runtime. It's simply for you to provide the IDE with a sample of what might happen during runtime, so it can update previews and the like.
I would say check the device type first if it has camera & 6.0+ then you need to ask for permission other wise just run your code normal

How to find source of a permission in an Android app?

My users are complaining that my app now requires "run at startup" permission according the listing on Google Play. I have no need for this permission so would like to remove it from my app. I assume it must be from a library that I use but which one? In the "Merged Manifest" there is nothing about "boot" or "startup". I just have these:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
How can I track this down? My users are acting like I'm the anti-Christ for having this extra permission and I look stupid(maybe accurately) for not knowing why. Also, is there a list somewhere that shows what permissions correspond to what text on the Play store description page?
I want to address the comment about removing the permission. I understand how that is done and that's not what I'm asking. I need to know how to find the permission. Else, how can you remove something if you don't know what is is? Also, I may want to keep the permission but need to explain what it is for to my end-users.
#Mike is probably correct about WorkManager API. Still the question is how did he find that out? Why doesn't Android Studio show the permission in the Merged Manifest?
Also, even stranger is that I have removed the WorkManager API so the permission should be gone. I did check out the code for the released version and there are no left over references to WorkManager.
The easy way is from Android Studio. First build your app. Then from the build menu select Analyze APK. From there you can see the full AndroidManifest.
https://developer.android.com/studio/build/apk-analyzer
In my case the permissions did not show up in the Merged Manifest tab. Could be a bug. I think what happened is that I used a library during beta testing. Removed the code that uses library but still had a reference in build.gradle. That added the permission to the released apk's Manifest.

Android RECORD_AUDIO permission in unity3d

android.permission.RECORD_AUDIO
I'm not using this permission in my manifest file and I even searched in my whole project and didn't find it. But still when I try to install my app, it asks for this permission and if I click on it, it gives me msg
Microphone
provided by Android System
android.permission.RECORD_AUDIO
I want it to be removed as I don't want to use it! Any idea how to remove it?
One of library accessing microphone in script and I think unity adds permission based on that by it self.
if you dont know who is adding it you can remove it in the final manifest by using xmlns tool like below
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto">
...
<uses-permission android:name="android.permission.RECORD_AUDIO" tools:node="remove" />
...
ofcourse just be careful and make sure no code really require it since you might crash if code or one of your plugins enters a point where it requires this permission to run

android: why is my app "not available" for my 2.3.3 device (in the market)

Yesterday I released my app and realised that it is not available for my android 2.3.3 device. (Does not get listet in search results, and when I access the app page directly, android market tells me that it is not available for my device).
The lines of my manifest, which could be the issue (IMO) look like that:
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-feature android:name="android.hardware.camera.autofocus" />
The only thing I can think of which could make a difference is that I have no SIM card inserted on that phone- but I have Wifi access. (will try it with SIM card in the evening)
Any ideas?
Application requires autofocus camera unless you add `android:required="false" to the use-feature tag.
From documentation, see last if statement:
Filtering based on explicitly declared features
An explicitly declared feature is one that your application declares in a element. The feature declaration can include an android:required=["true" | "false"] attribute (if you are compiling against API level 5 or higher), which lets you specify whether the application absolutely requires the feature and cannot function properly without it ("true"), or whether the application prefers to use the feature if available, but is designed to run without it ("false").
Android Market handles explicitly declared features in this way:
If a feature is explicitly declared as being required, Android Market adds the feature to the list of required features for the application. It then filters the application from users on devices that do not provide that feature. For example:
<uses-feature android:name="android.hardware.camera" android:required="true" />
If a feature is explicitly declared as not being required, Android Market does not add the feature to the list of required features. For that reason, an explicitly declared non-required feature is never considered when filtering the application. Even if the device does not provide the declared feature, Android Market will still consider the application compatible with the device and will show it to the user, unless other filtering rules apply. For example:
<uses-feature android:name="android.hardware.camera" android:required="false" />
If a feature is explicitly declared, but without an android:required attribute, Android Market assumes that the feature is required and sets up filtering on it.
The minSdkVersion="7" and targetSdkVersion="8" but you device is 2.3.3 which equal sdk version 10
This will help you to know the sdk versions
so change the versions range in your manafist file
<uses-sdk android:targetSdkVersion="8" android:minSdkVersion="7" android:maxSdkVersion="10" />

Categories

Resources