blob: 5ce7f5244ebf0de8f0b8d9a4f70be43adc29e3ad [file] [log] [blame]
Nicolas Geoffrayd2d62d12015-03-18 11:23:56 +00001#!/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
Roland Levillain2aab06b2017-03-01 14:14:10 +000020# 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
Nicolas Geoffrayd2d62d12015-03-18 11:23:56 +000028echo -e "${green}Date on device${nc}"
29adb shell date
30
Roland Levillain2aab06b2017-03-01 14:14:10 +000031host_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
Nicolas Geoffrayc2d199b2017-05-22 16:05:06 +010041# Kill logd first, so that when we set the adb buffer size later in this file,
42# it is brought up again.
43echo -e "${green}Killing logd, seen leaking on fugu/N${nc}"
44adb shell killall -9 /system/bin/logd
45
Roland Levillain2aab06b2017-03-01 14:14:10 +000046# Update date on device if the difference with host is more than one hour.
47if [ $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
50fi
51
Nicolas Geoffrayd2d62d12015-03-18 11:23:56 +000052echo -e "${green}Turn off selinux${nc}"
53adb shell setenforce 0
54adb shell getenforce
55
Nicolas Geoffray0a38a0e2015-03-25 17:22:34 +000056echo -e "${green}Setting local loopback${nc}"
57adb shell ifconfig lo up
58adb shell ifconfig
59
Roland Levillain30d26962018-03-29 19:36:29 +010060# Ensure netd is running, as otherwise the logcat would be spammed
61# with the following messages on devices running Android O:
Roland Levillain6f7d8b72018-03-15 15:45:00 +000062#
Roland Levillain30d26962018-03-29 19:36:29 +010063# E NetdConnector: Communications error: java.io.IOException: No such file or directory
64# E mDnsConnector: Communications error: java.io.IOException: No such file or directory
Roland Levillain6f7d8b72018-03-15 15:45:00 +000065#
Roland Levillain30d26962018-03-29 19:36:29 +010066# Netd was initially disabled as an attempt to solve issues with
67# network-related libcore and JDWP tests failing on devices running
68# Android O (MR1) (see b/74725685). These tests are currently
69# disabled. When a better solution has been found, we should remove
70# the following lines.
71echo -e "${green}Turning on netd${nc}"
72adb shell start netd
Roland Levillain6f7d8b72018-03-15 15:45:00 +000073adb shell getprop init.svc.netd
74
Nicolas Geoffrayd2d62d12015-03-18 11:23:56 +000075echo -e "${green}List properties${nc}"
76adb shell getprop
Nicolas Geoffrayb8703d62015-10-30 11:18:52 +000077
78echo -e "${green}Uptime${nc}"
79adb shell uptime
80
Nicolas Geoffray7ea57472016-02-24 09:53:09 +000081echo -e "${green}Battery info${nc}"
82adb shell dumpsys battery
83
Nicolas Geoffray80d9c852016-03-04 15:28:35 +000084echo -e "${green}Setting adb buffer size to 32MB${nc}"
85adb logcat -G 32M
86adb logcat -g
87
88echo -e "${green}Removing adb spam filter${nc}"
89adb logcat -P ""
90adb logcat -p
91
Nicolas Geoffrayb8703d62015-10-30 11:18:52 +000092echo -e "${green}Kill stalled dalvikvm processes${nc}"
Nicolas Geoffrayfe6f0b62016-03-07 13:33:37 +000093# 'ps' on M can sometimes hang.
94timeout 2s adb shell "ps"
95if [ $? = 124 ]; then
96 echo -e "${green}Rebooting device to fix 'ps'${nc}"
97 adb reboot
98 adb wait-for-device root
99else
100 processes=$(adb shell "ps" | grep dalvikvm | awk '{print $2}')
101 for i in $processes; do adb shell kill -9 $i; done
102fi