MCPcopy Index your code
hub / github.com/callstack/agent-device / handleSessionStateCommands

Function handleSessionStateCommands

src/daemon/handlers/session-state.ts:144–376  ·  view source on GitHub ↗
(params: {
  req: DaemonRequest;
  sessionName: string;
  logPath: string;
  sessionStore: SessionStore;
})

Source from the content-addressed store, hash-verified

142}
143
144export async function handleSessionStateCommands(params: {
145 req: DaemonRequest;
146 sessionName: string;
147 logPath: string;
148 sessionStore: SessionStore;
149}): Promise<DaemonResponse | null> {
150 const { req, sessionName, logPath, sessionStore } = params;
151
152 if (req.command === 'boot') {
153 const session = sessionStore.get(sessionName);
154 const flags = req.flags ?? {};
155 const guard = requireSessionOrExplicitSelector(req.command, session, flags);
156 if (guard) return guard;
157
158 const normalizedPlatform = flags.platform ?? session?.device.platform;
159 const targetsAndroid = normalizedPlatform === 'android';
160 const wantsAndroidHeadless = flags.headless === true;
161 if (wantsAndroidHeadless && !targetsAndroid) {
162 return errorResponse(
163 'INVALID_ARGS',
164 'boot --headless is supported only for Android emulators.',
165 );
166 }
167
168 const fallbackAvdName = resolveAndroidEmulatorAvdName({
169 flags,
170 sessionDevice: session?.device,
171 });
172 const canFallbackLaunchAndroidEmulator = targetsAndroid && Boolean(fallbackAvdName);
173
174 let device: DeviceInfo;
175 let launchedAndroidEmulator = false;
176 try {
177 device = await resolveCommandDevice({
178 session,
179 flags,
180 ensureReady: false,
181 allowStoppedAndroidAvdPlaceholders: true,
182 });
183 } catch (error) {
184 const appErr = asAppError(error);
185 if (
186 targetsAndroid &&
187 wantsAndroidHeadless &&
188 !fallbackAvdName &&
189 appErr.code === 'DEVICE_NOT_FOUND'
190 ) {
191 return errorResponse(
192 'INVALID_ARGS',
193 'boot --headless requires --device <avd-name> (or an Android emulator session target).',
194 );
195 }
196 if (
197 !canFallbackLaunchAndroidEmulator ||
198 appErr.code !== 'DEVICE_NOT_FOUND' ||
199 !fallbackAvdName
200 ) {
201 throw error;

Callers 3

handleSessionCommandsFunction · 0.90
runBootFunction · 0.90

Calls 15

errorResponseFunction · 0.90
resolveCommandDeviceFunction · 0.90
asAppErrorFunction · 0.90
ensureDeviceReadyFunction · 0.90
requireCommandSupportedFunction · 0.90
isIosFamilyFunction · 0.90
prewarmAppleRunnerCacheFunction · 0.90
publicPlatformStringFunction · 0.90
isApplePlatformFunction · 0.90

Tested by 1

runBootFunction · 0.72