@@ -4,18 +4,21 @@ import type {
44 AppDeploymentRuntimeOperations ,
55 DeployMaterializedAppInput ,
66 MaterializeAppSourceInput ,
7+ MaterializedAppSource ,
78 PushNotificationInput ,
89} from '@agent-device/contracts/app-deployment-runtime' ;
910import type { PlatformRuntimeHost } from '@agent-device/contracts/platform-runtime-operations' ;
1011import type { RuntimeOperationFact } from '@agent-device/contracts/platform-runtime' ;
1112import type { DeviceInfo } from '@agent-device/kernel/device' ;
1213import { AppError } from '@agent-device/kernel/errors' ;
14+ import { currentManagedDeviceScope } from '@agent-device/provision-kit/managed-device-scope' ;
1315import { ensureAndroidReady } from '../readiness/runtime.ts' ;
1416import {
1517 inferAndroidAppName ,
1618 installAndroidArtifact ,
1719 pushAndroidNotification ,
1820 uninstallAndroidPackage ,
21+ assertManagedAndroidInstallablePath ,
1922} from './native.ts' ;
2023
2124const available = Object . freeze ( { available : true } as const ) ;
@@ -66,36 +69,51 @@ async function deployAndroidApp(
6669 // cache boundary here in the Android deployment owner: clear before boot/resolve/uninstall
6770 // and after materialization/install, including partial failures.
6871 return await host . androidDeployment . withInvalidatedAppResolutionCache ( device , async ( ) => {
69- if ( device . booted !== true ) {
70- await ensureAndroidReady ( host , device , { headless : false } , signal ) ;
71- }
72- const packageName = await host . androidDeployment . resolveAppPackage ( device , input . app ) ;
73- await uninstallAndroidPackage ( host , device , packageName , signal ) ;
74- const artifact = await host . androidDeployment . prepareArtifact (
75- { source : { kind : 'path' , path : input . appPath } } ,
76- { resolveIdentity : false , signal } ,
77- ) ;
72+ let artifact : MaterializedAppSource | undefined ;
7873 try {
74+ if ( currentManagedDeviceScope ( ) ) {
75+ artifact = await host . androidDeployment . prepareArtifact (
76+ { source : { kind : 'path' , path : input . appPath } } ,
77+ { resolveIdentity : false , signal } ,
78+ ) ;
79+ assertManagedAndroidInstallablePath ( artifact . installablePath ) ;
80+ }
81+ if ( device . booted !== true ) {
82+ await ensureAndroidReady ( host , device , { headless : false } , signal ) ;
83+ }
84+ const packageName = await host . androidDeployment . resolveAppPackage ( device , input . app ) ;
85+ await uninstallAndroidPackage ( host , device , packageName , signal ) ;
86+ artifact ??= await host . androidDeployment . prepareArtifact (
87+ { source : { kind : 'path' , path : input . appPath } } ,
88+ { resolveIdentity : false , signal } ,
89+ ) ;
7990 await installAndroidArtifact ( host , device , artifact . installablePath , undefined , signal ) ;
8091 return { packageName, launchTarget : packageName } ;
8192 } finally {
82- await artifact . cleanup ( ) ;
93+ await artifact ? .cleanup ( ) ;
8394 }
8495 } ) ;
8596 }
8697
8798 // Existing install semantics wait for a selected Android target before taking the
8899 // before-install package inventory. Keep that platform rule here, rather than
89100 // reviving a daemon readiness adapter.
90- if ( device . booted !== true ) {
91- await ensureAndroidReady ( host , device , { headless : false } , signal ) ;
92- }
93-
94- const artifact = await host . androidDeployment . prepareArtifact (
95- { source : { kind : 'path' , path : input . appPath } } ,
96- { resolveIdentity : true , signal } ,
97- ) ;
101+ let artifact : MaterializedAppSource | undefined ;
98102 try {
103+ if ( currentManagedDeviceScope ( ) ) {
104+ artifact = await host . androidDeployment . prepareArtifact (
105+ { source : { kind : 'path' , path : input . appPath } } ,
106+ { resolveIdentity : true , signal } ,
107+ ) ;
108+ assertManagedAndroidInstallablePath ( artifact . installablePath ) ;
109+ }
110+ if ( device . booted !== true ) {
111+ await ensureAndroidReady ( host , device , { headless : false } , signal ) ;
112+ }
113+ artifact ??= await host . androidDeployment . prepareArtifact (
114+ { source : { kind : 'path' , path : input . appPath } } ,
115+ { resolveIdentity : true , signal } ,
116+ ) ;
99117 const packageName = await installAndroidArtifact (
100118 host ,
101119 device ,
@@ -113,7 +131,7 @@ async function deployAndroidApp(
113131 launchTarget : packageName ,
114132 } ;
115133 } finally {
116- await artifact . cleanup ( ) ;
134+ await artifact ? .cleanup ( ) ;
117135 }
118136}
119137
0 commit comments