Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SonyHomeBadger got an exception #175

Closed
AlanChiou opened this issue Feb 21, 2017 · 7 comments
Closed

SonyHomeBadger got an exception #175

AlanChiou opened this issue Feb 21, 2017 · 7 comments

Comments

@AlanChiou
Copy link

AlanChiou commented Feb 21, 2017

I called "applyCount" from a background thread and got this exception.
I used the "IsBadgeWorking?" app to try it, and then I got a crash.

Exception:
W/System.err: Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
W/System.err: at android.os.Handler.(Handler.java:200)
W/System.err: at android.os.Handler.(Handler.java:114)
W/System.err: at android.content.AsyncQueryHandler.(AsyncQueryHandler.java:125)
W/System.err: at me.leolin.shortcutbadger.impl.SonyHomeBadger$1.(SonyHomeBadger.java:78)
W/System.err: at me.leolin.shortcutbadger.impl.SonyHomeBadger.executeBadgeByContentProvider(SonyHomeBadger.java:78)
W/System.err: at me.leolin.shortcutbadger.impl.SonyHomeBadger.executeBadge(SonyHomeBadger.java:42)

Crash:
02-21 09:52:29.051 20488-2674/me.leolin.isbadgeworking E/AndroidRuntime: FATAL EXCEPTION: AsyncQueryWorker
Process: me.leolin.isbadgeworking, PID: 20488
java.lang.SecurityException: Missing permission to insert badges
at android.os.Parcel.readException(Parcel.java:1629)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:476)
at android.content.ContentResolver.insert(ContentResolver.java:1244)
at android.content.AsyncQueryHandler$WorkerHandler.handleMessage(AsyncQueryHandler.java:96)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.os.HandlerThread.run(HandlerThread.java:61)

screenshot_20170221-095920 1

@AlanChiou
Copy link
Author

Maybe my testing case is wrong.
I installed an unknown sony launcher.

But that the caller applies counts in a background thread still is an issue.

@LightZam
Copy link

public final class ShortcutBadger{
    public static void applyCountOrThrow(Context context, int badgeCount) throws ShortcutBadgeException {
        if (sShortcutBadger == null) {
            boolean launcherReady = initBadger(context);
            if (!launcherReady)
                throw new ShortcutBadgeException("No default launcher available");
        }
        try {
            sShortcutBadger.executeBadge(context, sComponentName, badgeCount);
        } catch (Exception e) {
            throw new ShortcutBadgeException("Unable to execute badge", e);
        }
    }
}
public class SonyHomeBadger implements Badger {
    private void executeBadgeByContentProvider(Context context, ComponentName componentName, int badgeCount) {
        if (badgeCount < 0) {
            return;
        }
        if (mQueryHandler == null) {
            mQueryHandler = new AsyncQueryHandler(
                    context.getApplicationContext().getContentResolver()) {
            };
        }
        insertBadgeAsync(badgeCount, componentName.getPackageName(), componentName.getClassName());
    }
}

mQueryHandler = new AsyncQueryHandler( context.getApplicationContext().getContentResolver()) { };

throw exception and catch by ShortcutBadger

java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

device : Sony E6653

@McLoo
Copy link
Contributor

McLoo commented Jul 21, 2017

@LightZam are you using a version >= 1.1.16?
Because this got fixed with f790e2e, f I'm not completely wrong...

@LightZam
Copy link

@McLoo i'm sorry, i am using the version:1.1.14, so maybe this issue should mark as resolve and close.

@LightZam
Copy link

LightZam commented Jul 25, 2017

i have upgraded to 1.1.17, and it worked!

@McLoo
Copy link
Contributor

McLoo commented Jul 25, 2017

I guess this issue should be closed.

@AlanChiou
Copy link
Author

This issue has been fixed so I close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants