10cfeb25707c87af285cc993967be486d9c95a176Omari Stephens#!/bin/bash
20cfeb25707c87af285cc993967be486d9c95a176Omari Stephens
30cfeb25707c87af285cc993967be486d9c95a176Omari Stephens# Copyright (C) 2009 The Android Open Source Project
40cfeb25707c87af285cc993967be486d9c95a176Omari Stephens#
50cfeb25707c87af285cc993967be486d9c95a176Omari Stephens# Licensed under the Apache License, Version 2.0 (the "License");
60cfeb25707c87af285cc993967be486d9c95a176Omari Stephens# you may not use this file except in compliance with the License.
70cfeb25707c87af285cc993967be486d9c95a176Omari Stephens# You may obtain a copy of the License at
80cfeb25707c87af285cc993967be486d9c95a176Omari Stephens#
90cfeb25707c87af285cc993967be486d9c95a176Omari Stephens#      http://www.apache.org/licenses/LICENSE-2.0
100cfeb25707c87af285cc993967be486d9c95a176Omari Stephens#
110cfeb25707c87af285cc993967be486d9c95a176Omari Stephens# Unless required by applicable law or agreed to in writing, software
120cfeb25707c87af285cc993967be486d9c95a176Omari Stephens# distributed under the License is distributed on an "AS IS" BASIS,
130cfeb25707c87af285cc993967be486d9c95a176Omari Stephens# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
140cfeb25707c87af285cc993967be486d9c95a176Omari Stephens# See the License for the specific language governing permissions and
150cfeb25707c87af285cc993967be486d9c95a176Omari Stephens# limitations under the License.
160cfeb25707c87af285cc993967be486d9c95a176Omari Stephens
170cfeb25707c87af285cc993967be486d9c95a176Omari Stephensexport ADB_OPTS="$@"
180cfeb25707c87af285cc993967be486d9c95a176Omari Stephens
190cfeb25707c87af285cc993967be486d9c95a176Omari Stephens# run adb with options
200cfeb25707c87af285cc993967be486d9c95a176Omari Stephensfunction a { $DRY_RUN adb $ADB_OPTS "$@"; }
210cfeb25707c87af285cc993967be486d9c95a176Omari Stephens
220cfeb25707c87af285cc993967be486d9c95a176Omari Stephens# restart adb as root and wait for it to come back again
230cfeb25707c87af285cc993967be486d9c95a176Omari Stephensfunction adb_root
240cfeb25707c87af285cc993967be486d9c95a176Omari Stephens{
250cfeb25707c87af285cc993967be486d9c95a176Omari Stephens    root_status=$(a root)
26bf5ac2aac32cc0a2d8a7221cb0891ed1bb3a2f24Omari Stephens    if [ "$root_status" != "adbd is already running as root" ]; then
270cfeb25707c87af285cc993967be486d9c95a176Omari Stephens        echo -n "Restarting adb as root..."
280cfeb25707c87af285cc993967be486d9c95a176Omari Stephens        sleep 2
290cfeb25707c87af285cc993967be486d9c95a176Omari Stephens        a 'wait-for-device'
300cfeb25707c87af285cc993967be486d9c95a176Omari Stephens        echo done.
310cfeb25707c87af285cc993967be486d9c95a176Omari Stephens    fi
320cfeb25707c87af285cc993967be486d9c95a176Omari Stephens}
330cfeb25707c87af285cc993967be486d9c95a176Omari Stephens
34