-
Notifications
You must be signed in to change notification settings - Fork 8
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
Conversation
} | ||
|
||
public void collectLocale() { | ||
Locale defaultLocale = Locale.getDefault(); |
There was a problem hiding this comment.
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.
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); | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay
thanks! |
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 )