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 17green='\033[0;32m' 18nc='\033[0m' 19 20# Setup as root, as the next buildbot step (device cleanup) requires it. 21# This is also required to set the date, if needed. 22adb root 23adb wait-for-device 24 25echo -e "${green}Date on host${nc}" 26date 27 28echo -e "${green}Date on device${nc}" 29adb shell date 30 31host_seconds_since_epoch=$(date -u +%s) 32device_seconds_since_epoch=$(adb shell date -u +%s) 33 34abs_time_difference_in_seconds=$(expr $host_seconds_since_epoch - $device_seconds_since_epoch) 35if [ $abs_time_difference_in_seconds -lt 0 ]; then 36 abs_time_difference_in_seconds=$(expr 0 - $abs_time_difference_in_seconds) 37fi 38 39seconds_per_hour=3600 40 41# Update date on device if the difference with host is more than one hour. 42if [ $abs_time_difference_in_seconds -gt $seconds_per_hour ]; then 43 echo -e "${green}Update date on device${nc}" 44 adb shell date -u @$host_seconds_since_epoch 45fi 46 47echo -e "${green}Turn off selinux${nc}" 48adb shell setenforce 0 49adb shell getenforce 50 51echo -e "${green}Setting local loopback${nc}" 52adb shell ifconfig lo up 53adb shell ifconfig 54 55echo -e "${green}List properties${nc}" 56adb shell getprop 57 58echo -e "${green}Uptime${nc}" 59adb shell uptime 60 61echo -e "${green}Battery info${nc}" 62adb shell dumpsys battery 63 64echo -e "${green}Killing logd, seen leaking on fugu/N${nc}" 65adb shell killall -9 /system/bin/logd 66 67echo -e "${green}Setting adb buffer size to 32MB${nc}" 68adb logcat -G 32M 69adb logcat -g 70 71echo -e "${green}Removing adb spam filter${nc}" 72adb logcat -P "" 73adb logcat -p 74 75echo -e "${green}Kill stalled dalvikvm processes${nc}" 76# 'ps' on M can sometimes hang. 77timeout 2s adb shell "ps" 78if [ $? = 124 ]; then 79 echo -e "${green}Rebooting device to fix 'ps'${nc}" 80 adb reboot 81 adb wait-for-device root 82else 83 processes=$(adb shell "ps" | grep dalvikvm | awk '{print $2}') 84 for i in $processes; do adb shell kill -9 $i; done 85fi 86