Skip to content

Commit 972eb88

Browse files
committed
feat: add Google login support with Chrome UA spoofing
When enabled, uses Chrome desktop User-Agent for accounts.google.com and shows warning dialog before loading Google login page.
1 parent 8105284 commit 972eb88

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

.github/workflows/build.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ on:
4141
description: 'No SSL - Not recommended!!'
4242
type: boolean
4343
default: false
44+
allow_google_login:
45+
description: 'Allow Google Login (fake browser)'
46+
type: boolean
47+
default: false
4448
jobs:
4549
id:
4650
# https://stackoverflow.com/a/73837663
@@ -140,6 +144,7 @@ jobs:
140144
BLOCK_MEDIA: ${{ inputs.block_media }}
141145
BLOCK_ADS: ${{ inputs.block_ads }}
142146
NO_SSL: ${{ inputs.no_ssl }}
147+
ALLOW_GOOGLE_LOGIN: ${{ inputs.allow_google_login }}
143148
- name: Rename APK
144149
run: mv app/build/outputs/apk/release/app-release.apk app/build/outputs/apk/release/webview-${{ env.PRIMARY_DOMAIN }}.apk
145150
- name: Create Release

app/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ android {
1616
compileSdkVersion 34
1717

1818
defaultConfig {
19-
buildConfigField "String", "ALLOWED_DOMAINS", "\"${System.getenv('ALLOWED_DOMAINS') ?: 'example.com'}\""
19+
def allowGoogleLogin = System.getenv('ALLOW_GOOGLE_LOGIN') == 'true'
20+
def baseDomains = System.getenv('ALLOWED_DOMAINS') ?: 'example.com'
21+
def allowedDomains = allowGoogleLogin ? "${baseDomains},accounts.google.com" : baseDomains
22+
buildConfigField "String", "ALLOWED_DOMAINS", "\"${allowedDomains}\""
23+
buildConfigField "boolean", "ALLOW_GOOGLE_LOGIN", "${allowGoogleLogin}"
2024
buildConfigField "String", "STARTUP_URL", "\"${System.getenv('STARTUP_URL') ?: '' }\""
2125
buildConfigField "String", "VIEW_MODE", "\"${System.getenv('VIEW_MODE') ?: 'AUTO'}\""
2226
buildConfigField "boolean", "BLOCK_MEDIA", "${System.getenv('BLOCK_MEDIA') ?: 'false'}"

app/src/main/java/com/webview/myapplication/MainActivity.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)