いつの間にかAndroid端末が充電中にもずっと画面がOnのままになってしまいました.充電時間が伸びるし電気が無駄です.
なにかの設定を触ってしまったのだろうと調べてみました.
Debian sid amd64環境ではパッケージがあるので簡単です,armhf/amd64/i386環境ではsnap版が存在します.その他幾つかのLinuxディストリビューションではパッケージがあったり,WindowsやmacOSでも動作するようです.
手元ではDebian sid amd64で動作しました.(Raspberry Pi OS armhfにsnap版を入れた環境ではエラーが発生.内容は未だ未確認)
Debian sid amd64環境だと以下のような感じで導入できました.このときAndroid端末は「開発者向けオプション」が有効になっていて,「USBデバッグ」が有効になっている状態でUSB接続されている必要があります.
$ sudo apt install adb scrcpy (1) $ lsusb (2) : Bus 002 Device 013: ID 05c6:9024 Qualcomm, Inc. SDM439-MTP _SN:472BF8D8 : $ echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="05c6" ATTR{idProduct}=="9024", MODE="0660", GROUP="plugdev", SYMLINK+="android%n"' \ | sudo tee -a /etc/udev/rules.d/51-android.rules (3) $ sudo udevadm control --reload (4) $ adb devices (5) * daemon not running; starting now at tcp:5037 * daemon started successfully List of devices attached 976d6a56 device
05c6:9024
)この状態で,scrcpy
を実行することでAndroidの画面転送が出来ました.普通に操作も出来ます.
スリープ状態のときは画面が真っ黒ですが,マウス右クリックで解除されます.
$ scrcpy INFO: scrcpy 1.14 <https://github.com/Genymobile/scrcpy> /usr/share/scrcpy/s...93 bytes in 0.008s) [server] INFO: Device: TINNO C330 (Android 9) INFO: OpenGL shaders: ENABLED INFO: Created renderer: opengl INFO: Renderer: opengl INFO: OpenGL version: 3.0 Mesa 20.2.4 INFO: Trilinear filtering enabled INFO: Initial texture: 720x1280
導入も簡単だしこれは便利.しかしメイン端末ではPCにUSB接続するとすぐに充電しなくなってしまうので長時間は使えません.
adb
のワイヤレス接続の設定をすると別の端末や充電器で充電しながら利用できそうなので試してみました.
対象のAndroid端末をPCにUSB接続した状態で tcpip
コマンドでリモート接続できるようにします.
$ adb tcpip 5555 restarting in TCP mode port: 5555
この状態でPCからAndroid端末を取り外し,Wi-Fi接続のIPアドレスを確認します.
PCでadbコマンドでAndroid端末に接続します.
$ adb connect <ANDROID_IP>>:5555
この状態で scrcpy
コマンドを実行すると画面が表示され操作できます.充電器などに接続した状態でも利用できます :)
scrcpy
には幾つかオプションがあります.便利そうなものとしては最大解像度を指定する -m, --max-size value
で解像度を下げて表示できます,
-n, --no-control
で表示だけで操作できなくします.
-r, --record file
で画面を録画します.
-w, --stay-awake
でscrcpyを実行中Android画面をロック,消灯しません.
-S, --turn-screen-off
Android端末のスクリーンを消したまま操作できます.
ショートカットでは
Ctrl + h
, マウス中キー
でホームボタン,
Ctrl + r
でAndroid画面回転,
Ctrl + s
でアプリケーション切り替え,
辺りが便利そうです,
Ctrl + c
でクリップボードのコピーなのですが,一旦Android側でコピーした後に Ctrl + c
でPCへのクリップボードコピーのようです,Ctrl + v
の貼り付けもAndroid感での貼り付けで,PCからAndroidのクリップボード貼り付けは Ctrl + Shift + v
でした.
詳細は scrcpy --help
を参照してください.
これでElectronアプリでPCで動かしているアプリをスマホで……とも思ったのですが日本語入力などはちょっと面倒.もう少し様子見しようと思います.
Androidでdeb系ぽいLinux環境を実現できるTermuxからAndroidを操作するAPIのTermux-APIのupdateがありました.
Add a USB API compatible with libusb – see https://wiki.termux.com/wiki/Termux-usb for more information.
なんだか気になる更新内容です.
早速試してみます.
$ pkg update $ pkg install root-repo $ pkg install termux-api $ pkg install libusb $ pkg install clang
termux-usb
コマンドでデバイスを確認してアクセス許可を与える(ここではUSBメモリ)$ termux-usb -l [ "/dev/bus/usb/001/004" ] $ termux-usb -r /dev/bus/usb/001/004 Access granted.
アクセスの許可はAndroidの画面で操作が必要です.
ちなみに,USB Keyboardは認識できませんでした(Androidでは利用できているのに!)
$ cat << __EOF__ > usbtest.c > $ cat usbtest.c > #include <stdio.h> > #include <assert.h> > #include <libusb-1.0/libusb.h> > > int main(int argc, char **argv) { > libusb_context *context; > libusb_device_handle *handle; > libusb_device *device; > struct libusb_device_descriptor desc; > unsigned char buffer[256]; > int fd; > assert((argc > 1) && (sscanf(argv[1], "%d", &fd) == 1)); > assert(!libusb_init(&context)); > assert(!libusb_wrap_sys_device(context, (intptr_t) fd, &handle)); > device = libusb_get_device(handle); > assert(!libusb_get_device_descriptor(device, &desc)); > printf("Vendor ID: %04x\n", desc.idVendor); > printf("Product ID: %04x\n", desc.idProduct); > assert(libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, buffer, 256) >= 0); > printf("Manufacturer: %s\n", buffer); > assert(libusb_get_string_descriptor_ascii(handle, desc.iProduct, buffer, 256) >= 0); > printf("Product: %s\n", buffer); > assert(libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, buffer, 256) >= 0); > printf("Serial No: %s\n", buffer); > libusb_exit(context); > } > __EOF__ $ gcc usbtest.c -lusb-1.0 -o usbtest $ termux-usb -e ./usbtest /dev/bus/usb/001/004 Vendor ID: 13fe Product ID: 3600 Manufacturer: Product: USB DISK 2.0 Serial No: 07AC10081C16381A
てことでTermuxからlibusbが使えるようになったようです.
ちなみに,lsusbを実行するとこんな感じです.rootedな端末だと使えるんでしょうけど.
$ lsusb lsusb: /sys/bus/usb/devices: Permission denied $ tsudo lsusb /data/data/com.termux/files/usr/bin/tsu: 146: exec: : Permission denied
$ dpkg-query -W termux-api libusb clang clang 8.0.1-4 libusb 1.0.23-rc1-1 termux-api 0.47 $ adb shell dumpsys package com.termux.api | grep -E 'versionCode|versionName' versionCode=38 minSdk=21 targetSdk=28 versionName=0.38 $ adb shell dumpsys package com.termux | grep -E 'versionCode|versionName' versionCode=75 minSdk=21 targetSdk=28 versionName=0.75 $ getprop ro.bootimage.build.fingerprint essential/mata/mata:10/QP1A.190711.122/420:user/release-keys $ getprop ro.build.version.security_patch 2019-09-05 $ getprop ro.product.cpu.abilist arm64-v8a,armeabi-v7a,armeabi
先日のttygifで作成したanimation gifをInstagramに投稿しようとしたところ,animation gifは投稿できるけどanimationせず1枚目の画像が表示されるだけです.ffmpegでmp4に変換するだけで良さそうだけど投稿できません.白い動画でプログレスがずっと表示され,「次へ」を押すとアプリ自体が落ちてしまいます.動画は同端末のvlcなどでは問題なく再生できています.
$ ffmpeg -i tty.gif tty.mp4
音声がないのがいけないのかな?と anullsrc
フィルタで無音の音声トラックを追加してみても変わらず.
$ ffmpeg -f lavfi -i anullsrc -i tty.gif -shortest tty.mp4
手詰まりになって検索してみると以下のページを発見.
このページによると以下の条件で投稿できないようです.
今回の動画は20秒ほどなので長さは問題無さそうです.
うまく行っていなかった動画を確認すると元記事と同様 yuv444p
を使っているようです.
$ ffprobe tty.mp4 2>&1 | grep -E "Stream.*Video" Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 802x750, 73 kb/s, 4.17 fps, 4.17 tbr, 12800 tbn, 8.33 tbc (default)
てことで,以下のようにカラーエンコーディングに yuv420p
を指定して変換すると投稿できました.(音声トラックはあってもなくてもどちらでもOKだった)
$ ffmpeg -i tty.gif -pix_fmt yuv420p -filter_complex "scale=trunc(iw/2)*2:trunc(ih/2)*2" tty.mp4 $ ffprobe tty.mp4 2>&1 | grep -E "Stream.*Video" Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1058x750, 97 kb/s, 16.08 fps, 16.08 tbr, 12352 tbn, 32.17 tbc (default)
公式の文章があればいいんですが見つからず.以下が少し近い?
$ dpkg-query -W ffmpeg ffmpeg 7:4.1.4-1+b2 $ lsb_release -dr Description: Debian GNU/Linux bullseye/sid Release: unstable $ uname -m x86_64
$ adb shell dumpsys package com.instagram.android | grep -E 'versionCode|versionName' versionCode=175574628 minSdk=23 targetSdk=28 versionName=113.0.0.39.122 $ adb shell getprop ro.bootimage.build.fingerprint essential/mata/mata:10/QP1A.190711.122/420:user/release-keys $ adb shell getprop ro.build.version.security_patch 2019-09-05 $ adb shell getprop ro.product.cpu.abilist arm64-v8a,armeabi-v7a,armeabi
Android 端末側でUSB デバッグを有効にしてUSB接続する.
デバイスが認識されているか確認.
$ adb devices List of devices attached PM1LHMA861102833 device
HostPC の adb コマンドで tcpip
コマンドで接続できるようにして,connect
コマンドで Android 端末の ip を指定して接続します.
5555
はポート番号で 5555
が規定値.既定値から変更した場合は,connect
コマンドの ip の後ろにポート番号の指定が必要になります.
$ adb tcpip 5555 $ adb connect 192.168.1.200 connected to 192.168.1.200:5555
この状態でusb 接続を解除して devides
コマンドに居ます :)
後は普通に使えます.
$ adb devices List of devices attached 192.168.1.200:5555 device $ adb logcat|head -1 --------- beginning of crash ^C
そして本命のバックアップ.
$ time adb backup -f ./PH-1.ab -all Now unlock your device and confirm the backup operation... real 26m2.104s user 0m0.171s sys 0m5.725s
用事が終わったら切断しておいたほうが安心ですね.
$ adb disconnect 192.168.1.200 disconnected 192.168.1.200 $ adb devices List of devices attached
mata:/ $ getprop ro.bootimage.build.fingerprint essential/mata/mata:9/PQ1A.190105.058/496:user/release-keys mata:/ $ getprop ro.build.version.security_patch 2019-05-05 mata:/ $ getprop ro.product.cpu.abilist arm64-v8a,armeabi-v7a,armeabi
$ dpkg-query -W adb adb 1:8.1.0+r23-5 $ lsb_release -dr Description: Debian GNU/Linux 10 (buster) Release: 10 $ uname -m x86_64
通常の DNS は暗号化されず改ざんが可能です.Intra は DNS を暗号化する DNS-over-HTTPS を Android 4.0 以降で利用できるようにするアプリです.
自分は基本的に出先では VPN を利用しているので必要ないかなと思うのですが,お手軽に無料でかつ古いデバイスにも対応しているので良さそうですね.ちなみにこの機能は Android Pie には標準搭載されているそうです.
#Wi-FiなんかでDNS改ざんして認証画面に飛ばしたりするようなのはどういう動きになるんだろう?
この記事で紹介されていたObscuraCamを試してみたところいい感じです.
画像の中の顔を認識してモザイクをかけてくれます.認識率は思ったよりも良さそうです.認識に漏れても簡単に手動でモザイクをかけることも出来ます.手動の場合,モザイクの他に黒塗りやマスク(ヒゲメガネ,スマイリー,マスクマン)も選べます.
イラストにも試してみましたがやはりあまり認識しません.でもおじさんは認識して以下の今井哲也(@imaitetsuya)さんのイラストだとそれぞれ蔵六と内藤だけモザイクに.
— 今井哲也 (@imaitetsuya) 2017年5月14日
— 今井哲也 (@imaitetsuya) 2017年6月6日
イベントとかで写真を撮ってすぐ投稿というときに良さそうです.
※この記事は「鹿児島Linux勉強会 2018.06」で発表したものに社会性フィルタをかけて加筆修正したものです.鹿児島らぐでは月一回位をペースにオフ会を行っています.
TermuxはAndroid上でLinux環境を構築するアプリケーションです.他に標準のLinuxディストリビューションがchroot環境で動作するソフトウェアが色々ある(Debian no root等)ので独自パッケージ管理なTermuxにはあまり惹かれていなかったのですが,API経由でAndroidデバイスの操作が出来るということを知り試してみました.
API利用時にはAPIアプリも導入が必要
※互換性の問題があるのでF-DroidとGoogle Playのアプリは混在させてはいけないらしいので注意.
Android 5.0 or newer.
Permissions
android.permission.INTERNET
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.WAKE_LOCK
android.permission.VIBRATE
android.permission.READ_EXTERNAL_STORAGE
Termux上で実行
$ pkg install termux-api
はじめTermux:APIで紹介されているものを確認しました.
パッケージを確認すると他にもコマンドがあったのでそちらも確認し直しました.
dpkg -L termux-api|grep /bin/|cut -d\/ -f8|sort
termux-audio-info
termux-battery-status
termux-brightness
termux-call-log
termux-camera-info
termux-camera-photo
termux-clipboard-get
termux-clipboard-set
termux-contact-list
termux-dialog
termux-download
termux-fingerprint
termux-infrared-frequencies
termux-infrared-transmit
termux-location
termux-media-player
termux-media-scan
termux-microphone-record
termux-notification
termux-notification-remove
termux-sensor
termux-share
termux-sms-inbox
termux-sms-send
termux-speech-to-text
termux-storage-get
termux-telephony-call
termux-telephony-cellinfo
termux-telephony-deviceinfo
termux-toast
termux-torch
termux-tts-engines
termux-tts-speak
termux-vibrate
termux-volume
termux-wallpaper
termux-wifi-connectioninfo
termux-wifi-enable
termux-wifi-scaninfo
基本的にjson形式で結果は帰って来ます.使い方がわからない場合は-h
オプションで簡易helpが表示されます.パーミッションを求められる場合はダイアログが表示されるので許可してあげる必要があります.(その回は失敗する)
SIMや赤外線通信の使えるAndroid 5以上の端末が手元にないのでその辺りの物は試せてません.
termux-audio-info
オーディオ情報の取得
$ termux-audio-info -h
Usage: termux-audio-info
Get information about audio capabilities.
$ termux-audio-info
{
"PROPERTY_OUTPUT_SAMPLE_RATE": "48000",
"PROPERTY_OUTPUT_FRAMES_PER_BUFFER": "960",
"STREAM_MUSIC_VOLUME": 1,
"STREAM_MUSIC_MAXVOLUME": 15,
"BLUETOOTH_A2DP_IS_ON": false,
"WIREDHEADSET_IS_CONNECTED": false,
"AUDIOTRACK_NATIVE_OUTPUT_SAMPLE_RATE": 48000
}
termux-battery-status
バッテリー情報の取得
$ termux-battery-status -h
Usage: termux-battery-status
Get the status of the device battery.
$ termux-battery-status
{
"health": "GOOD",
"percentage": 70,
"plugged": "PLUGGED_USB",
"status": "CHARGING",
"temperature": 36.900001525878906
}
termux-brightness
輝度の調整?0や255を指定しても動作が解らなかった
$ termux-brightness
Usage: termux-brightness brightness
Set the screen brightness between 0 and 255
$ termux-brightness 0
$ termux-brightness 255
termux-call-log
通話履歴の取得
$ termux-call-log -h
Usage: termux-call-log [-d] [-l limit] [-o offset]
List call log history
-l limit offset in call log list (default: 10)
-o offset offset in call log list (default: 0)
$ termux-call-log
termux-camera-info
カメラ情報が取得できる.カメラIDや解像度など.
$ termux-camera-info -h
Usage: termux-camera-info
Get information about device camera(s).
$ termux-camera-info
[
{
"id": "0",
"facing": "back",
"jpeg_output_sizes": [
{
"width": 5248,
"height": 3936
},
{
"width": 5248,
"height": 2952
},
{
"width": 3840,
"height": 2160
},
{
"width": 3264,
"height": 2448
},
{
"width": 2048,
"height": 1536
},
{
"width": 1920,
"height": 1080
},
{
"width": 1280,
"height": 720
},
{
"width": 640,
"height": 480
},
{
"width": 480,
"height": 320
},
{
"width": 320,
"height": 240
}
],
"focal_lengths": [
4.900000095367432
],
"auto_exposure_modes": [
"CONTROL_AE_MODE_ON",
"CONTROL_AE_MODE_ON_AUTO_FLASH",
"CONTROL_AE_MODE_ON_ALWAYS_FLASH",
"CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE"
],
"physical_size": {
"width": 6.219269752502441,
"height": 4.663866996765137
},
"capabilities": [
"backward_compatible"
]
},
{
"id": "1",
"facing": "front",
"jpeg_output_sizes": [
{
"width": 1920,
"height": 1080
},
{
"width": 1600,
"height": 1200
},
{
"width": 1280,
"height": 720
},
{
"width": 640,
"height": 480
},
{
"width": 480,
"height": 320
},
{
"width": 320,
"height": 240
}
],
"focal_lengths": [
1.809999942779541
],
"auto_exposure_modes": [
"CONTROL_AE_MODE_ON"
],
"physical_size": {
"width": 2.1837236881256104,
"height": 1.2063192129135132
},
"capabilities": [
"backward_compatible"
]
}
]
termux-camera-photo
カメラを使って写真撮影が出来る.引数にカメラID(option)や写真ファイル名(必須)が指定できる.写真はJPEG形式
$ termux-camera-photo -h
Usage: termux-camera-photo [-c camera-id] output-file
Take a photo and save it to a file in JPEG format.
-c camera-id ID of the camera to use (see termux-camera-info), default: 0
$ termux-camera-photo termix_photo.jpg
termux-clipboard-get
クリップボードの文字列を取得
$ termux-clipboard-get -h
Usage: termux-clipboard-get
Get the system clipboard text.
termux-clipboard-set
クリップボードに文字列を格納
$ termux-clipboard-set -h
Usage: termux-clipboard-set [text]
Set the system clipboard text. The text to set is either supplied as arguments or read from stdin if no arguments are given.
$ termux-clipboard-set hello
$ termux-clipboard-get
hello
termux-contact-list
全てのコンタクトリストが表示される
$ termux-contact-list -h
Usage: termux-contact-list
List all contacts.
$ termux-contact-list
[
{
"name": "MATOHARA Kenichiro",
"number": "0X0-XXXX-XXXX"
},
:
termux-dialog
ダイヤログを表示してその結果を取得できる.パスワード文字列などの指定も可能.
$ termux-dialog -h
Usage: termux-dialog [-i hint] [-m] [-p] [-t title]
Show a text entry dialog.
-i hint the input hint to show when the input is empty
-m use a textarea with multiple lines instead of a single
-p enter the input as a password
-t title the title to show for the input prompt
$ echo `termux-dialog`
hoge
$ echo `termux-dialog -i hint -m -t termux\ dialog`|od -xc
0000000 h o g e f u g a \n
6f68 6567 6620 6775 0a61
0000012
$ echo `termux-dialog -p`
passwordddd
termux-download
指定したURLからダウンロードが出来る.Androidのダウンロードアプリに渡される.(単にファイル取得ならwgetが入っている)
$ termux-download -h
Usage: termux-download [-d description] [-t title] url-to-download
Download a resource using the system download manager.
-d description description for the download request notification
-t title title for the download request notification
termux-fingerprint
指紋認証を行う?(未確認)
$ termux-fingerprint -h
Usage: termux-fingerprint
Use fingerprint sensor on device to check for authentication
NOTE: Only available on Marshmallow and later
$ termux-fingerprint
{
"errors": [
"ERROR_UNSUPPORTED_OS_VERSION"
],
"failed_attempts": 0,
"auth_result": "AUTH_RESULT_UNKNOWN"
termux-infrared-frequencies
赤外線通信情報を取得?(未確認)
$ termux-infrared-frequencies -h
Usage: termux-infrared-frequencies
Query the infrared transmitter's supported carrier frequencies.
$ termux-infrared-frequencies
[]
termux-infrared-transmit
赤外通信で送信する?(未確認)
$ termux-infrared-transmit -h
Usage: termux-infrared-transmit -f frequency pattern
Transmit an infrared pattern. The pattern is specified in comma-separated on/off intervals, such as '20,50,20,30'. Only patterns shorter than 2 seconds will be transmitted.
-f frequency IR carrier frequency in Hertz
termux-location
位置情報を取得.GPSを利用すると時間が掛かる.位置情報が取得できない場合はタイムアウト後何も帰ってこない.タイムアウトは65秒前後.
$ termux-location -h
usage: termux-location [-p provider] [-r request]
Get the device location.
-p provider location provider [gps/network/passive] (default: gps)
-r request kind of request to make [once/last/updates] (default: once)
$ termux-location -p gps
$ termux-location -p network
{
"latitude": 31.2529767,
"longitude": 130.8509959,
"altitude": 0.0,
"accuracy": 19.31999969482422,
"bearing": 0.0,
"speed": 0.0,
"elapsedMs": 39,
"provider": "network"
}
$ termux-location -p passive
{
"latitude": 34.77000045776367,
"longitude": 138.4600067138672,
"altitude": 0.0,
"accuracy": 976974.0625,
"bearing": 81.0,
"speed": 0.0,
"elapsedMs": 5,
"provider": "fused"
}
termux-media-player
メディアの再生,操作
$ termux-media-player -h
termux-media-player: Invalid cmd: '-h'
Usage: termux-media-player cmd [args]
help Shows this help
info Displays current playback information
play Resumes playback if paused
play <file> Plays specified media file
pause Pauses playback
stop Quits playback
$ termux-media-player play
No previous track to resume!
Please supply a new media file
$ termux-media-player play /storage/sdcard1/Android/data/com.bambuna.podcastaddict/files/podcast/エッジのたたないポッドキャスト/MzoRbgzFVe_3248.mp3
Now Playing: MzoRbgzFVe_3248.mp3
$ termux-media-player pause
Paused playback
$ termux-media-player play
Resumed playback
Track: MzoRbgzFVe_3248.mp3
Current Position: 00:27 / 13:39
$ termux-media-player info
Status: Playing
Track: MzoRbgzFVe_3248.mp3
Current Position: 01:10 / 13:39
$ termux-media-player info
No track currently!
$ termux-media-player play photo.jpg
Prepare failed.: status=0x1
termux-media-scan
メディアをスキャンする?
$ termux-media-scan -h
Usage: termux-media-scan [-v] [-r] file [file...]
Scan the specified file(s) and add it to the media content provider.
-r scan directories recursively
-v verbose mode
$ termux-media-scan -r /storage/sdcard1/Android/data/com.bambuna.podcastaddict/files/podcast/エッジのたたないポッドキャスト
Finished scanning 2 file(s)
$ termux-media-scan -r -v /storage/sdcard1/Android/data/com.bambuna.podcastaddict/files/podcast/エッジのたたないポッドキャスト
/storage/sdcard1/Android/data/com.bambuna.podcastaddict/files/podcast/エッジのたたないポッドキャスト
/storage/sdcard1/Android/data/com.bambuna.podcastaddict/files/podcast/エッジのたたないポッドキャスト/MzoRbgzFVe_3248.mp3
Finished scanning 2 file(s)
$ termux-media-player info
No track currently!
termux-microphone-record
録音をする.出力ファイル形式は3GPP
のよう
$ termux-microphone-record -h
Usage: termux-microphone-record [args]
Record using microphone on your device
-h Shows this help
-d Start recording w/ defaults
-f <file> Start recording to specific file
-l <limit> Start recording w/ specified limit (in seconds)
-i Get info about current recording
-q Quits recording
$ termux-microphone-record -d -f termux-record.mp3 -l 10
Recording started: /data/data/com.termux/files/home/termux-record
Max Duration: 00:10
$ termux-microphone-record -i
{
"isRecording": true,
"outputFile": "\/data\/data\/com.termux\/files\/home\/termux-record"
}
$ termux-microphone-record -i
{
"isRecording": false
}
file ./termux-record
./termux-record: ISO Media, MPEG v4 system, 3GPP
$ mv ./termux-record ./termux-record.3gpp
$ termux-media-player play ./termux-record.3gpp
Now Playing: termux-record.3gpp
termux-notification
通知を出力する.タイトル,メッセージ以外にもバイブレーションやサウンド,LEDなども操作できる.
$ termux-notification -h
Usage: termux-notification [options]
Display a system notification. Context text is read from stdin or specified using --content.
--action action action to execute when pressing the notification
--button1 text text to show on the first notification button
--button1-action action action to execute on the first notification button
--button2 text text to show on the second notification button
--button2-action action action to execute on the second notification button
--button3 text text to show on the third notification button
--button3-action action action to execute on the third notification button
--content content content to show in the notification. Read from stdin not specified here.
--id id notification id (will overwrite any previous notification with the same id)
--led-color rrggbb color of the blinking led as RRGGBB (default: none)
--led-on milliseconds number of milliseconds for the LED to be on while it's flashing (default: 800)
--led-off milliseconds number of milliseconds for the LED to be off while it's flashing (default: 800)
--on-delete action action to execute when the the notification is cleared
--priority prio notification priority (high/low/max/min/default)
--sound play a sound with the notification
--title title notification title to show
--vibrate pattern vibrate pattern, comma separated as in 500,1000,200
$ termux-notification --title hoge --content fuga
termux-notification-remove
termux-notification -id
で指定したidのメッセージを削除する.
$ termux-notification-remove -h
Usage: termux-notification-remove notification-id
Remove a notification previously shown with termux-notification --id.
$ termux-notification --content hoge --id tm01
$ termux-notification-remove tm01
termux-sensor
センサーの値を取得する.センサーの値は定期的に表示される(既定値は多分1秒間隔)
$ termux-sensor -h
Usage: termux-sensor
Get information about types of sensors as well as live data
-h, help Show this help
-a, all Listen to all sensors (WARNING! may have battery impact)
-c, cleanup Perform cleanup (release sensor resources)
-l, list Show list of available sensors
-s, sensors [,,,] Sensors to listen to (can contain just partial name)
-d, delay [ms] Delay time in milliseconds before receiving new sensor update
$ termux-sensor -l
{
"sensors": [
"BMA2X2 Accelerometer\/Temperature\/Double-tap",
"AK8963 Magnetometer",
"AK8963 Magnetometer Uncalibrated",
"BMG160 Gyroscope",
"BMG160 Gyroscope Uncalibrated",
"APDS-9930\/QPDS-T930 Proximity & Light",
"APDS-9930\/QPDS-T930 Proximity & Light",
"Gravity",
"Linear Acceleration",
"Rotation Vector",
"Step Detector",
"Step Counter",
"Significant Motion Detector",
"Game Rotation Vector",
"GeoMagnetic Rotation Vector",
"Orientation"
]
}
$ termux-sensor -s "BMA2X2 Accelerometer\/Temperature\/Double-tap"
No valid sensors were registered!
$ termux-sensor -s "AK8963 Magnetometer"
{
"AK8963 Magnetometer": {
"values": [
-11.248207092285156,
-37.157630920410156,
23.89850616455078
]
}
}
{
"AK8963 Magnetometer": {
"values": [
16.16058349609375,
-33.7738037109375,
-13.971900939941406
]
}
}
{
"AK8963 Magnetometer": {
"values": [
3.6207199096679688,
-38.532447814941406,
-17.789649963378906
]
}
}
^CCaught interrupt.. Finishing...
Performing sensor cleanup
Sensor cleanup successful!
$ termux-sensor -s "AK8963 Magnetometer Uncalibrated"
{
"AK8963 Magnetometer Uncalibrated": {
"values": [
-18.68438720703125,
-71.844482421875,
195.37200927734375,
-26.05126953125,
-30.462646484375,
221.81549072265625
]
}
}
{
"AK8963 Magnetometer Uncalibrated": {
"values": [
-18.6492919921875,
-70.87860107421875,
196.197509765625,
-26.05126953125,
-30.462646484375,
221.81549072265625
]
}
}
^CCaught interrupt.. Finishing...
Performing sensor cleanup
Sensor cleanup successful!
$ termux-sensor -s "BMG160 Gyroscope"
{
"BMG160 Gyroscope": {
"values": [
8.544921875E-4,
8.087158203125E-4,
8.544921875E-4
]
}
}
^CCaught interrupt.. Finishing...
Performing sensor cleanup
Sensor cleanup successful!
$ termux-sensor -s "BMG160 Gyroscope Uncalibrated"
{
"BMG160 Gyroscope Uncalibrated": {
"values": [
-0.006317138671875,
0.002044677734375,
0,
-0.006103517021983862,
0.0012359619140625,
-8.544921875E-4
]
}
}
^CCaught interrupt.. Finishing...
Performing sensor cleanup
Sensor cleanup successful!
$ termux-sensor -s "APDS-9930\/QPDS-T930 Proximity & Light"
No valid sensors were registered!
$ termux-sensor -s "Gravity"
{
"Gravity": {
"values": [
1.4136531352996826,
-1.045373558998108,
9.647754669189453
]
}
}
^CCaught interrupt.. Finishing...
Performing sensor cleanup
Sensor cleanup successful!
$ termux-sensor -s "Linear Acceleration"
{
"Linear Acceleration": {
"values": [
-0.0018668174743652344,
0.005246162414550781,
0.001544952392578125
]
}
}
^CCaught interrupt.. Finishing...
Performing sensor cleanup
Sensor cleanup successful!
$ termux-sensor -s "Rotation Vector"
{
"Rotation Vector": {
"values": [
0.07332251220941544,
-0.0574394166469574,
0.9877411723136902,
0.12526708841323853,
0.1745329201221466
]
}
}
^CCaught interrupt.. Finishing...
Performing sensor cleanup
Sensor cleanup successful!
$ termux-sensor -s "Step Detector"
{}
^CCaught interrupt.. Finishing...
Performing sensor cleanup
Sensor cleanup successful!
$ termux-sensor -s "Step Counter"
{
"Step Counter": {
"values": [
0
]
}
}
^CCaught interrupt.. Finishing...
Performing sensor cleanup
Sensor cleanup successful!
$ termux-sensor -s "Significant Motion Detector"
{}
{}
^CCaught interrupt.. Finishing...
Performing sensor cleanup
Sensor cleanup successful!
$ termux-sensor -s "Game Rotation Vector"
{
"Game Rotation Vector": {
"values": [
-0.04727154225111008,
-0.08051935583353043,
0.005690218415111303,
0.9956152439117432
]
}
}
^CCaught interrupt.. Finishing...
Performing sensor cleanup
Sensor cleanup successful!
$ termux-sensor -s "GeoMagnetic Rotation Vector"
{
"GeoMagnetic Rotation Vector": {
"values": [
0.07260913401842117,
-0.05879773199558258,
0.9851652383804321,
0.14394499361515045,
0.1745329201221466
]
}
}
^CCaught interrupt.. Finishing...
Performing sensor cleanup
Sensor cleanup successful!
$ termux-sensor -s "Orientation"
{
"Orientation": {
"values": [
194.80770874023438,
5.517017364501953,
9.214399337768555
]
}
}
^CCaught interrupt.. Finishing...
Performing sensor cleanup
Sensor cleanup successful!
termux-share
引数に指定されたファイルを共有する.
$ termux-share -h
Usage: termux-share [-a action] [-c content-type] [-d] [-t title] [file]
Share a file specified as argument or the text received on stdin if no file argument is given.
-a action which action to performed on the shared content:
edit/send/view (default:view)
-c content-type content-type to use (default: guessed from file extension,
text/plain for stdin)
-d share to the default receiver if one is selected
instead of showing a chooser
-t title title to use for shared content (default: shared file name)
$ termux-share photo.jpg
termux-sms-inbox
受信済のSMSメッセージを読み込む.(未確認.SIMなし端末で試したら0件表示された)
$ termux-sms-inbox -h
Usage: termux-sms-inbox [-d] [-l limit] [-n] [-o offset]
List received SMS messages.
-d show dates when messages were created
-l limit offset in sms list (default: 10)
-n show phone numbers
-o offset offset in sms list (default: 0)
$ termux-sms-inbox
termux-sms-send
smsメッセージを送信する.(未確認)
$ termux-sms-send -h
Usage: termux-sms-send -n number[,number2,number3,...] [text]
Send a SMS message to the specified recipient number(s). The text to send is either supplied as arguments or read from stdin if no arguments are given.
-n number(s) recipient number(s) - separate multiple numbers by commas
$ termux-sms-send -n 電話番号 message
termux-speech-to-text
音声認識した結果を表示する.端末上では空行しか見えないがodに流すと文字列が帰っているのが解る.多分英語のみ?
$ termux-speech-to-text -h
Usage: termux-speech-to-text
Converts speech to text, sending partial matches to stdout.
$ termux-speech-to-text
$ termux-speech-to-text|od -xc
0000000 \n \n \n H u d l \n
0a0a 480a 6475 0a6c
0000010
termux-storage-get
システムに指定したファイルを渡して開く?反応がない.
$ termux-storage-get -h
Usage: termux-storage-get output-file
Request a file from the system and output it to the specified file.
$ termux-storage-get photo.jpg
termux-telephony-call
指定した番号に電話を掛ける(mobile回線は未確認だが,電話のみでもアプリ選択画面にはなるのでWi-FiのみでもSIPなどで電話することは多分可能)
$ termux-telephony-call -h
Usage: termux-telephony-call <number>
Call a telephony number.
$ termux-telephony-call 電話番号
termux-telephony-cellinfo
電話基地局情報を取得?
$ termux-telephony-cellinfo -h
Usage: termux-telephony-cellinfo
Get information about all observed cell information from all radios on the device including the primary and neighboring cells.
$ termux-telephony-cellinfo
[
{
"type": "wcdma",
"registered": true,
"asu": 6,
"dbm": -101,
"level": 2,
"cid": 249053510,
"lac": 25994,
"mcc": 440,
"mnc": 10,
"psc": 33
}
]
termux-telephony-deviceinfo
テレフォニーデバイス情報を取得?
$ termux-telephony-deviceinfo -h
Usage: termux-telephony-deviceinfo
Get information about the telephony device.
$ termux-telephony-deviceinfo
{
"data_activity": "none",
"data_state": "disconnected",
"device_id": "357931051XXXXXXX",
"device_software_version": "81",
"phone_type": "gsm",
"network_operator": "",
"network_operator_name": "",
"network_country_iso": "",
"network_type": "unknown",
"network_roaming": false,
"sim_country_iso": "",
"sim_operator": "",
"sim_operator_name": "",
"sim_serial_number": null,
"sim_subscriber_id": null,
"sim_state": "absent"
}
termux-toast
Toast(一時的なポップアップ)メッセージを表示する
$ termux-toast -h
Usage: termux-toast [-s] [text]
Show text in a Toast (a transient popup). The text to show is either supplied as arguments or read from stdin if no arguments are given.
-s only show the toast for a short while
$ termux-toast hello
termux-torch
トーチをon/offする?手元の環境では反応がなかった.
$ termux-torch -h
Illegal parameter: -h
Usage: termux-torch [on | off]
Toggle LED Torch on device
$ termux-torch on
^C
termux-tts-engines
テキスト読み上げエンジン(tts)の一覧を表示する
$ termux-tts-engines -h
Usage: termux-tts-engines
Get information about the available text-to-speech (TTS) engines. The name of an engine may be given to the termux-tts-speak command using the -e option.
$ termux-tts-engines
[
{
"name": "com.google.android.tts",
"label": "Googleテキスト読み上げエンジン",
"default": false
},
{
"name": "jp.kddilabs.n2tts",
"label": "KDDILABS N2 TTS",
"default": true
}
]
termux-tts-speak
テキスト読み上げを行う.日本語に対応したttsであれば日本語も問題ない.標準入力からも受け付けるので記事や小説の読み上げも簡単.
$ termux-tts-speak こんにちは
$ echo '吾輩は猫である' | termux-tts-speak
$ w3m -dump https://www.aozora.gr.jp/cards/000148/files/789_14547.html | termux-tts-speak
termux-vibrate
バイブレートを実行.長さの指定やサイレントモードでも強行するモードもある.
$ termux-vibrate -h
Usage: termux-vibrate [-d duration] [-f]
Vibrate the device.
-d duration the duration to vibrate in ms (default:1000)
-f force vibration even in silent mode
$ termux-vibrate
termux-volume
ボリュームの変更.手元の環境では0〜15
で数字が大きいほど音量が大きくなった.16以上を指定しても15と同じ動きになった.
$ termux-volume -h
Invalid argument count
Usage: termux-volume stream volume
Change volume of audio stream
Valid audio streams are: alarm, music, notification, ring, system, call
Call w/o arguments to show information about each audio stream
$ termux-volume music 5
termux-wallpaper
壁紙を設定.位置合わせや切り抜き指定は出来ない.-u
が便利.
$ termux-wallpaper -h
Change wallpaper on your device
Usage: termux-wallpaper cmd [args]
-h show this help
-f <file> set wallpaper from file
-u <url> set wallpaper from url resource
-l set wallpaper for lockscreen (Nougat and later)
$ termux-wallpaper -u https://www.nasa.gov/sites/default/files/styles/full_width_feature/public/thumbnails/image/pia22422.jpg
Wallpaper set successfully!
termux-wifi-connectioninfo
Wi-Fi接続情報を表示.
$ termux-wifi-connectioninfo -h
Usage: termux-wifi-connectioninfo
Get information about the current wifi connection.
$ termux-wifi-connectioninfo
{
"bssid": "10:6f:3f:XX:XX:XX",
"frequency_mhz": 2462,
"ip": "192.168.2.211",
"link_speed_mbps": 54,
"mac_address": "68:76:4f:XX:XX:XX",
"network_id": 0,
"rssi": -51,
"ssid": "home-ap",
"ssid_hidden": false,
"supplicant_state": "COMPLETED"
}
termux-wifi-enable
Wi-Fiの有効無効設定.
$ termux-wifi-enable -h
Usage: termux-wifi-enable [true | false]
Toggle Wi-Fi On/Off
$ termux-wifi-enable false
$ termux-wifi-enable true
termux-wifi-scaninfo
Wi-Fiスキャン結果を表示.
$ termux-wifi-scaninfo -h
Usage: termux-wifi-scaninfo
Get information about the last wifi scan.
$ termux-wifi-scaninfo
[
{
"bssid": "12:6f:3f:XX:XX:XX",
"frequency_mhz": 2462,
"rssi": -55,
"ssid": "home-guest",
"timestamp": 2978153233
},
{
"bssid": "10:6f:3f:XX:XX:XX",
"frequency_mhz": 2462,
"rssi": -54,
"ssid": "home-ap",
"timestamp": 2978153243
},
{
"bssid": "10:6f:3f:XX:XX:XX",
"frequency_mhz": 2447,
"rssi": -78,
"ssid": "matohara",
"timestamp": 2978153249
}
]
Androidアプリケーションを作成しなくてもちょっとしたことならこのAPIの組み合わせで遊ぶことができそうです.(bash+Zenityみたいな?ちょっとちがうか)
Termux:Task/Boot等と組み合わせると更に活用の幅は広がりそうです.(未確認)
TermuxはAndroid上でLinux環境が構築できる独自パッケージシステムなアプリケーションです.端末ソフトも同梱されています.Termux-apiを使うとshellでAndroidの操作が出来てちょっと面白いのですが,Androidのタッチパネルで文字を打つのが面倒.リモート操作したいのでsshdが動かないか試してみました.
パッケージを検索してみます.定番のOpenSSHとDropbearが使えそうです.
$ pkg search ssh Hit:1 https://termux.net stable InRelease Reading package lists... Done Building dependency tree Reading state information... Done All packages are up to date. Sorting... Done Full Text Search... Done autossh/stable 1.4f arm Automatically restart SSH sessions and tunnels corkscrew/stable 2.0-1 arm A tool for tunneling SSH through HTTP proxies dropbear/stable,now 2018.76-1 arm [installed] Small SSH server and client libssh/stable 0.7.5-1 arm Tiny C SSH library libssh-dev/stable 0.7.5-1 arm Development files for libssh openssh/stable 7.7p1-2 arm Secure shell for logging into a remote machine sshpass/stable 1.06 arm Noninteractive ssh password provider
今回は操作ができればいいので消費リソースの少ないDropbearを選択しました.
$ pkg install dropbear
$ dropbear -h Dropbear server v2018.76 https://matt.ucc.asn.au/dropbear/dropbear.html Usage: dropbear [options] -b bannerfile Display the contents of bannerfile before user login (default: none) -r keyfile Specify hostkeys (repeatable) defaults: dss /data/data/com.termux/files/usr/etc/dropbear/dropbear_dss_host_key rsa /data/data/com.termux/files/usr/etc/dropbear/dropbear_rsa_host_key ecdsa /data/data/com.termux/files/usr/etc/dropbear/dropbear_ecdsa_host_key -R Create hostkeys as required -F Don't fork into background (Syslog support not compiled in, using stderr) -w Disallow root logins -G Restrict logins to members of specified group -T Maximum authentication tries (default 10) -j Disable local port forwarding -k Disable remote port forwarding -a Allow connections to forwarded ports from any host -c command Force executed command -p [address:]port Listen on specified tcp port (and optionally address), up to 10 can be specified (default port is 8022 if none specified) -P PidFile Create pid file PidFile (default /data/data/com.termux/files/usr/var/run/dropbear.pid) -i Start for inetd -W <receive_window_buffer> (default 24576, larger may be faster, max 1MB) -K <keepalive> (0 is never, default 0, in seconds) -I <idle_timeout> (0 is never, default 0, in seconds) -V Version
鍵を用意します.普通に~/.ssh/authorized_keys
に公開鍵を登録すれば良いようです.PCで作成した鍵ペアの公開鍵を登録しました.
$ cd && pwd /data/data/com.termux/files/home $ ls -lA ~/.ssh total 4 -rw------- 1 u0_a235 u0_a235 170 Jun 20 03:58 authorized_keys
sshデーモンを起動します.オプションは適当でポート番号を2222番にしています.
$ dropbear -w -T 2 -j -k -p 2222 -I 600
Androidのipアドレスを確認して,
$ ip r default via 192.168.2.1 dev wlan0 metric 322 100.93.0.128/26 dev rmnet0 proto kernel scope link src 100.93.0.160 192.168.2.0/24 dev wlan0 proto kernel scope link src 192.168.2.211 metric 322
PCからこんな感じで接続してみると繋がりました!
$ ssh u0_a235@192.168.2.211 -p 2222 -i ~/.ssh/id_ed25519_termux
これで操作が楽に&端末の結果を保存しやすくなりました.
追記)
Dropbearを止める
$ pgrep dropbear 10925 10958 $ pkill dropbear
Android端末の容量が少なくてGoogle Playがアプリを更新できないとエラーを出ています.確認すると「その他のファイル」が妙に容量を食っている.見ると「mhenv」というフォルダが殆どを占めています.
開発者も土が有効な状態でadb shell
で中に入って見てみると実体は/storage/emulated/legacy/mhenv/
ここで12GB以上です.
$ adb shell
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
shell@g2:/ $ cd /storage/emulated/legacy
$ du -ms mhenv
12467 mhenv
中を見ると「YMO!」(小説家になろうなどのオンライン小説リーダ)のデータが12GB以上食っている!
テキストデータだけじゃないの?と中を見るとこんな感じで更新時に毎回バックアップを取っているような感じです.
$ ls -l 猫正宗
-rw-rw---- root sdcard_r 988721 2018-05-24 13:14 隣の部屋の女騎士は、異世界人で飲み友達_n2059ek.txt
-rw-rw---- root sdcard_r 288071 2017-12-16 14:12 隣の部屋の女騎士は、異世界人で飲み友達_n2059ek_rev20171217001107.txt
-rw-rw---- root sdcard_r 325287 2017-12-23 23:52 隣の部屋の女騎士は、異世界人で飲み友達_n2059ek_rev20171226002611.txt
-rw-rw---- root sdcard_r 341974 2017-12-26 00:26 隣の部屋の女騎士は、異世界人で飲み友達_n2059ek_rev20171228101117.txt
:
恐らく「${作者名}/{タイトル}${小説コード}.txt」が最新で,「${作者名}/{タイトル}${小説コード}_rev${年月日??????}.txt」が古いもの.
念の為バックアップを取って,findで……無かったorz
$ find . -name "*_rev??????????.txt" -ls
ディレクトリ階層も決まっているので,こんな感じでlsで確認してから消してみました.12.5GB近かったのが0.5GB以下になりました.
$ ls */*_rev??????????????.txt
$ rm */*_rev??????????????.txt
$ du -ms .
493 .
アプリケーション側の動作も問題無さそうです.
ちなみにこの後Androidアプリケーション側の設定を確認すると,「データ保存先変更」で端末によってはSD Cardに移動できそうです.手元の端末では変更不可でした.
それと,「改定時ファイル保存設定」と「古い稿を残す基準を設定」といものがあり,この設定だけで良かった気がします…….