Update proto to use google protobuf timestamp
Test: atest DeviceLockControllerRoboTests
Bug: 270406144
Change-Id: Ibe95d012220d0cfc4554f6dad2c53f917c4fa8a6
diff --git a/DeviceLockController/Android.bp b/DeviceLockController/Android.bp
index 4ed6685..a9eaf87 100644
--- a/DeviceLockController/Android.bp
+++ b/DeviceLockController/Android.bp
@@ -160,7 +160,7 @@
"androidx.work_work-runtime",
"devicelockcontroller-activities-lib",
"devicelockcontroller-grpclib",
- "devicelockcontroller-protos-lite",
+ "devicelockcontroller-grpc-lite",
"devicelockcontroller-interface",
"devicelockcontroller-res-lib",
"devicelockcontroller-util-lib",
diff --git a/DeviceLockController/proto/Android.bp b/DeviceLockController/proto/Android.bp
index 373b080..00405e9 100644
--- a/DeviceLockController/proto/Android.bp
+++ b/DeviceLockController/proto/Android.bp
@@ -21,10 +21,12 @@
}
// Generate gRPC client code
-LITE_PROTO_CMD = "$(location aprotoc) " +
+LITE_PROTO_CMD = "mkdir -p $(genDir)/gen && " +
+ "$(location aprotoc) --java_opt=annotate_code=false " +
+ "-Iexternal/protobuf/src -Ipackages/modules/DeviceLock/DeviceLockController/proto " +
"--plugin=protoc-gen-grpc-java=$(location protoc-gen-grpc-java-plugin) " +
- "--grpc-java_out=lite:$(genDir) $(in) && " +
- "$(location soong_zip) -o $(out) -C $(genDir) -D $(genDir)"
+ "--grpc-java_out=lite:$(genDir)/gen $(in) && " +
+ "$(location soong_zip) -o $(out) -C $(genDir)/gen -D $(genDir)/gen"
genrule {
name: "checkIn-service-stub-lite",
@@ -43,18 +45,20 @@
}
java_library {
- name: "devicelockcontroller-protos-lite",
+ name: "devicelockcontroller-grpc-lite",
host_supported: true,
proto: {
type: "lite",
include_dirs: [
"external/protobuf/src",
"external/protobuf/java",
+ "packages/modules/DeviceLock/DeviceLockController/proto",
],
},
srcs: [
":checkIn-service-stub-lite",
"*.proto",
+ ":libprotobuf-internal-protos",
],
libs: ["javax_annotation-api_1.3.2"],
static_libs: [
diff --git a/DeviceLockController/proto/configuration_info.proto b/DeviceLockController/proto/configuration_info.proto
index 6c74d1b..6a95e16 100644
--- a/DeviceLockController/proto/configuration_info.proto
+++ b/DeviceLockController/proto/configuration_info.proto
@@ -16,7 +16,7 @@
syntax = "proto2";
-package devicelock;
+package devicelockcontroller;
option java_package = "com.android.devicelockcontroller.proto";
option java_multiple_files = true;
diff --git a/DeviceLockController/proto/date.proto b/DeviceLockController/proto/date.proto
deleted file mode 100644
index 7748d89..0000000
--- a/DeviceLockController/proto/date.proto
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-syntax = "proto2";
-
-package devicelock;
-
-option java_package = "com.android.devicelockcontroller.proto";
-option java_outer_classname = "DateProto";
-
-// Represents a whole or partial calendar date, such as a birthday. The time of
-// day and time zone are either specified elsewhere or are insignificant. The
-// date is relative to the Gregorian Calendar. This can represent one of the
-// following:
-//
-// * A full date, with non-zero year, month, and day values.
-// * A month and day, with a zero year (for example, an anniversary).
-// * A year on its own, with a zero month and a zero day.
-// * A year and month, with a zero day (for example, a credit card expiration
-// date).
-//
-message Date {
- // Year of the date. Must be from 1 to 9999, or 0 to specify a date without
- // a year.
- required int32 year = 1;
- // Month of a year. Must be from 1 to 12, or 0 to specify a year without a
- // month and day.
- required int32 month = 2;
- // Day of a month. Must be from 1 to 31 and valid for the year and month, or 0
- // to specify a year by itself or a year and month where the day isn't
- // significant.
- required int32 day = 3;
-}
\ No newline at end of file
diff --git a/DeviceLockController/proto/device_checkin_info.proto b/DeviceLockController/proto/device_checkin_info.proto
index e0dda46..c9cba87 100644
--- a/DeviceLockController/proto/device_checkin_info.proto
+++ b/DeviceLockController/proto/device_checkin_info.proto
@@ -16,7 +16,7 @@
syntax = "proto2";
-package devicelock;
+package devicelockcontroller;
option java_package = "com.android.devicelockcontroller.proto";
option java_multiple_files = true;
diff --git a/DeviceLockController/proto/device_info.proto b/DeviceLockController/proto/device_info.proto
index 78c1ede..a2df3b9 100644
--- a/DeviceLockController/proto/device_info.proto
+++ b/DeviceLockController/proto/device_info.proto
@@ -16,7 +16,7 @@
syntax = "proto2";
-package devicelock;
+package devicelockcontroller;
option java_package = "com.android.devicelockcontroller.proto";
option java_multiple_files = true;
diff --git a/DeviceLockController/proto/service.proto b/DeviceLockController/proto/service.proto
index 1144af9..64a13c1 100644
--- a/DeviceLockController/proto/service.proto
+++ b/DeviceLockController/proto/service.proto
@@ -16,12 +16,12 @@
syntax = "proto2";
-package devicelock;
+package devicelockcontroller;
-import "packages/modules/DeviceLock/DeviceLockController/proto/configuration_info.proto";
-import "packages/modules/DeviceLock/DeviceLockController/proto/date.proto";
-import "packages/modules/DeviceLock/DeviceLockController/proto/device_checkin_info.proto";
-import "packages/modules/DeviceLock/DeviceLockController/proto/device_info.proto";
+import "google/protobuf/timestamp.proto";
+import "configuration_info.proto";
+import "device_checkin_info.proto";
+import "device_info.proto";
option java_package = "com.android.devicelockcontroller.proto";
option java_multiple_files = true;
@@ -109,7 +109,7 @@
message NextCheckinInformation {
// Set by the Device Lock server which tells the Device Lock Android client
// the date when the next check-in should happen.
- optional Date next_checkin_date = 1;
+ optional google.protobuf.Timestamp next_checkin_timestamp = 1;
}
// Information needed by the Device Lock Android client for device provisioning.
diff --git a/DeviceLockController/src/com/android/devicelockcontroller/provision/checkin/DeviceCheckInHelper.java b/DeviceLockController/src/com/android/devicelockcontroller/provision/checkin/DeviceCheckInHelper.java
index ad9242e..8ef51c0 100644
--- a/DeviceLockController/src/com/android/devicelockcontroller/provision/checkin/DeviceCheckInHelper.java
+++ b/DeviceLockController/src/com/android/devicelockcontroller/provision/checkin/DeviceCheckInHelper.java
@@ -36,13 +36,14 @@
import androidx.work.WorkManager;
import com.android.devicelockcontroller.R;
-import com.android.devicelockcontroller.proto.DateProto;
import com.android.devicelockcontroller.provision.grpc.GetDeviceCheckInStatusResponseWrapper;
import com.android.devicelockcontroller.setup.UserPreferences;
import com.android.devicelockcontroller.util.LogUtil;
+import com.google.protobuf.Timestamp;
+
import java.time.Duration;
-import java.time.LocalDate;
+import java.time.Instant;
/**
* Helper class to perform the device check in process with device lock backend server
@@ -133,7 +134,7 @@
@NonNull
String getCarrierInfo() {
- // TODO: Figure out if we need carrier info of all sims.
+ // TODO(b/267507927): Figure out if we need carrier info of all sims.
return mTelephonyManager.getSimOperator();
}
@@ -152,13 +153,15 @@
LogUtil.w(TAG, "Received retry response with out next check-in information");
return false;
}
- DateProto.Date nextCheckInDate =
- nextStep.getNextCheckInInformation().getNextCheckinDate();
+ Timestamp nextCheckinTime =
+ nextStep.getNextCheckInInformation().getNextCheckinTimestamp();
- final Duration delay = Duration.between(LocalDate.now().atStartOfDay(),
- LocalDate.of(nextCheckInDate.getYear(), nextCheckInDate.getMonth(),
- nextCheckInDate.getDay()).atStartOfDay());
- if (delay.isZero() || delay.isNegative()) {
+ final Duration delay = Duration.between(Instant.now(),
+ Instant.ofEpochSecond(
+ nextCheckinTime.getSeconds(),
+ nextCheckinTime.getNanos()));
+ //TODO: Figure out whether there should be a minimum delay?
+ if (delay.isNegative()) {
LogUtil.w(TAG, "Next check in date is not in the future");
return false;
}
diff --git a/DeviceLockController/tests/robolectric/src/com/android/devicelockcontroller/provision/checkin/DeviceCheckInHelperTest.java b/DeviceLockController/tests/robolectric/src/com/android/devicelockcontroller/provision/checkin/DeviceCheckInHelperTest.java
index e1afc06..8dba2f6 100644
--- a/DeviceLockController/tests/robolectric/src/com/android/devicelockcontroller/provision/checkin/DeviceCheckInHelperTest.java
+++ b/DeviceLockController/tests/robolectric/src/com/android/devicelockcontroller/provision/checkin/DeviceCheckInHelperTest.java
@@ -37,12 +37,13 @@
import com.android.devicelockcontroller.TestDeviceLockControllerApplication;
import com.android.devicelockcontroller.proto.ClientCheckinStatus;
-import com.android.devicelockcontroller.proto.DateProto;
import com.android.devicelockcontroller.proto.GetDeviceCheckinStatusResponse;
import com.android.devicelockcontroller.proto.NextCheckinInformation;
import com.android.devicelockcontroller.provision.grpc.GetDeviceCheckInStatusResponseWrapper;
import com.android.devicelockcontroller.setup.UserPreferences;
+import com.google.protobuf.Timestamp;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -50,7 +51,8 @@
import org.robolectric.Shadows;
import org.robolectric.shadows.ShadowTelephonyManager;
-import java.time.LocalDate;
+import java.time.Duration;
+import java.time.Instant;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
@@ -59,7 +61,7 @@
@RunWith(RobolectricTestRunner.class)
public final class DeviceCheckInHelperTest {
- static final int TEST_CHECK_RETRY_DAYS = 30;
+ static final Duration TEST_CHECK_RETRY_DURATION = Duration.ofDays(30);
private TestDeviceLockControllerApplication mTestApplication;
static final int TOTAL_SLOT_COUNT = 2;
static final int TOTAL_ID_COUNT = 4;
@@ -121,7 +123,7 @@
throws ExecutionException, InterruptedException, TimeoutException {
final GetDeviceCheckInStatusResponseWrapper response = createMockResponse(
CLIENT_CHECKIN_STATUS_RETRY_CHECKIN,
- LocalDate.now().plusDays(TEST_CHECK_RETRY_DAYS));
+ Instant.now().plus(TEST_CHECK_RETRY_DURATION));
assertThat(mHelper.handleGetDeviceCheckInStatusResponse(response)).isTrue();
@@ -139,18 +141,17 @@
private static GetDeviceCheckInStatusResponseWrapper createMockResponse(
ClientCheckinStatus checkInStatus,
- @Nullable LocalDate nextCheckInDate) {
- GetDeviceCheckinStatusResponse.Builder builder = GetDeviceCheckinStatusResponse.newBuilder()
- .setClientCheckinStatus(checkInStatus);
+ @Nullable Instant nextCheckInTime) {
+ GetDeviceCheckinStatusResponse.Builder builder =
+ GetDeviceCheckinStatusResponse.newBuilder()
+ .setClientCheckinStatus(checkInStatus);
- if (nextCheckInDate != null) {
+ if (nextCheckInTime != null) {
builder.setNextCheckinInformation(
- NextCheckinInformation.newBuilder().setNextCheckinDate(
- DateProto.Date.newBuilder()
- .setYear(nextCheckInDate.getYear())
- .setMonth(nextCheckInDate.getMonthValue())
- .setDay(nextCheckInDate.getDayOfMonth())
- .build()));
+ NextCheckinInformation.newBuilder().setNextCheckinTimestamp(
+ Timestamp.newBuilder()
+ .setSeconds(nextCheckInTime.getEpochSecond())
+ .setNanos(nextCheckInTime.getNano())));
}
return new GetDeviceCheckInStatusResponseWrapper(builder.build());