Nicolas Geoffray | d2d62d1 | 2015-03-18 11:23:56 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2015 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | green='\033[0;32m' |
| 18 | nc='\033[0m' |
| 19 | |
Roland Levillain | 2aab06b | 2017-03-01 14:14:10 +0000 | [diff] [blame] | 20 | # Setup as root, as the next buildbot step (device cleanup) requires it. |
| 21 | # This is also required to set the date, if needed. |
| 22 | adb root |
| 23 | adb wait-for-device |
| 24 | |
| 25 | echo -e "${green}Date on host${nc}" |
| 26 | date |
| 27 | |
Nicolas Geoffray | d2d62d1 | 2015-03-18 11:23:56 +0000 | [diff] [blame] | 28 | echo -e "${green}Date on device${nc}" |
| 29 | adb shell date |
| 30 | |
Roland Levillain | 2aab06b | 2017-03-01 14:14:10 +0000 | [diff] [blame] | 31 | host_seconds_since_epoch=$(date -u +%s) |
| 32 | device_seconds_since_epoch=$(adb shell date -u +%s) |
| 33 | |
| 34 | abs_time_difference_in_seconds=$(expr $host_seconds_since_epoch - $device_seconds_since_epoch) |
| 35 | if [ $abs_time_difference_in_seconds -lt 0 ]; then |
| 36 | abs_time_difference_in_seconds=$(expr 0 - $abs_time_difference_in_seconds) |
| 37 | fi |
| 38 | |
| 39 | seconds_per_hour=3600 |
| 40 | |
Nicolas Geoffray | c2d199b | 2017-05-22 16:05:06 +0100 | [diff] [blame] | 41 | # Kill logd first, so that when we set the adb buffer size later in this file, |
| 42 | # it is brought up again. |
| 43 | echo -e "${green}Killing logd, seen leaking on fugu/N${nc}" |
| 44 | adb shell killall -9 /system/bin/logd |
| 45 | |
Roland Levillain | 2aab06b | 2017-03-01 14:14:10 +0000 | [diff] [blame] | 46 | # Update date on device if the difference with host is more than one hour. |
| 47 | if [ $abs_time_difference_in_seconds -gt $seconds_per_hour ]; then |
| 48 | echo -e "${green}Update date on device${nc}" |
| 49 | adb shell date -u @$host_seconds_since_epoch |
| 50 | fi |
| 51 | |
Nicolas Geoffray | d2d62d1 | 2015-03-18 11:23:56 +0000 | [diff] [blame] | 52 | echo -e "${green}Turn off selinux${nc}" |
| 53 | adb shell setenforce 0 |
| 54 | adb shell getenforce |
| 55 | |
Nicolas Geoffray | 0a38a0e | 2015-03-25 17:22:34 +0000 | [diff] [blame] | 56 | echo -e "${green}Setting local loopback${nc}" |
| 57 | adb shell ifconfig lo up |
| 58 | adb shell ifconfig |
| 59 | |
Nicolas Geoffray | d2d62d1 | 2015-03-18 11:23:56 +0000 | [diff] [blame] | 60 | echo -e "${green}List properties${nc}" |
| 61 | adb shell getprop |
Nicolas Geoffray | b8703d6 | 2015-10-30 11:18:52 +0000 | [diff] [blame] | 62 | |
| 63 | echo -e "${green}Uptime${nc}" |
| 64 | adb shell uptime |
| 65 | |
Nicolas Geoffray | 7ea5747 | 2016-02-24 09:53:09 +0000 | [diff] [blame] | 66 | echo -e "${green}Battery info${nc}" |
| 67 | adb shell dumpsys battery |
| 68 | |
Nicolas Geoffray | 80d9c85 | 2016-03-04 15:28:35 +0000 | [diff] [blame] | 69 | echo -e "${green}Setting adb buffer size to 32MB${nc}" |
| 70 | adb logcat -G 32M |
| 71 | adb logcat -g |
| 72 | |
| 73 | echo -e "${green}Removing adb spam filter${nc}" |
| 74 | adb logcat -P "" |
| 75 | adb logcat -p |
| 76 | |
Nicolas Geoffray | b8703d6 | 2015-10-30 11:18:52 +0000 | [diff] [blame] | 77 | echo -e "${green}Kill stalled dalvikvm processes${nc}" |
Nicolas Geoffray | fe6f0b6 | 2016-03-07 13:33:37 +0000 | [diff] [blame] | 78 | # 'ps' on M can sometimes hang. |
| 79 | timeout 2s adb shell "ps" |
| 80 | if [ $? = 124 ]; then |
| 81 | echo -e "${green}Rebooting device to fix 'ps'${nc}" |
| 82 | adb reboot |
| 83 | adb wait-for-device root |
| 84 | else |
| 85 | processes=$(adb shell "ps" | grep dalvikvm | awk '{print $2}') |
| 86 | for i in $processes; do adb shell kill -9 $i; done |
| 87 | fi |