Commit 9cac612c authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 715a507f
......@@ -32,10 +32,10 @@ android {
}
dependencies {
// implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
// implementation fileTree(dir: 'libs', include: ['*.jar'])
api 'com.alipay.sdk:alipaysdk-android:+@aar'
// api 'com.alipay.sdk:alipaysdk-android:+@aar'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
......
package com.jobo.content;
import android.content.ContentResolver;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.util.Log;
import java.util.Arrays;
class ApplicationContext extends ContextWrapper {
private static final String TAG = ApplicationContext.class.getSimpleName();
final Context base;
final String fakePackageName;
final String fakeLabel;
final String fakeVersionName;
final int fakeVersionCode;
final Signature fakeSignature;
private final PackageManager2 fakePm;
private final String realPackageName;
/**
* 这个奇怪的计数器是用来和C内部的各种检查对抗的,避免出现启动不了的问题,只有第三次调用的时候才需要返回真包名
*/
private int hackIntoCCodeHelperOfCounter = 0;
ApplicationContext(
Context base,
String fakePackageName,
String fakeLabel,
String fakeVersionName,
int fakeVersionCode,
Signature fakeSignature
) {
super(base);
this.base = base;
this.realPackageName = base.getPackageName();
this.fakePackageName = fakePackageName;
this.fakeLabel = fakeLabel;
this.fakeVersionName = fakeVersionName;
this.fakeVersionCode = fakeVersionCode;
this.fakeSignature = fakeSignature;
this.fakePm = new PackageManager2(this, base);
}
@Override
public String getPackageName() {
++hackIntoCCodeHelperOfCounter;
// 这句不是为了DEBUG,千万别删除!!!
RuntimeException runtimeException = new RuntimeException();
if (BuildConfig.IS_DEBUG)
Log.d(TAG, "getPackageName() STACK TRACE! called " + Arrays.toString(runtimeException.getStackTrace()));
/* 破解无奈之举
* 1. 如果是普通情况的getPackageName(),比如从C代码直接调用过来,其实就是判断包名,需要用假的
* 2. 如果是从Intent(Context, Class)调用过来,会调用ComponentName(String packageName, String componentName),此处应该使用真包名
*/
String result = fakePackageName;
StackTraceElement[] stackTrace = runtimeException.getStackTrace();
if (stackTrace.length > 1 &&
(containsIgnoreCase(stackTrace[1].getMethodName(), "component")
|| containsIgnoreCase(stackTrace[1].getClassName(), "component")
|| containsIgnoreCase(stackTrace[1].getClassName(), "intent"))) {
if (BuildConfig.IS_DEBUG)
Log.w(TAG, "getPackageName: MATCH!! on counter = " + hackIntoCCodeHelperOfCounter);
result = realPackageName;
}
if (BuildConfig.IS_DEBUG) Log.i(TAG, "getPackageName() called counter = " + hackIntoCCodeHelperOfCounter + " RESULT = " + result, new RuntimeException());
return result;
}
@Override
public PackageManager getPackageManager() {
if (BuildConfig.IS_DEBUG) Log.d(TAG, "getPackageManager() called", new RuntimeException());
return fakePm;
}
@Override public ApplicationInfo getApplicationInfo() {
if (BuildConfig.IS_DEBUG) Log.d(TAG, "getApplicationInfo() called", new RuntimeException());
return super.getApplicationInfo();
}
@Override public ContentResolver getContentResolver() {
if (BuildConfig.IS_DEBUG) Log.d(TAG, "getContentResolver() called", new RuntimeException());
return super.getContentResolver();
}
@Override public Context getApplicationContext() {
return this;
}
@Override public SharedPreferences getSharedPreferences(String name, int mode) {
if (BuildConfig.IS_DEBUG)
Log.d(TAG, "getSharedPreferences() called with: name = [" + name + "], mode = [" + mode + "]");
return super.getSharedPreferences(name, mode);
}
public static boolean containsIgnoreCase(String origin, String sub) {
return origin.toLowerCase().contains(sub.toLowerCase());
}
}
package com.jobo.content;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.util.Log;
public class Context {
private static String pkgName = "com.duben.xixiplaylet";
private static String pkgSign = "308203633082024ba0030201020204181c2ccb300d06092a864886f70d01010b05003062310b3009060355040613027a68310f300d06035504081306636a6474627a310f300d06035504071306636a6474627a310f300d060355040a1306636a6474627a310f300d060355040b1306636a6474627a310f300d06035504031306636a6474627a301e170d3233303331343036343631355a170d3438303330373036343631355a3062310b3009060355040613027a68310f300d06035504081306636a6474627a310f300d06035504071306636a6474627a310f300d060355040a1306636a6474627a310f300d060355040b1306636a6474627a310f300d06035504031306636a6474627a30820122300d06092a864886f70d01010105000382010f003082010a02820101008054bc7f8f0781be915f0da76eb2ded42e382028c7b146894b0fccd0b4fbb306c62b2d050f89e07e0c66b737935c655669f7dec88e51577d778b080cddee5aa90d686509c505f07bdba4bc4020b6fde1372c68602e0de1e7a6bcc1bebfe93f625a3802c6b27bb91532590ff3b2d7142f2f97d8d8d547719fe7bf6a0f0dd74774ac5c2fe6b297573b257e82863a23a8ccd04ac8cdc8fb3c387f6d55369ba42ff835b5c6995bb335536fddee08b69ef5652fc53816228c02e8c669003fed1d07416b46bb86aaaa1300e89767535ff3fa33eee54bad9c50bc69c4489a8406e72ebe8df62353536c524b4d2936de3418e89af954f7912432f01492a861ea08a72c690203010001a321301f301d0603551d0e04160414a98babd6de3e6ae067f9f80135dbca23156feacc300d06092a864886f70d01010b050003820101000e3ace706c29ec48b98d88e042986b182d54f0b704b3e0510e0670f75c380bbdc1ddcc3772d4c569138a070a43b078b6ce14bdd79da15372018679936bca96597da08438cdf133e7a08fd52dfa9890548ed9905044e4cdaad1abaa31cf7741462b68bb1e42ae063e6020b5ec53974d835cf8f79ac29dffe504e8b524564c53a971193d48a782992dc91ddbfb8cb4f36220f1f25692054a4ddf343868142d36e7e192bee6cc7b95dd8996d99b116cd8755aeed2abdb8453670bae7a8c0c0a2324ad25534cacc0934b2ec33b073fdd4fd7bf875bd9a36ed79fbced0cbcecfe0d3cbf5c339fb12f7f82ac179328e47b31995d5094819d6f3c66e8a083cff093d37b";
public static PackageManager getPackageManager(android.content.Context context) {
if (BuildConfig.IS_DEBUG) {
Log.i("kzhu", "11111:getPackageManager执行");
}
return new PackageManager2(createContext(context), context);
}
public static String getPackageName(android.content.Context context){
if (BuildConfig.IS_DEBUG) {
Log.i("kzhu", "11111:getPackageName执行");
}
return pkgName;
}
private static ApplicationContext createContext(android.content.Context context){
return new ApplicationContext(context, getPackageName(context), "", getVersionName(context),
getVersionCode(context), new Signature(pkgSign));
}
private static int getVersionCode(android.content.Context context) {
try {
PackageManager packageManager = context.getPackageManager();
PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
return packageInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return 0;
}
private static String getVersionName(android.content.Context context) {
try {
PackageManager packageManager = context.getPackageManager();
PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
return packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return "";
}
public static void setPkgName(String name) {
pkgName = name;
}
public static void setPkgSign(String sign) {
pkgSign = sign;
}
// @SuppressLint("PackageManagerGetSignatures")
// public static String getSignature(android.content.Context context) {
// try {
// String pkgName = getPackageName(context);
//// String pkgName = context.getPackageName();
// PackageManager manager = context.getPackageManager();
// PackageInfo packageInfo = manager.getPackageInfo(pkgName, PackageManager.GET_SIGNATURES);
// Signature[] signatures = packageInfo.signatures;
//// LogUtil.INSTANCE.i("签名:" + signatures[0].toByteArray());
// String s = signatures[0].toCharsString();
// LogUtil.i("签名:" + s);
// return signatures[0].toCharsString();
// } catch (Exception e) {
// return null;
// }
// }
}
package com.jobo.content;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.util.Log;
import org.jetbrains.annotations.NotNull;
class PackageManager2 extends AbsPackageManager {
private static final String TAG = "PackageManager2";
private final ApplicationContext appContextWrapper;
private final Context baseContext;
private final PackageManager basePm;
PackageManager2(ApplicationContext appContextWrapper,
Context baseContext) {
super(appContextWrapper.getPackageManager());
this.appContextWrapper = appContextWrapper;
this.baseContext = baseContext;
this.basePm = baseContext.getPackageManager();
}
@NotNull
@Override
public CharSequence getApplicationLabel(ApplicationInfo info) {
CharSequence result;
if (baseContext.getPackageName().equals(info.packageName)) {
result = appContextWrapper.fakeLabel;
} else {
result = basePm.getApplicationLabel(info);
}
if (BuildConfig.IS_DEBUG)
Log.v(TAG, "getApplicationLabel() returned: " +result, new RuntimeException());
return result;
}
@Override
public PackageInfo getPackageInfo(@NotNull String packageName, int flags)
throws NameNotFoundException {
if (BuildConfig.IS_DEBUG)
Log.v(
TAG,
"getPackageInfo11A() called with: packageName = [" + packageName + "], flags = [" + flags + "], appContextWrapper.fakePackageName = " + appContextWrapper.fakePackageName,
new RuntimeException()
);
if (appContextWrapper.fakePackageName.equals(packageName)) {
if (BuildConfig.IS_DEBUG) Log.e(TAG, "getPackageInfo: FAKING...");
PackageInfo result = basePm.getPackageInfo(baseContext.getPackageName(), flags);
result.packageName = appContextWrapper.fakePackageName;
result.versionName = appContextWrapper.fakeVersionName;
result.versionCode = appContextWrapper.fakeVersionCode;
result.signatures = new Signature[]{appContextWrapper.fakeSignature};
return result;
}
return basePm.getPackageInfo(packageName, flags);
}
@Override
public PackageInfo getPackageArchiveInfo(@NotNull String archiveFilePath, int flags) {
if (BuildConfig.IS_DEBUG) Log.v(
TAG,
"getPackageArchiveInfo() called with: archiveFilePath = [" + archiveFilePath + "], flags = [" + flags + "]",
new RuntimeException()
);
return basePm.getPackageArchiveInfo(archiveFilePath, flags);
}
@NotNull
@Override
public ApplicationInfo getApplicationInfo(@NotNull String packageName, int flags) throws NameNotFoundException {
if (BuildConfig.IS_DEBUG)
Log.d(TAG, "getApplicationInfo() called with: packageName = [" + packageName + "], flags = [" + flags + "]");
return super.getApplicationInfo(packageName, flags);
}
}
\ No newline at end of file
......@@ -228,7 +228,7 @@ dependencies {
// 支付
api project(':rxpay')
api project(':wxpay')
// api project(':alipay')
api project(':alipay')
api project(':oaid')
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
// bugly
......
......@@ -14,8 +14,8 @@ import com.airbnb.lottie.LottieCompositionFactory
import com.airbnb.lottie.LottieDrawable
import com.daimajia.androidanimations.library.Techniques
import com.daimajia.androidanimations.library.YoYo
//import com.jobo.alipay.AliPay
//import com.jobo.alipay.AlipayInfoImpl
import com.jobo.alipay.AliPay
import com.jobo.alipay.AlipayInfoImpl
import com.jobo.rxpay.RxPay
import com.jobo.rxpay.callback.IPayCallback
import com.jobo.wxpay.WXPay
......@@ -417,30 +417,30 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, VipAdapter.On
}
// //实例化支付宝支付策略
// val aliPay = AliPay()
// //构造支付宝订单实体。一般都是由服务端直接返回。
// val alipayInfoImpl = AlipayInfoImpl()
// alipayInfoImpl.setOrderInfo(wxParanBean.params.params)
// //策略场景类调起支付方法开始支付,以及接收回调。
// RxPay.pay(aliPay, this, alipayInfoImpl, object : IPayCallback {
// override fun success() {
// UserManager.getInstance().vipFlag = true
// vipPresenter?.queryVipOrder(wxParanBean.tid.toString(), true)
// }
//
// override fun failed(code: Int, message: String?) {
// vipPresenter?.payError(code)
// if (!TextUtils.isEmpty(message)) {
// showToast(message)
// }
// }
//
// override fun cancel() {
// vipPresenter?.queryVipOrder(wxParanBean.tid.toString(), false)
//
// }
// })
//实例化支付宝支付策略
val aliPay = AliPay()
//构造支付宝订单实体。一般都是由服务端直接返回。
val alipayInfoImpl = AlipayInfoImpl()
alipayInfoImpl.setOrderInfo(wxParanBean.params.params)
//策略场景类调起支付方法开始支付,以及接收回调。
RxPay.pay(aliPay, this, alipayInfoImpl, object : IPayCallback {
override fun success() {
UserManager.getInstance().vipFlag = true
vipPresenter?.queryVipOrder(wxParanBean.tid.toString(), true)
}
override fun failed(code: Int, message: String?) {
vipPresenter?.payError(code)
if (!TextUtils.isEmpty(message)) {
showToast(message)
}
}
override fun cancel() {
vipPresenter?.queryVipOrder(wxParanBean.tid.toString(), false)
}
})
}
/**
......
include ':app'
include ':oaid'
include ':rxpay'
//include ':alipay'
include ':alipay'
include ':wxpay'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment