bene25
bene25

Reputation: 588

Disable android content provider signature permission for debug build

For example content provider has signature permission for main build

  <provider
        android:name=".com.test.ContentProvider"
        android:authorities="com.test.provider"
        android:enabled="true"
        android:exported="true"
        android:permission="com.test.permission" />        

and signature permission

  <permission
        android:name="com.test.permission"
        android:protectionLevel="signature" /> 

How to disable this permission for debug build? Tried to add content provider with the same name but without android:permission="com.test.permission" line to AndroidManifest.xml (debug) without luck

Upd1: tried to add tools:node="remove" to permission itself, but this doesn't work:

   <permission
        tools:node="remove"
        android:name="com.test.permission"
        android:protectionLevel="signature" /> 

At the same time tools:node="remove" inside content provider removes content provider completely from debug build.

Upvotes: 0

Views: 352

Answers (2)

Jigar Rangani
Jigar Rangani

Reputation: 386

you can use build variant-specific manifest files in your Android project. This approach allows you to define different manifest files for different build types

create debug manifest src/debug/AndroidManifest.xml

In your debug-specific manifest, override the provider declaration. Since you want to disable the permission, you don't include the android:permission attribute in this declaration.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.test"
      xmlns:tools="http://schemas.android.com/tools">

<application>
    <provider
        android:name=".com.test.ContentProvider"
        android:authorities="com.test.provider"
        android:enabled="true"
        android:exported="true"
        tools:replace="android:permission" />
</application>

You can have additional manifests in directories named after each build variant, like src/debug for the debug build and src/release for the release build. These manifests only need to include the parts that are different from the base manifest.

Upvotes: 0

Tam Huynh
Tam Huynh

Reputation: 2487

I don't know much about ContentProvider permissions, but you may try these options:

1/ In your debug AndroidManifest.xml, use this declaration:

<provider
    android:name=".com.test.ContentProvider"
    tools:remove="android:permission" />

This will remove the permission in the merge manifest for the debug build

2/ Define the permission in a strings resources. Define the permission value in the main strings.xml, in the debug strings.xml leave it blank.

main: <string name="permission_name">com.test.permission</string>
debug: <string name="permission_name"></string>

Your provider tag simply references the string based on build:

<provider
    android:name=".com.test.ContentProvider"
    android:authorities="com.test.provider"
    android:enabled="true"
    android:exported="true"
    android:permission="@string/permission_name" />

Don't know if permission is required or not, these are just some ways to customize your configuration by different builds

Upvotes: 0

Related Questions