android_device_test.dart 25.4 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// @dart = 2.8

7
import 'dart:async';
8
import 'dart:convert';
9
import 'dart:typed_data';
10

11
import 'package:file/memory.dart';
12
import 'package:flutter_tools/src/android/android_console.dart';
13
import 'package:flutter_tools/src/android/android_device.dart';
14
import 'package:flutter_tools/src/android/android_sdk.dart';
15
import 'package:flutter_tools/src/base/file_system.dart';
16
import 'package:flutter_tools/src/base/io.dart';
17
import 'package:flutter_tools/src/base/logger.dart';
18
import 'package:flutter_tools/src/base/platform.dart';
19
import 'package:flutter_tools/src/build_info.dart';
20
import 'package:flutter_tools/src/device.dart';
21
import 'package:flutter_tools/src/project.dart';
22
import 'package:test/fake.dart';
23

24
import '../../src/common.dart';
25
import '../../src/fake_process_manager.dart';
26

27
void main() {
28 29 30 31
  testWithoutContext('AndroidDevice stores the requested id', () {
    final AndroidDevice device = setUpAndroidDevice();

    expect(device.id, '1234');
32
  });
33

34 35 36 37 38 39 40
  testWithoutContext('parseAdbDeviceProperties parses adb shell output', () {
    final Map<String, String> properties = parseAdbDeviceProperties(kAdbShellGetprop);

    expect(properties, isNotNull);
    expect(properties['ro.build.characteristics'], 'emulator');
    expect(properties['ro.product.cpu.abi'], 'x86_64');
    expect(properties['ro.build.version.sdk'], '23');
41
  });
42

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  testWithoutContext('adb exiting with heap corruption is only allowed on windows', () async {
    final List<FakeCommand> commands = <FakeCommand>[
      const FakeCommand(
        command: <String>['adb', '-s', '1234', 'shell', 'getprop'],
        stdout: '[ro.hardware]: [goldfish]\n[ro.build.characteristics]: [unused]',
        // Heap corruption exit code.
        exitCode: -1073740940,
      )
    ];

    final AndroidDevice windowsDevice = setUpAndroidDevice(
      processManager: FakeProcessManager.list(commands.toList()),
      platform: FakePlatform(operatingSystem: 'windows'),
    );
    final AndroidDevice linuxDevice = setUpAndroidDevice(
      processManager: FakeProcessManager.list(commands.toList()),
59
      platform: FakePlatform(),
60 61 62 63 64 65
    );
    final AndroidDevice macOsDevice = setUpAndroidDevice(
      processManager: FakeProcessManager.list(commands.toList()),
      platform: FakePlatform(operatingSystem: 'macos')
    );

66
    // Parsing succeeds despite the error.
67 68 69 70 71
    expect(await windowsDevice.isLocalEmulator, true);

    // Parsing fails and these default to false.
    expect(await linuxDevice.isLocalEmulator, false);
    expect(await macOsDevice.isLocalEmulator, false);
72 73
  });

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
  testWithoutContext('AndroidDevice can detect TargetPlatform from property '
    'abi and abiList', () async {
      // The format is [ABI, ABI list]: expected target platform.
    final Map<List<String>, TargetPlatform> values = <List<String>, TargetPlatform>{
      <String>['x86_64', 'unknown']: TargetPlatform.android_x64,
      <String>['x86', 'unknown']: TargetPlatform.android_x86,
      // The default ABI is arm32
      <String>['???', 'unknown']: TargetPlatform.android_arm,
      <String>['arm64-v8a', 'arm64-v8a,']: TargetPlatform.android_arm64,
      // The Kindle Fire runs 32 bit apps on 64 bit hardware.
      <String>['arm64-v8a', 'arm']: TargetPlatform.android_arm,
    };

    for (final MapEntry<List<String>, TargetPlatform> entry in values.entries) {
      final AndroidDevice device = setUpAndroidDevice(
        processManager: FakeProcessManager.list(<FakeCommand>[
          FakeCommand(
            command: const <String>['adb', '-s', '1234', 'shell', 'getprop'],
            stdout: '[ro.product.cpu.abi]: [${entry.key.first}]\n'
              '[ro.product.cpu.abilist]: [${entry.key.last}]'
          )
        ]),
      );

      expect(await device.targetPlatform, entry.value);
    }
100
  });
101

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
  testWithoutContext('AndroidDevice supports profile/release mode on arm and x64 targets '
    'abi and abiList', () async {
      // The format is [ABI, ABI list]: expected release mode support.
    final Map<List<String>, bool> values = <List<String>, bool>{
      <String>['x86_64', 'unknown']: true,
      <String>['x86', 'unknown']: false,
      // The default ABI is arm32
      <String>['???', 'unknown']: true,
      <String>['arm64-v8a', 'arm64-v8a,']: true,
      // The Kindle Fire runs 32 bit apps on 64 bit hardware.
      <String>['arm64-v8a', 'arm']: true,
    };

    for (final MapEntry<List<String>, bool> entry in values.entries) {
      final AndroidDevice device = setUpAndroidDevice(
        processManager: FakeProcessManager.list(<FakeCommand>[
          FakeCommand(
            command: const <String>['adb', '-s', '1234', 'shell', 'getprop'],
            stdout: '[ro.product.cpu.abi]: [${entry.key.first}]\n'
              '[ro.product.cpu.abilist]: [${entry.key.last}]'
          )
        ]),
      );

      expect(await device.supportsRuntimeMode(BuildMode.release), entry.value);
      // Debug is always supported.
      expect(await device.supportsRuntimeMode(BuildMode.debug), true);
      // jitRelease is never supported.
      expect(await device.supportsRuntimeMode(BuildMode.jitRelease), false);
    }
  });

134
  testWithoutContext('AndroidDevice can detect local emulator for known types', () async {
135
    for (final String hardware in kKnownHardware.keys) {
136 137 138 139 140 141 142 143 144 145 146 147
      final AndroidDevice device = setUpAndroidDevice(
        processManager: FakeProcessManager.list(<FakeCommand>[
          FakeCommand(
            command: const <String>[
              'adb', '-s', '1234', 'shell', 'getprop',
            ],
            stdout: '[ro.hardware]: [$hardware]\n'
              '[ro.build.characteristics]: [unused]'
          ),
        ])
      );

148
      expect(await device.isLocalEmulator, kKnownHardware[hardware] == HardwareType.emulator);
149
    }
150
  });
151

152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
  testWithoutContext('AndroidDevice can detect unknown hardware', () async {
    final AndroidDevice device = setUpAndroidDevice(
      processManager: FakeProcessManager.list(<FakeCommand>[
        const FakeCommand(
          command: <String>[
            'adb', '-s', '1234', 'shell', 'getprop',
          ],
          stdout: '[ro.hardware]: [unknown]\n'
            '[ro.build.characteristics]: [att]'
        ),
      ])
    );

    expect(await device.isLocalEmulator, false);
  });

  testWithoutContext('AndroidDevice can detect unknown emulator', () async {
    final AndroidDevice device = setUpAndroidDevice(
      processManager: FakeProcessManager.list(<FakeCommand>[
        const FakeCommand(
          command: <String>[
            'adb', '-s', '1234', 'shell', 'getprop',
          ],
          stdout: '[ro.hardware]: [unknown]\n'
            '[ro.build.characteristics]: [att,emulator]'
        ),
      ])
    );

    expect(await device.isLocalEmulator, true);
  });

  testWithoutContext('isSupportedForProject is true on module project', () async {
    final FileSystem fileSystem = MemoryFileSystem.test();
    fileSystem.file('pubspec.yaml')
187 188 189 190 191 192 193
      ..createSync()
      ..writeAsStringSync(r'''
name: example

flutter:
  module: {}
''');
194 195 196 197 198 199 200 201
    fileSystem.file('.packages').createSync();
    final FlutterProject flutterProject = FlutterProjectFactory(
      fileSystem: fileSystem,
      logger: BufferLogger.test(),
    ).fromDirectory(fileSystem.currentDirectory);
    final AndroidDevice device = setUpAndroidDevice(fileSystem: fileSystem);

    expect(device.isSupportedForProject(flutterProject), true);
202 203
  });

204 205 206 207 208 209 210 211 212
  testWithoutContext('isSupportedForProject is true with editable host app', () async {
    final FileSystem fileSystem = MemoryFileSystem.test();
    fileSystem.file('pubspec.yaml').createSync();
    fileSystem.file('.packages').createSync();
    fileSystem.directory('android').createSync();
    final FlutterProject flutterProject = FlutterProjectFactory(
      fileSystem: fileSystem,
      logger: BufferLogger.test(),
    ).fromDirectory(fileSystem.currentDirectory);
213

214 215 216
    final AndroidDevice device = setUpAndroidDevice(fileSystem: fileSystem);

    expect(device.isSupportedForProject(flutterProject), true);
217
  });
218

219 220 221 222 223 224 225 226 227 228 229 230 231
  testWithoutContext('isSupportedForProject is false with no host app and no module', () async {
    final FileSystem fileSystem = MemoryFileSystem.test();
    fileSystem.file('pubspec.yaml').createSync();
    fileSystem.file('.packages').createSync();
    final FlutterProject flutterProject = FlutterProjectFactory(
      fileSystem: fileSystem,
      logger: BufferLogger.test(),
    ).fromDirectory(fileSystem.currentDirectory);

    final AndroidDevice device = setUpAndroidDevice(fileSystem: fileSystem);

    expect(device.isSupportedForProject(flutterProject), false);
  });
232

233 234 235 236 237 238 239 240 241 242
  testWithoutContext('AndroidDevice returns correct ID for responsive emulator', () async {
    final AndroidDevice device = setUpAndroidDevice(
      processManager: FakeProcessManager.list(<FakeCommand>[
        const FakeCommand(
          command: <String>['adb', '-s', 'emulator-5555', 'shell', 'getprop'],
          stdout: '[ro.hardware]: [goldfish]'
        )
      ]),
      id: 'emulator-5555',
      androidConsoleSocketFactory: (String host, int port) async =>
243
        FakeWorkingAndroidConsoleSocket('dummyEmulatorId'),
244 245 246
    );

    expect(await device.emulatorId, equals('dummyEmulatorId'));
247
  });
248

249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
  testWithoutContext('AndroidDevice does not create socket for non-emulator devices', () async {
    bool socketWasCreated = false;

    // Still use an emulator-looking ID so we can be sure the failure is due
    // to the isLocalEmulator field and not because the ID doesn't contain a
    // port.
    final AndroidDevice device = setUpAndroidDevice(
      id: 'emulator-5555',
      processManager: FakeProcessManager.list(<FakeCommand>[
        const FakeCommand(
          command: <String>['adb', '-s', 'emulator-5555', 'shell', 'getprop'],
          stdout: '[ro.hardware]: [samsungexynos7420]'
        )
      ]),
      androidConsoleSocketFactory: (String host, int port) async {
264 265
        socketWasCreated = true;
        throw 'Socket was created for non-emulator';
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
      }
    );

    expect(await device.emulatorId, isNull);
    expect(socketWasCreated, isFalse);
  });

  testWithoutContext('AndroidDevice does not create socket for emulators with no port', () async {
    bool socketWasCreated = false;
    final AndroidDevice device = setUpAndroidDevice(
      processManager: FakeProcessManager.list(<FakeCommand>[
        const FakeCommand(
          command: <String>['adb', '-s', '1234', 'shell', 'getprop'],
          stdout: '[ro.hardware]: [goldfish]'
        )
      ]),
      androidConsoleSocketFactory: (String host, int port) async {
283 284 285
        socketWasCreated = true;
        throw 'Socket was created for emulator without port in ID';
      },
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
    );

    expect(await device.emulatorId, isNull);
    expect(socketWasCreated, isFalse);
  });

  testWithoutContext('AndroidDevice.emulatorId is null for connection error', () async {
    final AndroidDevice device = setUpAndroidDevice(
      processManager: FakeProcessManager.list(<FakeCommand>[
        const FakeCommand(
          command: <String>['adb', '-s', '1234', 'shell', 'getprop'],
          stdout: '[ro.hardware]: [goldfish]'
        )
      ]),
      androidConsoleSocketFactory: (String host, int port) => throw Exception('Fake socket error'),
    );

    expect(await device.emulatorId, isNull);
  });

  testWithoutContext('AndroidDevice.emulatorId is null for unresponsive device', () async {
    final AndroidDevice device = setUpAndroidDevice(
      processManager: FakeProcessManager.list(<FakeCommand>[
        const FakeCommand(
          command: <String>['adb', '-s', '1234', 'shell', 'getprop'],
          stdout: '[ro.hardware]: [goldfish]'
        )
      ]),
      androidConsoleSocketFactory: (String host, int port) async =>
315
        FakeUnresponsiveAndroidConsoleSocket(),
316 317 318 319 320 321 322 323 324 325 326 327 328 329
    );

    expect(await device.emulatorId, isNull);
  });

  testWithoutContext('AndroidDevice.emulatorId is null on early disconnect', () async {
    final AndroidDevice device = setUpAndroidDevice(
      processManager: FakeProcessManager.list(<FakeCommand>[
        const FakeCommand(
          command: <String>['adb', '-s', '1234', 'shell', 'getprop'],
          stdout: '[ro.hardware]: [goldfish]'
        )
      ]),
      androidConsoleSocketFactory: (String host, int port) async =>
330
        FakeDisconnectingAndroidConsoleSocket()
331 332 333
    );

    expect(await device.emulatorId, isNull);
334
  });
335

336 337 338 339 340 341 342 343 344 345
  testWithoutContext('AndroidDevice lastLogcatTimestamp returns null if shell command failed', () async {
    final AndroidDevice device = setUpAndroidDevice(
      processManager: FakeProcessManager.list(<FakeCommand>[
        const FakeCommand(
          command: <String>['adb', '-s', '1234', 'shell', '-x', 'logcat', '-v', 'time', '-t', '1'],
          exitCode: 1,
        )
      ])
    );

346
    expect(await device.lastLogcatTimestamp(), isNull);
347 348
  });

349 350 351 352 353 354 355 356 357
  testWithoutContext('AndroidDevice AdbLogReaders for past+future and future logs are not the same', () async {
    final AndroidDevice device = setUpAndroidDevice(
      processManager: FakeProcessManager.list(<FakeCommand>[
        const FakeCommand(
          command: <String>['adb', '-s', '1234', 'shell', 'getprop'],
          stdout: '[ro.build.version.sdk]: [23]',
          exitCode: 1,
        ),
        const FakeCommand(
358
          command: <String>['adb', '-s', '1234', 'shell', '-x', 'logcat', '-v', 'time', '-s', 'flutter'],
359 360
        ),
        const FakeCommand(
361
          command: <String>['adb', '-s', '1234', 'shell', '-x', 'logcat', '-v', 'time'],
362 363 364 365 366 367 368 369 370 371 372 373 374 375
        )
      ])
    );

    final DeviceLogReader pastLogReader = await device.getLogReader(includePastLogs: true);
    final DeviceLogReader defaultLogReader = await device.getLogReader();
    expect(pastLogReader, isNot(equals(defaultLogReader)));

    // Getting again is cached.
    expect(pastLogReader, equals(await device.getLogReader(includePastLogs: true)));
    expect(defaultLogReader, equals(await device.getLogReader()));
  });

  testWithoutContext('Can parse adb shell dumpsys info', () {
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
    const String exampleOutput = r'''
Applications Memory Usage (in Kilobytes):
Uptime: 441088659 Realtime: 521464097

** MEMINFO in pid 16141 [io.flutter.demo.gallery] **
                   Pss  Private  Private  SwapPss     Heap     Heap     Heap
                 Total    Dirty    Clean    Dirty     Size    Alloc     Free
                ------   ------   ------   ------   ------   ------   ------
  Native Heap     8648     8620        0       16    20480    12403     8076
  Dalvik Heap      547      424       40       18     2628     1092     1536
 Dalvik Other      464      464        0        0
        Stack      496      496        0        0
       Ashmem        2        0        0        0
      Gfx dev      212      204        0        0
    Other dev       48        0       48        0
     .so mmap    10770      708     9372       25
    .apk mmap      240        0        0        0
    .ttf mmap       35        0       32        0
    .dex mmap     2205        4     1172        0
    .oat mmap       64        0        0        0
    .art mmap     4228     3848       24        2
   Other mmap    20713        4    20704        0
    GL mtrack     2380     2380        0        0
      Unknown    43971    43968        0        1
        TOTAL    95085    61120    31392       62    23108    13495     9612

 App Summary
                       Pss(KB)
                        ------
           Java Heap:     4296
         Native Heap:     8620
                Code:    11288
               Stack:      496
            Graphics:     2584
       Private Other:    65228
              System:     2573

               TOTAL:    95085       TOTAL SWAP PSS:       62

 Objects
               Views:        9         ViewRootImpl:        1
         AppContexts:        3           Activities:        1
              Assets:        4        AssetManagers:        3
       Local Binders:       10        Proxy Binders:       18
       Parcel memory:        6         Parcel count:       24
    Death Recipients:        0      OpenSSL Sockets:        0
            WebViews:        0

 SQL
         MEMORY_USED:        0
  PAGECACHE_OVERFLOW:        0          MALLOC_SIZE:        0
''';

    final AndroidMemoryInfo result = parseMeminfoDump(exampleOutput);

    // Parses correctly
432
    expect(result.realTime, 521464097);
433 434 435 436 437 438 439 440 441 442 443
    expect(result.javaHeap, 4296);
    expect(result.nativeHeap, 8620);
    expect(result.code, 11288);
    expect(result.stack, 496);
    expect(result.graphics, 2584);
    expect(result.privateOther, 65228);
    expect(result.system, 2573);

    // toJson works correctly
    final Map<String, Object> json = result.toJson();

444
    expect(json, containsPair('Realtime', 521464097));
445 446 447 448 449 450 451 452 453 454 455 456 457 458
    expect(json, containsPair('Java Heap', 4296));
    expect(json, containsPair('Native Heap', 8620));
    expect(json, containsPair('Code', 11288));
    expect(json, containsPair('Stack', 496));
    expect(json, containsPair('Graphics', 2584));
    expect(json, containsPair('Private Other', 65228));
    expect(json, containsPair('System', 2573));

    // computed from summation of other fields.
    expect(json, containsPair('Total', 95085));

    // contains identifier for platform in memory info.
    expect(json, containsPair('platform', 'Android'));
  });
459
}
460

461 462 463 464 465 466 467 468
AndroidDevice setUpAndroidDevice({
  String id,
  AndroidSdk androidSdk,
  FileSystem fileSystem,
  ProcessManager processManager,
  Platform platform,
  AndroidConsoleSocketFactory androidConsoleSocketFactory = kAndroidConsoleSocketFactory,
}) {
469
  androidSdk ??= FakeAndroidSdk();
470 471
  return AndroidDevice(id ?? '1234',
    logger: BufferLogger.test(),
472
    platform: platform ?? FakePlatform(),
473 474 475 476 477 478 479
    androidSdk: androidSdk,
    fileSystem: fileSystem ?? MemoryFileSystem.test(),
    processManager: processManager ?? FakeProcessManager.any(),
    androidConsoleSocketFactory: androidConsoleSocketFactory,
  );
}

480 481 482 483
class FakeAndroidSdk extends Fake implements AndroidSdk {
  @override
  String get adbPath => 'adb';
}
484

485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
const String kAdbShellGetprop = '''
[dalvik.vm.dex2oat-Xms]: [64m]
[dalvik.vm.dex2oat-Xmx]: [512m]
[dalvik.vm.heapsize]: [384m]
[dalvik.vm.image-dex2oat-Xms]: [64m]
[dalvik.vm.image-dex2oat-Xmx]: [64m]
[dalvik.vm.isa.x86.variant]: [dalvik.vm.isa.x86.features=default]
[dalvik.vm.isa.x86_64.features]: [default]
[dalvik.vm.isa.x86_64.variant]: [x86_64]
[dalvik.vm.lockprof.threshold]: [500]
[dalvik.vm.stack-trace-file]: [/data/anr/traces.txt]
[debug.atrace.tags.enableflags]: [0]
[debug.force_rtl]: [0]
[gsm.current.phone-type]: [1]
[gsm.network.type]: [Unknown]
[gsm.nitz.time]: [1473102078793]
[gsm.operator.alpha]: []
[gsm.operator.iso-country]: []
[gsm.operator.isroaming]: [false]
[gsm.operator.numeric]: []
[gsm.sim.operator.alpha]: []
[gsm.sim.operator.iso-country]: []
[gsm.sim.operator.numeric]: []
[gsm.sim.state]: [NOT_READY]
[gsm.version.ril-impl]: [android reference-ril 1.0]
[init.svc.adbd]: [running]
[init.svc.bootanim]: [running]
[init.svc.console]: [running]
[init.svc.debuggerd]: [running]
[init.svc.debuggerd64]: [running]
[init.svc.drm]: [running]
[init.svc.fingerprintd]: [running]
[init.svc.gatekeeperd]: [running]
[init.svc.goldfish-logcat]: [stopped]
[init.svc.goldfish-setup]: [stopped]
[init.svc.healthd]: [running]
[init.svc.installd]: [running]
[init.svc.keystore]: [running]
[init.svc.lmkd]: [running]
[init.svc.logd]: [running]
[init.svc.logd-reinit]: [stopped]
[init.svc.media]: [running]
[init.svc.netd]: [running]
[init.svc.perfprofd]: [running]
[init.svc.qemu-props]: [stopped]
[init.svc.ril-daemon]: [running]
[init.svc.servicemanager]: [running]
[init.svc.surfaceflinger]: [running]
[init.svc.ueventd]: [running]
[init.svc.vold]: [running]
[init.svc.zygote]: [running]
[init.svc.zygote_secondary]: [running]
[net.bt.name]: [Android]
[net.change]: [net.qtaguid_enabled]
[net.eth0.dns1]: [10.0.2.3]
[net.eth0.gw]: [10.0.2.2]
[net.gprs.local-ip]: [10.0.2.15]
[net.hostname]: [android-ccd858aa3d3825ee]
[net.qtaguid_enabled]: [1]
[net.tcp.default_init_rwnd]: [60]
[persist.sys.dalvik.vm.lib.2]: [libart.so]
[persist.sys.profiler_ms]: [0]
[persist.sys.timezone]: [America/Los_Angeles]
[persist.sys.usb.config]: [adb]
[qemu.gles]: [1]
[qemu.hw.mainkeys]: [0]
[qemu.sf.fake_camera]: [none]
[qemu.sf.lcd_density]: [420]
[rild.libargs]: [-d /dev/ttyS0]
[rild.libpath]: [/system/lib/libreference-ril.so]
[ro.allow.mock.location]: [0]
[ro.baseband]: [unknown]
[ro.board.platform]: []
[ro.boot.hardware]: [ranchu]
[ro.bootimage.build.date]: [Wed Jul 20 21:03:09 UTC 2016]
[ro.bootimage.build.date.utc]: [1469048589]
[ro.bootimage.build.fingerprint]: [Android/sdk_google_phone_x86_64/generic_x86_64:6.0/MASTER/3079352:userdebug/test-keys]
[ro.bootloader]: [unknown]
[ro.bootmode]: [unknown]
[ro.build.characteristics]: [emulator]
[ro.build.date]: [Wed Jul 20 21:02:14 UTC 2016]
[ro.build.date.utc]: [1469048534]
[ro.build.description]: [sdk_google_phone_x86_64-userdebug 6.0 MASTER 3079352 test-keys]
[ro.build.display.id]: [sdk_google_phone_x86_64-userdebug 6.0 MASTER 3079352 test-keys]
[ro.build.fingerprint]: [Android/sdk_google_phone_x86_64/generic_x86_64:6.0/MASTER/3079352:userdebug/test-keys]
[ro.build.flavor]: [sdk_google_phone_x86_64-userdebug]
[ro.build.host]: [vpba14.mtv.corp.google.com]
[ro.build.id]: [MASTER]
[ro.build.product]: [generic_x86_64]
[ro.build.tags]: [test-keys]
[ro.build.type]: [userdebug]
[ro.build.user]: [android-build]
[ro.build.version.all_codenames]: [REL]
[ro.build.version.base_os]: []
[ro.build.version.codename]: [REL]
[ro.build.version.incremental]: [3079352]
[ro.build.version.preview_sdk]: [0]
[ro.build.version.release]: [6.0]
[ro.build.version.sdk]: [23]
[ro.build.version.security_patch]: [2015-10-01]
[ro.com.google.locationfeatures]: [1]
[ro.config.alarm_alert]: [Alarm_Classic.ogg]
[ro.config.nocheckin]: [yes]
[ro.config.notification_sound]: [OnTheHunt.ogg]
[ro.crypto.state]: [unencrypted]
[ro.dalvik.vm.native.bridge]: [0]
[ro.debuggable]: [1]
[ro.hardware]: [ranchu]
[ro.hardware.audio.primary]: [goldfish]
[ro.hwui.drop_shadow_cache_size]: [6]
[ro.hwui.gradient_cache_size]: [1]
[ro.hwui.layer_cache_size]: [48]
[ro.hwui.path_cache_size]: [32]
[ro.hwui.r_buffer_cache_size]: [8]
[ro.hwui.text_large_cache_height]: [1024]
[ro.hwui.text_large_cache_width]: [2048]
[ro.hwui.text_small_cache_height]: [1024]
[ro.hwui.text_small_cache_width]: [1024]
[ro.hwui.texture_cache_flushrate]: [0.4]
[ro.hwui.texture_cache_size]: [72]
[ro.kernel.android.checkjni]: [1]
[ro.kernel.android.qemud]: [1]
[ro.kernel.androidboot.hardware]: [ranchu]
[ro.kernel.clocksource]: [pit]
[ro.kernel.qemu]: [1]
[ro.kernel.qemu.gles]: [1]
[ro.opengles.version]: [131072]
[ro.product.board]: []
[ro.product.brand]: [Android]
[ro.product.cpu.abi]: [x86_64]
[ro.product.cpu.abilist]: [x86_64,x86]
[ro.product.cpu.abilist32]: [x86]
[ro.product.cpu.abilist64]: [x86_64]
[ro.product.device]: [generic_x86_64]
[ro.product.locale]: [en-US]
[ro.product.manufacturer]: [unknown]
[ro.product.model]: [Android SDK built for x86_64]
[ro.product.name]: [sdk_google_phone_x86_64]
[ro.radio.use-ppp]: [no]
[ro.revision]: [0]
[ro.secure]: [1]
[ro.serialno]: []
[ro.wifi.channels]: []
[ro.zygote]: [zygote64_32]
[selinux.reload_policy]: [1]
[service.bootanim.exit]: [0]
[status.battery.level]: [5]
[status.battery.level_raw]: [50]
[status.battery.level_scale]: [9]
[status.battery.state]: [Slow]
[sys.sysctl.extra_free_kbytes]: [24300]
[sys.usb.config]: [adb]
[sys.usb.state]: [adb]
[vold.has_adoptable]: [1]
[wlan.driver.status]: [unloaded]
[xmpp.auto-presence]: [true]
''';
642 643 644

/// A mock Android Console that presents a connection banner and responds to
/// "avd name" requests with the supplied name.
645 646
class FakeWorkingAndroidConsoleSocket extends Fake implements Socket {
  FakeWorkingAndroidConsoleSocket(this.avdName) {
647 648 649 650 651 652 653 654 655 656
    _controller.add('Android Console: Welcome!\n');
    // Include OK in the same packet here. In the response to "avd name"
    // it's sent alone to ensure both are handled.
    _controller.add('Android Console: Some intro text\nOK\n');
  }

  final String avdName;
  final StreamController<String> _controller = StreamController<String>();

  @override
657
  Stream<E> asyncMap<E>(FutureOr<E> Function(Uint8List event) convert) => _controller.stream as Stream<E>;
658 659 660 661 662 663 664 665 666 667 668 669 670

  @override
  void add(List<int> data) {
    final String text = ascii.decode(data);
    if (text == 'avd name\n') {
      _controller.add('$avdName\n');
      // Include OK in its own packet here. In welcome banner it's included
      // as part of the previous text to ensure both are handled.
      _controller.add('OK\n');
    } else {
      throw 'Unexpected command $text';
    }
  }
671 672 673

  @override
  void destroy() { }
674 675 676
}

/// An Android console socket that drops all input and returns no output.
677
class FakeUnresponsiveAndroidConsoleSocket extends Fake implements Socket {
678 679 680
  final StreamController<String> _controller = StreamController<String>();

  @override
681
  Stream<E> asyncMap<E>(FutureOr<E> Function(Uint8List event) convert) => _controller.stream as Stream<E>;
682 683 684

  @override
  void add(List<int> data) {}
685 686 687

  @override
  void destroy() { }
688
}
689

690
/// An Android console socket that drops all input and returns no output.
691 692
class FakeDisconnectingAndroidConsoleSocket extends Fake implements Socket {
  FakeDisconnectingAndroidConsoleSocket() {
693 694 695 696 697 698 699 700 701
    _controller.add('Android Console: Welcome!\n');
    // Include OK in the same packet here. In the response to "avd name"
    // it's sent alone to ensure both are handled.
    _controller.add('Android Console: Some intro text\nOK\n');
  }

  final StreamController<String> _controller = StreamController<String>();

  @override
702
  Stream<E> asyncMap<E>(FutureOr<E> Function(Uint8List event) convert) => _controller.stream as Stream<E>;
703 704 705 706 707

  @override
  void add(List<int> data) {
    _controller.close();
  }
708 709 710

  @override
  void destroy() { }
711
}