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

okhttp reflection meet Android P DP1 non-sdk restriction #3980

Open
zjupure opened this Issue Apr 26, 2018 · 13 comments

Comments

9 participants
@zjupure

zjupure commented Apr 26, 2018

okhttp use some reflection to config the network, such as ALPN, when run in android P, system will logcat the warning in the logcat.

see https://developer.android.com/preview/restrictions-non-sdk-interfaces.html for Android P behavior change

Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setAlpnProtocols([B)V (light greylist, reflection)
Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->getAlpnSelectedProtocol()[B (light greylist, reflection)
Accessing hidden method Lcom/android/org/conscrypt/TrustManagerImpl;-><init>(Ljava/security/KeyStore;)V (light greylist, reflection)
Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, reflection)
Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (light greylist, reflection)
Accessing hidden method Ldalvik/system/CloseGuard;->warnIfOpen()V (light greylist, reflection)

We look through okhttp source, and found the reflection are all in AndroidPlatform.java.

okhttp has some solution or workaround not to reflet system non-open api?

@swankjesse

This comment has been minimized.

Show comment
Hide comment
Member

swankjesse commented Apr 29, 2018

@swankjesse

This comment has been minimized.

Show comment
Hide comment
@swankjesse

swankjesse Apr 29, 2018

Member

For CloseGuard, we probably want to just delete the Android-specific overrides. We don’t particularly benefit from using CloseGuard instead of java.util.logging.Logger for configuration.

Member

swankjesse commented Apr 29, 2018

For CloseGuard, we probably want to just delete the Android-specific overrides. We don’t particularly benefit from using CloseGuard instead of java.util.logging.Logger for configuration.

@swankjesse

This comment has been minimized.

Show comment
Hide comment
@swankjesse

swankjesse Apr 29, 2018

Member

@zjupure which version of OkHttp were you running? I couldn’t find the reflective call to TrustManagerImpl;-><init> in the current source tree.

Member

swankjesse commented Apr 29, 2018

@zjupure which version of OkHttp were you running? I couldn’t find the reflective call to TrustManagerImpl;-><init> in the current source tree.

@af913337456

This comment has been minimized.

Show comment
Hide comment
@af913337456

af913337456 May 9, 2018

the same problem hit me

af913337456 commented May 9, 2018

the same problem hit me

@zjupure

This comment has been minimized.

Show comment
Hide comment
@zjupure

zjupure May 9, 2018

@swankjesse okhttp version in our app is 3.8.1

zjupure commented May 9, 2018

@swankjesse okhttp version in our app is 3.8.1

@AntoinePurnelle

This comment has been minimized.

Show comment
Hide comment
@AntoinePurnelle

AntoinePurnelle Jun 6, 2018

Strict mode now allows to have a stacktrace

StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectNonSdkApiUsage()
                .penaltyLog()
                .build());
06-06 19:52:56.935 8671-8671/? D/StrictMode: StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard;
        at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
        at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
        at java.lang.Class.getDeclaredMethodInternal(Native Method)
        at java.lang.Class.getPublicMethodRecursive(Class.java:2075)
        at java.lang.Class.getMethod(Class.java:2063)
        at java.lang.Class.getMethod(Class.java:1690)
        at io.intercom.okhttp3.internal.platform.AndroidPlatform$CloseGuard.get(AndroidPlatform.java:367)
        at io.intercom.okhttp3.internal.platform.AndroidPlatform.<init>(AndroidPlatform.java:55)
        at io.intercom.okhttp3.internal.platform.AndroidPlatform.buildIfSupported(AndroidPlatform.java:257)
        at io.intercom.okhttp3.internal.platform.Platform.findPlatform(Platform.java:184)
        at io.intercom.okhttp3.internal.platform.Platform.<clinit>(Platform.java:74)
        at io.intercom.okhttp3.internal.platform.Platform.get(Platform.java:80)
        at io.intercom.okhttp3.internal.tls.CertificateChainCleaner.get(CertificateChainCleaner.java:41)
        at io.intercom.okhttp3.OkHttpClient.<init>(OkHttpClient.java:254)
        at io.intercom.okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:914)
        at io.intercom.android.sdk.Injector.getNexusClient(Injector.java:153)
        at io.intercom.android.sdk.RealIntercom.create(RealIntercom.java:77)
        at io.intercom.android.sdk.Intercom.initialize(Intercom.java:68)
        at com.aproplan.aproplan.AproPlanApplication.onCreate(AproPlanApplication.java:113)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5858)
        at android.app.ActivityThread.access$1000(ActivityThread.java:197)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1634)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6642)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

