ADB Shell メモ

Androidをadbコマンドから操作するための自分用のメモです。

- /system のリマウント

```bash
mount -o rw,remount /system
```

- セキュリティロックの解除

```bash
sqlite3 /data/system/locksettings.db "UPDATE locksettings SET value = '1' WHERE name = 'lockscreen.disabled'"
sqlite3 /data/system/locksettings.db "UPDATE locksettings SET value = '0' WHERE name = 'lockscreen.password_type'"
sqlite3 /data/system/locksettings.db "UPDATE locksettings SET value = '0' WHERE name = 'lockscreen.password_type_alternate'"
echo "" > /data/system/password.key
```

- Tetheringの設定ページを開く ([その他](http://my.oschina.net/kylinhuang/blog?disp=2&p=1&catalog=402349))

```bash
am start -n 'com.android.settings/com.android.settings.TetherSettings'
```

- Location設定のページを開く ([その他](http://too.tokyo/android/2015/01/16/android-provider-settings%E3%80%80%E8%A8%AD%E5%AE%9A%E7%94%BB%E9%9D%A2%E3%82%92adb-shell-am%E3%81%A7%E9%96%8B%E3%81%8F/))

```bash
am start -a android.settings.LOCATION_SOURCE_SETTINGS
```

- スクリーンのTurn off

```bash
SCREEN_STATUS=`dumpsys power | grep mScreenOn`
if [[ $SCREEN_STATUS == *mScreenOn=true* ]]; then
  echo "Turn off the screen"
  # Turn off the screen
  input keyevent 26
fi

# input keyevent 26 #turn on the screen
```

-  apkに含まれるActivityの一覧を取得

```bash
android-sdk/build-tools/<version>/aapt dump xmltree <apk-file> AndroidManifest.xml
```

- タイムゾーンの設定

```bash
setprop persist.sys.timezone "America/Los_Angeles"
```

- 音量とディスプレイのタイムアウト

```bash
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "UPDATE system SET value = '7' WHERE name = 'volume_music'"
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "UPDATE system SET value = '0' WHERE name = 'volume_ring'"
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "UPDATE system SET value = '7' WHERE name = 'volume_system'"
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "UPDATE system SET value = '7' WHERE name = 'volume_voice'"
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "UPDATE system SET value = '0' WHERE name = 'volume_alarm'"
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "UPDATE system SET value = '0' WHERE name = 'volume_notification'"
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "UPDATE system SET value = '0' WHERE name = 'volume_bluetooth_sco'"
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "UPDATE system SET value = '-1' WHERE name = 'screen_off_timeout'"
```

- Home画面に戻る

```bash
am start com.android.launcher/com.android/launcher2  #デバイスによって異なるので、要調整
```

- SystemUIを殺す

```bash
# ProcID = 79 # for HONEYCOMB AND OLDER
ProcID = 42 # for ICS AND NEWER
service call activity <ProcID> s16 com.android.systemui
```

- SystemUIを復活

```bash
am startservice -n com.android.systemui/.SystemUIService
```

- スクリーンキャプチャ

```bash
screencap -p /sdcard/capture.png
```

- 画面のタッチ

```bash
input touchscreen tap <x> <y>
```

- 画面をスワイプ

```bash
input touchscreen swipe <x1> <y1> <x2> <y2>
```

- BluetoothのON/OFF

```bash
am start -a android.bluetooth.adapter.action.REQUEST_ENABLE
```

- Wifiの設定画面を開く

```bash
am start -n com.android.settings/.wifi.WifiSettings
```

- Wifiの取得

```bash
am start -n com.android.settings/.wifi.WifiInfo
```

- Wifiのステータス

```bash
am start -n com.android.settings/.wifi.WifiStatusTest
```

- 言語設定を開く

```bash
am start -n com.android.settings/.LanguageSettings
```

- 開発者オプションを開く

```bash
am start -n com.android.settings/.DevelopmentSettings
```

- 日付設定を開く

```bash
am start -n com.android.settings/.DateTimeSettingsSetupWizard
```

- 文字の入力 ("Hello World"と入力させる)
[※キーコード一覧](http://developer.android.com/reference/android/view/KeyEvent.html)

```bash
input text "Hello"
input keyevent 62  #space
input text "World"
input keyevent 66  #enter
```

- adbd をリスタートさせる (from [stack overflow](http://stackoverflow.com/a/15343729))

```bash
~$ adb shell id
uid=2000(shell) gid=2000(shell)

~$ adb root
restarting adbd as root

~$ adb shell id
uid=0(root) gid=0(root)

~$ adb shell 'setprop service.adb.root 0; setprop ctl.restart adbd'

~$ adb shell id
uid=2000(shell) gid=2000(shell)
```

- デバイスの再起動無しに、アプリケーション環境をリブートさせる
https://developer.mozilla.org/ja/Firefox_OS/Debugging/Installing_ADB

```bash
adb shell killall b2g
```

- adbの認証キー (SSHプライベートキー)

```bash
adb shell cat /data/misc/adb/adb_keys
```

- タイムゾーンの変更

```bash
~$ adb root
restarting adbd as root

~$ adb shell "setprop persist.sys.timezone \"America/Chicago\""
```


- プログラムのサービスをスタート

```bash
~$ adb shell "am startservice com.some.package.name/.YourServiceSubClassName"
```