forked from firka/flutter
Update Android CPU device detection (#45139)
This commit is contained in:
1
AUTHORS
1
AUTHORS
@@ -45,3 +45,4 @@ Sarbagya Dhaubanjar <mail@sarbagyastha.com.np>
|
||||
Rody Davis Jr <rody.davis.jr@gmail.com>
|
||||
Robin Jespersen <info@unitedpartners.de>
|
||||
Jefferson Quesado <jeff.quesado@gmail.com>
|
||||
Mark Diener <rpzrpzrpz@gmail.com>
|
||||
|
||||
@@ -192,7 +192,16 @@ class AndroidDevice extends Device {
|
||||
// http://developer.android.com/ndk/guides/abis.html (x86, armeabi-v7a, ...)
|
||||
switch (await _getProperty('ro.product.cpu.abi')) {
|
||||
case 'arm64-v8a':
|
||||
_platform = TargetPlatform.android_arm64;
|
||||
// Perform additional verification for 64 bit ABI. Some devices,
|
||||
// like the Kindle Fire 8, misreport the abilist. We might not
|
||||
// be able to retrieve this property, in which case we fall back
|
||||
// to assuming 64 bit.
|
||||
final String abilist = await _getProperty('ro.product.cpu.abilist');
|
||||
if (abilist == null || abilist.contains('arm64-v8a')) {
|
||||
_platform = TargetPlatform.android_arm64;
|
||||
} else {
|
||||
_platform = TargetPlatform.android_arm;
|
||||
}
|
||||
break;
|
||||
case 'x86_64':
|
||||
_platform = TargetPlatform.android_x64;
|
||||
|
||||
@@ -318,6 +318,77 @@ Use the 'android' tool to install them:
|
||||
});
|
||||
});
|
||||
|
||||
group('ABI detection', () {
|
||||
ProcessManager mockProcessManager;
|
||||
String cpu;
|
||||
String abilist;
|
||||
|
||||
setUp(() {
|
||||
mockProcessManager = MockProcessManager();
|
||||
cpu = 'unknown';
|
||||
abilist = 'unknown';
|
||||
when(mockProcessManager.run(
|
||||
argThat(contains('getprop')),
|
||||
stderrEncoding: anyNamed('stderrEncoding'),
|
||||
stdoutEncoding: anyNamed('stdoutEncoding'),
|
||||
)).thenAnswer((_) {
|
||||
final StringBuffer buf = StringBuffer()
|
||||
..writeln('[ro.product.cpu.abi]: [$cpu]')
|
||||
..writeln('[ro.product.cpu.abilist]: [$abilist]');
|
||||
final ProcessResult result = ProcessResult(1, 0, buf.toString(), '');
|
||||
return Future<ProcessResult>.value(result);
|
||||
});
|
||||
});
|
||||
|
||||
testUsingContext('detects x64', () async {
|
||||
cpu = 'x86_64';
|
||||
final AndroidDevice device = AndroidDevice('test');
|
||||
|
||||
expect(await device.targetPlatform, TargetPlatform.android_x64);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager
|
||||
});
|
||||
|
||||
testUsingContext('detects x86', () async {
|
||||
cpu = 'x86';
|
||||
final AndroidDevice device = AndroidDevice('test');
|
||||
|
||||
expect(await device.targetPlatform, TargetPlatform.android_x86);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager
|
||||
});
|
||||
|
||||
testUsingContext('unknown device defaults to 32bit arm', () async {
|
||||
cpu = '???';
|
||||
final AndroidDevice device = AndroidDevice('test');
|
||||
|
||||
expect(await device.targetPlatform, TargetPlatform.android_arm);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager
|
||||
});
|
||||
|
||||
testUsingContext('detects 64 bit arm', () async {
|
||||
cpu = 'arm64-v8a';
|
||||
abilist = 'arm64-v8a,';
|
||||
final AndroidDevice device = AndroidDevice('test');
|
||||
|
||||
// If both abi properties agree, we are 64 bit.
|
||||
expect(await device.targetPlatform, TargetPlatform.android_arm64);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager
|
||||
});
|
||||
|
||||
testUsingContext('detects kind fire ABI', () async {
|
||||
cpu = 'arm64-v8a';
|
||||
abilist = 'arm';
|
||||
final AndroidDevice device = AndroidDevice('test');
|
||||
|
||||
// If one does not contain arm64, assume 32 bit.
|
||||
expect(await device.targetPlatform, TargetPlatform.android_arm);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager
|
||||
});
|
||||
});
|
||||
|
||||
group('isLocalEmulator', () {
|
||||
final ProcessManager mockProcessManager = MockProcessManager();
|
||||
|
||||
Reference in New Issue
Block a user