AntoinePurnelle commented Jun 6, 2018

Strict mode now allows to have a stacktrace

StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectNonSdkApiUsage()
                .penaltyLog()
                .build());
06-06 19:52:56.935 8671-8671/? D/StrictMode: StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard;
        at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
        at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
        at java.lang.Class.getDeclaredMethodInternal(Native Method)
        at java.lang.Class.getPublicMethodRecursive(Class.java:2075)
        at java.lang.Class.getMethod(Class.java:2063)
        at java.lang.Class.getMethod(Class.java:1690)
        at io.intercom.okhttp3.internal.platform.AndroidPlatform$CloseGuard.get(AndroidPlatform.java:367)
        at io.intercom.okhttp3.internal.platform.AndroidPlatform.<init>(AndroidPlatform.java:55)
        at io.intercom.okhttp3.internal.platform.AndroidPlatform.buildIfSupported(AndroidPlatform.java:257)
        at io.intercom.okhttp3.internal.platform.Platform.findPlatform(Platform.java:184)
        at io.intercom.okhttp3.internal.platform.Platform.<clinit>(Platform.java:74)
        at io.intercom.okhttp3.internal.platform.Platform.get(Platform.java:80)
        at io.intercom.okhttp3.internal.tls.CertificateChainCleaner.get(CertificateChainCleaner.java:41)
        at io.intercom.okhttp3.OkHttpClient.<init>(OkHttpClient.java:254)
        at io.intercom.okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:914)
        at io.intercom.android.sdk.Injector.getNexusClient(Injector.java:153)
        at io.intercom.android.sdk.RealIntercom.create(RealIntercom.java:77)
        at io.intercom.android.sdk.Intercom.initialize(Intercom.java:68)
        at com.aproplan.aproplan.AproPlanApplication.onCreate(AproPlanApplication.java:113)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5858)
        at android.app.ActivityThread.access$1000(ActivityThread.java:197)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1634)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6642)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
@swankjesse

This comment has been minimized.

Show comment
Hide comment
Member

swankjesse commented Jul 5, 2018

@swankjesse

This comment has been minimized.

Show comment
Hide comment
@swankjesse

swankjesse Jul 5, 2018

Member

Nothing actionable here for now.

Member

swankjesse commented Jul 5, 2018

Nothing actionable here for now.

@swankjesse swankjesse added this to the Icebox milestone Jul 5, 2018

@swankjesse swankjesse added the android label Jul 5, 2018

@hacker1024

This comment has been minimized.

Show comment
Hide comment
@hacker1024

hacker1024 Aug 11, 2018

Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setAlpnProtocols([B)V (light greylist, reflection)
Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->getAlpnSelectedProtocol()[B (light greylist, reflection)

I have these messages too. Google have filed an internal bug, so there will probably hopefully be public APIs in the next Android release.

hacker1024 commented Aug 11, 2018

Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setAlpnProtocols([B)V (light greylist, reflection)
Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->getAlpnSelectedProtocol()[B (light greylist, reflection)

I have these messages too. Google have filed an internal bug, so there will probably hopefully be public APIs in the next Android release.

@FlappyElephant

This comment has been minimized.

Show comment
Hide comment
@FlappyElephant

FlappyElephant Sep 6, 2018

There is same problem .Any solution?

D/NetworkSecurityConfig: No Network Security Config specified, using platform default
W/android.dc.dem: Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, reflection)
Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (light greylist, reflection)
Accessing hidden method Ldalvik/system/CloseGuard;->warnIfOpen()V (light greylist, reflection)

FlappyElephant commented Sep 6, 2018

There is same problem .Any solution?

D/NetworkSecurityConfig: No Network Security Config specified, using platform default
W/android.dc.dem: Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, reflection)
Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (light greylist, reflection)
Accessing hidden method Ldalvik/system/CloseGuard;->warnIfOpen()V (light greylist, reflection)

@alashow

This comment has been minimized.

Show comment
Hide comment
@alashow

alashow Sep 7, 2018

This is causing my app to hang about 900ms for the first https request, even though my call is made on a background thread. Is this normal?
Is there a way to avoid the hang?

alashow commented Sep 7, 2018

This is causing my app to hang about 900ms for the first https request, even though my call is made on a background thread. Is this normal?
Is there a way to avoid the hang?

@korshaknn

This comment has been minimized.

Show comment
Hide comment
@korshaknn

korshaknn Sep 17, 2018

Are there any updates with ALPN methods?
Still have warnings:
Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setAlpnProtocols([B)V (light greylist, reflection)
Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->getAlpnSelectedProtocol()[B (light greylist, reflection)

Are they going to be fixed? or don't? What is their status?

Thanks!

korshaknn commented Sep 17, 2018

Are there any updates with ALPN methods?
Still have warnings:
Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setAlpnProtocols([B)V (light greylist, reflection)
Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->getAlpnSelectedProtocol()[B (light greylist, reflection)

Are they going to be fixed? or don't? What is their status?

Thanks!

@johnjohndoe

This comment has been minimized.

Show comment
Hide comment
@johnjohndoe

johnjohndoe Sep 18, 2018

Google "deferred this issue for consideration in a future release" at Aug 10, 2018.

I noticed the issue lately on Google Play's devices tests as part of the Beta channel Pre-launch report for a Google Pixel 2, Android 9.

StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: 
    Ldalvik/system/CloseGuard;->warnIfOpen()V
	at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
	at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
	at java.lang.Class.getDeclaredMethodInternal(Native Method)
	at java.lang.Class.getPublicMethodRecursive(Class.java:2075)
	at java.lang.Class.getMethod(Class.java:2063)
	at java.lang.Class.getMethod(Class.java:1690)
	at okhttp3.internal.platform.AndroidPlatform$CloseGuard.get(AndroidPlatform.java:372)
	at okhttp3.internal.platform.AndroidPlatform.<init>(AndroidPlatform.java:58)
	at okhttp3.internal.platform.AndroidPlatform.buildIfSupported(AndroidPlatform.java:260)
	at okhttp3.internal.platform.Platform.findPlatform(Platform.java:201)
	at okhttp3.internal.platform.Platform.<clinit>(Platform.java:78)
	at okhttp3.internal.platform.Platform.get(Platform.java:84)
	at okhttp3.internal.tls.CertificateChainCleaner.get(CertificateChainCleaner.java:41)
	at okhttp3.OkHttpClient$Builder.sslSocketFactory(OkHttpClient.java:694)

johnjohndoe commented Sep 18, 2018

Google "deferred this issue for consideration in a future release" at Aug 10, 2018.

I noticed the issue lately on Google Play's devices tests as part of the Beta channel Pre-launch report for a Google Pixel 2, Android 9.

StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: 
    Ldalvik/system/CloseGuard;->warnIfOpen()V
	at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
	at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
	at java.lang.Class.getDeclaredMethodInternal(Native Method)
	at java.lang.Class.getPublicMethodRecursive(Class.java:2075)
	at java.lang.Class.getMethod(Class.java:2063)
	at java.lang.Class.getMethod(Class.java:1690)
	at okhttp3.internal.platform.AndroidPlatform$CloseGuard.get(AndroidPlatform.java:372)
	at okhttp3.internal.platform.AndroidPlatform.<init>(AndroidPlatform.java:58)
	at okhttp3.internal.platform.AndroidPlatform.buildIfSupported(AndroidPlatform.java:260)
	at okhttp3.internal.platform.Platform.findPlatform(Platform.java:201)
	at okhttp3.internal.platform.Platform.<clinit>(Platform.java:78)
	at okhttp3.internal.platform.Platform.get(Platform.java:84)
	at okhttp3.internal.tls.CertificateChainCleaner.get(CertificateChainCleaner.java:41)
	at okhttp3.OkHttpClient$Builder.sslSocketFactory(OkHttpClient.java:694)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment