Skip to content

Conversation

@simonrozsival
Copy link
Member

Description of Change

This is an attempt at fixing adb: device unauthorized. by copying the ADB public key to the AVD before starting the emulator.

Issues Fixed

Fixes #32601

@simonrozsival
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@simonrozsival
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@simonrozsival
Copy link
Member Author

image

@simonrozsival
Copy link
Member Author

Android UI tests - emulator started correctly:

...
Waited 34 seconds for the emulator to boot up.

There are failing BoxView tests, but those are not relevant for this PR

BoxView failure logs
2025-11-19T10:59:54.3247946Z >>>>> 11/19/2025 10:59:54 FixtureSetup for BoxViewFeatureTests(Android)
2025-11-19T10:59:54.4799506Z   Passed Border_StrokeThicknessWithStrokeLineJoin_Bevel [3 s]
2025-11-19T11:01:56.1838686Z >>>>> 11/19/2025 11:01:56 Log types: logcat, bugreport, server
2025-11-19T11:01:56.3950401Z >>>>> 11/19/2025 11:01:56 Log types: logcat, bugreport, server
2025-11-19T11:01:56.6823576Z Setup failed for test fixture Microsoft.Maui.TestCases.Tests.BoxViewFeatureTests(Android)
2025-11-19T11:01:56.6829520Z System.TimeoutException : Timed out waiting for Go To Test button to appear
2025-11-19T11:01:56.6830361Z StackTrace:    at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2566
2025-11-19T11:01:56.6831004Z    at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 745
2025-11-19T11:01:56.6831666Z    at Microsoft.Maui.TestCases.Tests.UtilExtensions.NavigateToGallery(IApp app, String page) in /_/src/Controls/tests/TestCases.Shared.Tests/UtilExtensions.cs:line 34
2025-11-19T11:01:56.6840387Z    at Microsoft.Maui.TestCases.Tests.BoxViewFeatureTests.FixtureSetup() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/BoxViewFeatureTests.cs:line 20
2025-11-19T11:01:56.6840886Z    at UITest.Appium.NUnit.UITestBase.OneTimeSetup() in /_/src/TestUtils/src/UITest.NUnit/UITestBase.cs:line 111
2025-11-19T11:01:56.6841595Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:56.6842114Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:56.6842525Z    at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
2025-11-19T11:01:56.6843297Z    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2025-11-19T11:01:56.6862670Z >>>>> 11/19/2025 11:01:56 FixtureSetup for ButtonFeatureTests(Android)
2025-11-19T11:01:57.4848275Z   Failed BoxView_ColorWithOpacity [2 m 2 s]
2025-11-19T11:01:57.4848956Z   Error Message:
2025-11-19T11:01:57.4849387Z    OneTimeSetUp: System.TimeoutException : Timed out waiting for Go To Test button to appear
2025-11-19T11:01:57.4849746Z   Stack Trace:
2025-11-19T11:01:57.4850378Z      at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2566
2025-11-19T11:01:57.4851456Z    at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 745
2025-11-19T11:01:57.4852033Z    at Microsoft.Maui.TestCases.Tests.UtilExtensions.NavigateToGallery(IApp app, String page) in /_/src/Controls/tests/TestCases.Shared.Tests/UtilExtensions.cs:line 34
2025-11-19T11:01:57.4852581Z    at Microsoft.Maui.TestCases.Tests.BoxViewFeatureTests.FixtureSetup() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/BoxViewFeatureTests.cs:line 20
2025-11-19T11:01:57.4853018Z    at UITest.Appium.NUnit.UITestBase.OneTimeSetup() in /_/src/TestUtils/src/UITest.NUnit/UITestBase.cs:line 111
2025-11-19T11:01:57.4853508Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:57.4854008Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:57.4854399Z    at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
2025-11-19T11:01:57.4854862Z    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2025-11-19T11:01:57.4854987Z 
2025-11-19T11:01:57.4855334Z   Failed BoxView_ColorWithOpacityAndShadow [2 m 2 s]
2025-11-19T11:01:57.4855624Z   Error Message:
2025-11-19T11:01:57.4856018Z    OneTimeSetUp: System.TimeoutException : Timed out waiting for Go To Test button to appear
2025-11-19T11:01:57.4856301Z   Stack Trace:
2025-11-19T11:01:57.4856774Z      at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2566
2025-11-19T11:01:57.4857240Z    at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 745
2025-11-19T11:01:57.4857646Z    at Microsoft.Maui.TestCases.Tests.UtilExtensions.NavigateToGallery(IApp app, String page) in /_/src/Controls/tests/TestCases.Shared.Tests/UtilExtensions.cs:line 34
2025-11-19T11:01:57.4858016Z    at Microsoft.Maui.TestCases.Tests.BoxViewFeatureTests.FixtureSetup() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/BoxViewFeatureTests.cs:line 20
2025-11-19T11:01:57.4858410Z    at UITest.Appium.NUnit.UITestBase.OneTimeSetup() in /_/src/TestUtils/src/UITest.NUnit/UITestBase.cs:line 111
2025-11-19T11:01:57.4858777Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:57.4859134Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:57.4859456Z    at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
2025-11-19T11:01:57.4861718Z    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2025-11-19T11:01:57.4862246Z 
2025-11-19T11:01:57.4862679Z   Failed BoxView_CornerRadiusWithColor [2 m 2 s]
2025-11-19T11:01:57.4863080Z   Error Message:
2025-11-19T11:01:57.4863508Z    OneTimeSetUp: System.TimeoutException : Timed out waiting for Go To Test button to appear
2025-11-19T11:01:57.4863868Z   Stack Trace:
2025-11-19T11:01:57.4864428Z      at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2566
2025-11-19T11:01:57.4865338Z    at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 745
2025-11-19T11:01:57.4865851Z    at Microsoft.Maui.TestCases.Tests.UtilExtensions.NavigateToGallery(IApp app, String page) in /_/src/Controls/tests/TestCases.Shared.Tests/UtilExtensions.cs:line 34
2025-11-19T11:01:57.4866307Z    at Microsoft.Maui.TestCases.Tests.BoxViewFeatureTests.FixtureSetup() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/BoxViewFeatureTests.cs:line 20
2025-11-19T11:01:57.4866733Z    at UITest.Appium.NUnit.UITestBase.OneTimeSetup() in /_/src/TestUtils/src/UITest.NUnit/UITestBase.cs:line 111
2025-11-19T11:01:57.4867129Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:57.4867572Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:57.4868797Z    at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
2025-11-19T11:01:57.4869373Z    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2025-11-19T11:01:57.4869782Z 
2025-11-19T11:01:57.4870218Z   Failed BoxView_CornerRadiusWithColorAndShadow [2 m 2 s]
2025-11-19T11:01:57.4870589Z   Error Message:
2025-11-19T11:01:57.4870984Z    OneTimeSetUp: System.TimeoutException : Timed out waiting for Go To Test button to appear
2025-11-19T11:01:57.4871548Z   Stack Trace:
2025-11-19T11:01:57.4872131Z      at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2566
2025-11-19T11:01:57.4872755Z    at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 745
2025-11-19T11:01:57.4873331Z    at Microsoft.Maui.TestCases.Tests.UtilExtensions.NavigateToGallery(IApp app, String page) in /_/src/Controls/tests/TestCases.Shared.Tests/UtilExtensions.cs:line 34
2025-11-19T11:01:57.4873862Z    at Microsoft.Maui.TestCases.Tests.BoxViewFeatureTests.FixtureSetup() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/BoxViewFeatureTests.cs:line 20
2025-11-19T11:01:57.4874331Z    at UITest.Appium.NUnit.UITestBase.OneTimeSetup() in /_/src/TestUtils/src/UITest.NUnit/UITestBase.cs:line 111
2025-11-19T11:01:57.4874840Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:57.4875355Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:57.4875790Z    at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
2025-11-19T11:01:57.4876456Z    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2025-11-19T11:01:57.4876589Z 
2025-11-19T11:01:57.4876920Z   Failed BoxView_CornerRadiusWithFlowDirection [2 m 2 s]
2025-11-19T11:01:57.4877189Z   Error Message:
2025-11-19T11:01:57.4877546Z    OneTimeSetUp: System.TimeoutException : Timed out waiting for Go To Test button to appear
2025-11-19T11:01:57.4877805Z   Stack Trace:
2025-11-19T11:01:57.4878311Z      at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2566
2025-11-19T11:01:57.4878905Z    at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 745
2025-11-19T11:01:57.4879361Z    at Microsoft.Maui.TestCases.Tests.UtilExtensions.NavigateToGallery(IApp app, String page) in /_/src/Controls/tests/TestCases.Shared.Tests/UtilExtensions.cs:line 34
2025-11-19T11:01:57.4879805Z    at Microsoft.Maui.TestCases.Tests.BoxViewFeatureTests.FixtureSetup() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/BoxViewFeatureTests.cs:line 20
2025-11-19T11:01:57.4880194Z    at UITest.Appium.NUnit.UITestBase.OneTimeSetup() in /_/src/TestUtils/src/UITest.NUnit/UITestBase.cs:line 111
2025-11-19T11:01:57.4880635Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:57.4881063Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:57.4881568Z    at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
2025-11-19T11:01:57.4881976Z    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2025-11-19T11:01:57.4882100Z 
2025-11-19T11:01:57.4882414Z   Failed BoxView_CornerRadiusWithOpacityAndShadow [2 m 2 s]
2025-11-19T11:01:57.4882690Z   Error Message:
2025-11-19T11:01:57.4883032Z    OneTimeSetUp: System.TimeoutException : Timed out waiting for Go To Test button to appear
2025-11-19T11:01:57.4883308Z   Stack Trace:
2025-11-19T11:01:57.4883798Z      at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2566
2025-11-19T11:01:57.4884321Z    at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 745
2025-11-19T11:01:57.4884764Z    at Microsoft.Maui.TestCases.Tests.UtilExtensions.NavigateToGallery(IApp app, String page) in /_/src/Controls/tests/TestCases.Shared.Tests/UtilExtensions.cs:line 34
2025-11-19T11:01:57.4885220Z    at Microsoft.Maui.TestCases.Tests.BoxViewFeatureTests.FixtureSetup() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/BoxViewFeatureTests.cs:line 20
2025-11-19T11:01:57.4885603Z    at UITest.Appium.NUnit.UITestBase.OneTimeSetup() in /_/src/TestUtils/src/UITest.NUnit/UITestBase.cs:line 111
2025-11-19T11:01:57.4886048Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:57.4886479Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:57.4886922Z    at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
2025-11-19T11:01:57.4887320Z    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2025-11-19T11:01:57.4887446Z 
2025-11-19T11:01:57.4887726Z   Failed BoxView_IsVisible [2 m 2 s]
2025-11-19T11:01:57.4887996Z   Error Message:
2025-11-19T11:01:57.4888335Z    OneTimeSetUp: System.TimeoutException : Timed out waiting for Go To Test button to appear
2025-11-19T11:01:57.4888606Z   Stack Trace:
2025-11-19T11:01:57.4889087Z      at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2566
2025-11-19T11:01:57.4889665Z    at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 745
2025-11-19T11:01:57.4890114Z    at Microsoft.Maui.TestCases.Tests.UtilExtensions.NavigateToGallery(IApp app, String page) in /_/src/Controls/tests/TestCases.Shared.Tests/UtilExtensions.cs:line 34
2025-11-19T11:01:57.4890570Z    at Microsoft.Maui.TestCases.Tests.BoxViewFeatureTests.FixtureSetup() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/BoxViewFeatureTests.cs:line 20
2025-11-19T11:01:57.4890953Z    at UITest.Appium.NUnit.UITestBase.OneTimeSetup() in /_/src/TestUtils/src/UITest.NUnit/UITestBase.cs:line 111
2025-11-19T11:01:57.4891476Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:57.4891926Z    at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
2025-11-19T11:01:57.4892287Z    at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
2025-11-19T11:01:57.4892701Z    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2025-11-19T11:01:57.4892815Z 

@simonrozsival simonrozsival marked this pull request as ready for review November 19, 2025 14:28
Copilot AI review requested due to automatic review settings November 19, 2025 14:28
@simonrozsival
Copy link
Member Author

All test failures are unrelated

Copilot finished reviewing on behalf of simonrozsival November 19, 2025 14:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR attempts to fix "adb: device unauthorized" errors by pre-authorizing ADB keys before starting the Android emulator. It adds a new code block that ensures ADB keys exist and copies them to the AVD directory before boot, plus improves error logging in exception handlers.

Key changes:

  • Pre-authorization logic that calls EnsureAdbKeys and copies the public key to the AVD directory before emulator boot
  • Enhanced error handling with warning messages instead of silent catch blocks

Comment on lines +463 to +490
// Pre-authorize ADB keys before starting emulator to avoid "device unauthorized" errors
Information("Pre-authorizing ADB keys for emulator...");
try
{
// Ensure ADB keys exist
EnsureAdbKeys(adbSettings);

// Copy the public key to the AVD directory so it's trusted from boot
var homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var adbKeyPubSource = System.IO.Path.Combine(homeDir, ".android", "adbkey.pub");
var avdPath = System.IO.Path.Combine(homeDir, ".android", "avd", $"{avdName}.avd");
var avdAdbKeysDest = System.IO.Path.Combine(avdPath, "adbkey.pub");

if (System.IO.File.Exists(adbKeyPubSource) && System.IO.Directory.Exists(avdPath))
{
System.IO.File.Copy(adbKeyPubSource, avdAdbKeysDest, overwrite: true);
Information($"Pre-authorized ADB key copied to: {avdAdbKeysDest}");
}
else
{
Warning($"Could not pre-authorize ADB key. Source exists: {System.IO.File.Exists(adbKeyPubSource)}, AVD path exists: {System.IO.Directory.Exists(avdPath)}");
}
}
catch (Exception ex)
{
Warning($"Failed to pre-authorize ADB keys (will retry during boot): {ex.Message}");
}

Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pre-authorization approach may not work as intended. The standard Android emulator authorization mechanism expects authorized keys to be in /data/misc/adb/adb_keys on the running emulator, not in the AVD directory structure before boot.

Copying adbkey.pub to {avdName}.avd/adbkey.pub is not a documented Android emulator feature. The emulator reads authorized keys from its internal /data/misc/adb/adb_keys file at runtime, which is already handled by the existing EnsureAdbKeys function (see lines 951-992 where it pushes keys to /data/misc/adb/adb_keys).

Consider testing whether this pre-authorization actually prevents "device unauthorized" errors, or if the existing runtime authorization mechanism (already in EnsureAdbKeys) is sufficient.

Suggested change
// Pre-authorize ADB keys before starting emulator to avoid "device unauthorized" errors
Information("Pre-authorizing ADB keys for emulator...");
try
{
// Ensure ADB keys exist
EnsureAdbKeys(adbSettings);
// Copy the public key to the AVD directory so it's trusted from boot
var homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var adbKeyPubSource = System.IO.Path.Combine(homeDir, ".android", "adbkey.pub");
var avdPath = System.IO.Path.Combine(homeDir, ".android", "avd", $"{avdName}.avd");
var avdAdbKeysDest = System.IO.Path.Combine(avdPath, "adbkey.pub");
if (System.IO.File.Exists(adbKeyPubSource) && System.IO.Directory.Exists(avdPath))
{
System.IO.File.Copy(adbKeyPubSource, avdAdbKeysDest, overwrite: true);
Information($"Pre-authorized ADB key copied to: {avdAdbKeysDest}");
}
else
{
Warning($"Could not pre-authorize ADB key. Source exists: {System.IO.File.Exists(adbKeyPubSource)}, AVD path exists: {System.IO.Directory.Exists(avdPath)}");
}
}
catch (Exception ex)
{
Warning($"Failed to pre-authorize ADB keys (will retry during boot): {ex.Message}");
}
// Ensure ADB keys exist and are authorized at runtime
EnsureAdbKeys(adbSettings);

Copilot uses AI. Check for mistakes.
@PureWeen PureWeen merged commit 46270fd into main Nov 19, 2025
161 of 170 checks passed
@PureWeen PureWeen deleted the dev/srozsival/attempt-to-fix-adb-keys-setup branch November 19, 2025 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android emulator fails to boot for UI Tests: adb device unauthorized error

4 participants