Skip to content

Commit

Permalink
feat(android): fix cookie sync, no need to call removeSessionCookie
Browse files Browse the repository at this point in the history
(cherry picked from commit 8f32a98)
  • Loading branch information
genesisli authored and zoomchan-cxj committed Aug 9, 2021
1 parent 84cbe79 commit 69c7d6f
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.tencent.mtt.hippy.modules.nativemodules.network;

import android.os.Build;
import android.text.TextUtils;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
Expand Down Expand Up @@ -152,7 +153,7 @@ public void setCookie(String url, String keyValue, String expires) {
saveCookie2Manager(url, keyValue);
}

mCookieSyncManager.sync();
syncCookie();
}
}

Expand Down Expand Up @@ -183,11 +184,18 @@ private static CookieManager getCookieManager() {

CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.removeSessionCookie();
}
return CookieManager.getInstance();
}

private static void syncCookie() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().flush();
} else if (mCookieSyncManager != null) {
mCookieSyncManager.sync();
}
}

private static class HttpTaskCallbackImpl implements HippyHttpAdapter.HttpTaskCallback {

private final Promise mPromise;
Expand Down Expand Up @@ -236,7 +244,7 @@ public void onTaskSuccess(HippyHttpRequest request, HippyHttpResponse response)
}
}
if (hasSetCookie) {
mCookieSyncManager.sync();
syncCookie();
}
}

Expand Down

0 comments on commit 69c7d6f

Please sign in to comment.