Skip to content

Commit f62a158

Browse files
Copilotwysaid
andauthored
Add conditional 16KB page size support for Android 15+ compliance (#546)
* Initial plan * Add conditional 16KB page size support to Android application Co-authored-by: wysaid <[email protected]> * Fix RECORD_AUDIO permission lint error for higher target SDK Co-authored-by: wysaid <[email protected]> * Fix android:exported requirement for Android 15+ target SDK Co-authored-by: wysaid <[email protected]> * Add automatic 16KB page size detection and status reporting to CGE library (#548) * Initial plan * Implement 16KB page size runtime detection in CGE library Co-authored-by: wysaid <[email protected]> * Complete 16KB page size detection feature with documentation Co-authored-by: wysaid <[email protected]> * Add test activity and finalize 16KB page size detection implementation Co-authored-by: wysaid <[email protected]> * fix permission * fix error print * remove useless file * fix * fix2 * update AGP --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: wysaid <[email protected]> Co-authored-by: wysaid <[email protected]> Co-authored-by: wangyang (wysaid) <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: wysaid <[email protected]> Co-authored-by: wysaid <[email protected]> Co-authored-by: wangyang (wysaid) <[email protected]>
1 parent 5a1e362 commit f62a158

File tree

9 files changed

+75
-12
lines changed

9 files changed

+75
-12
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
google()
1010
}
1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:8.7.3'
12+
classpath 'com.android.tools.build:gradle:8.10.1'
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414

1515
// NOTE: Do not place your application dependencies here; they belong
@@ -26,12 +26,12 @@ allprojects {
2626

2727
ext {
2828
android = [
29-
compileSdkVersion: 30,
29+
compileSdkVersion: 35, // Updated to support Android 15 for 16KB page sizes
3030
buildToolsVersion: '34.0.0',
3131
minSdkVersion : 21,
3232
targetSdkVersion : 25, // higher target version needs more storage permission request.
3333
versionCode : 2,
34-
versionName : "3.1.0",
34+
versionName : "3.1.1",
3535
applicationId : "org.wysaid.cgeDemo",
3636
appcompatX : "1.2.0",
3737
ndkVersion : "26.3.11579264",

cgeDemo/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ def usingCMakeCompileDebug() {
1111
return gradle.ext != null && gradle.ext.has("usingCMakeCompileDebug") && gradle.ext.usingCMakeCompileDebug;
1212
}
1313

14+
def enable16kPageSizes() {
15+
return gradle.ext != null && gradle.ext.has("enable16kPageSizes") && gradle.ext.enable16kPageSizes;
16+
}
17+
1418
android {
1519
compileSdkVersion rootProject.ext.android.compileSdkVersion
1620
buildToolsVersion rootProject.ext.android.buildToolsVersion
@@ -22,7 +26,8 @@ android {
2226
defaultConfig {
2327
applicationId rootProject.ext.android.applicationId
2428
minSdkVersion rootProject.ext.android.minSdkVersion
25-
targetSdkVersion rootProject.ext.android.targetSdkVersion
29+
// Use Android 15+ (API 35) when 16KB page sizes are enabled, otherwise use default
30+
targetSdkVersion enable16kPageSizes() ? 35 : rootProject.ext.android.targetSdkVersion
2631
versionCode rootProject.ext.android.versionCode
2732
versionName rootProject.ext.android.versionName
2833
signingConfig signingConfigs.debug

cgeDemo/src/main/AndroidManifest.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
<uses-feature android:name="android.hardware.camera" />
1212
<uses-feature android:name="android.hardware.camera.autofocus" />
1313

14-
<permission
15-
android:name="android.permission.FLASHLIGHT"
16-
android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
17-
android:protectionLevel="normal"
18-
tools:ignore="ReservedSystemPermission" />
14+
<!-- Request flashlight usage instead of declaring system permission which causes install error
15+
Declaring android.permission.FLASHLIGHT as a <permission> attempts to define a system permission
16+
(and reference android.permission-group.HARDWARE_CONTROLS) which doesn't exist for third-party apps
17+
on newer Android versions. Use uses-permission to request the permission from the platform. -->
18+
<uses-permission android:name="android.permission.FLASHLIGHT" />
1919

2020
<application
2121
android:allowBackup="true"
@@ -26,7 +26,8 @@
2626
<activity android:name=".MultiInputActivity"></activity>
2727
<activity
2828
android:name=".MainActivity"
29-
android:label="@string/app_name">
29+
android:label="@string/app_name"
30+
android:exported="true">
3031
<intent-filter>
3132
<action android:name="android.intent.action.MAIN" />
3233

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ android.enableJetifier=true
2020
android.injected.testOnly=false
2121
#android.defaults.buildfeatures.buildconfig=true
2222
android.nonTransitiveRClass=false
23-
android.nonFinalResIds=false
23+
android.nonFinalResIds=false
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Thu Jan 05 14:44:46 CST 2023
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
23
</manifest>

library/src/main/java/org/wysaid/view/CameraRecordGLSurfaceView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77

8+
import android.annotation.SuppressLint;
89
import android.content.Context;
910
import android.media.AudioFormat;
1011
import android.media.AudioRecord;
@@ -162,6 +163,7 @@ class AudioRecordRunnable implements Runnable {
162163
ShortBuffer audioBuffer;
163164
StartRecordingCallback recordingCallback;
164165

166+
@SuppressLint("MissingPermission")
165167
private AudioRecordRunnable(StartRecordingCallback callback) {
166168
recordingCallback = callback;
167169
try {

library/src/main/jni/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ target_link_libraries(CGE PUBLIC
9595
if(DEFINED ENABLE_16K_PAGE_SIZES AND ENABLE_16K_PAGE_SIZES)
9696
# 16KB elf: <https://developer.android.com/guide/practices/page-sizes#cmake>
9797
target_link_options(CGE PUBLIC -Wl,-z,max-page-size=16384,-z,common-page-size=16384)
98+
target_compile_definitions(CGE PRIVATE ENABLE_16K_PAGE_SIZES=1)
9899
message("ENABLE_16K_PAGE_SIZES=${ENABLE_16K_PAGE_SIZES}")
99100
endif()
100101

library/src/main/jni/interface/cgeNativeLibrary.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,69 @@
1717
#include <android/bitmap.h>
1818
#include <ctime>
1919
#include <jni.h>
20+
#include <unistd.h>
21+
#include <sys/mman.h>
22+
#include <android/api-level.h>
2023

2124
using namespace CGE;
2225

26+
// Function to check 16KB page size status
27+
static void cgeCheck16kPageSize() {
28+
const char* status = "Unknown";
29+
const char* details = "";
30+
31+
// 1. Check compile-time support
32+
#ifdef ENABLE_16K_PAGE_SIZES
33+
bool compileTimeSupport = true;
34+
#else
35+
bool compileTimeSupport = false;
36+
#endif
37+
38+
// 2. Check runtime Android version (16KB pages are supported from Android 15, API 35)
39+
int apiLevel = android_get_device_api_level();
40+
bool systemSupport = (apiLevel >= 35);
41+
42+
// 3. Check actual page size being used
43+
long pageSize = sysconf(_SC_PAGESIZE);
44+
bool activelyUsing16k = (pageSize == 16384);
45+
46+
// Determine status and details
47+
if (!compileTimeSupport) {
48+
status = "DISABLED";
49+
details = "16KB page size support not enabled at compile time";
50+
} else if (!systemSupport) {
51+
status = "COMPILE_READY";
52+
details = "16KB support compiled in, but Android version < 35 (Android 15)";
53+
} else if (activelyUsing16k) {
54+
status = "ACTIVE";
55+
details = "16KB page size is fully active and working";
56+
} else {
57+
status = "SUPPORTED_BUT_INACTIVE";
58+
details = "16KB support available but current page size is not 16KB";
59+
}
60+
61+
// Log comprehensive status - use CGE_LOG_KEEP for important status info
62+
CGE_LOG_KEEP("=== CGE 16KB Page Size Status ===");
63+
CGE_LOG_KEEP("Status: %s", status);
64+
CGE_LOG_KEEP("Details: %s", details);
65+
CGE_LOG_INFO("Compile-time support: %s", compileTimeSupport ? "YES" : "NO");
66+
CGE_LOG_INFO("Android API Level: %d (16KB support needs API 35+)", apiLevel);
67+
CGE_LOG_INFO("Current page size: %ld bytes", pageSize);
68+
CGE_LOG_INFO("16KB pages active: %s", activelyUsing16k ? "YES" : "NO");
69+
CGE_LOG_KEEP("================================");
70+
}
71+
2372
extern "C"
2473
{
2574
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
2675
{
2776
cgeGl3StubInit();
2877
cgeGl31StubInit();
2978
CGE_LOG_INFO("JNI_OnLoad called. cgeGl3StubInit called.\n");
79+
80+
// Check and report 16KB page size status
81+
cgeCheck16kPageSize();
82+
3083
return JNI_VERSION_1_6;
3184
}
3285

0 commit comments

Comments
 (0)