-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathstartAppFunctionTestingAgent
More file actions
executable file
·99 lines (87 loc) · 3.37 KB
/
Copy pathstartAppFunctionTestingAgent
File metadata and controls
executable file
·99 lines (87 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
#
# Copyright 2026 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
#
# https://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.
#
set -e
PACKAGE_NAME="com.example.appfunctions.agent"
INSTRUMENTATION_NAME="${PACKAGE_NAME}/.ShellIdentityInstrumentation"
SERIAL=""
usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -s, --serial SERIAL ADB device serial number"
echo " -h, --help Show this help message"
echo ""
echo "Description:"
echo " Launches the AppFunction Testing Agent app with elevated privileges"
echo " using ShellIdentityInstrumentation."
echo " Note: The app must be manually installed before running this script."
}
while [[ "$#" -gt 0 ]]; do
case $1 in
-s|--serial) SERIAL="$2"; shift ;;
-h|--help) usage; exit 0 ;;
*) echo "Unknown parameter: $1"; usage; exit 1 ;;
esac
shift
done
# Device disambiguation
DEVICE_COUNT=$(adb devices | grep -v "List of devices attached" | grep -w "device" | wc -l | tr -d ' ')
if [[ -n "$SERIAL" ]]; then
ADB="adb -s $SERIAL"
elif [[ "$DEVICE_COUNT" -eq 1 ]]; then
SERIAL=$(adb devices | grep -v "List of devices attached" | grep -w "device" | awk '{print $1}')
ADB="adb -s $SERIAL"
echo "📱 Using device: $SERIAL"
elif [[ "$DEVICE_COUNT" -eq 0 ]]; then
echo "❌ No devices connected via ADB."
exit 1
else
echo "❌ Multiple devices connected. Please specify one with -s or --serial:"
adb devices | grep -v "List of devices attached" | grep -w "device"
exit 1
fi
echo "🔍 Verifying package installation..."
if ! $ADB shell pm list packages | grep -q "$PACKAGE_NAME"; then
echo "❌ Package $PACKAGE_NAME is not installed on $SERIAL."
echo "Please install it first."
exit 1
fi
SDK_VERSION=$($ADB shell getprop ro.build.version.sdk)
if [[ $SDK_VERSION -ge 37 ]]; then
echo "🔑 Adding package to allowlist..."
$ADB shell cmd app_function purge-allowlist-cache
$ADB shell cmd allowlist add-package-multimap 2 ${PACKAGE_NAME}:2b2a355227c3fa4b666269bcdb2dbda5287142603927956e6cecae41a8e949ec "'*'"
else
echo "Skipping allowlist for SDK version $SDK_VERSION..."
fi
echo "🛑 Stopping any existing AppFunction Testing Agent instances..."
$ADB shell am force-stop "$PACKAGE_NAME"
echo "🚀 Starting AppFunction Testing Agent via ShellIdentityInstrumentation..."
# Run in background with -w to ensure UiAutomation is available
$ADB shell am instrument -w "$INSTRUMENTATION_NAME" > ./.instrumentation_output.txt 2>&1 &
PID=$!
sleep 2
if ! kill -0 $PID 2>/dev/null; then
echo "⚠️ Instrumentation failed to start immediately."
OUTPUT=$(cat ./.instrumentation_output.txt)
echo "$OUTPUT"
echo "Falling back to normal app launch..."
$ADB shell am start -n "$PACKAGE_NAME/.MainActivity" --es "EXTRA_INSTRUMENTATION_ERROR" "$OUTPUT"
rm ./.instrumentation_output.txt
else
echo "✅ Instrumentation started successfully."
fi