Skip to content

Commit d0061d4

Browse files
committed
Add protovalidate annotations to DeviceSpec
These annotations are equivalent to the validation that bundletool itself performs in DeviceSpecParser.validateDeviceSpec() in bundletool 1.18.1. Adding protovalidate annotations makes it easier for protovalidate-using consumers of android-bundle to validate device specs. The code for the upstream validation method can be found at https://github.com/google/bundletool/blob/1.18.1/src/main/java/com/android/tools/build/bundletool/device/DeviceSpecParser.java#L77.
1 parent b60048a commit d0061d4

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

android/bundle/devices.proto

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ syntax = "proto3";
22

33
package android.bundle;
44

5+
import "buf/validate/validate.proto";
56
import "google/protobuf/wrappers.proto";
67

78
option java_package = "com.android.bundle";
@@ -10,10 +11,10 @@ message DeviceSpec {
1011
// Supported ABI architectures in the order of preference.
1112
// The values should be the string as reported by the platform, e.g.
1213
// "armeabi-v7a" or "x86_64".
13-
repeated string supported_abis = 1;
14+
repeated string supported_abis = 1 [(buf.validate.field).repeated.min_items = 1];
1415

1516
// All installed locales represented as BCP-47 strings.
16-
repeated string supported_locales = 2;
17+
repeated string supported_locales = 2 [(buf.validate.field).repeated.min_items = 1];
1718

1819
// List of device features returned by the package manager utility.
1920
repeated string device_features = 3;
@@ -22,10 +23,10 @@ message DeviceSpec {
2223
repeated string gl_extensions = 4;
2324

2425
// Screen dpi.
25-
uint32 screen_density = 5;
26+
uint32 screen_density = 5 [(buf.validate.field).uint32.gt = 0];
2627

2728
// getprop ro.build.version.sdk
28-
uint32 sdk_version = 6;
29+
uint32 sdk_version = 6 [(buf.validate.field).uint32.gt = 0];
2930

3031
// getprop ro.build.version.codename
3132
string codename = 7;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Copyright (C) The Android Open Source Project
2+
Copyright 2025 Logan Magee
23

34
SPDX-License-Identifier: Apache-2.0

buf.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Generated by buf. DO NOT EDIT.
2+
version: v2
3+
deps:
4+
- name: buf.build/bufbuild/protovalidate
5+
commit: 52f32327d4b045a79293a6ad4e7e1236
6+
digest: b5:cbabc98d4b7b7b0447c9b15f68eeb8a7a44ef8516cb386ac5f66e7fd4062cd6723ed3f452ad8c384b851f79e33d26e7f8a94e2b807282b3def1cd966c7eace97

buf.lock.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Copyright 2025 Logan Magee
2+
3+
SPDX-License-Identifier: Apache-2.0

buf.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ version: v2
66
modules:
77
- path: .
88
name: buf.build/accrescent/android-bundle
9+
deps:
10+
- buf.build/bufbuild/protovalidate:v1.0.0
911
lint:
1012
ignore:
1113
- android/bundle

0 commit comments

Comments
 (0)