mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-03 14:11:58 +00:00
Update SNET extension dialog interface
This commit is contained in:
145
snet/src/main/java/com/topjohnwu/snet/ModdedGPSUtil.java
Normal file
145
snet/src/main/java/com/topjohnwu/snet/ModdedGPSUtil.java
Normal file
@@ -0,0 +1,145 @@
|
||||
package com.topjohnwu.snet;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Resources;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.gms.common.GooglePlayServicesUtil;
|
||||
import com.google.android.gms.common.internal.zzg;
|
||||
import com.google.android.gms.internal.zzlu;
|
||||
|
||||
/* Decompiled and modified from GooglePlayServiceUtil.class */
|
||||
public class ModdedGPSUtil {
|
||||
|
||||
private static final String TAG = "GooglePlayServicesUtil";
|
||||
static String dexPath;
|
||||
|
||||
static Dialog getErrorDialog(int errCode, Activity activity, int requestCode) {
|
||||
SwapResContext ctx = new SwapResContext(activity, dexPath);
|
||||
Resources res = ctx.getResources();
|
||||
if (zzlu.zzQ(ctx) && errCode == 2) {
|
||||
errCode = 42;
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
|
||||
builder.setMessage(GooglePlayServicesUtil.zze(ctx, errCode));
|
||||
|
||||
String btnMsg = GooglePlayServicesUtil.zzf(ctx, errCode);
|
||||
if (btnMsg != null) {
|
||||
Intent intent = GooglePlayServicesUtil.zzan(errCode);
|
||||
builder.setPositiveButton(btnMsg, new zzg(activity, intent, requestCode));
|
||||
}
|
||||
|
||||
switch(errCode) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_google_play_services_install_title)).create();
|
||||
case 2:
|
||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_google_play_services_update_title)).create();
|
||||
case 3:
|
||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_google_play_services_enable_title)).create();
|
||||
case 4:
|
||||
case 6:
|
||||
return builder.create();
|
||||
case 5:
|
||||
Log.e(TAG, "An invalid account was specified when connecting. Please provide a valid account.");
|
||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_google_play_services_invalid_account_title)).create();
|
||||
case 7:
|
||||
Log.e(TAG, "Network error occurred. Please retry request later.");
|
||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_google_play_services_network_error_title)).create();
|
||||
case 8:
|
||||
Log.e(TAG, "Internal error occurred. Please see logs for detailed information");
|
||||
return builder.create();
|
||||
case 9:
|
||||
Log.e(TAG, "Google Play services is invalid. Cannot recover.");
|
||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_google_play_services_unsupported_title)).create();
|
||||
case 10:
|
||||
Log.e(TAG, "Developer error occurred. Please see logs for detailed information");
|
||||
return builder.create();
|
||||
case 11:
|
||||
Log.e(TAG, "The application is not licensed to the user.");
|
||||
return builder.create();
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
case 18:
|
||||
case 19:
|
||||
case 20:
|
||||
case 21:
|
||||
case 22:
|
||||
case 23:
|
||||
case 24:
|
||||
case 25:
|
||||
case 26:
|
||||
case 27:
|
||||
case 28:
|
||||
case 29:
|
||||
case 30:
|
||||
case 31:
|
||||
case 32:
|
||||
case 33:
|
||||
case 34:
|
||||
case 35:
|
||||
case 36:
|
||||
case 37:
|
||||
case 38:
|
||||
case 39:
|
||||
case 40:
|
||||
case 41:
|
||||
default:
|
||||
Log.e(TAG, "Unexpected error code " + errCode);
|
||||
return builder.create();
|
||||
case 16:
|
||||
Log.e(TAG, "One of the API components you attempted to connect to is not available.");
|
||||
return builder.create();
|
||||
case 17:
|
||||
Log.e(TAG, "The specified account could not be signed in.");
|
||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_google_play_services_sign_in_failed_title)).create();
|
||||
case 42:
|
||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_android_wear_update_title)).create();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SwapResContext extends ContextWrapper {
|
||||
|
||||
private AssetManager asset;
|
||||
private Resources resources;
|
||||
|
||||
public SwapResContext(Context base, String apk) {
|
||||
super(base);
|
||||
asset = getAssets(apk);
|
||||
Resources res = base.getResources();
|
||||
resources = new Resources(asset, res.getDisplayMetrics(), res.getConfiguration());
|
||||
}
|
||||
|
||||
private AssetManager getAssets(String apk) {
|
||||
try {
|
||||
AssetManager asset = AssetManager.class.newInstance();
|
||||
AssetManager.class.getMethod("addAssetPath", String.class).invoke(asset, apk);
|
||||
return asset;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resources getResources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssetManager getAssets() {
|
||||
return asset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.topjohnwu.snet;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -11,16 +12,15 @@ import com.google.android.gms.common.api.GoogleApiClient;
|
||||
import com.google.android.gms.common.api.ResultCallback;
|
||||
import com.google.android.gms.safetynet.SafetyNet;
|
||||
import com.google.android.gms.safetynet.SafetyNetApi;
|
||||
import com.topjohnwu.magisk.asyncs.CheckSafetyNet;
|
||||
import com.topjohnwu.magisk.components.Activity;
|
||||
import com.topjohnwu.magisk.utils.ISafetyNetHelper;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
public class SafetyNetHelper implements ISafetyNetHelper, GoogleApiClient.ConnectionCallbacks,
|
||||
public class SafetyNetHelper implements InvocationHandler, GoogleApiClient.ConnectionCallbacks,
|
||||
GoogleApiClient.OnConnectionFailedListener, ResultCallback<SafetyNetApi.AttestationResult> {
|
||||
|
||||
public static final int CAUSE_SERVICE_DISCONNECTED = 0x01;
|
||||
@@ -31,25 +31,24 @@ public class SafetyNetHelper implements ISafetyNetHelper, GoogleApiClient.Connec
|
||||
public static final int BASIC_PASS = 0x10;
|
||||
public static final int CTS_PASS = 0x20;
|
||||
|
||||
public static final int SNET_EXT_VER = 8;
|
||||
public static final int SNET_EXT_VER = 9;
|
||||
|
||||
private GoogleApiClient mGoogleApiClient;
|
||||
private Activity mActivity;
|
||||
private Callback callback;
|
||||
private Object callback;
|
||||
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return SNET_EXT_VER;
|
||||
}
|
||||
|
||||
public SafetyNetHelper(Activity activity, Callback cb) {
|
||||
SafetyNetHelper(Activity activity, Object cb) {
|
||||
mActivity = activity;
|
||||
callback = cb;
|
||||
}
|
||||
|
||||
// Entry point to start test
|
||||
@Override
|
||||
public void attest() {
|
||||
/* Override ISafetyNetHelper.getVersion */
|
||||
private int getVersion() {
|
||||
return SNET_EXT_VER;
|
||||
}
|
||||
|
||||
/* Override ISafetyNetHelper.attest */
|
||||
private void attest() {
|
||||
// Connect Google Service
|
||||
mGoogleApiClient = new GoogleApiClient.Builder(mActivity)
|
||||
.addApi(SafetyNet.API)
|
||||
@@ -59,17 +58,33 @@ public class SafetyNetHelper implements ISafetyNetHelper, GoogleApiClient.Connec
|
||||
mGoogleApiClient.connect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(Object o, Method method, Object[] args) {
|
||||
if (method.getName().equals("attest")) {
|
||||
attest();
|
||||
} else if (method.getName().equals("getVersion")) {
|
||||
return getVersion();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void invokeCallback(int code) {
|
||||
Class<?> clazz = callback.getClass();
|
||||
try {
|
||||
clazz.getMethod("onResponse", int.class).invoke(callback, code);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionSuspended(int i) {
|
||||
callback.onResponse(i);
|
||||
invokeCallback(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionFailed(@NonNull ConnectionResult result) {
|
||||
mActivity.swapResources(CheckSafetyNet.dexPath.getPath());
|
||||
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), mActivity, 0).show();
|
||||
mActivity.restoreResources();
|
||||
callback.onResponse(CONNECTION_FAIL);
|
||||
if (GooglePlayServicesUtil.isUserRecoverableError(result.getErrorCode()))
|
||||
ModdedGPSUtil.getErrorDialog(result.getErrorCode(), mActivity, 0).show();
|
||||
invokeCallback(CONNECTION_FAIL);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,6 +116,6 @@ public class SafetyNetHelper implements ISafetyNetHelper, GoogleApiClient.Connec
|
||||
mGoogleApiClient.disconnect();
|
||||
|
||||
// Return results
|
||||
callback.onResponse(code);
|
||||
invokeCallback(code);
|
||||
}
|
||||
}
|
||||
|
||||
13
snet/src/main/java/com/topjohnwu/snet/Snet.java
Normal file
13
snet/src/main/java/com/topjohnwu/snet/Snet.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.topjohnwu.snet;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
public class Snet {
|
||||
public static Object newHelper(Class<?> clazz, String dexPath, Activity activity, Object cb) {
|
||||
ModdedGPSUtil.dexPath = dexPath;
|
||||
return Proxy.newProxyInstance(SafetyNetHelper.class.getClassLoader(),
|
||||
new Class[] { clazz }, new SafetyNetHelper(activity, cb));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user