2015-02-19 00:29:43 +00:00
|
|
|
/*
|
2017-06-12 22:30:41 +00:00
|
|
|
* Copyright (C) 2013-2017 microG Project Team
|
2015-02-19 00:29:43 +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.checkin;
|
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import org.microg.gms.common.Build;
|
|
|
|
import org.microg.gms.common.DeviceConfiguration;
|
|
|
|
import org.microg.gms.common.DeviceIdentifier;
|
|
|
|
import org.microg.gms.common.PhoneInfo;
|
2015-08-06 15:38:46 +00:00
|
|
|
import org.microg.gms.common.Utils;
|
2015-02-19 00:29:43 +00:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.URL;
|
2015-03-07 14:19:06 +00:00
|
|
|
import java.util.ArrayList;
|
2015-02-19 00:29:43 +00:00
|
|
|
import java.util.Arrays;
|
2015-07-08 16:23:20 +00:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Date;
|
2015-02-19 00:29:43 +00:00
|
|
|
import java.util.List;
|
2015-07-08 16:23:20 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Random;
|
|
|
|
import java.util.TimeZone;
|
|
|
|
import java.util.zip.GZIPInputStream;
|
|
|
|
import java.util.zip.GZIPOutputStream;
|
2015-02-19 00:29:43 +00:00
|
|
|
|
|
|
|
public class CheckinClient {
|
|
|
|
private static final String TAG = "GmsCheckinClient";
|
2015-02-26 22:59:37 +00:00
|
|
|
private static final Object TODO = null; // TODO
|
2021-05-31 20:01:07 +00:00
|
|
|
private static final List<String> TODO_LIST_STRING = new ArrayList<>(); // TODO
|
|
|
|
private static final List<CheckinRequest.Checkin.Statistic> TODO_LIST_CHECKIN = new ArrayList<>(); // TODO
|
2015-02-19 00:29:43 +00:00
|
|
|
private static final String SERVICE_URL = "https://android.clients.google.com/checkin";
|
|
|
|
|
|
|
|
public static CheckinResponse request(CheckinRequest request) throws IOException {
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) new URL(SERVICE_URL).openConnection();
|
|
|
|
connection.setRequestMethod("POST");
|
|
|
|
connection.setDoInput(true);
|
|
|
|
connection.setDoOutput(true);
|
2015-07-24 00:55:58 +00:00
|
|
|
connection.setRequestProperty("Content-type", "application/x-protobuffer");
|
2015-07-08 16:23:20 +00:00
|
|
|
connection.setRequestProperty("Content-Encoding", "gzip");
|
|
|
|
connection.setRequestProperty("Accept-Encoding", "gzip");
|
|
|
|
connection.setRequestProperty("User-Agent", "Android-Checkin/2.0 (vbox86p JLS36G); gzip");
|
2015-02-19 00:29:43 +00:00
|
|
|
|
|
|
|
Log.d(TAG, "-- Request --\n" + request);
|
2015-07-08 16:23:20 +00:00
|
|
|
OutputStream os = new GZIPOutputStream(connection.getOutputStream());
|
2020-08-01 20:21:23 +00:00
|
|
|
os.write(request.encode());
|
2015-02-19 00:29:43 +00:00
|
|
|
os.close();
|
|
|
|
|
|
|
|
if (connection.getResponseCode() != 200) {
|
2015-07-08 16:23:20 +00:00
|
|
|
try {
|
2015-08-06 15:38:46 +00:00
|
|
|
throw new IOException(new String(Utils.readStreamToEnd(new GZIPInputStream(connection.getErrorStream()))));
|
2015-07-08 16:23:20 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
throw new IOException(connection.getResponseMessage(), e);
|
|
|
|
}
|
2015-02-19 00:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InputStream is = connection.getInputStream();
|
2020-08-01 20:21:23 +00:00
|
|
|
CheckinResponse response = CheckinResponse.ADAPTER.decode(new GZIPInputStream(is));
|
2015-02-19 00:29:43 +00:00
|
|
|
is.close();
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2015-07-08 16:23:20 +00:00
|
|
|
public static CheckinRequest makeRequest(Build build, DeviceConfiguration deviceConfiguration,
|
|
|
|
DeviceIdentifier deviceIdent, PhoneInfo phoneInfo,
|
|
|
|
LastCheckinInfo checkinInfo, Locale locale,
|
|
|
|
List<Account> accounts) {
|
2015-02-26 23:11:49 +00:00
|
|
|
CheckinRequest.Builder builder = new CheckinRequest.Builder()
|
2021-05-31 20:01:07 +00:00
|
|
|
.accountCookie(new ArrayList<>())
|
|
|
|
.androidId(checkinInfo.getAndroidId())
|
2015-07-08 16:23:20 +00:00
|
|
|
.checkin(new CheckinRequest.Checkin.Builder()
|
|
|
|
.build(new CheckinRequest.Checkin.Build.Builder()
|
|
|
|
.bootloader(build.bootloader)
|
|
|
|
.brand(build.brand)
|
|
|
|
.clientId("android-google")
|
|
|
|
.device(build.device)
|
|
|
|
.fingerprint(build.fingerprint)
|
|
|
|
.hardware(build.hardware)
|
|
|
|
.manufacturer(build.manufacturer)
|
|
|
|
.model(build.model)
|
|
|
|
.otaInstalled(false) // TODO?
|
|
|
|
//.packageVersionCode(Constants.MAX_REFERENCE_VERSION)
|
|
|
|
.product(build.product)
|
|
|
|
.radio(build.radio)
|
|
|
|
.sdkVersion(build.sdk)
|
|
|
|
.time(build.time / 1000)
|
|
|
|
.build())
|
|
|
|
.cellOperator(phoneInfo.cellOperator)
|
|
|
|
.event(Collections.singletonList(new CheckinRequest.Checkin.Event.Builder()
|
2021-05-31 20:01:07 +00:00
|
|
|
.tag(checkinInfo.getAndroidId() == 0 ? "event_log_start" : "system_update")
|
|
|
|
.value(checkinInfo.getAndroidId() == 0 ? null : "1536,0,-1,NULL")
|
2015-07-08 16:23:20 +00:00
|
|
|
.timeMs(new Date().getTime())
|
|
|
|
.build()))
|
2021-05-31 20:01:07 +00:00
|
|
|
.lastCheckinMs(checkinInfo.getLastCheckin())
|
2020-08-04 15:24:02 +00:00
|
|
|
.requestedGroup(TODO_LIST_STRING)
|
2015-07-08 16:23:20 +00:00
|
|
|
.roaming(phoneInfo.roaming)
|
|
|
|
.simOperator(phoneInfo.simOperator)
|
2020-08-04 15:24:02 +00:00
|
|
|
.stat(TODO_LIST_CHECKIN)
|
2015-07-08 16:23:20 +00:00
|
|
|
.userNumber(0)
|
|
|
|
.build())
|
|
|
|
.deviceConfiguration(new CheckinRequest.DeviceConfig.Builder()
|
|
|
|
.availableFeature(deviceConfiguration.availableFeatures)
|
|
|
|
.densityDpi(deviceConfiguration.densityDpi)
|
|
|
|
.glEsVersion(deviceConfiguration.glEsVersion)
|
|
|
|
.glExtension(deviceConfiguration.glExtensions)
|
|
|
|
.hasFiveWayNavigation(deviceConfiguration.hasFiveWayNavigation)
|
|
|
|
.hasHardKeyboard(deviceConfiguration.hasHardKeyboard)
|
|
|
|
.heightPixels(deviceConfiguration.heightPixels)
|
|
|
|
.keyboardType(deviceConfiguration.keyboardType)
|
|
|
|
.locale(deviceConfiguration.locales)
|
|
|
|
.nativePlatform(deviceConfiguration.nativePlatforms)
|
|
|
|
.navigation(deviceConfiguration.navigation)
|
2015-07-24 00:55:58 +00:00
|
|
|
.screenLayout(deviceConfiguration.screenLayout & 0xF)
|
2015-07-08 16:23:20 +00:00
|
|
|
.sharedLibrary(deviceConfiguration.sharedLibraries)
|
|
|
|
.touchScreen(deviceConfiguration.touchScreen)
|
|
|
|
.widthPixels(deviceConfiguration.widthPixels)
|
|
|
|
.build())
|
2021-05-31 20:01:07 +00:00
|
|
|
.digest(checkinInfo.getDigest())
|
2015-02-19 00:29:43 +00:00
|
|
|
.esn(deviceIdent.esn)
|
2015-02-28 19:56:05 +00:00
|
|
|
.fragment(0)
|
2015-07-08 16:23:20 +00:00
|
|
|
.locale(locale.toString())
|
|
|
|
.loggingId(new Random().nextLong()) // TODO: static
|
2015-02-19 00:29:43 +00:00
|
|
|
.meid(deviceIdent.meid)
|
2015-07-08 16:23:20 +00:00
|
|
|
.otaCert(Collections.singletonList("71Q6Rn2DDZl1zPDVaaeEHItd"))
|
|
|
|
.serial(build.serial)
|
|
|
|
.timeZone(TimeZone.getDefault().getID())
|
2015-02-19 00:29:43 +00:00
|
|
|
.userName((String) TODO)
|
|
|
|
.userSerialNumber((Integer) TODO)
|
2015-02-26 23:11:49 +00:00
|
|
|
.version(3);
|
2015-03-07 14:19:06 +00:00
|
|
|
for (Account account : accounts) {
|
|
|
|
builder.accountCookie.add("[" + account.name + "]");
|
|
|
|
builder.accountCookie.add(account.authToken);
|
|
|
|
}
|
2015-07-08 16:23:20 +00:00
|
|
|
if (builder.accountCookie.isEmpty()) builder.accountCookie.add("");
|
2015-02-28 19:56:05 +00:00
|
|
|
if (deviceIdent.wifiMac != null) {
|
|
|
|
builder.macAddress(Arrays.asList(deviceIdent.wifiMac))
|
|
|
|
.macAddressType(Arrays.asList("wifi"));
|
|
|
|
}
|
2021-05-31 20:01:07 +00:00
|
|
|
if (checkinInfo.getSecurityToken() != 0) {
|
|
|
|
builder.securityToken(checkinInfo.getSecurityToken())
|
2015-02-28 19:56:05 +00:00
|
|
|
.fragment(1);
|
|
|
|
}
|
2015-02-26 23:11:49 +00:00
|
|
|
return builder.build();
|
2015-03-07 14:19:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class Account {
|
|
|
|
public final String name;
|
|
|
|
public final String authToken;
|
|
|
|
|
|
|
|
public Account(String accountName, String authToken) {
|
|
|
|
this.name = accountName;
|
|
|
|
this.authToken = authToken;
|
|
|
|
}
|
2015-02-19 00:29:43 +00:00
|
|
|
}
|
|
|
|
}
|