Skip to content

Conversation

@anod
Copy link
Member

@anod anod commented Dec 23, 2025

Fix #1372 Not Compatible with latest android room 2.7.2

Unblock android apps for upgrading Room library

  • Remove running a query from constructor, there is a check in Room that queries should run always on background thread
  • Bump gradle and AGP versions to minimum required
  • Bump min sdk to minimum required version
  • Fix EventsTest app compilation and run

In addition bump gradle and AGP version
@anod anod requested a review from Copilot December 23, 2025 13:02
@anod anod requested a review from a team as a code owner December 23, 2025 13:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Android Room library from version 2.4.3 to 2.8.4 to fix compatibility issues with modern Android applications. The main change addresses Room's requirement that database queries must not run on the main thread, particularly in constructors.

Key Changes:

  • Refactored OfflineRoom constructor to remove PRAGMA queries and implement lazy initialization of page size
  • Updated build infrastructure: Gradle 7.5 → 8.5, AGP 7.3.1 → 8.2.2, minimum SDK 19 → 23
  • Simplified native library dependencies by linking maesdk directly via CMake subdirectory

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/OfflineRoom.java Core fix: moved database queries from constructor to lazy-loaded initPageSize() method; improved field encapsulation
lib/android_build/maesdk/build.gradle Updated Room dependency to 2.8.4 and test dependencies; added Kotlin generation flag
lib/android_build/build.gradle Bumped Android Gradle Plugin from 7.3.1 to 8.2.2
lib/android_build/tools.gradle Updated compile/target SDK from 32/31 to 34/34, min SDK from 19 to 23
lib/android_build/gradle/wrapper/gradle-wrapper.properties Updated Gradle wrapper from 7.5 to 8.5
lib/android_build/gradlew Updated Gradle wrapper scripts with newer template
lib/android_build/gradlew.bat Updated Windows Gradle wrapper script
lib/android_build/gradle/wrapper/gradle-wrapper.jar Binary update for Gradle 8.5 wrapper
tools/build-android-aar.sh New script for building Android AAR files locally with NDK support
tests/unittests/PalTests.cpp Added Android-specific path handling for filesystem tests
lib/android_build/app/src/main/cpp/CMakeLists.txt Changed from importing prebuilt library to building maesdk via subdirectory
lib/android_build/app/src/main/java/com/microsoft/applications/events/maesdktest/MainActivity.java Removed explicit maesdk library loading (handled by CMake now)
lib/android_build/app/src/androidTest/java/com/microsoft/applications/events/maesdktest/SDKUnitNativeTest.java Removed explicit maesdk library loading
lib/android_build/app/src/androidTest/java/com/microsoft/applications/events/maesdktest/OfflineRoomUnitTest.java Added test for lazy-loaded page size; updated deprecated assertion syntax
lib/android_build/app/build.gradle Updated test dependencies to match maesdk module

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 291 to 306
private void initPageSize() {
if (m_pageSize == -1) {
try (Cursor c = m_db.query("PRAGMA page_size", null)) {
if (c.getCount() == 1 && c.getColumnCount() == 1) {
c.moveToFirst();
m_pageSize = c.getLong(0);
} else {
m_pageSize = PAGE_SIZE_DEFAULT;
Log.e("MAE",
String.format("Unexpected result from PRAGMA page_size: %d rows, %d columns",
c.getCount(),
c.getColumnCount()));
}
}
}
}
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initPageSize() method is not thread-safe. Multiple threads calling methods like totalSize() or loadPageSize() concurrently could result in race conditions where the PRAGMA query is executed multiple times simultaneously. Consider adding synchronization to ensure the page size is loaded only once.

Copilot uses AI. Check for mistakes.
assertEquals(1, room.getRecordCount(StorageRecord.EventLatency_Normal));
assertThat(room.totalSize(), Matchers.greaterThan(new Long(0)));
assertThat(room.totalSize(), Matchers.greaterThan(0L));
assertNotEquals(room.loadPageSize(), -1L);
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test now verifies that loadPageSize() returns a value not equal to -1L, which is good for testing the lazy initialization. However, consider also adding a test to verify that the returned value is actually a valid page size (e.g., greater than 0 and typically a power of 2 like 4096).

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Copy link
Contributor

Copilot AI commented Dec 23, 2025

@anod I've opened a new pull request, #1395, to work on those changes. Once the pull request is ready, I'll request review from you.

anod and others added 3 commits December 23, 2025 16:33
…ons/events/OfflineRoom.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Initial plan

* Enhance loadPageSize test to verify valid page size

Co-authored-by: anod <171704+anod@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: anod <171704+anod@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not Compatible with latest android room 2.7.2

2 participants