Skip to content

Commit

Permalink
Fix INSTALL_FAILED_DUPLICATE_PERMISSION for P
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard20181 committed Dec 13, 2023
1 parent e10aaef commit 1c094e9
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 43 deletions.
7 changes: 5 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ android {
}
}
}
packagingOptions {
packaging {
jniLibs {
excludes += "META-INF/**"
}
Expand Down Expand Up @@ -61,6 +61,9 @@ android {
abortOnError = false
}
namespace = "com.coderstory.toolkit"
buildFeatures {
buildConfig = true
}
}

dependencies {
Expand All @@ -72,7 +75,7 @@ val optimizeReleaseRes = task("optimizeReleaseRes").doLast {
"build-tools", project.android.buildToolsVersion, "aapt2"
)
val zip = Paths.get(
project.buildDir.path, "intermediates",
project.layout.buildDirectory.get().asFile.path, "intermediates",
"optimized_processed_res", "release", "resources-release-optimize.ap_"
)
val optimized = File("${zip}.opt")
Expand Down
36 changes: 19 additions & 17 deletions app/src/main/java/toolkit/coderstory/CorePatchForQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ public class CorePatchForQ extends XposedHelper implements IXposedHookLoadPackag
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws IllegalAccessException, InvocationTargetException, InstantiationException {
// 允许降级
Class<?> packageClazz = XposedHelpers.findClass("android.content.pm.PackageParser.Package", loadPackageParam.classLoader);
hookAllMethods("com.android.server.pm.PackageManagerService", loadPackageParam.classLoader, "checkDowngrade", new XC_MethodHook() {
public void beforeHookedMethod(MethodHookParam methodHookParam) throws Throwable {
super.beforeHookedMethod(methodHookParam);
if (prefs.getBoolean("downgrade", true)) {
Object packageInfoLite = methodHookParam.args[0];
hookAllMethods("com.android.server.pm.PackageManagerService", loadPackageParam.classLoader, "checkDowngrade", new XC_MethodHook() {
public void beforeHookedMethod(MethodHookParam methodHookParam) throws Throwable {
super.beforeHookedMethod(methodHookParam);
if (prefs.getBoolean("downgrade", true)) {
Object packageInfoLite = methodHookParam.args[0];

if (prefs.getBoolean("downgrade", true)) {
Field field = packageClazz.getField("mVersionCode");
field.setAccessible(true);
field.set(packageInfoLite, 0);
field = packageClazz.getField("mVersionCodeMajor");
field.setAccessible(true);
field.set(packageInfoLite, 0);
}
if (prefs.getBoolean("downgrade", true)) {
Field field = packageClazz.getField("mVersionCode");
field.setAccessible(true);
field.set(packageInfoLite, 0);
field = packageClazz.getField("mVersionCodeMajor");
field.setAccessible(true);
field.set(packageInfoLite, 0);
}
}
});
}
});

hookAllMethods("android.util.jar.StrictJarVerifier", loadPackageParam.classLoader, "verifyMessageDigest",
new ReturnConstant(prefs, "authcreak", true));
Expand Down Expand Up @@ -114,7 +114,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// if app is system app, allow to use hidden api, even if app not using a system signature
findAndHookMethod("android.content.pm.ApplicationInfo", loadPackageParam.classLoader, "isPackageWhitelistedForHiddenApis", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
if (prefs.getBoolean("digestCreak", true)) {
ApplicationInfo info = (ApplicationInfo) param.thisObject;
Expand All @@ -124,15 +124,17 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
}
}
}
});
});

