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

197 lines
5.8 KiB
Java
Raw Normal View History

2015-02-01 22:27:46 +00:00
/*
* Copyright (C) 2013-2017 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;
2022-01-28 00:15:01 +00:00
import static org.microg.gms.common.HttpFormClient.RequestContent;
import static org.microg.gms.common.HttpFormClient.RequestHeader;
2015-02-03 22:08:55 +00:00
import android.content.Context;
2020-07-08 18:04:23 +00:00
import org.microg.gms.checkin.LastCheckinInfo;
2015-02-03 22:08:55 +00:00
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;
2022-01-28 00:15:01 +00:00
import org.microg.gms.profile.Build;
2022-01-26 05:26:56 +00:00
import org.microg.gms.profile.ProfileManager;
2015-02-03 22:08:55 +00:00
import java.io.IOException;
import java.util.Locale;
2015-02-01 22:27:46 +00:00
public class AuthRequest extends HttpFormClient.Request {
private static final String SERVICE_URL = "https://android.googleapis.com/auth";
private static final String USER_AGENT = "GoogleAuth/1.4 (%s %s); gzip";
2015-02-01 22:27:46 +00:00
@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")
public int gmsVersion = Constants.GMS_VERSION_CODE;
@RequestContent("accountType")
public String accountType;
@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")
public String source;
@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("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
2022-01-26 05:26:56 +00:00
public AuthRequest build(Context context) {
ProfileManager.ensureInitialized(context);
sdkVersion = Build.VERSION.SDK_INT;
deviceName = Build.DEVICE;
buildVersion = Build.ID;
2015-02-03 22:08:55 +00:00
return this;
}
public AuthRequest source(String source) {
this.source = source;
return this;
}
2015-02-03 22:08:55 +00:00
public AuthRequest locale(Locale locale) {
this.locale = locale.toString();
this.countryCode = locale.getCountry().toLowerCase();
this.operatorCountryCode = locale.getCountry().toLowerCase();
2015-02-03 22:08:55 +00:00
return this;
}
public AuthRequest fromContext(Context context) {
2022-01-26 05:26:56 +00:00
build(context);
2015-02-03 22:08:55 +00:00
locale(Utils.getLocale(context));
2021-06-26 07:45:33 +00:00
androidIdHex = Long.toHexString(LastCheckinInfo.read(context).getAndroidId());
2015-02-03 22:08:55 +00:00
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 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
}