Skip to content
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

feat: collecting device states on SDK #97

Merged
merged 2 commits into from
Sep 19, 2024

Conversation

satsukies
Copy link
Member

@satsukies satsukies commented Sep 17, 2024

Collect any device states when creating a capture.
Some attributes are collected on the host app better correctly.
(e.g. per-app language preference: https://developer.android.com/guide/topics/resources/app-languages?hl=ja )

@satsukies satsukies self-assigned this Sep 17, 2024
}

public void collectLocale() {
Locale defaultLocale = Locale.getDefault();
Copy link
Member Author

@satsukies satsukies Sep 17, 2024

Choose a reason for hiding this comment

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

We need to use AppCompat 1.6.0~ if we collect per-app language preferences with backward compatibility.

But we should avoid adding new dependencies, so I use Locale instead.

In the future, this implementation will be updated if we can collect by another way.

@satsukies satsukies marked this pull request as ready for review September 17, 2024 06:29
@satsukies satsukies requested a review from jmatsu September 17, 2024 06:29
Comment on lines 25 to 59
ArrayList<Pair<String, Object>> data = new ArrayList<>();
data.add(new Pair<String, Object>("toString", defaultLocale.toString()));
data.add(new Pair<String, Object>("getLanguage", defaultLocale.getLanguage()));
data.add(new Pair<String, Object>("getCountry", defaultLocale.getCountry()));
data.add(new Pair<String, Object>("getVariant", defaultLocale.getVariant()));
data.add(new Pair<String, Object>("getDisplayCountry", defaultLocale.getDisplayCountry()));
data.add(new Pair<String, Object>("getDisplayLanguage", defaultLocale.getDisplayLanguage()));
data.add(new Pair<String, Object>("getDisplayName", defaultLocale.getDisplayName()));
data.add(new Pair<String, Object>("getDisplayVariant", defaultLocale.getDisplayVariant()));
data.add(new Pair<String, Object>("getISO3Country", defaultLocale.getISO3Country()));
data.add(new Pair<String, Object>("getISO3Language", defaultLocale.getISO3Language()));

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
data.add(new Pair<String, Object>("getDisplayScript", defaultLocale.getDisplayScript()));
data.add(new Pair<String, Object>("toLanguageTag", defaultLocale.toLanguageTag()));
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
data.add(new Pair<String, Object>("getScript", defaultLocale.getScript()));
}

putAll(Locale.class.getName(), data);
}

private void putAll(String fqcn, List<Pair<String, Object>> data) {
for (Pair<String, Object> pair : data) {
String key = String.format("%s$%s", fqcn, pair.first);
try {
states.put(key, pair.second);
} catch (JSONException e) {
Logger.w(e, "Failed to put info: key=%s, value=%s", key, pair.second);
}
}

}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please put a pair one by one instead of collecting pairs and put them at once. It may be a cost to hold many pairs and iterate them.

Copy link
Member Author

Choose a reason for hiding this comment

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

I fix it on 3a6113e.
Rename "putAll" method to "put" and reuse the implementation of handing JSONException with try-catch block. We should handle that for each put operation not whole operations.

@@ -273,6 +273,8 @@ public void onForeground(
long elapsedRealtime,
TimeUnit timeUnit
) {
getSdkDeviceStatesCollector().collectLocale();
Copy link
Member Author

Choose a reason for hiding this comment

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

We collect Locale information when the host app becomes foreground.

@satsukies satsukies requested a review from jmatsu September 19, 2024 02:02
Copy link
Contributor

@jmatsu jmatsu left a comment

Choose a reason for hiding this comment

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

yay

@satsukies
Copy link
Member Author

thanks!

@satsukies satsukies merged commit 7459c66 into master Sep 19, 2024
6 checks passed
@satsukies satsukies deleted the feat/collecting-device-state branch September 19, 2024 04:49
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.

2 participants