Skip to content

Instantly share code, notes, and snippets.

@bertrandmartel
Last active August 29, 2015 14:27
Show Gist options
  • Save bertrandmartel/b2231967f182db2d6b13 to your computer and use it in GitHub Desktop.
Save bertrandmartel/b2231967f182db2d6b13 to your computer and use it in GitHub Desktop.
[ SHELL ] Start / Stop / show service status (usage is : ./android_services.sh [start/stop/ps]
#!/bin/bash
#put your service intent name here
declare -a start_service_intent=("fr.bouyguestelecom.bboxapi.StartService" "fr.bouyguestelecom.bboxapi.rest.StartService" "fr.bouyguestelecom.tv.bboxiot.IBboxIotService")
#put your service / app to be stopped package-name here
declare -a stop_service_package=("fr.bouyguestelecom.bboxapi.main" "fr.bouyguestelecom.bboxapi.rest" "fr.bouyguestelecom.bboxapi" "fr.bouyguestelecom.tv.bboxiot.main")
SERVICE_PACKAGE_PREFIX="fr.bouyguestelecom"
if [ -z $1 ]; then
echo -ne "\x1B[01;29m"
printf "$0 : parameter error - task name required\n\n"
printf "Usage: start_stop_services.sh [task]\n\n"
printf "Task list:\n"
printf "\tstart : start services\n"
printf "\tstop : stop services\n"
printf "\tps : show service process\n\n"
echo -ne "\x1B[0m"
fi
if [ "$1" == "start" ]; then
echo -e "\x1B[01;32mstarting services..."
for service_intent in "${start_service_intent[@]}"
do
echo "starting ${service_intent} ..."
adb shell am startservice -a "${service_intent}" --user 0
done
echo -ne "\x1B[0m"
elif [ "$1" == "stop" ]; then
echo -e "\x1B[31mstopping services..."
for service_package in "${stop_service_package[@]}"
do
echo "stopping ${service_package} ..."
adb shell am force-stop "${service_package}"
done
echo -ne "\x1B[0m"
elif [ "$1" == "ps" ]; then
echo -ne "\x1B[01;93m"
adb shell "ps | grep '$SERVICE_PACKAGE_PREFIX.*'"
echo -ne "\x1B[0m"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment