Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
f320d140
Unverified
Commit
f320d140
authored
Mar 03, 2022
by
Emmanuel Garcia
Committed by
GitHub
Mar 03, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix lifecycle for API level 28 (#99433)
parent
9bd88165
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
57 deletions
+30
-57
devices.dart
dev/devicelab/lib/framework/devices.dart
+4
-1
android_lifecycles_test.dart
dev/devicelab/lib/tasks/android_lifecycles_test.dart
+26
-56
No files found.
dev/devicelab/lib/framework/devices.dart
View file @
f320d140
...
...
@@ -446,6 +446,7 @@ class AndroidDevice extends Device {
@override
final
String
deviceId
;
String
deviceInfo
=
''
;
int
apiLevel
=
0
;
/// Whether the device is awake.
@override
...
...
@@ -539,8 +540,10 @@ class AndroidDevice extends Device {
}
final
List
<
String
>
list
=
info
.
split
(
'
\n
'
);
if
(
list
.
length
==
3
)
{
deviceInfo
=
'fingerprint:
${list[0]}
os:
${list[1]}
api-level:
${list[2]}
'
;
apiLevel
=
int
.
parse
(
list
[
2
]);
deviceInfo
=
'fingerprint:
${list[0]}
os:
${list[1]}
api-level:
$apiLevel
'
;
}
else
{
apiLevel
=
0
;
deviceInfo
=
''
;
}
}
...
...
dev/devicelab/lib/tasks/android_lifecycles_test.dart
View file @
f320d140
...
...
@@ -17,8 +17,8 @@ const String _kOrgName = 'com.example.activitydestroy';
final
RegExp
_lifecycleSentinelRegExp
=
RegExp
(
r'==== lifecycle\: (.+) ===='
);
/// Tests the following Android lifecycles: Activity#onStop(), Activity#onResume(), Activity#onPause()
/// from Dart perspective in debug, profile, and release modes.
/// Tests the following Android lifecycles: Activity#onStop(), Activity#onResume(), Activity#onPause()
,
///
and Activity#onDestroy()
from Dart perspective in debug, profile, and release modes.
TaskFunction
androidLifecyclesTest
(
{
Map
<
String
,
String
>?
environment
,
})
{
...
...
@@ -69,10 +69,11 @@ void main() {
}
'''
,
flush:
true
);
final
List
<
String
>
androidLifecycles
=
<
String
>[];
Future
<
TaskResult
>
runTestFor
(
String
mode
)
async
{
section
(
'Flutter run (mode:
$mode
)'
);
final
AndroidDevice
device
=
await
devices
.
workingDevice
as
AndroidDevice
;
await
device
.
unlock
();
section
(
'Flutter run on device running API level
${device.apiLevel}
(mode:
$mode
)'
);
late
Process
run
;
await
inDirectory
(
path
.
join
(
tempDir
.
path
,
'app'
),
()
async
{
...
...
@@ -82,10 +83,8 @@ void main() {
);
});
final
AndroidDevice
device
=
await
devices
.
workingDevice
as
AndroidDevice
;
await
device
.
unlock
();
final
StreamController
<
String
>
lifecyles
=
StreamController
<
String
>();
final
StreamIterator
<
String
>
lifecycleItr
=
StreamIterator
<
String
>(
lifecyles
.
stream
);
final
StreamSubscription
<
void
>
stdout
=
run
.
stdout
.
transform
<
String
>(
utf8
.
decoder
)
...
...
@@ -97,8 +96,6 @@ void main() {
return
;
}
final
String
lifecycle
=
match
[
1
]!;
androidLifecycles
.
add
(
lifecycle
);
print
(
'stdout: Found app lifecycle:
$lifecycle
'
);
lifecyles
.
add
(
lifecycle
);
});
...
...
@@ -110,73 +107,44 @@ void main() {
print
(
'stderr:
$log
'
);
});
final
StreamIterator
<
String
>
lifecycleItr
=
StreamIterator
<
String
>(
lifecyles
.
stream
);
{
const
String
expected
=
'AppLifecycleState.resumed'
;
Future
<
void
>
expectedLifecycle
(
String
expected
)
async
{
section
(
'Wait for lifecycle:
$expected
(mode:
$mode
)'
);
await
lifecycleItr
.
moveNext
();
final
String
got
=
lifecycleItr
.
current
;
if
(
expected
!=
got
)
{
return
TaskResult
.
failure
(
'expected lifecycles: `
$expected
`, but got`
$got
`'
);
throw
TaskResult
.
failure
(
'expected lifecycles: `
$expected
`, but got`
$got
`'
);
}
}
await
expectedLifecycle
(
'AppLifecycleState.resumed'
);
section
(
'Toggling app switch (mode:
$mode
)'
);
await
device
.
shellExec
(
'input'
,
<
String
>[
'keyevent'
,
'KEYCODE_APP_SWITCH'
]);
{
const
String
expected
=
'AppLifecycleState.inactive'
;
await
lifecycleItr
.
moveNext
();
final
String
got
=
lifecycleItr
.
current
;
if
(
expected
!=
got
)
{
return
TaskResult
.
failure
(
'expected lifecycles: `
$expected
`, but got`
$got
`'
);
}
await
expectedLifecycle
(
'AppLifecycleState.inactive'
);
if
(
device
.
apiLevel
==
28
)
{
// Device lab currently runs 28.
await
expectedLifecycle
(
'AppLifecycleState.paused'
);
await
expectedLifecycle
(
'AppLifecycleState.detached'
);
}
section
(
'Bring activity to foreground (mode:
$mode
)'
);
await
device
.
shellExec
(
'am'
,
<
String
>[
'start'
,
'-
-activity-single-top
'
,
'
$_kOrgName
.app/.MainActivity'
]);
await
device
.
shellExec
(
'am'
,
<
String
>[
'start'
,
'-
n
'
,
'
$_kOrgName
.app/.MainActivity'
]);
{
const
String
expected
=
'AppLifecycleState.resumed'
;
await
lifecycleItr
.
moveNext
();
final
String
got
=
lifecycleItr
.
current
;
if
(
expected
!=
got
)
{
return
TaskResult
.
failure
(
'expected lifecycles: `
$expected
`, but got`
$got
`'
);
}
}
await
expectedLifecycle
(
'AppLifecycleState.resumed'
);
section
(
'Launch Settings app (mode:
$mode
)'
);
await
device
.
shellExec
(
'am'
,
<
String
>[
'start'
,
'-a'
,
'android.settings.SETTINGS'
]);
{
const
String
expected
=
'AppLifecycleState.inactive'
;
await
lifecycleItr
.
moveNext
();
final
String
got
=
lifecycleItr
.
current
;
if
(
expected
!=
got
)
{
return
TaskResult
.
failure
(
'expected lifecycles: `
$expected
`, but got`
$got
`'
);
}
}
{
const
String
expected
=
'AppLifecycleState.paused'
;
await
lifecycleItr
.
moveNext
();
final
String
got
=
lifecycleItr
.
current
;
if
(
expected
!=
got
)
{
return
TaskResult
.
failure
(
'expected lifecycles: `
$expected
`, but got`
$got
`'
);
}
await
expectedLifecycle
(
'AppLifecycleState.inactive'
);
if
(
device
.
apiLevel
==
28
)
{
// Device lab currently runs 28.
await
expectedLifecycle
(
'AppLifecycleState.paused'
);
await
expectedLifecycle
(
'AppLifecycleState.detached'
);
}
section
(
'Bring activity to foreground (mode:
$mode
)'
);
await
device
.
shellExec
(
'am'
,
<
String
>[
'start'
,
'-
-activity-single-top
'
,
'
$_kOrgName
.app/.MainActivity'
]);
await
device
.
shellExec
(
'am'
,
<
String
>[
'start'
,
'-
n
'
,
'
$_kOrgName
.app/.MainActivity'
]);
{
const
String
expected
=
'AppLifecycleState.resumed'
;
await
lifecycleItr
.
moveNext
();
final
String
got
=
lifecycleItr
.
current
;
if
(
expected
!=
got
)
{
return
TaskResult
.
failure
(
'expected lifecycles: `
$expected
`, but got`
$got
`'
);
}
}
await
expectedLifecycle
(
'AppLifecycleState.resumed'
);
run
.
kill
();
...
...
@@ -205,6 +173,8 @@ void main() {
}
return
TaskResult
.
success
(
null
);
}
on
TaskResult
catch
(
error
)
{
return
error
;
}
finally
{
rmTree
(
tempDir
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment