0

Are there any restrictions on pushing static cards to the timeline from various threads? I'm pushing a card and getting this exception, but the card shows up anyway. Want to make sure i'm not doing something wrong:

456-456/? D/StrictMode﹕ StrictMode policy violation; ~duration=9 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=31 violation=2
        at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1089)
        at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1557)
        at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1449)
        at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1405)
        at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1485)
        at com.google.android.glass.timeline.TimelineProvider.queryInternal(TimelineProvider.java:347)
        at com.google.android.glass.timeline.TimelineProvider.query(TimelineProvider.java:237)
        at android.content.ContentProvider$Transport.query(ContentProvider.java:178)
        at android.content.ContentResolver.query(ContentResolver.java:311)
        at com.google.android.glass.timeline.PastCardDeck.queryCards(PastCardDeck.java:302)
        at com.google.android.glass.timeline.PastCardDeck.refresh(PastCardDeck.java:254)
        at com.google.android.glass.timeline.PastCardDeck.access$200(PastCardDeck.java:51)
        at com.google.android.glass.timeline.PastCardDeck$1.onChange(PastCardDeck.java:150)
        at android.database.ContentObserver$NotificationRunnable.run(ContentObserver.java:43)
        at android.os.Handler.handleCallback(Handler.java:624)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4424)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
        at dalvik.system.NativeStart.main(Native Method)

EDIT: I'm adding the card to the TimelineManager from a separate thread, not the UI thread, and not the service thread.

kolosy
  • 3,029
  • 3
  • 29
  • 48

1 Answers1

0

You need to call this function in your application..

public void enableUIThread() {

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
            .permitAll().build();
    StrictMode.setThreadPolicy(policy);
}
Quamber Ali
  • 2,170
  • 25
  • 46
  • why? i don't want to mask the warning, i want to understand why it's happening. – kolosy Jan 02 '14 at 18:18
  • well for the details . StrictMode is actually added from API level 9 it makes sure that you do not perform any tast related to network or disk in the main thread. Which is orignally good. but if you know what are you doing and can handle it you can permit all the things as i have added in the function above. For full details you can read the documentation of this http://developer.android.com/reference/android/os/StrictMode.html – Quamber Ali Jan 03 '14 at 04:59
  • If you see the first line of the Log in your Question. you are voilating the 'StrictModeDiskReadViolation'. – Quamber Ali Jan 03 '14 at 05:01
  • I can see what the exception is, and know what it means. Look at the full trace - there is no user code there, it's all system / glass code, and it's apparently trying to refresh either the newly inserted card, or others around it. Hence the question - is there a recommended way to insert static cards from outside the main thread. Simply turning off the check is going to mask whatever problem this is. – kolosy Jan 03 '14 at 15:26