Skip to content

Fix IncorrectContextUse warning #540

@eloev

Description

@eloev

When StrictMode is enabled, Android 11 or higher will display a warning if the app requests WindowManager on application contexts.
When trying to send event

E/ContextImpl: Tried to access visual service WindowManager from a non-visual Context:com.myApp@82752ca 
Visual services, such as WindowManager, WallpaperService or LayoutInflater should be accessed from Activity
 or other visual Context. Use an Activity or a Context created with Context#createWindowContext(int, Bundle), 
which are adjusted to the configuration and visual bounds of an area on screen.
    java.lang.IllegalAccessException: Tried to access visual service WindowManager from a non-visual Context:com.myApp@82752ca
        at android.app.ContextImpl.getSystemService(ContextImpl.java:1926)
        at android.content.ContextWrapper.getSystemService(ContextWrapper.java:814)
        at com.adjust.sdk.sig.NativeLibHelper.nSign(Native Method)
        at com.adjust.sdk.sig.NativeLibHelper.sign(NativeLibHelper.java:15)
        at com.adjust.sdk.sig.SignerInstance.sign(SignerInstance.java:112)
        at com.adjust.sdk.sig.Signer.sign(Signer.java:74)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.adjust.sdk.Reflection.invokeMethod(Unknown Source:8)
        at com.adjust.sdk.Reflection.invokeInstanceMethod(Unknown Source:4)
        at com.adjust.sdk.AdjustSigner.sign(Unknown Source:46)
        at com.adjust.sdk.PackageBuilder.buildEventPackage(Unknown Source:36)

When tried to handle deeplink

E/ContextImpl: Tried to access visual service WindowManager from a non-visual Context:com.myApp@82752ca 
Visual services, such as WindowManager, WallpaperService or LayoutInflater should be accessed from Activity
 or other visual Context. Use an Activity or a Context created with Context#createWindowContext(int, Bundle), 
which are adjusted to the configuration and visual bounds of an area on screen.
    java.lang.IllegalAccessException: Tried to access visual service WindowManager from a non-visual Context:com.myApp@82752ca
        at android.app.ContextImpl.getSystemService(ContextImpl.java:1926)
        at android.content.ContextWrapper.getSystemService(ContextWrapper.java:814)
        at com.adjust.sdk.sig.NativeLibHelper.nSign(Native Method)
        at com.adjust.sdk.sig.NativeLibHelper.sign(NativeLibHelper.java:15)
        at com.adjust.sdk.sig.SignerInstance.sign(SignerInstance.java:112)
        at com.adjust.sdk.sig.Signer.sign(Signer.java:74)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.adjust.sdk.Reflection.invokeMethod(Unknown Source:8)
        at com.adjust.sdk.Reflection.invokeInstanceMethod(Unknown Source:4)
        at com.adjust.sdk.AdjustSigner.sign(Unknown Source:46)
        at com.adjust.sdk.PackageBuilder.buildClickPackage(Unknown Source:69)
        at com.adjust.sdk.PackageFactory.buildDeeplinkSdkClickPackage(Unknown Source:135)

Appcenter have the same bug in past, and this commit will help you
facebook/facebook-android-sdk@235a0a0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions