VancedMicroG/play-services-core/src/main/java/org/microg/gms/auth/AuthRequest.java

196 lines
5.7 KiB
Java
Raw Normal View History

2015-02-01 22:27:46 +00:00
/*
* Copyright 2013-2015 microG Project Team
2015-02-01 22:27:46 +00:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.microg.gms.auth;
2015-02-03 22:08:55 +00:00
import android.content.Context;
import org.microg.gms.common.Build;
import org.microg.gms.common.Constants;
import org.microg.gms.common.HttpFormClient;
2015-02-03 22:08:55 +00:00
import org.microg.gms.common.Utils;
import java.io.IOException;
import java.util.Locale;
2015-02-01 22:27:46 +00:00
import static org.microg.gms.common.HttpFormClient.RequestContent;
import static org.microg.gms.common.HttpFormClient.RequestHeader;
public class AuthRequest extends HttpFormClient.Request {
private static final String SERVICE_URL = "https://android.clients.google.com/auth";
2015-02-01 22:27:46 +00:00
private static final String USER_AGENT = "GoogleAuth/1.4 (%s %s)";
@RequestHeader("User-Agent")
private String userAgent;
@RequestHeader("app")
@RequestContent("app")
2015-02-01 22:27:46 +00:00
public String app;
@RequestContent("client_sig")
2015-02-01 22:27:46 +00:00
public String appSignature;
@RequestContent("callerPkg")
2015-02-01 22:27:46 +00:00
public String caller;
@RequestContent("callerSig")
2015-02-01 22:27:46 +00:00
public String callerSignature;
@RequestHeader(value = "device", nullPresent = true)
@RequestContent(value = "androidId", nullPresent = true)
2015-02-01 22:27:46 +00:00
public String androidIdHex;
@RequestContent("sdk_version")
2015-02-01 22:27:46 +00:00
public int sdkVersion;
@RequestContent("device_country")
2015-02-01 22:27:46 +00:00
public String countryCode;
@RequestContent("operatorCountry")
2015-02-01 22:27:46 +00:00
public String operatorCountryCode;
@RequestContent("lang")
2015-02-01 22:27:46 +00:00
public String locale;
@RequestContent("google_play_services_version")
2015-02-03 22:08:55 +00:00
public int gmsVersion = Constants.MAX_REFERENCE_VERSION;
@RequestContent("accountType")
2015-02-01 22:27:46 +00:00
public String accountType = "HOSTED_OR_GOOGLE";
@RequestContent("Email")
2015-02-01 22:27:46 +00:00
public String email;
@RequestContent("service")
2015-02-01 22:27:46 +00:00
public String service;
@RequestContent("source")
2015-02-01 22:27:46 +00:00
public String source = "android";
@RequestContent({"is_called_from_account_manager", "_opt_is_called_from_account_manager"})
2015-02-01 22:27:46 +00:00
public boolean isCalledFromAccountManager;
@RequestContent("Token")
2015-02-01 22:27:46 +00:00
public String token;
@RequestContent("system_partition")
2015-02-03 22:08:55 +00:00
public boolean systemPartition;
@RequestContent("get_accountid")
2015-02-01 22:27:46 +00:00
public boolean getAccountId;
@RequestContent("ACCESS_TOKEN")
2015-02-01 22:27:46 +00:00
public boolean isAccessToken;
@RequestContent("droidguard_results")
2015-02-01 22:27:46 +00:00
public String droidguardResults;
@RequestContent("has_permission")
2015-02-01 22:27:46 +00:00
public boolean hasPermission;
@RequestContent("add_account")
2015-02-01 22:27:46 +00:00
public boolean addAccount;
public String deviceName;
public String buildVersion;
2015-02-01 22:27:46 +00:00
@Override
protected void prepare() {
userAgent = String.format(USER_AGENT, deviceName, buildVersion);
2015-02-01 22:27:46 +00:00
}
2015-02-03 22:08:55 +00:00
public AuthRequest build(Build build) {
sdkVersion = build.sdk;
deviceName = build.device;
buildVersion = build.id;
return this;
}
public AuthRequest locale(Locale locale) {
this.locale = locale.toString();
this.countryCode = locale.getCountry();
this.operatorCountryCode = locale.getCountry();
return this;
}
public AuthRequest fromContext(Context context) {
build(Utils.getBuild(context));
locale(Utils.getLocale(context));
androidIdHex = Utils.getAndroidIdHex(context);
return this;
}
public AuthRequest email(String email) {
this.email = email;
return this;
}
public AuthRequest token(String token) {
this.token = token;
return this;
}
public AuthRequest service(String service) {
this.service = service;
return this;
}
public AuthRequest app(String app, String appSignature) {
this.app = app;
this.appSignature = appSignature;
return this;
}
public AuthRequest appIsGms() {
return app(Constants.GMS_PACKAGE_NAME, Constants.GMS_PACKAGE_SIGNATURE_SHA1);
}
public AuthRequest callerIsGms() {
return caller(Constants.GMS_PACKAGE_NAME, Constants.GMS_PACKAGE_SIGNATURE_SHA1);
}
public AuthRequest callerIsApp() {
return caller(app, appSignature);
}
public AuthRequest caller(String caller, String callerSignature) {
this.caller = caller;
this.callerSignature = callerSignature;
return this;
}
public AuthRequest calledFromAccountManager() {
isCalledFromAccountManager = true;
return this;
}
public AuthRequest addAccount() {
addAccount = true;
return this;
}
public AuthRequest systemPartition() {
systemPartition = true;
return this;
}
public AuthRequest hasPermission() {
hasPermission = true;
return this;
}
public AuthRequest getAccountId() {
getAccountId = true;
return this;
}
public AuthRequest isAccessToken() {
isAccessToken = true;
return this;
}
public AuthRequest droidguardResults(String droidguardResults) {
this.droidguardResults = droidguardResults;
return this;
}
public AuthResponse getResponse() throws IOException {
return HttpFormClient.request(SERVICE_URL, this, AuthResponse.class);
2015-02-03 22:08:55 +00:00
}
public void getResponseAsync(HttpFormClient.Callback<AuthResponse> callback) {
HttpFormClient.requestAsync(SERVICE_URL, this, AuthResponse.class, callback);
2015-02-03 22:08:55 +00:00
}
2015-02-01 22:27:46 +00:00
}