1

I have a strange problem with home widget on Android >= 4.2. Every time a try call some method on AppWidgetManager (for example in AppWidgetProvider onUpdate, when I try to add widget to home screen), app crashes with this:

02-20 08:32:48.281: E/AndroidRuntime(18978): java.lang.RuntimeException: Unable to start receiver cz.szn.app.launcher.LauncherWidget: java.lang.SecurityException: Permission Denial: AppWidgetService from com.android.server asks to run as user 23886906 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
02-20 08:32:48.281: E/AndroidRuntime(18978):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2453)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at android.app.ActivityThread.access$1700(ActivityThread.java:139)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1286)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at android.os.Handler.dispatchMessage(Handler.java:102)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at android.os.Looper.loop(Looper.java:136)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at android.app.ActivityThread.main(ActivityThread.java:5102)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at java.lang.reflect.Method.invokeNative(Native Method)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at java.lang.reflect.Method.invoke(Method.java:515)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at dalvik.system.NativeStart.main(Native Method)
02-20 08:32:48.281: E/AndroidRuntime(18978): Caused by: java.lang.SecurityException: Permission Denial: AppWidgetService from com.android.server asks to run as user 23886906 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
02-20 08:32:48.281: E/AndroidRuntime(18978):    at android.os.Parcel.readException(Parcel.java:1465)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at android.os.Parcel.readException(Parcel.java:1419)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.updateAppWidgetIds(IAppWidgetService.java:612)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at android.appwidget.AppWidgetManager.updateAppWidget(AppWidgetManager.java:378)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at android.appwidget.AppWidgetManager.updateAppWidget(AppWidgetManager.java:445)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at cz.szn.app.launcher.LauncherWidget.onUpdate(LauncherWidget.java:79)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at android.appwidget.AppWidgetProvider.onReceive(AppWidgetProvider.java:66)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at cz.szn.app.launcher.LauncherWidget.onReceive(LauncherWidget.java:41)
02-20 08:32:48.281: E/AndroidRuntime(18978):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2446)
02-20 08:32:48.281: E/AndroidRuntime(18978):    ... 10 more

In manifest is this:

<receiver android:name="cz.szn.app.launcher.LauncherWidget">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    </intent-filter>

    <meta-data
         android:name="android.appwidget.provider"
         android:resource="@xml/app_launcher_widget" />
 </receiver>

In AppWidgetProvider sublcass:

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    final int appWidgetCount = appWidgetIds.length;

    for (int i = 0; i < appWidgetCount; i++) {
        final int appWidgetId = appWidgetIds[i];

        PendingIntent openEmailIntent = PendingIntent.getActivity(context, 0, new Intent(
                context, FolderActivity.class), 0);

        PendingIntent writeMessageIntent = PendingIntent.getActivity(context, 0, new Intent(
                Intent.ACTION_SEND, null, context, FolderActivity.class), 0);

        PendingIntent syncIntent = PendingIntent.getBroadcast(context, 0, new Intent(
                Intent.ACTION_SYNC, null, context, EmailLauncherWidget.class), 0);

        final RemoteViews views = new RemoteViews(context.getPackageName(),
                R.layout.widget_launcher);
        views.setOnClickPendingIntent(R.id.launcherWidgetLogo, openEmailIntent);
        views.setOnClickPendingIntent(R.id.launcherWidgetWrite, writeMessageIntent);
        views.setOnClickPendingIntent(R.id.launcherWidgetSync, syncIntent);

        views.setTextViewText(R.id.launcherWidgetName, "Moje Jmeno");

        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

I read App Widgets guide and went step by step, but I can't see what is wrong. The only thing different from example is that my app also implements AccountAuthenticator and requires account, uses SyncAdapter and has custom Application class.

I've also noticed that it works (I can add widget to homescreen) before I obtain account from AccountManager, after login it crashes. It also works when I login from app, then clear apps data (but the account remains in system).

Any help? Thanks!

barbucha
  • 332
  • 4
  • 8
  • possible duplicate of [What do I do about: this requires android.permission.INTERACT\_ACROSS\_USERS\_FULL](http://stackoverflow.com/questions/19756727/what-do-i-do-about-this-requires-android-permission-interact-across-users-full) – 2Dee Feb 20 '14 at 08:56
  • I've read this one and other posts about permission INTERACT_ACROSS_USERS_FULL and I know it is "signature level permission....", but there is no post about homescreen widgets and AppWidgetService. And implementig widget isn't something unusual, so I wonder what is the cause of it. – barbucha Feb 20 '14 at 09:16
  • @barbucha - Did you ever resolve this? – Justin Morgan - On strike Jan 09 '15 at 17:03
  • @Justin Morgan - Yes, but I still don't know, what the problem is exactly. I was using custom Application class in my app. When I removed it and used default, it started working. – barbucha Feb 17 '15 at 15:36

0 Answers0