Skip to content

Use sockets to LiveSync changes on Android #3797

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

Closed
rosen-vladimirov opened this issue Aug 7, 2018 · 0 comments
Closed

Use sockets to LiveSync changes on Android #3797

rosen-vladimirov opened this issue Aug 7, 2018 · 0 comments

Comments

@rosen-vladimirov
Copy link
Contributor

rosen-vladimirov commented Aug 7, 2018

The current implementation of LiveSync for Android works in the following way:

  1. CLI uploads files to /data/local/tmp/<app id> on the device. NOTE: This directory is just a temp dir on the device. As CLI uses adb shell to push the files there, all files are owned by the root user.
  2. Once application starts, Android runtime checks if there are any files inside /data/local/tmp/<app id> and in case yes, it copies them in the application sandbox. After that, the Android runtime tries to remove the files from /data/local/tmp/<app id> as they have already been copied in the sandbox.
  3. Application starts with all LiveSynced files.

When a change is applied during LiveSync, CLI uploads the modified file to the same location ( /data/local/tmp/<app id>) and the same logic is applied.
However, the last part of step 2 (runtime trying to delete files from /data/local/tmp/<app id>) fails on all Samsung devices and also on all new API versions. The reason is that the runtime runs with a different user, not the root one, and it does not have permissions to delete the files CLI created with root user. CLI cannot use the same user as the runtime does, so the only possibility is to use root user for uploading files to the /data/local/tmp/<app id> location.
When the files in /data/local/tmp/<app id> are not deleted, the LiveSync continues working, but the files in the application may not be the one you've exepected, i.e. its behavior becomes unknown. For example, in case you stop the LiveSync, apply several changes in your application, build and deploy it on device (without using LiveSync), the .apk you've deployed will contain your changes. However, once the application starts, it will check the /data/local/tmp/<app id> location, the last synced files will still be there, as the runtime was unable to delete them, and they'll be taken in the Application sandbox. So once the application starts, you may see the old files of your app.

In order to resolve this issue, implement LiveSync through sockets. The idea is:

  1. When LiveSync starts, CLI creates a temp file on device, inside /data/local/tmp/<app-id>-livesync-in-progress.
  2. CLI starts Android runtime, so a connection between CLI and application can be established.
  3. Android runtime opens a new connection, so CLI can start transferring files.
  4. Android runtime checks if there's a file /data/local/tmp/<app-id>-livesync-in-progress and if it is created less than a minute ago. In case yes, runtime does not start the JS application, i.e. it does not run the v8 engine, as the LiveSync operation is in progress.
  5. CLI transfers all files through socket.
  6. CLI deletes the /data/local/tmp/<app-id>-liveSync-in-progress file from device.
  7. CLI restarts the application.
  8. Runtime starts and detectes there's no /data/local/tmp/<app-id>-livesync-in-progress file, so it loads the v8 engine and starts the application.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants