🐛 [tool] Installs the APK regardless of version (#160432)

Resolves https://github.com/flutter/flutter/issues/160402

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
Alex Li 2024-12-30 10:26:27 +08:00 committed by GitHub
parent 01971467ef
commit 9fd5bddc65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 120 deletions

View File

@ -406,17 +406,12 @@ class AndroidDevice extends Device {
if (!await _adbIsValid) { if (!await _adbIsValid) {
return false; return false;
} }
final bool wasInstalled = await isAppInstalled(app, userIdentifier: userIdentifier);
if (wasInstalled && await isLatestBuildInstalled(app)) {
_logger.printTrace('Latest build already installed.');
return true;
}
_logger.printTrace('Installing APK.'); _logger.printTrace('Installing APK.');
if (await _installApp(app, userIdentifier: userIdentifier)) { if (await _installApp(app, userIdentifier: userIdentifier)) {
return true; return true;
} }
_logger.printTrace('Warning: Failed to install APK.'); _logger.printTrace('Warning: Failed to install APK.');
if (!wasInstalled) { if (!await isAppInstalled(app, userIdentifier: userIdentifier)) {
return false; return false;
} }
_logger.printStatus('Uninstalling old version...'); _logger.printStatus('Uninstalling old version...');

View File

@ -87,11 +87,6 @@ void main() {
command: <String>['adb', '-s', '1234', 'shell', 'am', 'force-stop', 'FlutterApp'], command: <String>['adb', '-s', '1234', 'shell', 'am', 'force-stop', 'FlutterApp'],
), ),
); );
processManager.addCommand(
const FakeCommand(
command: <String>['adb', '-s', '1234', 'shell', 'pm', 'list', 'packages', 'FlutterApp'],
),
);
processManager.addCommand( processManager.addCommand(
const FakeCommand( const FakeCommand(
command: <String>['adb', '-s', '1234', 'install', '-t', '-r', 'app-debug.apk'], command: <String>['adb', '-s', '1234', 'install', '-t', '-r', 'app-debug.apk'],
@ -212,22 +207,6 @@ void main() {
], ],
), ),
); );
processManager.addCommand(
const FakeCommand(
command: <String>[
'adb',
'-s',
'1234',
'shell',
'pm',
'list',
'packages',
'--user',
'10',
'FlutterApp',
],
),
);
processManager.addCommand( processManager.addCommand(
const FakeCommand( const FakeCommand(
command: <String>[ command: <String>[

View File

@ -101,21 +101,6 @@ void main() {
command: <String>['adb', '-s', '1234', 'shell', 'getprop'], command: <String>['adb', '-s', '1234', 'shell', 'getprop'],
stdout: '[ro.build.version.sdk]: [16]', stdout: '[ro.build.version.sdk]: [16]',
), ),
const FakeCommand(
command: <String>[
'adb',
'-s',
'1234',
'shell',
'pm',
'list',
'packages',
'--user',
'10',
'app',
],
stdout: '\n',
),
kInstallCommand, kInstallCommand,
kStoreShaCommand, kStoreShaCommand,
]); ]);
@ -137,21 +122,6 @@ void main() {
kAdbVersionCommand, kAdbVersionCommand,
kAdbStartServerCommand, kAdbStartServerCommand,
const FakeCommand(command: <String>['adb', '-s', '1234', 'shell', 'getprop']), const FakeCommand(command: <String>['adb', '-s', '1234', 'shell', 'getprop']),
const FakeCommand(
command: <String>[
'adb',
'-s',
'1234',
'shell',
'pm',
'list',
'packages',
'--user',
'10',
'app',
],
stdout: '\n',
),
kInstallCommand, kInstallCommand,
kStoreShaCommand, kStoreShaCommand,
]); ]);
@ -174,22 +144,6 @@ void main() {
kAdbStartServerCommand, kAdbStartServerCommand,
const FakeCommand(command: <String>['adb', '-s', '1234', 'shell', 'getprop']), const FakeCommand(command: <String>['adb', '-s', '1234', 'shell', 'getprop']),
// This command is run before the user is checked and is allowed to fail. // This command is run before the user is checked and is allowed to fail.
const FakeCommand(
command: <String>[
'adb',
'-s',
'1234',
'shell',
'pm',
'list',
'packages',
'--user',
'jane',
'app',
],
stderr: 'Blah blah',
exitCode: 1,
),
const FakeCommand( const FakeCommand(
command: <String>[ command: <String>[
'adb', 'adb',
@ -204,7 +158,9 @@ void main() {
], ],
exitCode: 1, exitCode: 1,
stderr: stderr:
'Exception occurred while executing: java.lang.IllegalArgumentException: Bad user number: jane', 'Exception occurred while executing: '
'java.lang.IllegalArgumentException: '
'Bad user number: jane',
), ),
]); ]);
final File apk = fileSystem.file('app-debug.apk')..createSync(); final File apk = fileSystem.file('app-debug.apk')..createSync();
@ -220,13 +176,14 @@ void main() {
expect( expect(
logger.errorText, logger.errorText,
contains( contains(
'Error: User "jane" not found. Run "adb shell pm list users" to see list of available identifiers.', 'Error: User "jane" not found. Run "adb shell pm list users" '
'to see list of available identifiers.',
), ),
); );
expect(processManager, hasNoRemainingExpectations); expect(processManager, hasNoRemainingExpectations);
}); });
testWithoutContext('Will skip install if the correct version is up to date', () async { testWithoutContext('Will continue install if the correct version is up to date', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[ final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
kAdbVersionCommand, kAdbVersionCommand,
kAdbStartServerCommand, kAdbStartServerCommand,
@ -234,23 +191,19 @@ void main() {
command: <String>['adb', '-s', '1234', 'shell', 'getprop'], command: <String>['adb', '-s', '1234', 'shell', 'getprop'],
stdout: '[ro.build.version.sdk]: [16]', stdout: '[ro.build.version.sdk]: [16]',
), ),
kInstallCommand,
const FakeCommand( const FakeCommand(
command: <String>[ command: <String>[
'adb', 'adb',
'-s', '-s',
'1234', '1234',
'shell', 'shell',
'pm', 'echo',
'list', '-n',
'packages', 'example_sha',
'--user', '>',
'10', '/data/local/tmp/sky.app.sha1',
'app',
], ],
stdout: 'package:app\n',
),
const FakeCommand(
command: <String>['adb', '-s', '1234', 'shell', 'cat', '/data/local/tmp/sky.app.sha1'],
stdout: 'example_sha', stdout: 'example_sha',
), ),
]); ]);
@ -278,25 +231,6 @@ void main() {
command: <String>['adb', '-s', '1234', 'shell', 'getprop'], command: <String>['adb', '-s', '1234', 'shell', 'getprop'],
stdout: '[ro.build.version.sdk]: [16]', stdout: '[ro.build.version.sdk]: [16]',
), ),
const FakeCommand(
command: <String>[
'adb',
'-s',
'1234',
'shell',
'pm',
'list',
'packages',
'--user',
'10',
'app',
],
stdout: 'package:app\n',
),
const FakeCommand(
command: <String>['adb', '-s', '1234', 'shell', 'cat', '/data/local/tmp/sky.app.sha1'],
stdout: 'different_example_sha',
),
const FakeCommand( const FakeCommand(
command: <String>[ command: <String>[
'adb', 'adb',
@ -312,6 +246,21 @@ void main() {
exitCode: 1, exitCode: 1,
stderr: '[INSTALL_FAILED_INSUFFICIENT_STORAGE]', stderr: '[INSTALL_FAILED_INSUFFICIENT_STORAGE]',
), ),
const FakeCommand(
command: <String>[
'adb',
'-s',
'1234',
'shell',
'pm',
'list',
'packages',
'--user',
'10',
'app',
],
stdout: 'package:app\n',
),
const FakeCommand( const FakeCommand(
command: <String>['adb', '-s', '1234', 'uninstall', '--user', '10', 'app'], command: <String>['adb', '-s', '1234', 'uninstall', '--user', '10', 'app'],
), ),
@ -355,21 +304,6 @@ void main() {
command: <String>['adb', '-s', '1234', 'shell', 'getprop'], command: <String>['adb', '-s', '1234', 'shell', 'getprop'],
stdout: '[ro.build.version.sdk]: [16]', stdout: '[ro.build.version.sdk]: [16]',
), ),
const FakeCommand(
command: <String>[
'adb',
'-s',
'1234',
'shell',
'pm',
'list',
'packages',
'--user',
'10',
'app',
],
stdout: '\n',
),
const FakeCommand( const FakeCommand(
command: <String>[ command: <String>[
'adb', 'adb',