From ded5d2de157a46378f9dd1c666d8baf68e3fd898 Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Fri, 24 May 2024 14:13:47 -0700 Subject: [PATCH] More envsetup.sh cleanup -- move these to standalone scripts Bug: 340648588 Test: Run them Change-Id: I11d086bcaa2f9eb52f7c556d94666321010b75fa --- bin/core | 48 +++++++++++++++++++++++++++++++++++++++++ bin/coredump_enable | 32 +++++++++++++++++++++++++++ bin/coredump_setup | 45 ++++++++++++++++++++++++++++++++++++++ bin/getlastscreenshot | 33 ++++++++++++++++++++++++++++ bin/getprebuilt | 18 ++++++++++++++++ bin/getscreenshotpath | 26 ++++++++++++++++++++++ bin/getsdcardpath | 26 ++++++++++++++++++++++ bin/gettargetarch | 18 ++++++++++++++++ bin/hmm | 16 ++++++++------ bin/is64bit | 32 +++++++++++++++++++++++++++ bin/isviewserverstarted | 26 ++++++++++++++++++++++ bin/key_back | 26 ++++++++++++++++++++++ bin/key_home | 26 ++++++++++++++++++++++ bin/key_menu | 26 ++++++++++++++++++++++ bin/startviewserver | 30 ++++++++++++++++++++++++++ bin/stopviewserver | 26 ++++++++++++++++++++++ bin/systemstack | 21 ++++++++++++++++++ 17 files changed, 468 insertions(+), 7 deletions(-) create mode 100755 bin/core create mode 100755 bin/coredump_enable create mode 100755 bin/coredump_setup create mode 100755 bin/getlastscreenshot create mode 100755 bin/getprebuilt create mode 100755 bin/getscreenshotpath create mode 100755 bin/getsdcardpath create mode 100755 bin/gettargetarch create mode 100755 bin/is64bit create mode 100755 bin/isviewserverstarted create mode 100755 bin/key_back create mode 100755 bin/key_home create mode 100755 bin/key_menu create mode 100755 bin/startviewserver create mode 100755 bin/stopviewserver create mode 100755 bin/systemstack diff --git a/bin/core b/bin/core new file mode 100755 index 000000000..01dbd13e3 --- /dev/null +++ b/bin/core @@ -0,0 +1,48 @@ +#!/bin/bash + +# Copyright (C) 2024 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# core - send SIGV and pull the core for process +# $1 = PID of process (e.g., $(pid mediaserver)) +# +# NOTE: coredump_setup must be called once per boot for core dumps to be +# enabled globally. + +set -e + +PID=$1; + +if [ -z "$PID" ]; then + printf "Expecting a PID!\n"; + exit 1 +fi; + +CORENAME=core.$PID; +COREPATH=/cores/$CORENAME; +SIG=SEGV; + +coredump_enable $1; + +done=0; +while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do + printf "\tSending SIG%s to %d...\n" $SIG $PID; + adb shell kill -$SIG $PID; + sleep 1; +done; + +adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done" +echo "Done: core is under $COREPATH on device."; + + diff --git a/bin/coredump_enable b/bin/coredump_enable new file mode 100755 index 000000000..da63a0c3c --- /dev/null +++ b/bin/coredump_enable @@ -0,0 +1,32 @@ +#!/bin/bash + +# Copyright (C) 2024 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# coredump_enable - enable core dumps for the specified process +# $1 = PID of process (e.g., $(pid mediaserver)) +# +# NOTE: coredump_setup must have been called as well for a core +# dump to actually be generated. + +set -e + +PID=$1; +if [ -z "$PID" ]; then + printf "Expecting a PID!\n"; + exit 1 +fi; +echo "Setting core limit for $PID to infinite..."; +adb shell /system/bin/ulimit -P $PID -c unlimited + diff --git a/bin/coredump_setup b/bin/coredump_setup new file mode 100755 index 000000000..76476594d --- /dev/null +++ b/bin/coredump_setup @@ -0,0 +1,45 @@ +#!/bin/bash + +# Copyright (C) 2024 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# coredump_setup - enable core dumps globally for any process +# that has the core-file-size limit set correctly +# +# NOTE: You must call also coredump_enable for a specific process +# if its core-file-size limit is not set already. +# NOTE: Core dumps are written to ramdisk; they will not survive a reboot! + +set -e + +echo "Getting root..."; +adb root; +adb wait-for-device; + +echo "Remounting root partition read-write..."; +adb shell mount -w -o remount -t rootfs rootfs; +sleep 1; +adb wait-for-device; +adb shell mkdir -p /cores; +adb shell mount -t tmpfs tmpfs /cores; +adb shell chmod 0777 /cores; + +echo "Granting SELinux permission to dump in /cores..."; +adb shell restorecon -R /cores; + +echo "Set core pattern."; +adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern'; + +echo "Done." + diff --git a/bin/getlastscreenshot b/bin/getlastscreenshot new file mode 100755 index 000000000..dfe9a6b3d --- /dev/null +++ b/bin/getlastscreenshot @@ -0,0 +1,33 @@ +#!/bin/bash + +# Copyright (C) 2024 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# coredump_enable - enable core dumps for the specified process +# $1 = PID of process (e.g., $(pid mediaserver)) +# +# NOTE: coredump_setup must have been called as well for a core +# dump to actually be generated. + +set -e + +screenshot_path=$(getscreenshotpath) +screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1` +if [ "$screenshot" = "" ]; then + echo "No screenshots found." + exit 1 +fi +echo "${screenshot}" +adb ${adbOptions} pull ${screenshot_path}/${screenshot} + diff --git a/bin/getprebuilt b/bin/getprebuilt new file mode 100755 index 000000000..68e65b49f --- /dev/null +++ b/bin/getprebuilt @@ -0,0 +1,18 @@ +#!/bin/bash + +# Copyright (C) 2024 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +get_abs_build_var ANDROID_PREBUILTS + diff --git a/bin/getscreenshotpath b/bin/getscreenshotpath new file mode 100755 index 000000000..ff8e327da --- /dev/null +++ b/bin/getscreenshotpath @@ -0,0 +1,26 @@ +#!/bin/bash + +# Copyright (C) 2024 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# coredump_enable - enable core dumps for the specified process +# $1 = PID of process (e.g., $(pid mediaserver)) +# +# NOTE: coredump_setup must have been called as well for a core +# dump to actually be generated. + +set -e + +echo "$(getsdcardpath)/Pictures/Screenshots" + diff --git a/bin/getsdcardpath b/bin/getsdcardpath new file mode 100755 index 000000000..655659a57 --- /dev/null +++ b/bin/getsdcardpath @@ -0,0 +1,26 @@ +#!/bin/bash + +# Copyright (C) 2024 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# coredump_enable - enable core dumps for the specified process +# $1 = PID of process (e.g., $(pid mediaserver)) +# +# NOTE: coredump_setup must have been called as well for a core +# dump to actually be generated. + +set -e + +adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\} + diff --git a/bin/gettargetarch b/bin/gettargetarch new file mode 100755 index 000000000..e53ce3fc3 --- /dev/null +++ b/bin/gettargetarch @@ -0,0 +1,18 @@ +#!/bin/bash + +# Copyright (C) 2024 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +get_build_var TARGET_ARCH + diff --git a/bin/hmm b/bin/hmm index c3d60fa4d..161bad67f 100755 --- a/bin/hmm +++ b/bin/hmm @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (C) 2022 The Android Open Source Project +# Copyright (C) 2024 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,6 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Common script utilities +source $(cd $(dirname $BASH_SOURCE) &> /dev/null && pwd)/../../make/shell_utils.sh + cat <