2021年1月1日星期五

OkHttp Interceptor and CookieJar dont work on most recent Huawei like P40

My app is using OkHttp 3 and Retrofit2 for networking. It communicates with server, that returns session after successful login. I need to save this session and attach it to request header for all requests that will be executed after login.

I have used Cookie Jar for this and it worked just fine on emulator and my Samsung phone, but my client reported problem on Huawei P40 Lite. After some log checking on server, I figured that session wasnt sent to server and it caused verification problem.

After that I used Huawei live debuging to test my app on remote Huawei P40 device and reported problem persisted. After some playing around with my app and testing I concluded that OkHttp 3 Cookie Jar and Interceptor that i use to handle saving and attaching session were not working on Huawei at all. Could this be related to Google services ban for newest Huawei devices as app is working fine on older ones like P30?

Any tips or solutions are more than welcome.

I have overcame this by manually extracting session from response and attaching it to my calls with @Header, but this solution is very unclean.

Here is my code for OkHttpClient. Keep in mind it worked and it still is working just fine in production for over 2 years on non newest Huawei phones.

return new OkHttpClient.Builder()      .sslSocketFactory(sslContext.getSocketFactory(), loadX509TrustManager(tmf))      .hostnameVerifier(hostnameVerifier)      .readTimeout(60, TimeUnit.SECONDS)      .writeTimeout(60, TimeUnit.SECONDS)      .cookieJar(new JavaNetCookieJar(cookieManager))      .cache(cache)      .addNetworkInterceptor(logInterceptor)      .build();  
https://stackoverflow.com/questions/65534696/okhttp-interceptor-and-cookiejar-dont-work-on-most-recent-huawei-like-p40 January 02, 2021 at 07:39AM

没有评论:

发表评论