Shrink snet APK, and prevent crashing

This commit is contained in:
topjohnwu 2018-07-28 23:40:41 +08:00
parent a747fdd27d
commit b8eaff66fa
5 changed files with 28 additions and 23 deletions

View File

@ -39,7 +39,7 @@ public class Const {
// Versions
public static final int UPDATE_SERVICE_VER = 1;
public static final int SNET_VER = 9;
public static final int SNET_VER = 10;
public static int MIN_MODULE_VER() {
return MagiskManager.get().magiskVersionCode >= MAGISK_VER.REMOVE_LEGACY_LINK ? 1500 : 1400;
@ -81,7 +81,7 @@ public class Const {
public static class Url {
public static final String STABLE_URL = "https://raw.githubusercontent.com/topjohnwu/magisk_files/master/stable.json";
public static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/magisk_files/master/beta.json";
public static final String SNET_URL = "https://github.com/topjohnwu/magisk_files/raw/fc819e3974e96d0e4430a2957df4410971ebd6f3/snet.apk";
public static final String SNET_URL = "https://github.com/topjohnwu/magisk_files/raw/a300521162587da23e45010797bfd8c9a03594f6/snet.apk";
public static final String REPO_URL = "https://api.github.com/users/Magisk-Modules-Repo/repos?per_page=100&page=%d";
public static final String FILE_URL = "https://raw.githubusercontent.com/Magisk-Modules-Repo/%s/master/%s";
public static final String ZIP_URL = "https://github.com/Magisk-Modules-Repo/%s/archive/master.zip";

View File

@ -16,12 +16,15 @@ android {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.gms:play-services-safetynet:7.0.0' /* The oldest version */
/* The oldest version */
implementation('com.google.android.gms:play-services-safetynet:7.0.0') {
exclude module: 'support-v4'
}
}

View File

@ -20,6 +20,7 @@
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keep class com.topjohnwu.snet.* { *; }
-ignorewarnings
-keep class com.topjohnwu.snet.Snet { *; }
-dontwarn java.lang.invoke**
-dontwarn com.google.android.gms.common.GooglePlayServicesUtil**

View File

@ -5,13 +5,14 @@ import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
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 */
@ -20,7 +21,7 @@ public class ModdedGPSUtil {
private static final String TAG = "GooglePlayServicesUtil";
static String dexPath;
static Dialog getErrorDialog(int errCode, Activity activity, int requestCode) {
static Dialog getErrorDialog(int errCode, final Activity activity, final int requestCode) {
SwapResContext ctx = new SwapResContext(activity, dexPath);
Resources res = ctx.getResources();
if (zzlu.zzQ(ctx) && errCode == 2) {
@ -33,8 +34,16 @@ public class ModdedGPSUtil {
String btnMsg = GooglePlayServicesUtil.zzf(ctx, errCode);
if (btnMsg != null) {
Intent intent = GooglePlayServicesUtil.zzan(errCode);
builder.setPositiveButton(btnMsg, new zzg(activity, intent, requestCode));
final Intent intent = GooglePlayServicesUtil.zzan(errCode);
builder.setPositiveButton(btnMsg, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
PackageManager pm = activity.getPackageManager();
if (intent != null && intent.resolveActivity(pm) != null)
activity.startActivityForResult(intent, requestCode);
dialog.dismiss();
}
});
}
switch(errCode) {
@ -116,20 +125,14 @@ public class ModdedGPSUtil {
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();
asset = AssetManager.class.newInstance();
AssetManager.class.getMethod("addAssetPath", String.class).invoke(asset, apk);
return asset;
} catch (Exception e) {
e.printStackTrace();
return null;
}
Resources res = base.getResources();
resources = new Resources(asset, res.getDisplayMetrics(), res.getConfiguration());
}
@Override

View File

@ -2,8 +2,6 @@ package com.topjohnwu.snet;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Base64;
import com.google.android.gms.common.ConnectionResult;
@ -31,7 +29,7 @@ public class SafetyNetHelper implements InvocationHandler, GoogleApiClient.Conne
public static final int BASIC_PASS = 0x10;
public static final int CTS_PASS = 0x20;
public static final int SNET_EXT_VER = 9;
public static final int SNET_EXT_VER = 10;
private GoogleApiClient mGoogleApiClient;
private Activity mActivity;
@ -81,14 +79,14 @@ public class SafetyNetHelper implements InvocationHandler, GoogleApiClient.Conne
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult result) {
public void onConnectionFailed(ConnectionResult result) {
if (GooglePlayServicesUtil.isUserRecoverableError(result.getErrorCode()))
ModdedGPSUtil.getErrorDialog(result.getErrorCode(), mActivity, 0).show();
invokeCallback(CONNECTION_FAIL);
}
@Override
public void onConnected(@Nullable Bundle bundle) {
public void onConnected(Bundle bundle) {
// Create nonce
byte[] nonce = new byte[24];
new SecureRandom().nextBytes(nonce);