Commit 80e62a0c authored by Kuo Jen Wei's avatar Kuo Jen Wei Committed by Commit Bot

[CCA] Close camera of invisible idle window in tablet mode.

This CL add logic for monitering visibility of CCA window and close
camera stream when window is idle (not recording) and is non-visible in
tablet mode.

Bug: 1035653
Test: Pass tast run <DUT> 'camera.CCAUI*'.
Test: Manually test camera stream is closed when CCA is idle and is
invisible in tablet mode.
Test: Manually test recording can be continued when CCA is invisible in
tablet mode.

Change-Id: I05c1ddf3c16dce3897d694e07208b18fd78acc42
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1986468Reviewed-by: default avatarShik Chen <shik@chromium.org>
Commit-Queue: Kuo Jen Wei <inker@chromium.org>
Auto-Submit: Kuo Jen Wei <inker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728464}
parent 0e7fe37b
......@@ -159,16 +159,46 @@ cca.views.Camera = class extends cca.views.View {
});
chrome.app.window.current().onMinimized.addListener(() => this.start());
document.addEventListener('visibilitychange', async () => {
const isTabletBackground = await this.isTabletBackground_();
const recording = cca.state.get(cca.state.State.TAKING) &&
cca.state.get(cca.Mode.VIDEO);
if (isTabletBackground && !recording) {
this.start();
}
});
this.configuring_ = null;
}
/**
* @return {boolean} Returns if window is fully overlapped by other window in
* both window mode or tablet mode.
* @private
*/
get isVisible_() {
return document.visibilityState !== 'hidden';
}
/**
* @return {!Promise<boolean>} Resolved to boolean value indicating whether
* window is put to background in tablet mode.
* @private
*/
async isTabletBackground_() {
const isTabletMode =
await cca.mojo.ChromeHelper.getInstance().isTabletMode();
return isTabletMode && !this.isVisible_;
}
/**
* Whether app window is suspended.
* @return {boolean}
* @return {!Promise<boolean>}
*/
get suspended() {
async isSuspended() {
return this.locked_ || chrome.app.window.current().isMinimized() ||
cca.state.get(cca.state.State.SUSPEND);
cca.state.get(cca.state.State.SUSPEND) ||
await this.isTabletBackground_();
}
/**
......@@ -335,7 +365,7 @@ cca.views.Camera = class extends cca.views.View {
}
for (const {resolution: captureR, previewCandidates} of resolCandidates) {
for (const constraints of previewCandidates) {
if (this.suspended) {
if (await this.isSuspended()) {
throw new cca.views.CameraSuspendedError();
}
try {
......@@ -389,7 +419,7 @@ cca.views.Camera = class extends cca.views.View {
async start_() {
try {
await this.infoUpdater_.lockDeviceInfo(async () => {
if (!this.suspended) {
if (!await this.isSuspended()) {
for (const id of await this.options_.videoDeviceIds()) {
if (await this.startWithDevice_(id)) {
// Make the different active camera announced by screen reader.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment