@@ -112,6 +112,9 @@ public class MainActivity extends Activity {
112112 private static final boolean BLOCK_MEDIA = BuildConfig .BLOCK_MEDIA ;
113113 private static final boolean BLOCK_ADS = BuildConfig .BLOCK_ADS ;
114114 private static final boolean NO_SSL = BuildConfig .NO_SSL ;
115+ private static final boolean ALLOW_GOOGLE_LOGIN = BuildConfig .ALLOW_GOOGLE_LOGIN ;
116+ private static final String CHROME_USER_AGENT = "Mozilla/5.0 (Linux; Android 12; Pixel 6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Mobile Safari/537.36" ;
117+ private String defaultUserAgent ;
115118 private WebView mWebView ;
116119 private View mCustomView ;
117120 private CustomViewCallback mCustomViewCallback ;
@@ -170,6 +173,7 @@ protected void onCreate(Bundle savedInstanceState) {
170173 mWebView = findViewById (R .id .activity_main_webview );
171174 mProgressBar = findViewById (R .id .progressBar );
172175 WebSettings webSettings = mWebView .getSettings ();
176+ defaultUserAgent = webSettings .getUserAgentString ();
173177 webSettings .setJavaScriptEnabled (true );
174178 webSettings .setDomStorageEnabled (true );
175179 webSettings .setLoadWithOverviewMode (true );
@@ -303,11 +307,30 @@ public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
303307 }
304308
305309 if (isAllowed ) {
310+ boolean isGoogleLogin = host != null && (host .equals ("accounts.google.com" ) || host .equals ("www.accounts.google.com" ));
311+
312+ if (isGoogleLogin && ALLOW_GOOGLE_LOGIN ) {
313+ view .getSettings ().setUserAgentString (CHROME_USER_AGENT );
314+
315+ new AlertDialog .Builder (MainActivity .this )
316+ .setTitle ("אזהרה" )
317+ .setMessage ("גוגל אוסרת התחברות מדפדפנים מותאמים אישית. השימוש על אחריותך בלבד." )
318+ .setPositiveButton ("הבנתי" , (dialog , which ) -> {
319+ mProgressBar .setVisibility (View .VISIBLE );
320+ view .loadUrl (url );
321+ })
322+ .setCancelable (false )
323+ .show ();
324+ return true ;
325+ } else if (!isGoogleLogin ) {
326+ view .getSettings ().setUserAgentString (defaultUserAgent );
327+ }
328+
306329 mProgressBar .setVisibility (View .VISIBLE );
307330 view .loadUrl (url );
308331 return true ;
309332 } else {
310- Toast .makeText (view .getContext (), "This URL is not allowed (" + host + ")" , Toast .LENGTH_SHORT ).show ();
333+ Toast .makeText (view .getContext (), "כתובת זו אינה מורשית (" + host + ")" , Toast .LENGTH_SHORT ).show ();
311334 return true ;
312335 }
313336 }
0 commit comments