Skip to content

Use ContentProvider instead of hashmap for numberMatch data, AB#3308440, Fixes AB#3308440 #2692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from

Conversation

siddhijain
Copy link
Contributor

@siddhijain siddhijain commented Jun 26, 2025

AB#3308440
In the current implementation for number matching feature, the data is stored in the hashmap. On testing, I found out that the data in the hashmap was not accessible since this is an interprocess communication. This PR uses ContentProvider to enable interprocess communication.

@Copilot Copilot AI review requested due to automatic review settings June 26, 2025 19:43
@siddhijain siddhijain requested a review from a team as a code owner June 26, 2025 19:43
Copy link

❌ Work item link check failed. Description does not contain AB#{ID}.

Click here to Learn more.

Copy link
Contributor

@Copilot 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 replaces in-memory storage of number match data with a ContentProvider for proper interprocess communication.

  • Refactors NumberMatchHelper to use a ContentProvider for storing, retrieving, and clearing number match entries.
  • Adds NumberMatchDbHelper and NumberMatchContentProvider to manage a SQLite-backed table.
  • Updates tests and the JavaScript interface/WebView client to inject and use Context for ContentResolver operations.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
common/src/test/java/com/microsoft/identity/common/internal/numberMatch/NumberMatchHelperTest.kt Tests updated to mock ContentResolver and drive new store/get methods with Context
common/src/test/java/com/microsoft/identity/common/internal/broker/AuthUxJavaScriptInterfaceTest.kt Injects a mocked Context into the JS interface constructor
common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java Passes application context into the JS interface (incorrectly via getActivity())
common/src/main/java/com/microsoft/identity/common/internal/numberMatch/NumberMatchHelper.kt Refactored helper methods to use ContentResolver and ContentProvider URIs
common/src/main/java/com/microsoft/identity/common/internal/numberMatch/NumberMatchDbHelper.kt New SQLiteOpenHelper creating the number_match table
common/src/main/java/com/microsoft/identity/common/internal/numberMatch/NumberMatchContentProvider.kt New ContentProvider implementation with query/insert/delete/update
common/src/main/java/com/microsoft/identity/common/internal/broker/AuthUxJavaScriptInterface.kt JS interface now takes Context and calls NumberMatchHelper.storeNumberMatch(context,…)
Comments suppressed due to low confidence (1)

common/src/main/java/com/microsoft/identity/common/internal/numberMatch/NumberMatchHelper.kt:95

  • There’s no unit test covering clearNumberMatchMap(context). Add a test to verify that calling it deletes all entries and subsequent getNumberMatch returns null.
        fun clearNumberMatchMap(context: Context) {

@github-actions github-actions bot changed the title Use ContentProvider instead of hashmap for numberMatch data Use ContentProvider instead of hashmap for numberMatch data, Fixes AB#3308440 Jun 26, 2025
Copy link

✅ Work item link check complete. Description contains link AB#3308440 to an Azure Boards work item.

@siddhijain siddhijain changed the title Use ContentProvider instead of hashmap for numberMatch data, Fixes AB#3308440 Use ContentProvider instead of hashmap for numberMatch data, AB#3308440 Jun 27, 2025
@github-actions github-actions bot changed the title Use ContentProvider instead of hashmap for numberMatch data, AB#3308440 Use ContentProvider instead of hashmap for numberMatch data, AB#3308440, Fixes AB#3308440 Jun 27, 2025
@siddhijain siddhijain added the No-Changelog This Pull-Request has no associated changelog entry. label Jun 27, 2025
@siddhijain siddhijain added the Skip-Consumers-Check Only include this if making a breaking change purposefully, and there is an MSAL/ADAL/Broker PR label Jun 27, 2025
*/
fun storeNumberMatch(sessionId: String?, numberMatch: String?) {
Copy link
Contributor

Choose a reason for hiding this comment

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

storeNumberMatch

This is called broker side right, so why the overhead of content resolver here insert here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not understand. This is called as part of the javascript API call made by the AuthUx. Are you saying we should be calling ContentProvider directly?

*
* @param context The context to use for locating paths to the the database
*/
class NumberMatchDbHelper(context: Context) : SQLiteOpenHelper(context, "number_match.db", null, 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

NumberMatchDbHelper

Is persistent storage need?

Your content provider can you hashmap as its (in-memory) storage.. and no need of disk operations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

HashMap will not work for IPC. That is the main reason of this PR and change. Let me know if I am missing something.

*
* The provider uses NumberMatchDbHelper for database management and exposes its data via a content URI.
*/
class NumberMatchContentProvider : ContentProvider() {
Copy link
Contributor

Choose a reason for hiding this comment

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

NumberMatchContentProvider

We have BrokerContentProvider.. any reason not to use it?

NumberMatchHelper.clearNumberMatchMap()
MockitoAnnotations.openMocks(this)
Mockito.reset(context, contentResolver, cursor)
`when`(context.contentResolver).thenReturn(contentResolver)
Copy link
Contributor

Choose a reason for hiding this comment

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

when

nit: you can use kotlin mockito and whenever

@siddhijain siddhijain closed this Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
No-Changelog This Pull-Request has no associated changelog entry. Skip-Consumers-Check Only include this if making a breaking change purposefully, and there is an MSAL/ADAL/Broker PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants