mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2024-06-29 16:26:33 +02:00
Adapt auth implementation to better reflect current play services
This commit is contained in:
parent
6174997cb7
commit
45ee4903f8
|
@ -197,6 +197,7 @@ public class AuthManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AuthRequest request = new AuthRequest().fromContext(context)
|
AuthRequest request = new AuthRequest().fromContext(context)
|
||||||
|
.source("android")
|
||||||
.app(packageName, getPackageSignature())
|
.app(packageName, getPackageSignature())
|
||||||
.email(accountName)
|
.email(accountName)
|
||||||
.token(getAccountManager().getPassword(account))
|
.token(getAccountManager().getPassword(account))
|
||||||
|
|
|
@ -30,8 +30,8 @@ import static org.microg.gms.common.HttpFormClient.RequestContent;
|
||||||
import static org.microg.gms.common.HttpFormClient.RequestHeader;
|
import static org.microg.gms.common.HttpFormClient.RequestHeader;
|
||||||
|
|
||||||
public class AuthRequest extends HttpFormClient.Request {
|
public class AuthRequest extends HttpFormClient.Request {
|
||||||
private static final String SERVICE_URL = "https://android.clients.google.com/auth";
|
private static final String SERVICE_URL = "https://android.googleapis.com/auth";
|
||||||
private static final String USER_AGENT = "GoogleAuth/1.4 (%s %s)";
|
private static final String USER_AGENT = "GoogleAuth/1.4 (%s %s); gzip";
|
||||||
|
|
||||||
@RequestHeader("User-Agent")
|
@RequestHeader("User-Agent")
|
||||||
private String userAgent;
|
private String userAgent;
|
||||||
|
@ -59,13 +59,13 @@ public class AuthRequest extends HttpFormClient.Request {
|
||||||
@RequestContent("google_play_services_version")
|
@RequestContent("google_play_services_version")
|
||||||
public int gmsVersion = Constants.MAX_REFERENCE_VERSION;
|
public int gmsVersion = Constants.MAX_REFERENCE_VERSION;
|
||||||
@RequestContent("accountType")
|
@RequestContent("accountType")
|
||||||
public String accountType = "HOSTED_OR_GOOGLE";
|
public String accountType;
|
||||||
@RequestContent("Email")
|
@RequestContent("Email")
|
||||||
public String email;
|
public String email;
|
||||||
@RequestContent("service")
|
@RequestContent("service")
|
||||||
public String service;
|
public String service;
|
||||||
@RequestContent("source")
|
@RequestContent("source")
|
||||||
public String source = "android";
|
public String source;
|
||||||
@RequestContent({"is_called_from_account_manager", "_opt_is_called_from_account_manager"})
|
@RequestContent({"is_called_from_account_manager", "_opt_is_called_from_account_manager"})
|
||||||
public boolean isCalledFromAccountManager;
|
public boolean isCalledFromAccountManager;
|
||||||
@RequestContent("Token")
|
@RequestContent("Token")
|
||||||
|
@ -97,10 +97,15 @@ public class AuthRequest extends HttpFormClient.Request {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AuthRequest source(String source) {
|
||||||
|
this.source = source;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public AuthRequest locale(Locale locale) {
|
public AuthRequest locale(Locale locale) {
|
||||||
this.locale = locale.toString();
|
this.locale = locale.toString();
|
||||||
this.countryCode = locale.getCountry();
|
this.countryCode = locale.getCountry().toLowerCase();
|
||||||
this.operatorCountryCode = locale.getCountry();
|
this.operatorCountryCode = locale.getCountry().toLowerCase();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,19 +21,17 @@ import android.accounts.AccountManager;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.v4.view.LayoutInflaterCompat;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
@ -73,7 +71,6 @@ import static android.view.View.VISIBLE;
|
||||||
import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT;
|
import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT;
|
||||||
import static org.microg.gms.common.Constants.GMS_PACKAGE_NAME;
|
import static org.microg.gms.common.Constants.GMS_PACKAGE_NAME;
|
||||||
import static org.microg.gms.common.Constants.MAX_REFERENCE_VERSION;
|
import static org.microg.gms.common.Constants.MAX_REFERENCE_VERSION;
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
public class LoginActivity extends AssistantActivity {
|
public class LoginActivity extends AssistantActivity {
|
||||||
public static final String TMPL_NEW_ACCOUNT = "new_account";
|
public static final String TMPL_NEW_ACCOUNT = "new_account";
|
||||||
|
@ -110,18 +107,13 @@ public class LoginActivity extends AssistantActivity {
|
||||||
webView.setWebViewClient(new WebViewClient() {
|
webView.setWebViewClient(new WebViewClient() {
|
||||||
@Override
|
@Override
|
||||||
public void onPageFinished(WebView view, String url) {
|
public void onPageFinished(WebView view, String url) {
|
||||||
Log.d(TAG, "pageFinished: " + url);
|
Log.d(TAG, "pageFinished: " + view.getUrl());
|
||||||
Uri uri = Uri.parse(url);
|
Uri uri = Uri.parse(view.getUrl());
|
||||||
|
|
||||||
// Begin login.
|
// Begin login.
|
||||||
// UNUSED: uri=...#identifier never happens. if commented out, webView still appears!
|
// Only required if client code does not invoke showView() via JSBridge
|
||||||
if ("identifier".equals(uri.getFragment()))
|
if ("identifier".equals(uri.getFragment()) || uri.getPath().endsWith("/identifier"))
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(() -> webView.setVisibility(VISIBLE));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
webView.setVisibility(VISIBLE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Normal login.
|
// Normal login.
|
||||||
if ("close".equals(uri.getFragment()))
|
if ("close".equals(uri.getFragment()))
|
||||||
|
@ -185,12 +177,7 @@ public class LoginActivity extends AssistantActivity {
|
||||||
setMessage(R.string.auth_connecting);
|
setMessage(R.string.auth_connecting);
|
||||||
CookieManager.getInstance().setAcceptCookie(true);
|
CookieManager.getInstance().setAcceptCookie(true);
|
||||||
if (SDK_INT >= LOLLIPOP) {
|
if (SDK_INT >= LOLLIPOP) {
|
||||||
CookieManager.getInstance().removeAllCookies(new ValueCallback<Boolean>() {
|
CookieManager.getInstance().removeAllCookies(value -> start());
|
||||||
@Override
|
|
||||||
public void onReceiveValue(Boolean value) {
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
CookieManager.getInstance().removeAllCookie();
|
CookieManager.getInstance().removeAllCookie();
|
||||||
|
@ -231,23 +218,10 @@ public class LoginActivity extends AssistantActivity {
|
||||||
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
|
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
|
||||||
if (networkInfo != null && networkInfo.isConnected()) {
|
if (networkInfo != null && networkInfo.isConnected()) {
|
||||||
if (LastCheckinInfo.read(this).androidId == 0) {
|
if (LastCheckinInfo.read(this).androidId == 0) {
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> {
|
||||||
@Override
|
Runnable next;
|
||||||
public void run() {
|
next = checkin(false) ? this::loadLoginPage : () -> showError(R.string.auth_general_error_desc);
|
||||||
Runnable next;
|
LoginActivity.this.runOnUiThread(next);
|
||||||
next = checkin(false) ? new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
loadLoginPage();
|
|
||||||
}
|
|
||||||
} : new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
showError(R.string.auth_general_error_desc);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
LoginActivity.this.runOnUiThread(next);
|
|
||||||
}
|
|
||||||
}).start();
|
}).start();
|
||||||
} else {
|
} else {
|
||||||
loadLoginPage();
|
loadLoginPage();
|
||||||
|
@ -263,7 +237,7 @@ public class LoginActivity extends AssistantActivity {
|
||||||
setMessage(errorRes);
|
setMessage(errorRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setMessage(@StringRes int res) {
|
private void setMessage(@StringRes int res) {
|
||||||
setMessage(getText(res));
|
setMessage(getText(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,12 +252,7 @@ public class LoginActivity extends AssistantActivity {
|
||||||
|
|
||||||
private void closeWeb(boolean programmaticAuth) {
|
private void closeWeb(boolean programmaticAuth) {
|
||||||
setMessage(R.string.auth_finalize);
|
setMessage(R.string.auth_finalize);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(() -> webView.setVisibility(INVISIBLE));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
webView.setVisibility(INVISIBLE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
String cookies = CookieManager.getInstance().getCookie(programmaticAuth ? PROGRAMMATIC_AUTH_URL : EMBEDDED_SETUP_URL);
|
String cookies = CookieManager.getInstance().getCookie(programmaticAuth ? PROGRAMMATIC_AUTH_URL : EMBEDDED_SETUP_URL);
|
||||||
String[] temp = cookies.split(";");
|
String[] temp = cookies.split(";");
|
||||||
for (String ar1 : temp) {
|
for (String ar1 : temp) {
|
||||||
|
@ -299,12 +268,11 @@ public class LoginActivity extends AssistantActivity {
|
||||||
private void retrieveRtToken(String oAuthToken) {
|
private void retrieveRtToken(String oAuthToken) {
|
||||||
new AuthRequest().fromContext(this)
|
new AuthRequest().fromContext(this)
|
||||||
.appIsGms()
|
.appIsGms()
|
||||||
|
.callerIsGms()
|
||||||
.service("ac2dm")
|
.service("ac2dm")
|
||||||
.token(oAuthToken).isAccessToken()
|
.token(oAuthToken).isAccessToken()
|
||||||
.addAccount()
|
.addAccount()
|
||||||
.getAccountId()
|
.getAccountId()
|
||||||
.systemPartition()
|
|
||||||
.hasPermission()
|
|
||||||
.droidguardResults(null /*TODO*/)
|
.droidguardResults(null /*TODO*/)
|
||||||
.getResponseAsync(new HttpFormClient.Callback<AuthResponse>() {
|
.getResponseAsync(new HttpFormClient.Callback<AuthResponse>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -325,12 +293,9 @@ public class LoginActivity extends AssistantActivity {
|
||||||
setResult(RESULT_OK);
|
setResult(RESULT_OK);
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Account NOT created!");
|
Log.w(TAG, "Account NOT created!");
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(() -> {
|
||||||
@Override
|
showError(R.string.auth_general_error_desc);
|
||||||
public void run() {
|
setNextButtonText(android.R.string.ok);
|
||||||
showError(R.string.auth_general_error_desc);
|
|
||||||
setNextButtonText(android.R.string.ok);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
state = -2;
|
state = -2;
|
||||||
}
|
}
|
||||||
|
@ -348,6 +313,7 @@ public class LoginActivity extends AssistantActivity {
|
||||||
authManager.setPermitted(true);
|
authManager.setPermitted(true);
|
||||||
new AuthRequest().fromContext(this)
|
new AuthRequest().fromContext(this)
|
||||||
.appIsGms()
|
.appIsGms()
|
||||||
|
.callerIsGms()
|
||||||
.service(authManager.getService())
|
.service(authManager.getService())
|
||||||
.email(account.name)
|
.email(account.name)
|
||||||
.token(AccountManager.get(this).getPassword(account))
|
.token(AccountManager.get(this).getPassword(account))
|
||||||
|
@ -405,9 +371,28 @@ public class LoginActivity extends AssistantActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class JsBridge {
|
private class JsBridge {
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
public final void addAccount(String json) {
|
||||||
|
Log.d(TAG, "JSBridge: addAccount " + json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
public final void closeView() {
|
||||||
|
Log.d(TAG, "JSBridge: closeView");
|
||||||
|
closeWeb(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
public final String fetchVerifiedPhoneNumber() {
|
||||||
|
Log.d(TAG, "JSBridge: fetchVerifiedPhoneNumber");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("MissingPermission")
|
@SuppressWarnings("MissingPermission")
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public final String getAccounts() {
|
public final String getAccounts() {
|
||||||
|
Log.d(TAG, "JSBridge: getAccounts");
|
||||||
Account[] accountsByType = accountManager.getAccountsByType(accountType);
|
Account[] accountsByType = accountManager.getAccountsByType(accountType);
|
||||||
JSONArray json = new JSONArray();
|
JSONArray json = new JSONArray();
|
||||||
for (Account account : accountsByType) {
|
for (Account account : accountsByType) {
|
||||||
|
@ -418,16 +403,23 @@ public class LoginActivity extends AssistantActivity {
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public final String getAllowedDomains() {
|
public final String getAllowedDomains() {
|
||||||
|
Log.d(TAG, "JSBridge: getAllowedDomains");
|
||||||
return new JSONArray().toString();
|
return new JSONArray().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public final String getAndroidId() {
|
public final String getAndroidId() {
|
||||||
long androidId = LastCheckinInfo.read(LoginActivity.this).androidId;
|
long androidId = LastCheckinInfo.read(LoginActivity.this).androidId;
|
||||||
|
Log.d(TAG, "JSBridge: getAndroidId " + androidId);
|
||||||
if (androidId == 0 || androidId == -1) return null;
|
if (androidId == 0 || androidId == -1) return null;
|
||||||
return Long.toHexString(androidId);
|
return Long.toHexString(androidId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
public final int getAuthModuleVersionCode() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public final int getBuildVersionSdk() {
|
public final int getBuildVersionSdk() {
|
||||||
return SDK_INT;
|
return SDK_INT;
|
||||||
|
@ -438,6 +430,11 @@ public class LoginActivity extends AssistantActivity {
|
||||||
Log.d(TAG, "JSBridge: getDroidGuardResult: " + s);
|
Log.d(TAG, "JSBridge: getDroidGuardResult: " + s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
public final int getDeviceDataVersionInfo() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public final String getFactoryResetChallenges() {
|
public final String getFactoryResetChallenges() {
|
||||||
return new JSONArray().toString();
|
return new JSONArray().toString();
|
||||||
|
@ -484,14 +481,29 @@ public class LoginActivity extends AssistantActivity {
|
||||||
inputMethodManager.hideSoftInputFromWindow(webView.getWindowToken(), 0);
|
inputMethodManager.hideSoftInputFromWindow(webView.getWindowToken(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
public final boolean isUserOwner() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public final void launchEmergencyDialer() {
|
public final void launchEmergencyDialer() {
|
||||||
Log.d(TAG, "JSBridge: launchEmergencyDialer");
|
Log.d(TAG, "JSBridge: launchEmergencyDialer");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
public final void log(String s) {
|
||||||
|
Log.d(TAG, "JSBridge: log " + s);
|
||||||
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public final void notifyOnTermsOfServiceAccepted() {
|
public final void notifyOnTermsOfServiceAccepted() {
|
||||||
Log.d(TAG, "Terms of service accepted. (who cares?)");
|
Log.d(TAG, "JSBridge: notifyOnTermsOfServiceAccepted");
|
||||||
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
public final void setAccountIdentifier(String accountIdentifier) {
|
||||||
|
Log.d(TAG, "JSBridge: setAccountIdentifier " + accountIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(HONEYCOMB)
|
@TargetApi(HONEYCOMB)
|
||||||
|
@ -510,7 +522,7 @@ public class LoginActivity extends AssistantActivity {
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public final void setNewAccountCreated() {
|
public final void setNewAccountCreated() {
|
||||||
Log.d(TAG, "New account created. (who cares?)");
|
Log.d(TAG, "JSBridge: setNewAccountCreated");
|
||||||
}
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
|
@ -522,12 +534,7 @@ public class LoginActivity extends AssistantActivity {
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public final void showView() {
|
public final void showView() {
|
||||||
Log.d(TAG, "JSBridge: showView");
|
Log.d(TAG, "JSBridge: showView");
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(() -> webView.setVisibility(VISIBLE));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
webView.setVisibility(VISIBLE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
|
|
Loading…
Reference in New Issue
Block a user