这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@Epictek
Copy link
Contributor

@Epictek Epictek commented Nov 17, 2018

This PR replaces the Broadcast Reciever with a service listening on a socket resulting in a much faster response (miliseconds instead of seconds).
JSON is sent over the termux-input socket and the results get returned on termux-output

This is more of a proof of concept for the time being a lot is not working/not yet implemented, I'm open to any feedback on how to improve this.

A test suite would be nice for testing all the APIs, any suggestions for how to implement that would be nice.

Tested APIs

  • WifiAPI.java
  • AudioAPI.java
  • TorchAPI.java
  • ToastAPI.java
  • BatteryStatusAPI.java
  • CallLogAPI.java
  • CameraInfoAPI.java
  • VolumeAPI.java
  • BrightnessAPI.java -
  • ContactListAPI.java
  • NotificationListAPI.java
  • NotificationAPI.java
  • SmsInboxAPI.java
  • VibrateAPI.java
  • FingerprintAPI.java
  • PhotoAPI.java
  • TextToSpeechAPI.java
  • InfraredAPI.java - Can't test (no IR on my phone)
  • SensorAPI.java
  • KeystoreAPI.java
  • ShareAPI.java
  • LocationAPI.java
  • MediaPlayerAPI.java
  • SmsSendAPI.java
  • MediaScannerAPI.java
  • SpeechToTextAPI.java
  • WallpaperAPI.java
  • ClipboardAPI.java - Crashes
  • MicRecorderAPI.java
  • StorageGetAPI.java
  • TelephonyAPI.java
  • DialogActivity.java
  • DownloadAPI.java

Bugs/Issues:

Out of memory exception happens with dialogs, current work around is android:largeHeap="true" but this is obviosuly not a permanent fix. fixed

Usage Examples:

This PR Requires the modified termux-api binary from here https://github.com/Epictek/termux-api-package/blob/master/termux-api.c PR incoming for that soon once I figure out how to handle rewriting all the scripts.

# Start the service (This will be implemented in to termux-api.c later)
am broadcast --user 0 -n com.termux.api/.TermuxApiReceiver
# Call logs
echo "{'api_method':'CallLog'}" | ./termux-api
# Date input
echo "{'api_method':'Dialog','input_method':'date'}" | ./termux-api

@Epictek Epictek changed the title Change of app to use sockets with json instead of Intents [WIP] Change app to use sockets with json instead of Intents [WIP] Nov 17, 2018
@Grimler91
Copy link
Member

Hi, I tested it on my phone the other day (really sorry for not looking at it earlier), something like this would be really nice to speed up termux-api.

Could you rebase this against master?
I've added a commit for JobScheduler over at my own branch: Grimler91@55ec049.

Regarding the clipboard crash, seems that the code need to be refactored to not call
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
in onReceive, that's at least my interpretation of the logcat:

01-22 14:04:17.782 18751 18767 E AndroidRuntime: FATAL EXCEPTION: Thread-5
01-22 14:04:17.782 18751 18767 E AndroidRuntime: Process: com.termux.api, PID: 18751
01-22 14:04:17.782 18751 18767 E AndroidRuntime: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
01-22 14:04:17.782 18751 18767 E AndroidRuntime:        at android.os.Handler.<init>(Handler.java:203)
01-22 14:04:17.782 18751 18767 E AndroidRuntime:        at android.os.Handler.<init>(Handler.java:117)
01-22 14:04:17.782 18751 18767 E AndroidRuntime:        at android.content.ClipboardManager$2.<init>(ClipboardManager.java:84)
01-22 14:04:17.782 18751 18767 E AndroidRuntime:        at android.content.ClipboardManager.<init>(ClipboardManager.java:84)
01-22 14:04:17.782 18751 18767 E AndroidRuntime:        at android.app.SystemServiceRegistry$12.createService(SystemServiceRegistry.java:375)
01-22 14:04:17.782 18751 18767 E AndroidRuntime:        at android.app.SystemServiceRegistry$12.createService(SystemServiceRegistry.java:373)
01-22 14:04:17.782 18751 18767 E AndroidRuntime:        at android.app.SystemServiceRegistry$CachedServiceFetcher.getService(SystemServiceRegistry.java:1374)
01-22 14:04:17.782 18751 18767 E AndroidRuntime:        at android.app.SystemServiceRegistry.getSystemService(SystemServiceRegistry.java:1326)
01-22 14:04:17.782 18751 18767 E AndroidRuntime:        at android.app.ContextImpl.getSystemService(ContextImpl.java:1695)
01-22 14:04:17.782 18751 18767 E AndroidRuntime:        at android.content.ContextWrapper.getSystemService(ContextWrapper.java:727)
01-22 14:04:17.782 18751 18767 E AndroidRuntime:        at com.termux.api.ClipboardAPI.onReceive(ClipboardAPI.java:20)
01-22 14:04:17.782 18751 18767 E AndroidRuntime:        at com.termux.api.TermuxApiService.runApiMethod(TermuxApiService.java:120)
01-22 14:04:17.782 18751 18767 E AndroidRuntime:        at com.termux.api.TermuxApiService$1.run(TermuxApiService.java:62)
01-22 14:04:17.782 18751 18767 E AndroidRuntime:        at java.lang.Thread.run(Thread.java:764)

@Epictek
Copy link
Contributor Author

Epictek commented Jan 23, 2019

Hi I've been a bit busy recently but I'm glad their is some intrest in this PR. I'm going to continue working on it soon, thanks for the commit and the details about the clipboard crash. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants