@@ -413,234 +413,6 @@ AvdInfo* createAVD(AndroidOptions* opts, int* inAndroidBuild)
413
413
return ret ;
414
414
}
415
415
416
-
417
-
418
-
419
- #ifdef CONFIG_STANDALONE_UI
420
-
421
- #include "android/protocol/core-connection.h"
422
- #include "android/protocol/fb-updates-impl.h"
423
- #include "android/protocol/user-events-proxy.h"
424
- #include "android/protocol/core-commands-proxy.h"
425
- #include "android/protocol/ui-commands-impl.h"
426
- #include "android/protocol/attach-ui-impl.h"
427
-
428
- /* Emulator's core port. */
429
- int android_base_port = 0 ;
430
-
431
- // Base console port
432
- #define CORE_BASE_PORT 5554
433
-
434
- // Maximum number of core porocesses running simultaneously on a machine.
435
- #define MAX_CORE_PROCS 16
436
-
437
- // Socket timeout in millisec (set to 5 seconds)
438
- #define CORE_PORT_TIMEOUT_MS 5000
439
-
440
- #include "android/async-console.h"
441
-
442
- typedef struct {
443
- LoopIo io [1 ];
444
- int port ;
445
- int ok ;
446
- AsyncConsoleConnector connector [1 ];
447
- } CoreConsole ;
448
-
449
- static void
450
- coreconsole_io_func (void * opaque , int fd , unsigned events )
451
- {
452
- CoreConsole * cc = opaque ;
453
- AsyncStatus status ;
454
- status = asyncConsoleConnector_run (cc -> connector );
455
- if (status == ASYNC_COMPLETE ) {
456
- cc -> ok = 1 ;
457
- }
458
- }
459
-
460
- static void
461
- coreconsole_init (CoreConsole * cc , const SockAddress * address , Looper * looper )
462
- {
463
- int fd = socket_create_inet (SOCKET_STREAM );
464
- AsyncStatus status ;
465
- cc -> port = sock_address_get_port (address );
466
- cc -> ok = 0 ;
467
- loopIo_init (cc -> io , looper , fd , coreconsole_io_func , cc );
468
- if (fd >= 0 ) {
469
- status = asyncConsoleConnector_connect (cc -> connector , address , cc -> io );
470
- if (status == ASYNC_ERROR ) {
471
- cc -> ok = 0 ;
472
- }
473
- }
474
- }
475
-
476
- static void
477
- coreconsole_done (CoreConsole * cc )
478
- {
479
- socket_close (cc -> io -> fd );
480
- loopIo_done (cc -> io );
481
- }
482
-
483
- /* List emulator core processes running on the given machine.
484
- * This routine is called from main() if -list-cores parameter is set in the
485
- * command line.
486
- * Param:
487
- * host Value passed with -list-core parameter. Must be either "localhost", or
488
- * an IP address of a machine where core processes must be enumerated.
489
- */
490
- static void
491
- list_running_cores (const char * host )
492
- {
493
- Looper * looper ;
494
- CoreConsole cores [MAX_CORE_PROCS ];
495
- SockAddress address ;
496
- int nn , found ;
497
-
498
- if (sock_address_init_resolve (& address , host , CORE_BASE_PORT , 0 ) < 0 ) {
499
- derror ("Unable to resolve hostname %s: %s" , host , errno_str );
500
- return ;
501
- }
502
-
503
- looper = looper_newGeneric ();
504
-
505
- for (nn = 0 ; nn < MAX_CORE_PROCS ; nn ++ ) {
506
- int port = CORE_BASE_PORT + nn * 2 ;
507
- sock_address_set_port (& address , port );
508
- coreconsole_init (& cores [nn ], & address , looper );
509
- }
510
-
511
- looper_runWithTimeout (looper , CORE_PORT_TIMEOUT_MS * 2 );
512
-
513
- found = 0 ;
514
- for (nn = 0 ; nn < MAX_CORE_PROCS ; nn ++ ) {
515
- int port = CORE_BASE_PORT + nn * 2 ;
516
- if (cores [nn ].ok ) {
517
- if (found == 0 ) {
518
- fprintf (stdout , "Running emulator core processes:\n" );
519
- }
520
- fprintf (stdout , "Emulator console port %d\n" , port );
521
- found ++ ;
522
- }
523
- coreconsole_done (& cores [nn ]);
524
- }
525
- looper_free (looper );
526
-
527
- if (found == 0 ) {
528
- fprintf (stdout , "There were no running emulator core processes found on %s.\n" ,
529
- host );
530
- }
531
- }
532
-
533
- /* Attaches starting UI to a running core process.
534
- * This routine is called from main() when -attach-core parameter is set,
535
- * indicating that this UI instance should attach to a running core, rather than
536
- * start a new core process.
537
- * Param:
538
- * opts Android options containing non-NULL attach_core.
539
- * Return:
540
- * 0 on success, or -1 on failure.
541
- */
542
- static int
543
- attach_to_core (AndroidOptions * opts ) {
544
- int iter ;
545
- SockAddress console_socket ;
546
- SockAddress * * sockaddr_list ;
547
- QEmulator * emulator ;
548
-
549
- // Parse attach_core param extracting the host name, and the port name.
550
- char * console_address = strdup (opts -> attach_core );
551
- char * host_name = console_address ;
552
- char * port_num = strchr (console_address , ':' );
553
- if (port_num == NULL ) {
554
- // The host name is ommited, indicating the localhost
555
- host_name = "localhost" ;
556
- port_num = console_address ;
557
- } else if (port_num == console_address ) {
558
- // Invalid.
559
- derror ("Invalid value %s for -attach-core parameter\n" ,
560
- opts -> attach_core );
561
- return -1 ;
562
- } else {
563
- * port_num = '\0' ;
564
- port_num ++ ;
565
- if (* port_num == '\0' ) {
566
- // Invalid.
567
- derror ("Invalid value %s for -attach-core parameter\n" ,
568
- opts -> attach_core );
569
- return -1 ;
570
- }
571
- }
572
-
573
- /* Create socket address list for the given address, and pull appropriate
574
- * address to use for connection. Note that we're fine copying that address
575
- * out of the list, since INET and IN6 will entirely fit into SockAddress
576
- * structure. */
577
- sockaddr_list =
578
- sock_address_list_create (host_name , port_num , SOCKET_LIST_FORCE_INET );
579
- free (console_address );
580
- if (sockaddr_list == NULL ) {
581
- derror ("Unable to resolve address %s: %s\n" ,
582
- opts -> attach_core , errno_str );
583
- return -1 ;
584
- }
585
- for (iter = 0 ; sockaddr_list [iter ] != NULL ; iter ++ ) {
586
- if (sock_address_get_family (sockaddr_list [iter ]) == SOCKET_INET ||
587
- sock_address_get_family (sockaddr_list [iter ]) == SOCKET_IN6 ) {
588
- memcpy (& console_socket , sockaddr_list [iter ], sizeof (SockAddress ));
589
- break ;
590
- }
591
- }
592
- if (sockaddr_list [iter ] == NULL ) {
593
- derror ("Unable to resolve address %s. Note that 'port' parameter passed to -attach-core\n"
594
- "must be resolvable into an IP address.\n" , opts -> attach_core );
595
- sock_address_list_free (sockaddr_list );
596
- return -1 ;
597
- }
598
- sock_address_list_free (sockaddr_list );
599
-
600
- if (attachUiImpl_create (& console_socket )) {
601
- return -1 ;
602
- }
603
-
604
- // Save core's port, and set the title.
605
- android_base_port = sock_address_get_port (& console_socket );
606
- emulator = qemulator_get ();
607
- qemulator_set_title (emulator );
608
-
609
- return 0 ;
610
- }
611
-
612
-
613
- void handle_ui_options ( AndroidOptions * opts )
614
- {
615
- // Lets see if user just wants to list core process.
616
- if (opts -> list_cores ) {
617
- fprintf (stdout , "Enumerating running core processes.\n" );
618
- list_running_cores (opts -> list_cores );
619
- exit (0 );
620
- }
621
- }
622
-
623
- int attach_ui_to_core ( AndroidOptions * opts )
624
- {
625
- // Lets see if we're attaching to a running core process here.
626
- if (opts -> attach_core ) {
627
- if (attach_to_core (opts )) {
628
- return -1 ;
629
- }
630
- // Connect to the core's UI control services.
631
- if (coreCmdProxy_create (attachUiImpl_get_console_socket ())) {
632
- return -1 ;
633
- }
634
- // Connect to the core's user events service.
635
- if (userEventsProxy_create (attachUiImpl_get_console_socket ())) {
636
- return -1 ;
637
- }
638
- }
639
- return 0 ;
640
- }
641
-
642
- #else /* !CONFIG_STANDALONE_UI */
643
-
644
416
void handle_ui_options ( AndroidOptions * opts )
645
417
{
646
418
return ;
@@ -650,5 +422,3 @@ int attach_ui_to_core( AndroidOptions* opts )
650
422
{
651
423
return 0 ;
652
424
}
653
-
654
- #endif /* CONFIG_STANDALONE_UI */
0 commit comments