Commit graph

173 commits

Author SHA1 Message Date
Romain Vimont
ad6209f6ff Terminate the device process gracefully
Call shutdown() on the device socket to make the device process finish
its execution quickly and gracefully, without killing it.
2018-02-16 11:47:42 +01:00
Romain Vimont
a5b6c6cc2d Enable debug logs only for debug builds on server
Print the logs only if their level is not under the threshold, which is
defined to INFO in release mode and DEBUG in debug mode.
2018-02-12 17:19:52 +01:00
Romain Vimont
000c70a644 Decompose accented characters
Characters like 'é' or 'î' are not resolved by getEvents(). For example,
getEvents("é") returns null.

However, it is possible to decompose them. For example,
getEvents("\u0301e") returns the events generating "é".

Thank you Philippe! ;)
2018-02-12 14:17:10 +01:00
Romain Vimont
063cfd1326 Turn screen on in control()
Turning the screen on is semantically associated to control(): only
creating the EventController object should not turn the screen on.
2018-02-09 14:03:25 +01:00
Romain Vimont
c683872bbc Avoid server stacktraces on close
On close, the socket is closed by the client, and the server process is
killed.

This leads to (expected) exceptions, that should not be printed.
2018-02-09 10:59:15 +01:00
Romain Vimont
e55e42a442 Apply Genymobile rules for Android projects
Apply Genymobile checkstyle and gradle build files organization.
2018-02-07 20:58:18 +01:00
Romain Vimont
285fc97d02 Fix horizontal scrolling constant
Use AXIS_HSCROLL (available since API 12) instead of AXIS_SCROLL (since
API 26).
2018-02-07 20:50:58 +01:00
Romain Vimont
c6d01331ed Simplify EventController
In handleEvent(), connection.receiveControlEvent() may never return
null: either it returns a valid ControlEvent, either it throws an
Exception.

Therefore, there is no need to propagate a flag to indicate whether it
returned a valid ControlEvent.
2018-02-07 17:48:21 +01:00
Romain Vimont
03c5f97e3f Extract control event parsing to separate methods
Use one parse method per control event type.
2018-02-07 17:45:28 +01:00
Romain Vimont
5f51d605c0 Recreate codec and display on rotation changed
On some devices, we can reuse the same codec and display, but on some
others (e.g. Nexus 5X with Android 7.1.2), it crashes on codec.stop()
with an IllegalStateException.

Therefore, always recreate the codec and display, so that it works on
all devices.
2018-02-07 16:32:16 +01:00
Romain Vimont
d5acc8adc5 Always release output buffer
If rotation changed, the dequeued output buffer was never released. Move
it to a finally block to avoid the leak.
2018-02-07 15:50:38 +01:00
Romain Vimont
1ac37c4291 Hide services in Device
Expose useful methods directly in Device, without exposing the service
managers.
2018-02-02 17:06:57 +01:00
Romain Vimont
06333e1e08 Cache managers in ServiceManager
To guarantee that we instantiate services only one, cache the value the
first time.
2018-02-02 16:25:37 +01:00
Romain Vimont
3365460658 Turn screen on on start
When starting scrcpy, immediately turn the screen on.
2018-02-02 14:57:33 +01:00
Romain Vimont
a139509f11 Turn screen on on right-click
The right-click is almost useless on Android, so use it to turn the
screen on.

Add a new control event type (command) to request the server to turn the
screen on.
2018-02-02 14:56:03 +01:00
Romain Vimont
228545cefd Reformat EventController
Reformated by Android Studio.
2018-02-02 14:52:00 +01:00
Romain Vimont
6b546a87ab Add bit-rate command-line option
Add a command-line option (-b/--bit-rate) to customize the video
bit-rate.
2018-02-01 17:11:40 +01:00
Romain Vimont
ee93f3f23a Rename maximum_size to max_size
The long option is --max-size, so for consistency, adapt the code
accordingly.
2018-02-01 17:11:40 +01:00
Romain Vimont
865ebb3862 Encode video using MediaCodec API
Replace screenrecord execution by manual screen encoding using the
MediaCodec API.

The "screenrecord" solution had several drawbacks:
 - screenrecord output is buffered, so tiny frames may not be accessible
   immediately;
 - it did not output a frame until the surface changed, leading to a
   black screen on start;
 - it is limited to 3 minutes recording, so it needed to be restarted;
 - screenrecord added black borders in the video when the requested
   dimensions did not preserve aspect-ratio exactly (sometimes
   unavoidable since video dimensions must be multiple of 8);
 - rotation handling was hacky (killing the process and starting a new
   one).

Handling the encoding manually allows to solve all these problems.
2018-01-31 19:51:43 +01:00
Romain Vimont
7ed334915e Register uncaught exception handler
Never miss an exception by using an uncaught exception handler.
2018-01-31 19:50:45 +01:00
Romain Vimont
8c4a454d68 Extract argument parsing
Move argument parsing to a separate method.
2018-01-31 19:49:49 +01:00
Romain Vimont
73831a0837 Use the Point class from the framework
Replace our custom Point class by android.graphics.Point.
2018-01-31 19:42:08 +01:00
Romain Vimont
b67907e24e Convert server to an Android project
To simplify the device server-side build, use gradle to create an APK,
even if we use it as a simple jar, by running its main() method.
2018-01-30 12:01:36 +01:00