-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add Localization on Android #590
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
]); | ||
|
||
// if user did not use the device before it might not have system_locales property | ||
// as en-US is the default locale we assume that no value is the same as en-US |
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 assume that no value is the same as en-US" I don't understand this part.
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.
If there is no value and the user selected locale is en-US I don't want to trigger locale change as it is already a correct one
|
||
// it is necessary to use SIGTERM 9 as it would take to much time otherwise and would degrade user experience | ||
// having said that use this function with caution only in scenarios when you are sure that no user data will be lost | ||
private async resetDevice() { |
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.
forcefullyResetDevice
to signify this isn't typical reboot sequence?
// If the device uses google mobile services persist.sys.locale can not be changed, as it requires a root access | ||
// TODO: Find a way to change or remove persist.sys.locale without root access. note: removing the whole | ||
// data/property/persistent_properties file would also work as we persist device settings globally in Radon IDE | ||
private async changeLocale(newLocale: Locale): Promise<boolean> { |
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.
Isn't it always returning true? What does the return value mean?
]); | ||
|
||
if (!stdout) { | ||
return true; |
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.
add some logging here such that we can diagnose it for the users who may've set the language using settings app
// If persist.sys.locale exist try to set it to match the newLocale. | ||
try { | ||
await exec(ADB_PATH, [ | ||
"-s", | ||
this.serial!, | ||
"shell", | ||
"su", | ||
"0", | ||
"setprop", | ||
"persist.sys.locale", | ||
locale, | ||
]); | ||
} catch (e) { | ||
// this is expected if device is using google mobile services | ||
Logger.debug( | ||
"CHANGE LOCALE - Device is not allowing root access, moving on without modifying persist.sys.locale" | ||
); | ||
} | ||
|
||
return true; |
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 think it should be ok to remove this part. It is unlikely that someone would change the language via settings, and even if they do, it is unlikely you can actually use sudo on Android devices as it is only available on pure AOSP builds which are rarely used in practice
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 see my inline comments and add test plan to PR description.
I believe the way you tested this was by changing it while the Android device was booted. But what happen when you change language on iOS and then switch to Android, or when you change the language before the device is fully booted.
]); | ||
|
||
// this is needed to make sure that changes will persist | ||
await exec(ADB_PATH, ["shell", "sync"]); |
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.
why we don't pass "-s", this.serial
here?
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.
it was a mistake thank you
// this is needed to make sure that changes will persist | ||
await exec(ADB_PATH, ["shell", "sync"]); | ||
|
||
if (stdout) { |
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.
would feel more natural if we made this check before the other exec
call given you use a transient stdout variable
This PR adds localization on android.
Screen.Recording.2024-10-03.at.16.47.57.mov
Additional context:
How Android changes the locale settings when the user does it in the settings app?
Android changes the memory responsible for holding information about locale and tigers a change in two types of persistent storage, one is system prop
persist.sys.locale
and the second one issystem_locales
prop in system level settings.Before user changes the settings both of those fields are empty. When Android boots it either sets a locale to the default one or to the one specified in one of the persistent locations, it seems that if only one location exist android will still retrive the information, but conflict between
persist.sys.locale
andsystem_locales
leads to unpredictable behavior.How to change the properties with adb?
adb allows us to change system properties including
persist.sys.locale
granted we have a root access, this is achieved either by usingadb root
command orsu
command inside shell. The root access is only possible on emulators without GMS (google mobile services). adb also allows us to chage system settings usingadb shell settings
command and it does not require root access.How emulator command changes settings when using
-change-locale
option?Underneath emulator calls
adb shell su 0 setprop persist.sys.locale ${locale}
.Uncovered case:
Because of the above I did not find a way to reliably change
persist.sys.locale
and scenario in which user manually changes locale (in the settings app).Test Plan: