-
Notifications
You must be signed in to change notification settings - Fork 33
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eff5b0c
init
filip131311 5c93259
init2
filip131311 cd2a1bc
changes after CR
filip131311 eb14f0c
changes after CR
filip131311 1cc4a2f
setTimeout workaround
filip131311 f2eaba1
add qemu.img syncronisation
filip131311 2e54c3f
changes after CR
filip131311 4cced63
changes in coments
filip131311 f080b13
Merge branch 'main' into @Filip131311/AddAndroidLocalization
filip131311 22e981c
fixes after CR
filip131311 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import { ChildProcess, exec, lineReader } from "../utilities/subprocess"; | |
import { BuildResult } from "../builders/BuildManager"; | ||
import { AndroidSystemImageInfo, DeviceInfo, DevicePlatform } from "../common/DeviceManager"; | ||
import { Logger } from "../Logger"; | ||
import { AppPermissionType, DeviceSettings } from "../common/Project"; | ||
import { AppPermissionType, DeviceSettings, Locale } from "../common/Project"; | ||
import { getAndroidSystemImages } from "../utilities/sdkmanager"; | ||
import { EXPO_GO_PACKAGE_NAME, fetchExpoLaunchDeeplink } from "../builders/expoGo"; | ||
import { Platform } from "../utilities/platform"; | ||
|
@@ -78,7 +78,71 @@ export class AndroidEmulatorDevice extends DeviceBase { | |
}, DISPOSE_TIMEOUT); | ||
} | ||
|
||
private async shouldUpdateLocale(newLocale: Locale) { | ||
const locale = newLocale.replace("_", "-"); | ||
const { stdout } = await exec(ADB_PATH, [ | ||
"-s", | ||
this.serial!, | ||
"shell", | ||
"settings", | ||
"get", | ||
"system", | ||
"system_locales", | ||
]); | ||
|
||
// if user did not use the device before it might not have system_locales property | ||
// as en-US is the default locale, used by the system, when no setting is provided | ||
// we assume that no value in stdout is the same as en-US | ||
if ((stdout ?? "en-US") === locale) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* This method changes device locale by modifying system_locales system setting. | ||
*/ | ||
private async changeLocale(newLocale: Locale): Promise<void> { | ||
const locale = newLocale.replace("_", "-"); | ||
|
||
await exec(ADB_PATH, [ | ||
"-s", | ||
this.serial!, | ||
"shell", | ||
"settings", | ||
"put", | ||
"system", | ||
"system_locales", | ||
locale, | ||
]); | ||
|
||
// this is needed to make sure that changes will persist | ||
await exec(ADB_PATH, ["-s", this.serial!, "shell", "sync"]); | ||
|
||
// 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 | ||
const { stdout } = await exec(ADB_PATH, [ | ||
"-s", | ||
this.serial!, | ||
"shell", | ||
"getprop", | ||
"persist.sys.locale", | ||
]); | ||
|
||
if (stdout) { | ||
Logger.warn( | ||
"Updating locale will not take effect as the device has altered locale via system settings which always takes precedence over the device setting the IDE uses." | ||
); | ||
} | ||
} | ||
|
||
async changeSettings(settings: DeviceSettings) { | ||
let shouldRestart = false; | ||
if (await this.shouldUpdateLocale(settings.locale)) { | ||
shouldRestart = true; | ||
await this.changeLocale(settings.locale); | ||
} | ||
|
||
await exec(ADB_PATH, [ | ||
"-s", | ||
this.serial!, | ||
|
@@ -125,10 +189,29 @@ export class AndroidEmulatorDevice extends DeviceBase { | |
settings.location.latitude.toString(), | ||
]); | ||
} | ||
return false; | ||
return shouldRestart; | ||
} | ||
|
||
/** | ||
* This method restarts the emulator process using SIGKILL signal. | ||
* Should be used for the situations when quick reboot is necessary | ||
* and when we don't care about the emulator's process state | ||
*/ | ||
private async forcefullyResetDevice() { | ||
this.emulatorProcess?.kill(9); | ||
await this.internalBootDevice(); | ||
} | ||
|
||
async bootDevice(deviceSettings: DeviceSettings): Promise<void> { | ||
await this.internalBootDevice(); | ||
|
||
let shouldRestart = await this.changeSettings(deviceSettings); | ||
if (shouldRestart) { | ||
await this.forcefullyResetDevice(); | ||
} | ||
} | ||
|
||
async bootDevice(settings: DeviceSettings) { | ||
async internalBootDevice() { | ||
// this prevents booting device with the same AVD twice | ||
await ensureOldEmulatorProcessExited(this.avdId); | ||
|
||
|
@@ -144,6 +227,7 @@ export class AndroidEmulatorDevice extends DeviceBase { | |
"-no-boot-anim", | ||
"-grpc-use-token", | ||
"-no-snapshot-save", | ||
"-writable-system", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this option? why are we adding it here? It should be explained in PR description |
||
], | ||
{ env: { ANDROID_AVD_HOME: avdDirectory } } | ||
); | ||
|
@@ -172,8 +256,6 @@ export class AndroidEmulatorDevice extends DeviceBase { | |
}); | ||
|
||
this.serial = await initPromise; | ||
|
||
await this.changeSettings(settings); | ||
} | ||
|
||
async configureExpoDevMenu(packageName: string) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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