Skip to content

A scriptable Desktop tool to control your Android

Notifications You must be signed in to change notification settings

jiejohn/Wrench

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wrench: control your Android phone from your Desktop

http://baohaojun.github.io/images/Wrench-2.png

Install

There are prebuilt versions for Windows, Mac and Linux (ubuntu 14.04). They are released at https://github.com/SmartisanTech/Wrench-releases/releases .

Compilation

Under Linux, compile Wrench with the build-linux.sh script. You should be able to run this script directly.

For Windows version, I compile with Wine under Linux, with the Qt for msys installed as compiler. Please refer to the ./build-wine.sh script.

For Mac version, please refer to the ./build-mac.sh script.

You need to adapt the ./build-wine.sh and ./build-mac.sh scripts, there are some hardcoded parameters (such as the PATH environment and the Mac hostname).

How does it work

Android has builtin input command, which allows you to fake touch, keyboard, text events and so on.

Starting from the input command, I made some improvements.

You can use adb shell input text <string> to input a string, but the string is limited: it can’t contain spaces or any other special characters, such as quote and double quote, or Chinese characters.

So I decided to use the android clipboard. When I want to input any string, I put the string into the android clipboard. Then I trigger a special key with adb shell input, which will cause my Wrench helper input method to send the desired string in the clipboard to the current App, like a IME candidate has been chosen.

Then, there are some performance improvements. adb shell input is very slow, because every time it will load an Input.jar. adb shell am is used a lot, to start Activities or Services. It is also very slow, because every time it will load an Am.jar.

I wrote an Setclip.apk, which will also be open sourced when I find time. It contains the functionality of Input.jar and Am.jar, and it will reside in the background, so that do not need to load the .jar/.apk files everytime.

WrenchIme.apk will also be open sourced later. It’s a very small change to the Google Pinyin Ime.

Update: both Setclip.apk and WrenchIme has been open sourced, they are under the separate git subtrees: SetClip, WrenchIME and droidVncServer. The last one is for VNC server for syncing phone screen to the desktop.

Both Input.jar and Am.jar are from AOSP, with userdebug build to make sure the .dex class files are not optimized away and thus dalvik loadable. They will be loaded by the SetClip.apk, when it is run as a separate dalvik process (besides being started as an Android activity/service).

Here’s the workflow of Wrench:

  1. Use app_process to start Setclip.apk in the background, for the functionality of Input.jar and Am.jar.

    The background process will listen for commands on a UNIX domain socket. Input commands and Am commands are allowed. Only shell/root users are allowed to connect to the socket.

  2. Use adb forward to create a TCP socket on the Desktop which will delegate to Input/Am on the phone.
  3. Write am start Setclip.apk putclip <string> (something like that) to the local TCP socket. The Am.jar functionality got executed on the phone. The Setclip.apk’s service got started, which put the string in the android clipboard.
  4. Write input key scroll_lock to the local TCP socket. The key is interpreted by WrenchIme.apk, and the clipboard string is sent to the current Apk.

How to use Wrench

Please refer to this youtube video.

Contribute

Bug reports, patches, ideas are welcome.

If you like Wrench, you may also donate to me with alipay:

./bhj-alipay.png

About

A scriptable Desktop tool to control your Android

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 35.9%
  • C++ 31.2%
  • HTML 19.7%
  • Shell 2.6%
  • Java 2.6%
  • M4 2.0%
  • Other 6.0%