How to automate apps that have been pinned?

Hello, I am having an issue with getting Appium to run. I am getting the following screen loglines. For context, this is at my job, and we make custom android devices for business customers. the app that I’m trying to automate is the first-run app that runs before the android device is fully setup.

debug] [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {
[debug] [BaseDriver]   "alwaysMatch": {
[debug] [BaseDriver]     "platformName": "Android",
[debug] [BaseDriver]     "browserVersion": "7.1.2",
[debug] [BaseDriver]     "appium:deviceName": "<redacted>",
[debug] [BaseDriver]     "appium:version": "7.1.2",
[debug] [BaseDriver]     "appium:realDevice": true,
[debug] [BaseDriver]     "appium:appPackage": "<redacted>",
[debug] [BaseDriver]     "appium:appActivity": "<redacted>"
[debug] [BaseDriver]   },
[debug] [BaseDriver]   "firstMatch": [
[debug] [BaseDriver]     {}
[debug] [BaseDriver]   ]
[debug] [BaseDriver] }
[BaseDriver] The following capabilities were provided, but are not recognized by Appium:
[BaseDriver]   browserVersion
[BaseDriver]   version
[BaseDriver]   realDevice
[BaseDriver] Session created with session id: 4a9ae13f-d894-4939-b1ad-3eca8edbf27e
[UiAutomator2] Starting 'com.bymason.platform.preflight' directly on the device
[ADB] Found 5 'build-tools' folders under '/home/christopheryeemon/Android/Sdk' (newest first):
[ADB]     /home/christopheryeemon/Android/Sdk/build-tools/31.0.0-rc4
[ADB]     /home/christopheryeemon/Android/Sdk/build-tools/31.0.0-rc2
[ADB]     /home/christopheryeemon/Android/Sdk/build-tools/30.0.3
[ADB]     /home/christopheryeemon/Android/Sdk/build-tools/30.0.2
[ADB]     /home/christopheryeemon/Android/Sdk/build-tools/29.0.3
[ADB] Using 'adb' from '/home/christopheryeemon/Android/Sdk/platform-tools/adb'
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 start-server'
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices
[debug] [ADB] Connected devices: [{"udid":"bc951568","state":"device"}]
[AndroidDriver] Using device: bc951568
[ADB] Using 'adb' from '/home/christopheryeemon/Android/Sdk/platform-tools/adb'
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 start-server'
[debug] [ADB] Setting device id to bc951568
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell getprop ro.build.version.sdk'
[debug] [ADB] Current device property 'ro.build.version.sdk': 25
[debug] [ADB] Device API level: 25
[AndroidDriver] No app sent in, not parsing package/activity
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 wait-for-device'
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell echo ping'
[debug] [AndroidDriver] Pushing settings apk to device...
[debug] [ADB] Getting install status for io.appium.settings
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell dumpsys package io.appium.settings'
[debug] [ADB] 'io.appium.settings' is installed
[debug] [ADB] Getting package info for 'io.appium.settings'
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell dumpsys package io.appium.settings'
[debug] [ADB] The version name of the installed 'io.appium.settings' is greater or equal to the application version name ('3.3.0' >= '3.3.0')
[debug] [ADB] There is no need to install/upgrade '/home/christopheryeemon/.nvm/versions/node/v12.16.2/lib/node_modules/appium/node_modules/io.appium.settings/apks/settings_apk-debug.apk'
[debug] [ADB] Getting IDs of all 'io.appium.settings' processes
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep --help; echo $?''
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep ^appium\\.settings$ || pgrep ^io\\.appium\\.setti$''
[debug] [ADB] Getting IDs of all 'io.appium.settings' processes
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep ^appium\\.settings$ || pgrep ^io\\.appium\\.setti$''
[debug] [ADB] Starting Appium Settings app
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell am start -n io.appium.settings/.Settings -a android.intent.action.MAIN -c android.intent.category.LAUNCHER'
[debug] [ADB] Getting IDs of all 'io.appium.settings' processes
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep ^appium\\.settings$ || pgrep ^io\\.appium\\.setti$''
[debug] [ADB] Getting IDs of all 'io.appium.settings' processes
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep ^appium\\.settings$ || pgrep ^io\\.appium\\.setti$''
[debug] [ADB] Getting IDs of all 'io.appium.settings' processes
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep ^appium\\.settings$ || pgrep ^io\\.appium\\.setti$''
[debug] [ADB] Getting IDs of all 'io.appium.settings' processes
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep ^appium\\.settings$ || pgrep ^io\\.appium\\.setti$''
[debug] [ADB] Getting IDs of all 'io.appium.settings' processes
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep ^appium\\.settings$ || pgrep ^io\\.appium\\.setti$''
[debug] [ADB] Getting IDs of all 'io.appium.settings' processes
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep ^appium\\.settings$ || pgrep ^io\\.appium\\.setti$''
[debug] [ADB] Getting IDs of all 'io.appium.settings' processes
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep ^appium\\.settings$ || pgrep ^io\\.appium\\.setti$''
[debug] [ADB] Getting IDs of all 'io.appium.settings' processes
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep ^appium\\.settings$ || pgrep ^io\\.appium\\.setti$''
[debug] [ADB] Getting IDs of all 'io.appium.settings' processes
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep ^appium\\.settings$ || pgrep ^io\\.appium\\.setti$''
[debug] [ADB] Getting IDs of all 'io.appium.settings' processes
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep ^appium\\.settings$ || pgrep ^io\\.appium\\.setti$''
[debug] [ADB] Getting IDs of all 'io.appium.settings' processes
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep ^appium\\.settings$ || pgrep ^io\\.appium\\.setti$''
[debug] [ADB] Getting IDs of all 'io.appium.settings' processes
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell 'pgrep ^appium\\.settings$ || pgrep ^io\\.appium\\.setti$''
[debug] [AndroidDriver] Error: Appium Settings app is not running after 5000ms
[debug] [AndroidDriver]     at ADB.requireRunningSettingsApp (/home/christopheryeemon/.nvm/versions/node/v12.16.2/lib/node_modules/appium/node_modules/appium-adb/lib/tools/settings-client-commands.js:70:11)
[debug] [UiAutomator2] Deleting UiAutomator2 session
[debug] [ADB] Running '/home/christopheryeemon/Android/Sdk/platform-tools/adb -P 5037 -s bc951568 shell am force-stop com.bymason.platform.preflight'
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1626741352437 (17:35:52 GMT-0700 (Pacific Daylight Time))
[debug] [W3C] Encountered internal error running command: Error: Appium Settings app is not running after 5000ms
[debug] [W3C]     at ADB.requireRunningSettingsApp (/home/christopheryeemon/.nvm/versions/node/v12.16.2/lib/node_modules/appium/node_modules/appium-adb/lib/tools/settings-client-commands.js:70:11)
[HTTP] <-- POST /wd/hub/session 500 8095 ms - 673
[HTTP] 

We think it’s because of this issue debugging - Android studio: Error: Activity not started, unknown error code 5 - Stack Overflow where you can’t run appium if the app you have is pinned and uses startLockTask() to prevent other apps from running. Either that or something like it because when I try to run the io.appium.settings app manually with adb start, I get the unknown error code 5 message. It happens when i try to run any app with adb start while at these screens. Also it obviously makes sense, without having the code looked at, since the app under test is a preflight app similar to any normal google play android phone’s first-run screens, and would likely have this set.

christopheryeemon@system76-pc:~/src/<redacted>/tests$ adb shell am start -n com.android.settings/.Settings
Starting: Intent { cmp=com.android.settings/.Settings }
Error: Activity not started, unknown error code 5

My question is, do we perceive any possible workaround for this? Can I install and run the necessary apps on the device manually? Are these apps absolutely needed? (I’m assuming yes for now) Is the issue most likely because of that linked issue about startLockTask() blocking other apps from running? Is there documentation anywhere for what these apps like io.appium.settings and io.appium.uiautomator2 are for?

Why you need test app while it pinned? Just remove ping mode and test.

This app doesn’t do that in production, so i want to avoid having to make a special build just for automation. I figured out a workaround

adb shell am task lock stop

That stops all task locks, and even though it doesn’t match exactly, at least I can still have appium run and then rerun the app.

1 Like