var keySetManagerClass = findClass("com.android.server.pm.KeySetManagerService", loadPackageParam.classLoader);
if (keySetManagerClass != null) {
var shouldBypass = new ThreadLocal<Boolean>();
hookAllMethods(keySetManagerClass, "shouldCheckUpgradeKeySetLocked", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (prefs.getBoolean("digestCreak", true) && Arrays.stream(Thread.currentThread().getStackTrace()).anyMatch((o) -> "preparePackageLI".equals(o.getMethodName()))) {
if (prefs.getBoolean("digestCreak", true) &&
Arrays.stream(Thread.currentThread().getStackTrace()).anyMatch((o) ->
(/* API 29 */ "preparePackageLI".equals(o.getMethodName()) || /* API 28 */ "installPackageLI".equals(o.getMethodName())))) {
shouldBypass.set(true);
param.setResult(true);
} else {
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/toolkit/coderstory/CorePatchForR.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package toolkit.coderstory;


import android.annotation.TargetApi;
import android.app.AndroidAppHelper;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.os.Build;
import android.util.Log;

import com.coderstory.toolkit.BuildConfig;
Expand All @@ -20,6 +22,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.zip.ZipEntry;

import de.robv.android.xposed.IXposedHookLoadPackage;
Expand All @@ -31,6 +34,7 @@
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

@TargetApi(Build.VERSION_CODES.R)
public class CorePatchForR extends XposedHelper implements IXposedHookLoadPackage, IXposedHookZygoteInit {
private final static Method deoptimizeMethod;

Expand Down Expand Up @@ -186,8 +190,8 @@ public void afterHookedMethod(MethodHookParam methodHookParam) throws Throwable
} else {
pI = PM.getPackageArchiveInfo((String) methodHookParam.args[0], 0);
}
PackageInfo InstpI = PM.getPackageInfo(pI.packageName, PackageManager.GET_SIGNATURES);
lastSigs = InstpI.signatures;
PackageInfo InstpI = PM.getPackageInfo(pI.packageName, PackageManager.GET_SIGNING_CERTIFICATES);
lastSigs = InstpI.signingInfo.getSigningCertificateHistory();
}
}
} catch (Throwable ignored) {
Expand All @@ -207,11 +211,7 @@ public void afterHookedMethod(MethodHookParam methodHookParam) throws Throwable
}
} catch (Throwable ignored) {
}
if (lastSigs != null) {
signingDetailsArgs[0] = lastSigs;
} else {
signingDetailsArgs[0] = new Signature[]{new Signature(SIGNATURE)};
}
signingDetailsArgs[0] = Objects.requireNonNullElseGet(lastSigs, () -> new Signature[]{new Signature(SIGNATURE)});
Object newInstance = findConstructorExact.newInstance(signingDetailsArgs);

//修复 java.lang.ClassCastException: Cannot cast android.content.pm.PackageParser$SigningDetails to android.util.apk.ApkSignatureVerifier$SigningDetailsWithDigests
Expand Down
52 changes: 42 additions & 10 deletions app/src/main/java/toolkit/coderstory/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
import android.app.AlertDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Insets;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowInsetsController;

import com.coderstory.toolkit.R;

import java.lang.reflect.Method;

@SuppressWarnings("deprecation")
public class SettingsActivity extends Activity {

@Override
Expand Down Expand Up @@ -49,18 +58,35 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesName("conf");
addPreferencesFromResource(R.xml.prefs);
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
View list = view.findViewById(android.R.id.list);
list.setOnApplyWindowInsetsListener((v, insets) -> {
list.setPadding(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getStableInsetBottom());
return insets.consumeSystemWindowInsets();
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
view.setOnApplyWindowInsetsListener((v, windowInsets) -> {
Insets insets = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
insets = windowInsets.getInsets(WindowInsets.Type.systemBars());
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
insets = windowInsets.getSystemWindowInsets();
}
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
mlp.leftMargin = insets.left;
mlp.bottomMargin = insets.bottom;
mlp.rightMargin = insets.right;
mlp.topMargin = insets.top;
} else {
mlp.leftMargin = windowInsets.getSystemWindowInsetLeft();
mlp.bottomMargin = windowInsets.getSystemWindowInsetBottom();
mlp.rightMargin = windowInsets.getSystemWindowInsetRight();
mlp.topMargin = windowInsets.getSystemWindowInsetTop();
}
v.setLayoutParams(mlp);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return WindowInsets.CONSUMED;
} else return windowInsets.consumeSystemWindowInsets();
});

super.onViewCreated(view, savedInstanceState);
}

Expand All @@ -81,9 +107,15 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
}

@Override
public void onDestroy() {
super.onDestroy();
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
public void onResume() {
super.onResume();
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}

@Override
public void onPause() {
super.onPause();
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
}
}
}
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:fitsSystemWindows="true" />
1 change: 1 addition & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<style name="AppTheme" parent="android:Theme.Material.Light.LightStatusBar">
<item name="android:colorAccent">#3F51B5</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowLightNavigationBar">true</item>
</style>

</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/xml/prefs.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?><!--suppress ALL -->
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference android:summary="@string/corepatch" />
<PreferenceCategory android:title="@string/settings">
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:8.1.2")
classpath("com.android.tools.build:gradle:8.2.0")
}
}

Expand Down
4 changes: 0 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
# org.gradle.parallel=true
#Fri Nov 17 23:21:15 CST 2017
android.useAndroidX=true
android.nonTransitiveRClass=true
android.enableAppCompileTimeRClass=true
android.enableR8.fullMode=true
android.experimental.enableNewResourceShrinker=true
android.experimental.enableNewResourceShrinker.preciseShrinking=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false

0 comments on commit 1c094e9

Please sign in to comment.