Skip to content

Wires up Android API to set section locale #173364

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

chunhtai
Copy link
Contributor

@chunhtai chunhtai commented Aug 6, 2025

related #99600

what still missing:

  1. iOS equivalence
  2. set application level locale

internal only doc: go/flutter-semantics-language

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@chunhtai chunhtai requested a review from a team as a code owner August 6, 2025 18:56
@github-actions github-actions bot added platform-android Android applications specifically engine flutter/engine repository. See also e: labels. a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) team-android Owned by Android platform team labels Aug 6, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request wires up the Android accessibility API to support setting a locale on a semantics node. The changes span from the UI layer in C++ down to the Android platform-specific Java code. My review includes a few suggestions: fixing a bug in a new unit test, using the correct log level for a debug message, and removing an unused parameter from a function signature. Overall, the changes look good and the new test coverage is appreciated.

@flutter-dashboard
Copy link

CI had a failure that stopped further tests from running. We need to investigate to determine the root cause.

SHA at time of execution: 494a34b.

Possible causes:

  • Configuration Changes: The .ci.yaml file might have been modified between the creation of this pull request and the start of this test run. This can lead to ci yaml validation errors.
  • Infrastructure Issues: Problems with the CI environment itself (e.g., quota) could have caused the failure.

A blank commit, or merging to head, will be required to resume running CI for this PR.

Error Details:

GitHub Error: You have exceeded a secondary rate limit. Please wait a few minutes before you try again. If you reach out to GitHub Support for help, please include the request ID B89A:2C3875:3D1A6AA:9252E28:6893DBCA.

Stack trace:

#0      GitHub.handleStatusCode (package:github/src/common/github.dart:486:5)
#1      GitHub.request (package:github/src/common/github.dart:422:7)
<asynchronous suspension>
#2      GitHub.requestJson (package:github/src/common/github.dart:323:22)
<asynchronous suspension>
#3      RetryOptions.retry (package:retry/retry.dart:131:16)
<asynchronous suspension>
#4      LuciBuildService.scheduleTryBuilds (package:cocoon_service/src/service/luci_build_service.dart:246:24)
<asynchronous suspension>
#5      Scheduler._runCiTestingStage (package:cocoon_service/src/service/scheduler.dart:1255:9)
<asynchronous suspension>
#6      Scheduler.proceedToCiTestingStage (package:cocoon_service/src/service/scheduler.dart:1316:7)
<asynchronous suspension>
#7      Scheduler._closeSuccessfulEngineBuildStage (package:cocoon_service/src/service/scheduler.dart:1127:5)
<asynchronous suspension>
#8      Scheduler.processCheckRunCompletion (package:cocoon_service/src/service/scheduler.dart:1060:9)
<asynchronous suspension>
#9      Scheduler.processCheckRun (package:cocoon_service/src/service/scheduler.dart:1400:9)
<asynchronous suspension>
#10     GithubWebhookSubscription.post (package:cocoon_service/src/request_handlers/github/webhook_subscription.dart:120:24)
<asynchronous suspension>
#11     RequestHandler.service (package:cocoon_service/src/request_handling/request_handler.dart:45:20)
<asynchronous suspension>
#12     SubscriptionHandler.service (package:cocoon_service/src/request_handling/subscription_handler.dart:140:5)
<asynchronous suspension>
#13     createServer.<anonymous closure> (package:cocoon_service/server.dart:329:7)
<asynchronous suspension>

@chunhtai chunhtai requested a review from reidbaker August 14, 2025 17:40
@chunhtai chunhtai force-pushed the issues/99600 branch 2 times, most recently from 1519545 to a946cbb Compare August 15, 2025 20:36
@chunhtai
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request wires up the Android accessibility API to support setting a locale on a semantics node. The changes span across Dart, C++, and Java to pass the locale information from the framework to the Android accessibility services. The implementation is mostly correct, but I've found a critical issue in the Java code where an incorrect locale format will cause a runtime crash. I've also pointed out an unused parameter in the C++ code that should be addressed.

@@ -69,7 +69,9 @@ void SemanticsUpdateBuilder::updateNode(
std::string linkUrl,
int role,
const std::vector<std::string>& controlsNodes,
int validationResult) {
int validationResult,
int inputType,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The inputType parameter is accepted by updateNode but it is not used within the function's body. This could indicate an incomplete implementation or leftover code. To improve code clarity and maintainability, this unused parameter should be either utilized or removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this bot comment correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is not used because there is no usage outside of web (this file is the glue code for non-web engine), but i have to keep it here because this is a positional parameter so that I can use the locale parameter

Comment on lines 269 to 239
if (node.locale.empty()) {
buffer_int32[position++] = -1;
} else {
buffer_int32[position++] = strings.size();
strings.push_back(node.locale);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

No change you need to make but this makes me sad to review. This type of message passing is so easy to mess up in a way that is hard for authors or reviewers to realize. There are formats for passing data via strings and the conversion code is all generated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are formats for passing data via strings and the conversion code is all generated.

Do you have example? I only know json, but think that may not be efficient

Copy link
Contributor

@reidbaker reidbaker Aug 18, 2025

Choose a reason for hiding this comment

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

protobuffs, msgpack, even pigeon which we maintain lets authors author a platform independent object that is typesafe after serialization across the wire.

@@ -266,6 +266,13 @@ void PlatformViewAndroidDelegate::UpdateSemantics(
strings.push_back(node.linkUrl);
}

if (node.locale.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Somewhere in this code please articulate the meaning of the magical number -1 when used in the local location and the expected format of the local string. Especially if the assumption is for it to match some standard.

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 refactored out the code so less duplicate, but I am not sure how can i addressed the magical number -1 here since defining a constant won't be useful outside this class (it can't be use from java side when decoding the buffer)

@@ -69,7 +69,9 @@ void SemanticsUpdateBuilder::updateNode(
std::string linkUrl,
int role,
const std::vector<std::string>& controlsNodes,
int validationResult) {
int validationResult,
int inputType,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this bot comment correct?

@chunhtai chunhtai force-pushed the issues/99600 branch 2 times, most recently from 6ebed01 to c3fa588 Compare August 19, 2025 15:40
@chunhtai chunhtai requested a review from reidbaker August 19, 2025 16:04
@chunhtai chunhtai force-pushed the issues/99600 branch 3 times, most recently from 5fc4116 to 1d44e84 Compare August 22, 2025 18:51
Copy link
Contributor

@reidbaker reidbaker left a comment

Choose a reason for hiding this comment

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

Couple of comments, In addition to my review please get a review from someone who is more comfortable in c++

private static String getStringFromBuffer(@NonNull ByteBuffer buffer, @NonNull String[] strings) {
int stringIndex = buffer.getInt();

return stringIndex == -1 ? null : strings[stringIndex];
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make -1 a private constant. Maybe name it NOT_FOUND?

* <p>Use {@code addLocale} to set the locale and/or {@code addUrl} to set the url for the entire
* string. Uses {@code addAttributes} to add any additional {@code StringAttribute} to the string
*/
private static class AccessibilityStringBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider putting this into its own file. This file is already pretty large.

expected_strings.push_back(node0.identifier);
buffer_int32[position++] = expected_strings.size(); // node0.label
expected_strings.push_back(node0.label);
buffer_int32[position++] = -1; // node0.labelAttributes
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for labeling these values it helps with readability.

@reidbaker reidbaker requested a review from gmackall August 22, 2025 18:58
@chunhtai chunhtai requested a review from gaaclarke August 22, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) engine flutter/engine repository. See also e: labels. platform-android Android applications specifically team-android Owned by Android platform team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants