Skip to content

Commit 4ca1e97

Browse files
committed
Merge branch 'stage' into fix/ADFA-3366-include-analysis-api-as-dependency
2 parents a70fd66 + bfd285b commit 4ca1e97

File tree

21 files changed

+348
-234
lines changed

21 files changed

+348
-234
lines changed

annotation-processors/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import com.itsaky.androidide.build.config.BuildConfig
19+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
1920
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2021

2122
plugins {
@@ -45,5 +46,5 @@ dependencies {
4546
}
4647

4748
tasks.withType<KotlinCompile> {
48-
kotlinOptions.jvmTarget = "17"
49+
compilerOptions.jvmTarget.set(JvmTarget.JVM_17)
4950
}

app/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ android {
183183
}
184184
}
185185

186+
sentry {
187+
includeProguardMapping = false
188+
}
189+
186190
kapt { arguments { arg("eventBusIndex", "${BuildConfig.PACKAGE_NAME}.events.AppEventsIndex") } }
187191

188192
desugaring {
@@ -293,6 +297,7 @@ dependencies {
293297
implementation(projects.gradlePluginConfig)
294298
implementation(projects.subprojects.aaptcompiler)
295299
implementation(projects.subprojects.javacServices)
300+
implementation(projects.subprojects.kotlinAnalysisApi)
296301
implementation(projects.subprojects.shizukuApi)
297302
implementation(projects.subprojects.shizukuManager)
298303
implementation(projects.subprojects.shizukuProvider)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.itsaky.androidide.app
2+
3+
import com.itsaky.androidide.utils.FeatureFlags
4+
import leakcanary.LeakCanary
5+
6+
internal object LeakCanaryConfig {
7+
fun applyFromFeatureFlags() {
8+
if (FeatureFlags.isLeakCanaryDumpInhibited) {
9+
LeakCanary.config = LeakCanary.config.copy(dumpHeap = false)
10+
}
11+
}
12+
}

app/src/main/java/com/itsaky/androidide/app/CredentialProtectedApplicationLoader.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ internal object CredentialProtectedApplicationLoader : ApplicationLoader {
7373
Environment.init(app)
7474

7575
FeatureFlags.initialize()
76+
LeakCanaryConfig.applyFromFeatureFlags()
7677

7778
EventBus.getDefault().register(this)
7879

app/src/main/java/com/itsaky/androidide/app/DeviceProtectedApplicationLoader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ internal object DeviceProtectedApplicationLoader :
6262
StrictModeManager.install(
6363
StrictModeConfig(
6464
enabled = BuildConfig.DEBUG && !FeatureFlags.isPardonEnabled,
65-
isReprieveEnabled = true,
65+
isReprieveEnabled = true,
6666
),
6767
)
6868

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package org.jetbrains.kotlin.com.intellij.util.containers;
2+
3+
import android.util.Log;
4+
import java.lang.reflect.Field;
5+
import java.lang.reflect.Method;
6+
import java.util.Arrays;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.kotlin.com.intellij.util.ReflectionUtil;
9+
import org.lsposed.hiddenapibypass.HiddenApiBypass;
10+
11+
@SuppressWarnings("ALL")
12+
public class UnsafeImpl {
13+
14+
private static final Object unsafe;
15+
16+
private static final Method putObjectVolatile;
17+
private static final Method getObjectVolatile;
18+
private static final Method compareAndSwapObject;
19+
private static final Method compareAndSwapInt;
20+
private static final Method compareAndSwapLong;
21+
private static final Method getAndAddInt;
22+
private static final Method objectFieldOffset;
23+
private static final Method arrayIndexScale;
24+
private static final Method arrayBaseOffset;
25+
// private static final Method copyMemory;
26+
27+
private static final String TAG = "UnsafeImpl";
28+
29+
static {
30+
try {
31+
unsafe = ReflectionUtil.getUnsafe();
32+
putObjectVolatile = find("putObjectVolatile", Object.class, long.class, Object.class);
33+
getObjectVolatile = find("getObjectVolatile", Object.class, long.class);
34+
compareAndSwapObject = find("compareAndSwapObject", Object.class, long.class, Object.class, Object.class);
35+
compareAndSwapInt = find("compareAndSwapInt", Object.class, long.class, int.class, int.class);
36+
compareAndSwapLong = find("compareAndSwapLong", Object.class, long.class, long.class, long.class);
37+
getAndAddInt = find("getAndAddInt", Object.class, long.class, int.class);
38+
objectFieldOffset = find("objectFieldOffset", Field.class);
39+
arrayBaseOffset = find("arrayBaseOffset", Class.class);
40+
arrayIndexScale = find("arrayIndexScale", Class.class);
41+
// copyMemory = find("copyMemory", Object.class, long.class, Object.class, long.class, long.class);
42+
} catch (Throwable t) {
43+
throw new Error(t);
44+
}
45+
}
46+
47+
public static int arrayBaseOffset(Class<?> arrayClass) {
48+
try {
49+
return (int) arrayBaseOffset.invoke(unsafe, arrayClass);
50+
} catch (Throwable t) {
51+
throw new RuntimeException(t);
52+
}
53+
}
54+
55+
public static int arrayIndexScale(Class<?> arrayClass) {
56+
try {
57+
return (int) arrayIndexScale.invoke(unsafe, arrayClass);
58+
} catch (Throwable t) {
59+
throw new RuntimeException(t);
60+
}
61+
}
62+
63+
public static boolean compareAndSwapInt(Object object, long offset, int expected, int value) {
64+
try {
65+
return (boolean) compareAndSwapInt.invoke(unsafe, object, offset, expected, value);
66+
} catch (Throwable t) {
67+
throw new RuntimeException(t);
68+
}
69+
}
70+
71+
public static boolean compareAndSwapLong(@NotNull Object object, long offset, long expected, long value) {
72+
try {
73+
return (boolean) compareAndSwapLong.invoke(unsafe, object, offset, expected, value);
74+
} catch (Throwable t) {
75+
throw new RuntimeException(t);
76+
}
77+
}
78+
79+
public static boolean compareAndSwapObject(Object o, long offset, Object expected, Object x) {
80+
try {
81+
return (boolean) compareAndSwapObject.invoke(unsafe, o, offset, expected, x);
82+
} catch (Throwable t) {
83+
throw new RuntimeException(t);
84+
}
85+
}
86+
87+
public static void copyMemory(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes) {
88+
throw new UnsupportedOperationException("Not supported on Android!");
89+
}
90+
91+
public static int getAndAddInt(Object object, long offset, int v) {
92+
try {
93+
return (int) getAndAddInt.invoke(unsafe, object, offset, v);
94+
} catch (Throwable t) {
95+
throw new RuntimeException(t);
96+
}
97+
}
98+
99+
public static Object getObjectVolatile(Object object, long offset) {
100+
try {
101+
return getObjectVolatile.invoke(unsafe, object, offset);
102+
} catch (Throwable t) {
103+
throw new RuntimeException(t);
104+
}
105+
}
106+
107+
public static long objectFieldOffset(Field f) {
108+
try {
109+
return (long) objectFieldOffset.invoke(unsafe, f);
110+
} catch (Throwable t) {
111+
throw new RuntimeException(t);
112+
}
113+
}
114+
115+
public static void putObjectVolatile(Object o, long offset, Object x) {
116+
try {
117+
putObjectVolatile.invoke(unsafe, o, offset, x);
118+
} catch (Throwable t) {
119+
throw new RuntimeException(t);
120+
}
121+
}
122+
123+
private static @NotNull Method find(String name, Class<?>... params) throws Exception {
124+
Log.d(TAG, "find: name=" + name + ", params=" + Arrays.toString(params));
125+
Method m = HiddenApiBypass.getDeclaredMethod(unsafe.getClass(), name, params);
126+
m.setAccessible(true);
127+
return m;
128+
}
129+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.itsaky.androidide.app
2+
3+
internal object LeakCanaryConfig {
4+
fun applyFromFeatureFlags() {}
5+
}

common/src/main/java/com/itsaky/androidide/utils/FeatureFlags.kt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ private data class FlagsCache(
1313
val debugLoggingEnabled: Boolean = false,
1414
val emulatorUseEnabled: Boolean = false,
1515
val reprieveEnabled: Boolean = false,
16-
val pardonEnabled: Boolean = false,
16+
val pardonEnabled: Boolean = false,
17+
val leakCanaryDumpInhibited: Boolean = false,
1718
) {
1819
companion object {
1920
/**
@@ -28,7 +29,8 @@ object FeatureFlags {
2829
private const val LOGD_FILE_NAME = "CodeOnTheGo.logd"
2930
private const val EMULATOR_FILE_NAME = "S153.txt"
3031
private const val REPRIEVE_FILE_NAME = "CodeOnTheGo.a3s19"
31-
private const val PARDON_FILE_NAME = "CodeOnTheGo.a2s2"
32+
private const val PARDON_FILE_NAME = "CodeOnTheGo.a2s2"
33+
private const val LEAKCANARY_FILE_NAME = "CodeOnTheGo.lc"
3234

3335
private val logger = LoggerFactory.getLogger(FeatureFlags::class.java)
3436

@@ -62,13 +64,19 @@ object FeatureFlags {
6264
val isReprieveEnabled: Boolean
6365
get() = flags.reprieveEnabled
6466

65-
/**
66-
* Whether pardon is enabled or not.
67-
*/
68-
val isPardonEnabled: Boolean
69-
get() = flags.pardonEnabled
67+
/**
68+
* Whether pardon is enabled or not.
69+
*/
70+
val isPardonEnabled: Boolean
71+
get() = flags.pardonEnabled
72+
73+
/**
74+
* Whether LeakCanary heap dumping is inhibited (CodeOnTheGo.lc present in Downloads).
75+
*/
76+
val isLeakCanaryDumpInhibited: Boolean
77+
get() = flags.leakCanaryDumpInhibited
7078

71-
/**
79+
/**
7280
* Initialize feature flag values. This is thread-safe and idempotent i.e.
7381
* subsequent calls do not access disk.
7482
*/
@@ -90,7 +98,8 @@ object FeatureFlags {
9098
debugLoggingEnabled = checkFlag(LOGD_FILE_NAME),
9199
emulatorUseEnabled = checkFlag(EMULATOR_FILE_NAME),
92100
reprieveEnabled = checkFlag(REPRIEVE_FILE_NAME),
93-
pardonEnabled = checkFlag(PARDON_FILE_NAME),
101+
pardonEnabled = checkFlag(PARDON_FILE_NAME),
102+
leakCanaryDumpInhibited = checkFlag(LEAKCANARY_FILE_NAME),
94103
)
95104
}.getOrElse { error ->
96105
logger.error("Failed to load feature flags. Falling back to default values.", error)

composite-builds/build-deps/java-compiler/build.gradle.kts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@
1616
*/
1717

1818
plugins {
19-
id("java-library")
19+
id("java-library")
2020
}
2121

2222
java {
23-
sourceCompatibility = JavaVersion.VERSION_1_8
24-
targetCompatibility = JavaVersion.VERSION_1_8
25-
}
23+
sourceCompatibility = JavaVersion.VERSION_1_8
24+
targetCompatibility = JavaVersion.VERSION_1_8
25+
}
26+
27+
dependencies {
28+
annotationProcessor(libs.google.auto.service)
29+
implementation(libs.google.auto.service.annotations)
30+
}

composite-builds/build-deps/java-compiler/src/main/java/javac/internal/jrtfs/JrtFileSystemProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
package javac.internal.jrtfs;
2727

28+
import com.google.auto.service.AutoService;
29+
2830
import java.io.*;
2931
import java.net.MalformedURLException;
3032
import java.net.URL;
@@ -53,6 +55,7 @@
5355
* but also compiled and delivered as part of the jrtfs.jar to support access
5456
* to the jimage file provided by the shipped JDK by tools running on JDK 8.
5557
*/
58+
@AutoService(FileSystemProvider.class)
5659
public final class JrtFileSystemProvider extends FileSystemProvider {
5760

5861
private volatile FileSystem theFileSystem;

0 commit comments

Comments
 (0)