11import type {
22 AppDeploymentInput ,
3+ AppDeploymentInstaller ,
34 AppDeploymentResult ,
45 AppDeploymentRuntimeOperations ,
56 AppUninstallInput ,
@@ -45,17 +46,19 @@ export function createAndroidAppDeploymentOperations(params: {
4546 host : PlatformRuntimeHost ;
4647 device : DeviceInfo ;
4748 signal : AbortSignal ;
49+ install ?: AppDeploymentInstaller ;
4850} ) : Partial < AppDeploymentRuntimeOperations > {
4951 const { host, device, signal } = params ;
52+ const install = params . install ;
5053 const facts = androidAppDeploymentFacts ( device ) ;
5154 if ( ! facts . deployApp . available ) return Object . freeze ( { } ) ;
5255 return Object . freeze ( {
5356 deployApp : async ( input : AppDeploymentInput ) =>
54- await deployAndroidApp ( host , device , input , signal ) ,
57+ await deployAndroidApp ( host , device , input , signal , install ) ,
5558 materializeAppSource : async ( input : MaterializeAppSourceInput ) =>
5659 await host . androidDeployment . prepareArtifact ( input , { signal } ) ,
5760 deployMaterializedApp : async ( input : DeployMaterializedAppInput ) =>
58- await deployPreparedAndroidApp ( host , device , input , signal ) ,
61+ await deployPreparedAndroidApp ( host , device , input , signal , install ) ,
5962 sendPushNotification : async ( input : PushNotificationInput ) =>
6063 await pushAndroidNotification ( host , device , input , signal ) ,
6164 uninstallApp : async ( input : AppUninstallInput ) =>
@@ -96,6 +99,7 @@ async function deployAndroidApp(
9699 device : DeviceInfo ,
97100 input : AppDeploymentInput ,
98101 signal : AbortSignal ,
102+ install ?: AppDeploymentInstaller ,
99103) : Promise < AppDeploymentResult > {
100104 if ( input . replaceExisting ) {
101105 // Reinstall resolves its fuzzy target during uninstall. Keep the old whole-operation
@@ -113,7 +117,9 @@ async function deployAndroidApp(
113117 { source : { kind : 'path' , path : input . appPath } } ,
114118 { resolveIdentity : false , signal } ,
115119 ) ;
116- await installAndroidArtifact ( host , device , artifact . installablePath , undefined , signal ) ;
120+ if ( install ) await install ( artifact , signal ) ;
121+ else
122+ await installAndroidArtifact ( host , device , artifact . installablePath , undefined , signal ) ;
117123 return { packageName, launchTarget : packageName } ;
118124 } finally {
119125 await artifact ?. cleanup ( ) ;
@@ -133,22 +139,8 @@ async function deployAndroidApp(
133139 { source : { kind : 'path' , path : input . appPath } } ,
134140 { resolveIdentity : true , signal } ,
135141 ) ;
136- const packageName = await installAndroidArtifact (
137- host ,
138- device ,
139- artifact . installablePath ,
140- artifact . packageName ,
141- signal ,
142- ) ;
143- // Plain install has historically succeeded even when the device cannot report the
144- // installed package identity. Source installation is stricter because its response
145- // contract promises an identity after materialization.
146- if ( ! packageName ) return { } ;
147- return {
148- packageName,
149- appName : inferAndroidAppName ( packageName ) ,
150- launchTarget : packageName ,
151- } ;
142+ // Plain install permits an unknown identity; source install promises one.
143+ return await installAndroidApp ( host , device , artifact , signal , install ) ;
152144 } finally {
153145 await artifact ?. cleanup ( ) ;
154146 }
@@ -159,24 +151,43 @@ async function deployPreparedAndroidApp(
159151 device : DeviceInfo ,
160152 input : DeployMaterializedAppInput ,
161153 signal : AbortSignal ,
154+ install ?: AppDeploymentInstaller ,
162155) : Promise < AppDeploymentResult > {
163- const packageName = await installAndroidArtifact (
164- host ,
165- device ,
166- input . artifact . installablePath ,
167- input . artifact . packageName ,
168- signal ,
169- ) ;
170- if ( ! packageName ) {
156+ const result = await installAndroidApp ( host , device , input . artifact , signal , install ) ;
157+ if ( ! result . packageName ) {
171158 throw new AppError (
172159 'COMMAND_FAILED' ,
173160 'Installed Android app identity could not be resolved from the artifact or device state' ,
174161 ) ;
175162 }
163+ return result ;
164+ }
165+
166+ async function installAndroidApp (
167+ host : PlatformRuntimeHost ,
168+ device : DeviceInfo ,
169+ artifact : MaterializedAppSource ,
170+ signal : AbortSignal ,
171+ install ?: AppDeploymentInstaller ,
172+ ) : Promise < AppDeploymentResult > {
173+ const result = install
174+ ? await install ( artifact , signal )
175+ : {
176+ packageName : await installAndroidArtifact (
177+ host ,
178+ device ,
179+ artifact . installablePath ,
180+ artifact . packageName ,
181+ signal ,
182+ ) ,
183+ } ;
184+ const packageName = result . packageName ?? artifact . packageName ;
185+ if ( ! packageName ) return result ;
176186 return {
187+ ...result ,
177188 packageName,
178- appName : inferAndroidAppName ( packageName ) ,
179- launchTarget : packageName ,
189+ appName : result . appName ?? artifact . appName ?? inferAndroidAppName ( packageName ) ,
190+ launchTarget : result . launchTarget ?? packageName ,
180191 } ;
181192}
182193
0 commit comments