mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2025-02-22 23:41:09 +01:00
Add support for login and deviceconfig to checkin
This commit is contained in:
parent
5227caab6c
commit
2db2a2c371
@ -31,6 +31,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@ -118,7 +119,9 @@ public class CheckinClient {
|
||||
|
||||
private static CheckinRequest makeRequest(CheckinRequest.Checkin checkin,
|
||||
CheckinRequest.DeviceConfig deviceConfig,
|
||||
DeviceIdentifier deviceIdent, LastCheckinInfo checkinInfo) {
|
||||
DeviceIdentifier deviceIdent,
|
||||
LastCheckinInfo checkinInfo,
|
||||
List<Account> accounts) {
|
||||
CheckinRequest.Builder builder = new CheckinRequest.Builder()
|
||||
.accountCookie(Arrays.asList("")) // TODO
|
||||
.androidId(checkinInfo.androidId)
|
||||
@ -136,6 +139,11 @@ public class CheckinClient {
|
||||
.userName((String) TODO)
|
||||
.userSerialNumber((Integer) TODO)
|
||||
.version(3);
|
||||
builder.accountCookie(new ArrayList<String>());
|
||||
for (Account account : accounts) {
|
||||
builder.accountCookie.add("[" + account.name + "]");
|
||||
builder.accountCookie.add(account.authToken);
|
||||
}
|
||||
if (deviceIdent.wifiMac != null) {
|
||||
builder.macAddress(Arrays.asList(deviceIdent.wifiMac))
|
||||
.macAddressType(Arrays.asList("wifi"));
|
||||
@ -150,8 +158,19 @@ public class CheckinClient {
|
||||
|
||||
public static CheckinRequest makeRequest(Build build, DeviceConfiguration deviceConfiguration,
|
||||
DeviceIdentifier deviceIdent, PhoneInfo phoneInfo,
|
||||
LastCheckinInfo checkinInfo) {
|
||||
LastCheckinInfo checkinInfo,
|
||||
List<Account> accounts) {
|
||||
return makeRequest(makeCheckin(makeBuild(build), phoneInfo, checkinInfo),
|
||||
makeDeviceConfig(deviceConfiguration), deviceIdent, checkinInfo);
|
||||
makeDeviceConfig(deviceConfiguration), deviceIdent, checkinInfo, accounts);
|
||||
}
|
||||
|
||||
public static class Account {
|
||||
public final String name;
|
||||
public final String authToken;
|
||||
|
||||
public Account(String accountName, String authToken) {
|
||||
this.name = accountName;
|
||||
this.authToken = authToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,13 @@
|
||||
|
||||
package org.microg.gms.checkin;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
|
||||
import org.microg.gms.auth.AuthManager;
|
||||
import org.microg.gms.common.Constants;
|
||||
import org.microg.gms.common.DeviceConfiguration;
|
||||
import org.microg.gms.common.DeviceIdentifier;
|
||||
import org.microg.gms.common.PhoneInfo;
|
||||
@ -26,14 +30,26 @@ import org.microg.gms.common.Utils;
|
||||
import org.microg.gms.gservices.GServices;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CheckinManager {
|
||||
private static final long MIN_CHECKIN_INTERVAL = 3 * 60 * 60 * 1000; // 3 hours
|
||||
|
||||
public static synchronized LastCheckinInfo checkin(Context context) throws IOException {
|
||||
public static synchronized LastCheckinInfo checkin(Context context, boolean force) throws IOException {
|
||||
LastCheckinInfo info = LastCheckinInfo.read(context);
|
||||
if (info.lastCheckin > System.currentTimeMillis() - MIN_CHECKIN_INTERVAL) return null;
|
||||
CheckinRequest request = CheckinClient.makeRequest(Utils.getBuild(context), new DeviceConfiguration(), new DeviceIdentifier(), new PhoneInfo(), info); // TODO
|
||||
if (!force && info.lastCheckin > System.currentTimeMillis() - MIN_CHECKIN_INTERVAL)
|
||||
return null;
|
||||
List<CheckinClient.Account> accounts = new ArrayList<>();
|
||||
AccountManager accountManager = AccountManager.get(context);
|
||||
for (Account account : accountManager.getAccountsByType("com.google")) {
|
||||
String token = AuthManager.getToken(context, account, Constants.GMS_PACKAGE_NAME,
|
||||
Constants.GMS_PACKAGE_SIGNATURE_SHA1, "ac2dm");
|
||||
accounts.add(new CheckinClient.Account(account.name, token));
|
||||
}
|
||||
CheckinRequest request =
|
||||
CheckinClient.makeRequest(Utils.getBuild(context), new DeviceConfiguration(context),
|
||||
new DeviceIdentifier(), new PhoneInfo(), info, accounts); // TODO
|
||||
return handleResponse(context, CheckinClient.request(request));
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,6 @@ import android.app.IntentService;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CheckinService extends IntentService {
|
||||
private static final String TAG = "GmsCheckinSvc";
|
||||
|
||||
@ -32,7 +30,7 @@ public class CheckinService extends IntentService {
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
try {
|
||||
LastCheckinInfo info = CheckinManager.checkin(this);
|
||||
LastCheckinInfo info = CheckinManager.checkin(this, intent.getBooleanExtra("force", false));
|
||||
if (info != null) {
|
||||
Log.d(TAG, "Checked in as " + Long.toHexString(info.androidId));
|
||||
}
|
||||
|
@ -27,6 +27,10 @@ public class TriggerReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d(TAG, "Trigger checkin: " + intent);
|
||||
context.startService(new Intent(context, CheckinService.class));
|
||||
Intent subIntent = new Intent(context, CheckinService.class);
|
||||
if ("android.provider.Telephony.SECRET_CODE".equals(intent.getAction())) {
|
||||
subIntent.putExtra("force", true);
|
||||
}
|
||||
context.startService(subIntent);
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,25 @@
|
||||
|
||||
package org.microg.gms.common;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ConfigurationInfo;
|
||||
import android.content.pm.FeatureInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.opengl.GLES10;
|
||||
import android.os.Build;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.egl.EGLContext;
|
||||
import javax.microedition.khronos.egl.EGLDisplay;
|
||||
|
||||
public class DeviceConfiguration {
|
||||
public List<String> availableFeatures;
|
||||
public int densityDpi;
|
||||
@ -34,4 +51,97 @@ public class DeviceConfiguration {
|
||||
public List<String> sharedLibraries;
|
||||
public int touchScreen;
|
||||
public int widthPixels;
|
||||
|
||||
public DeviceConfiguration(Context context) {
|
||||
ConfigurationInfo configurationInfo = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getDeviceConfigurationInfo();
|
||||
touchScreen = configurationInfo.reqTouchScreen;
|
||||
keyboardType = configurationInfo.reqKeyboardType;
|
||||
navigation = configurationInfo.reqNavigation;
|
||||
Configuration configuration = context.getResources().getConfiguration();
|
||||
screenLayout = configuration.screenLayout;
|
||||
hasHardKeyboard = (configurationInfo.reqInputFeatures & ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD) > 0;
|
||||
hasFiveWayNavigation = (configurationInfo.reqInputFeatures & ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV) > 0;
|
||||
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
||||
densityDpi = displayMetrics.densityDpi;
|
||||
glEsVersion = configurationInfo.reqGlEsVersion;
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
sharedLibraries = Arrays.asList(packageManager.getSystemSharedLibraryNames());
|
||||
availableFeatures = new ArrayList<>();
|
||||
for (FeatureInfo featureInfo : packageManager.getSystemAvailableFeatures()) {
|
||||
if (featureInfo.name != null) availableFeatures.add(featureInfo.name);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
nativePlatforms = Arrays.asList(Build.SUPPORTED_ABIS);
|
||||
} else {
|
||||
nativePlatforms = new ArrayList<>();
|
||||
nativePlatforms.add(Build.CPU_ABI);
|
||||
if (Build.CPU_ABI2 != null) nativePlatforms.add(Build.CPU_ABI2);
|
||||
}
|
||||
widthPixels = displayMetrics.widthPixels;
|
||||
heightPixels = displayMetrics.heightPixels;
|
||||
locales = Arrays.asList(context.getAssets().getLocales());
|
||||
glExtensions = new ArrayList<>();
|
||||
addEglExtensions(glExtensions);
|
||||
}
|
||||
|
||||
private static void addEglExtensions(List<String> glExtensions) {
|
||||
EGL10 egl10 = (EGL10) EGLContext.getEGL();
|
||||
if (egl10 != null) {
|
||||
EGLDisplay display = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
|
||||
egl10.eglInitialize(display, new int[2]);
|
||||
int cf[] = new int[1];
|
||||
if (egl10.eglGetConfigs(display, null, 0, cf)) {
|
||||
EGLConfig[] configs = new EGLConfig[cf[0]];
|
||||
if (egl10.eglGetConfigs(display, configs, cf[0], cf)) {
|
||||
int[] a1 =
|
||||
new int[]{EGL10.EGL_WIDTH, EGL10.EGL_PBUFFER_BIT, EGL10.EGL_HEIGHT, EGL10.EGL_PBUFFER_BIT,
|
||||
EGL10.EGL_NONE};
|
||||
int[] a2 = new int[]{12440, EGL10.EGL_PIXMAP_BIT, EGL10.EGL_NONE};
|
||||
int[] a3 = new int[1];
|
||||
for (int i = 0; i < cf[0]; i++) {
|
||||
egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_CONFIG_CAVEAT, a3);
|
||||
if (a3[0] != EGL10.EGL_SLOW_CONFIG) {
|
||||
egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_SURFACE_TYPE, a3);
|
||||
if ((1 & a3[0]) != 0) {
|
||||
egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_RENDERABLE_TYPE, a3);
|
||||
if ((1 & a3[0]) != 0) {
|
||||
addExtensionsForConfig(egl10, display, configs[i], a1, null, glExtensions);
|
||||
}
|
||||
if ((4 & a3[0]) != 0) {
|
||||
addExtensionsForConfig(egl10, display, configs[i], a1, a2, glExtensions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
egl10.eglTerminate(display);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addExtensionsForConfig(EGL10 egl10, EGLDisplay egldisplay, EGLConfig eglconfig, int ai[],
|
||||
int ai1[], List<String> set) {
|
||||
EGLContext eglcontext = egl10.eglCreateContext(egldisplay, eglconfig, EGL10.EGL_NO_CONTEXT, ai1);
|
||||
if (eglcontext != EGL10.EGL_NO_CONTEXT) {
|
||||
javax.microedition.khronos.egl.EGLSurface eglsurface =
|
||||
egl10.eglCreatePbufferSurface(egldisplay, eglconfig, ai);
|
||||
if (eglsurface == EGL10.EGL_NO_SURFACE) {
|
||||
egl10.eglDestroyContext(egldisplay, eglcontext);
|
||||
} else {
|
||||
egl10.eglMakeCurrent(egldisplay, eglsurface, eglsurface, eglcontext);
|
||||
String s = GLES10.glGetString(7939);
|
||||
if (s != null && !s.isEmpty()) {
|
||||
String as[] = s.split(" ");
|
||||
int i = as.length;
|
||||
for (int j = 0; j < i; j++) {
|
||||
set.add(as[j]);
|
||||
}
|
||||
|
||||
}
|
||||
egl10.eglMakeCurrent(egldisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
|
||||
egl10.eglDestroySurface(egldisplay, eglsurface);
|
||||
egl10.eglDestroyContext(egldisplay, eglcontext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user