dcanh121
dcanh121

Reputation: 4695

Custom permission failing on Motorola devices

I wrote a custom permission for receiving broadcasts for my widget, I get a permission denial for Motorola devices.

Creating permission

<permission
    android:name="com.sample.app.WIDGET_PERMISSION"
    android:description="@string/widgetDesc"
    android:label="@string/widgetLabel"
    android:protectionLevel="signature" >
</permission>

Adding permission to Manifest file

    <uses-permission android:name="com.sample.app.WIDGET_PERMISSION" />

Adding receiver

    <receiver android:name=".MyWidget" android:label="MyApp"
                android:icon="@drawable/image" 
                android:permission="com.sample.app.WIDGET_PERMISSION">
                <intent-filter>
                    <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
                     <category android:name="com.sample.app" />
                </intent-filter>
</receiver>

I get permission denial message only for Motorola devices,

07-17 11:48:18.781: W/ActivityManager(479): Permission Denial: broadcasting Intent { act=android.appwidget.action.APPWIDGET_ENABLED cmp=com.sample.app/.MyWidget} from android (pid=3116, uid=10006) requires com.sample.app.WIDGET_PERMISSION due to receiver com.sample.app/com.sample.app.MyWidget

07-17 11:48:18.781: W/ActivityManager(479): Permission Denial: broadcasting Intent { act=android.appwidget.action.APPWIDGET_UPDATE cmp=com.sample.app/.MyWidget(has extras) } from android (pid=3116, uid=10006) requires com.sample.app.WIDGET_PERMISSION due to receiver com.sample.app/com.sample.app.MyWidget

07-17 11:48:18.828: W/ActivityManager(479): Permission Denial: broadcasting Intent { act=com.motorola.blur.home.ACTION_SET_WIDGET_SIZE cmp=com.sample.app/.MyWidget(has extras) } from com.motorola.blur.home (pid=3116, uid=10006) requires com.sample.app.WIDGET_PERMISSION due to receiver com.sample.app/com.sample.app.MyWidget

Upvotes: 1

Views: 2503

Answers (1)

Erol
Erol

Reputation: 6526

Try removing android:permission="com.sample.app.WIDGET_PERMISSION" from your receiver tag and only include <uses-permission android:name="com.sample.app.WIDGET_PERMISSION" /> under your manifest tag, outside any application and activity.

EDIT: The problem is that the broadcaster should send the permission together with the broadcast so that it passes through your BroadcastReceiver. When you are testing it using the command line, somehow, the permission is not being sent.

I think what you are doing about declaring the permission inside your receiver is correct but the issue is because of your permission protection level being signature. This level is described in the Android developers page like this:

A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission. If the certificates match, the system automatically grants the permission without notifying the user or asking for the user's explicit approval.

This leads me to think that, in Motorola devices, this is not satisfied somehow. Try changing

android:protectionLevel="signature"

to

android:protectionLevel="normal".

If it still doesn't work, I would say there is a bug with Motorola configurations.

Upvotes: 1

Related Questions