Skip to content

Commit b7f5701

Browse files
OmniLab Teamcopybara-github
authored andcommitted
Internal change
PiperOrigin-RevId: 938557744
1 parent 5efe451 commit b7f5701

13 files changed

Lines changed: 190 additions & 41 deletions

File tree

src/devtools/mobileharness/fe/v6/angular/app/core/models/host_action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export declare interface ActionUnavailable {
110110
export type VersionIssueType =
111111
| 'TYPE_UNSPECIFIED'
112112
| 'NO_VERSION_RECORD'
113-
| 'VERSION_TOO_OLD';
113+
| 'CURRENT_VERSION_UNAVAILABLE';
114114

115115
/**
116116
* Version is unavailable; user needs to select a version before proceeding.

src/devtools/mobileharness/fe/v6/angular/app/core/services/host/fake_host_service.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,11 @@ TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0`,
328328
override preflightLabServerLifecycle(
329329
hostName: string,
330330
action: LifecycleActionType,
331-
expectedActivity: string,
332331
): Observable<PreflightLabServerLifecycleResponse> {
333-
// Default fake: always return ready with the expected activity.
332+
// Default fake: always return ready with a mock running activity.
334333
return of({
335334
ready: {
336-
actualActivity: expectedActivity,
335+
actualActivity: 'RUNNING',
337336
},
338337
}).pipe(delay(1000));
339338
}

src/devtools/mobileharness/fe/v6/angular/app/core/services/host/host_service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ export abstract class HostService {
8989
abstract preflightLabServerLifecycle(
9090
hostName: string,
9191
action: LifecycleActionType,
92-
expectedActivity: string,
9392
): Observable<PreflightLabServerLifecycleResponse>;
9493

9594
/**

src/devtools/mobileharness/fe/v6/angular/app/core/services/host/http_host_service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,11 @@ export class HttpHostService extends HostService {
103103
override preflightLabServerLifecycle(
104104
hostName: string,
105105
action: LifecycleActionType,
106-
expectedActivity: string,
107106
): Observable<PreflightLabServerLifecycleResponse> {
108107
return this.http.post<PreflightLabServerLifecycleResponse>(
109108
`${this.apiUrl}/${hostName}:preflightLifecycle`,
110109
{
111110
action,
112-
expectedActivity,
113111
},
114112
);
115113
}

src/devtools/mobileharness/fe/v6/service/proto/host/host_service.proto

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,11 @@ message PreflightLabServerLifecycleRequest {
312312
}
313313
ActionType action = 2;
314314

315-
// The Activity currently displayed on the Lab Server card in the frontend.
316-
// Used to detect stale page state (e.g. "RUNNING", "STOPPED").
317-
string expected_activity = 3;
315+
// Field 3 was a previously-planned `expected_activity` for stale-page
316+
// detection. The backend determines availability from the freshly-fetched
317+
// actual_activity instead, so the field was removed.
318+
reserved 3;
319+
reserved "expected_activity";
318320

319321
// The universe of the host.
320322
string universe = 4;
@@ -335,10 +337,11 @@ message PreflightLabServerLifecycleResponse {
335337
enum Type {
336338
TYPE_UNSPECIFIED = 0;
337339
NO_VERSION_RECORD = 1; // Never deployed, no version history
338-
VERSION_TOO_OLD = 2; // Previous version is deprecated
340+
CURRENT_VERSION_UNAVAILABLE =
341+
2; // Current version is no longer supported
339342
}
340343
Type type = 1;
341-
string current_version = 2; // Reserved
344+
string current_version = 2; // The current running version, if any
342345
repeated DeployableVersion available_versions = 3; // Versions to choose
343346
}
344347

src/java/com/google/devtools/mobileharness/fe/v6/service/host/handlers/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ java_library(
4444
"//src/java/com/google/devtools/mobileharness/fe/v6/service/host/util:host_types",
4545
"//src/java/com/google/devtools/mobileharness/fe/v6/service/host/util:host_version_util",
4646
"//src/java/com/google/devtools/mobileharness/fe/v6/service/host/util:lab_activities",
47+
"//src/java/com/google/devtools/mobileharness/fe/v6/service/host/util:lab_server_action_availabilities",
4748
"//src/java/com/google/devtools/mobileharness/fe/v6/service/shared",
4849
"//src/java/com/google/devtools/mobileharness/fe/v6/service/shared/providers:lab_info_provider",
4950
"//src/java/com/google/devtools/mobileharness/fe/v6/service/shared/remotecontrol",

src/java/com/google/devtools/mobileharness/fe/v6/service/host/handlers/LabServerRestartButtonBuilder.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.devtools.mobileharness.api.query.proto.LabQueryProto.LabInfo;
2020
import com.google.devtools.mobileharness.fe.v6.service.host.util.HostTypes;
21+
import com.google.devtools.mobileharness.fe.v6.service.host.util.LabServerActionAvailabilities;
2122
import com.google.devtools.mobileharness.fe.v6.service.proto.common.ActionButtonState;
2223
import com.google.devtools.mobileharness.fe.v6.service.proto.host.DaemonServerInfo;
2324
import com.google.devtools.mobileharness.fe.v6.service.proto.host.HostConnectivityStatus;
@@ -51,8 +52,6 @@ public ActionButtonState build(
5152
HostConnectivityStatus connectivityStatus,
5253
DaemonServerInfo.Status daemonStatus) {
5354

54-
// TODO: Refactor this logic into a shared util class when it is needed by 2 consumers (e.g.,
55-
// for the preflight request).
5655
if (!featureManagerFactory.create(universe).isLabServerRestartFeatureEnabled()) {
5756
return ActionButtonState.newBuilder().setVisible(false).build();
5857
}
@@ -63,14 +62,9 @@ public ActionButtonState build(
6362
return ActionButtonState.newBuilder().setVisible(false).build();
6463
}
6564

66-
boolean daemonRunning = daemonStatus.getState() == DaemonServerInfo.State.RUNNING;
67-
68-
boolean isTargetActivityState =
69-
activity.getState() == LabServerInfo.ActivityState.STARTED
70-
|| activity.getState() == LabServerInfo.ActivityState.STARTED_BUT_DISCONNECTED
71-
|| activity.getState() == LabServerInfo.ActivityState.ERROR;
72-
73-
boolean visibleCondition = daemonRunning && isTargetActivityState;
65+
boolean visibleCondition =
66+
LabServerActionAvailabilities.isRestartAvailable(
67+
activity.getState(), daemonStatus.getState());
7468

7569
if (!visibleCondition) {
7670
return ActionButtonState.newBuilder().setVisible(false).build();

src/java/com/google/devtools/mobileharness/fe/v6/service/host/handlers/LabServerStartButtonBuilder.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.devtools.mobileharness.api.query.proto.LabQueryProto.LabInfo;
2020
import com.google.devtools.mobileharness.fe.v6.service.host.util.HostTypes;
21+
import com.google.devtools.mobileharness.fe.v6.service.host.util.LabServerActionAvailabilities;
2122
import com.google.devtools.mobileharness.fe.v6.service.proto.common.ActionButtonState;
2223
import com.google.devtools.mobileharness.fe.v6.service.proto.host.DaemonServerInfo;
2324
import com.google.devtools.mobileharness.fe.v6.service.proto.host.HostConnectivityStatus;
@@ -51,8 +52,6 @@ public ActionButtonState build(
5152
HostConnectivityStatus connectivityStatus,
5253
DaemonServerInfo.Status daemonStatus) {
5354

54-
// TODO: Refactor this logic into a shared util class when it is needed by 2 consumers (e.g.,
55-
// for the preflight request).
5655
if (!featureManagerFactory.create(universe).isLabServerStartFeatureEnabled()) {
5756
return ActionButtonState.newBuilder().setVisible(false).build();
5857
}
@@ -63,15 +62,11 @@ public ActionButtonState build(
6362
return ActionButtonState.newBuilder().setVisible(false).build();
6463
}
6564

66-
boolean isTargetActivityState =
67-
activity.getState() == LabServerInfo.ActivityState.DRAINED
68-
|| activity.getState() == LabServerInfo.ActivityState.STOPPED
69-
|| activity.getState() == LabServerInfo.ActivityState.UNKNOWN;
70-
7165
boolean daemonRunning = daemonStatus.getState() == DaemonServerInfo.State.RUNNING;
72-
boolean daemonMissing = daemonStatus.getState() == DaemonServerInfo.State.MISSING;
7366

74-
boolean visibleCondition = daemonMissing || (daemonRunning && isTargetActivityState);
67+
boolean visibleCondition =
68+
LabServerActionAvailabilities.isStartAvailable(
69+
activity.getState(), daemonStatus.getState());
7570

7671
if (!visibleCondition) {
7772
return ActionButtonState.newBuilder().setVisible(false).build();

src/java/com/google/devtools/mobileharness/fe/v6/service/host/handlers/LabServerStopButtonBuilder.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.devtools.mobileharness.api.query.proto.LabQueryProto.LabInfo;
2020
import com.google.devtools.mobileharness.fe.v6.service.host.util.HostTypes;
21+
import com.google.devtools.mobileharness.fe.v6.service.host.util.LabServerActionAvailabilities;
2122
import com.google.devtools.mobileharness.fe.v6.service.proto.common.ActionButtonState;
2223
import com.google.devtools.mobileharness.fe.v6.service.proto.host.DaemonServerInfo;
2324
import com.google.devtools.mobileharness.fe.v6.service.proto.host.HostConnectivityStatus;
@@ -51,8 +52,6 @@ public ActionButtonState build(
5152
HostConnectivityStatus connectivityStatus,
5253
DaemonServerInfo.Status daemonStatus) {
5354

54-
// TODO: Refactor this logic into a shared util class when it is needed by 2 consumers (e.g.,
55-
// for the preflight request).
5655
if (!featureManagerFactory.create(universe).isLabServerStopFeatureEnabled()) {
5756
return ActionButtonState.newBuilder().setVisible(false).build();
5857
}
@@ -63,14 +62,8 @@ public ActionButtonState build(
6362
return ActionButtonState.newBuilder().setVisible(false).build();
6463
}
6564

66-
boolean daemonRunning = daemonStatus.getState() == DaemonServerInfo.State.RUNNING;
67-
68-
boolean isTargetActivityState =
69-
activity.getState() == LabServerInfo.ActivityState.STARTED
70-
|| activity.getState() == LabServerInfo.ActivityState.STARTED_BUT_DISCONNECTED
71-
|| activity.getState() == LabServerInfo.ActivityState.ERROR;
72-
73-
boolean visibleCondition = daemonRunning && isTargetActivityState;
65+
boolean visibleCondition =
66+
LabServerActionAvailabilities.isStopAvailable(activity.getState(), daemonStatus.getState());
7467

7568
if (!visibleCondition) {
7669
return ActionButtonState.newBuilder().setVisible(false).build();

src/java/com/google/devtools/mobileharness/fe/v6/service/host/util/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ java_library(
5959
],
6060
)
6161

62+
java_library(
63+
name = "lab_server_action_availabilities",
64+
srcs = ["LabServerActionAvailabilities.java"],
65+
deps = [
66+
"//src/devtools/mobileharness/fe/v6/service/proto/host:host_resources_java_proto",
67+
],
68+
)
69+
6270
java_library(
6371
name = "host_version_util",
6472
srcs = ["HostVersionUtil.java"],

0 commit comments

Comments
 (0)