summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yi Jin <jinyithu@google.com> 2018-04-03 15:10:34 -0700
committer Yi Jin <jinyithu@google.com> 2018-04-04 16:29:55 -0700
commitad3e6e5d5a9746bfe9d4600172798c9d6309b149 (patch)
tree44c6eb169ebdb86f7bc9e73d8b9f3d97d96f2d4e
parent3275d9a004a45f4a2a9e30bbe7c662955ebdb9ff (diff)
This cl tries to fix cts tests IncidentdTest
1. Disable BatteryType section which is device-specific 2. Make timeout longer since meminfo section timedout in test 3. make some negative values sint 4. varint can be 64 bits, there is a bug implicitly convert it to 32 which loses values. 5. Found another bug which failed to read 64 bits varint, create a native test to make sure it works. Bug: 77291057 Test: atest CtsIncidentHostTestCases:com.android.server.cts.IncidentdTest Change-Id: I04cc730741f7901f37ac57a11af7777d57118a23
-rw-r--r--cmds/incidentd/src/PrivacyBuffer.cpp2
-rw-r--r--cmds/incidentd/src/Section.h2
-rw-r--r--core/proto/android/os/incident.proto2
-rw-r--r--core/proto/android/service/notification.proto6
-rw-r--r--libs/protoutil/Android.bp17
-rw-r--r--libs/protoutil/AndroidTest.xml26
-rw-r--r--libs/protoutil/src/EncodedBuffer.cpp10
-rw-r--r--libs/protoutil/tests/EncodedBuffer_test.cpp25
8 files changed, 80 insertions, 10 deletions
diff --git a/cmds/incidentd/src/PrivacyBuffer.cpp b/cmds/incidentd/src/PrivacyBuffer.cpp
index 6cd2fe15c1d8..d753e5e6404e 100644
--- a/cmds/incidentd/src/PrivacyBuffer.cpp
+++ b/cmds/incidentd/src/PrivacyBuffer.cpp
@@ -34,7 +34,7 @@ namespace incidentd {
void PrivacyBuffer::writeFieldOrSkip(uint32_t fieldTag, bool skip) {
uint8_t wireType = read_wire_type(fieldTag);
size_t bytesToWrite = 0;
- uint32_t varint = 0;
+ uint64_t varint = 0;
switch (wireType) {
case WIRE_TYPE_VARINT:
diff --git a/cmds/incidentd/src/Section.h b/cmds/incidentd/src/Section.h
index 34a3613cf0d0..20ecdb1cdfbd 100644
--- a/cmds/incidentd/src/Section.h
+++ b/cmds/incidentd/src/Section.h
@@ -31,7 +31,7 @@ namespace android {
namespace os {
namespace incidentd {
-const int64_t REMOTE_CALL_TIMEOUT_MS = 10 * 1000; // 10 seconds
+const int64_t REMOTE_CALL_TIMEOUT_MS = 30 * 1000; // 30 seconds
/**
* Base class for sections
diff --git a/core/proto/android/os/incident.proto b/core/proto/android/os/incident.proto
index 6467976bbf59..2a7c256031fe 100644
--- a/core/proto/android/os/incident.proto
+++ b/core/proto/android/os/incident.proto
@@ -170,7 +170,7 @@ message IncidentProto {
];
optional BatteryTypeProto battery_type = 2006 [
- (section).type = SECTION_FILE,
+ (section).type = SECTION_NONE, // disabled since the path is device specific!
(section).args = "/sys/class/power_supply/bms/battery_type"
];
diff --git a/core/proto/android/service/notification.proto b/core/proto/android/service/notification.proto
index cccd2fe56800..bcd7f29a2fcf 100644
--- a/core/proto/android/service/notification.proto
+++ b/core/proto/android/service/notification.proto
@@ -65,7 +65,7 @@ message NotificationRecordProto {
optional bool can_vibrate = 7;
optional bool can_show_light = 8;
optional string group_key = 9 [ (.android.privacy).dest = DEST_EXPLICIT ];
- optional int32 importance = 10;
+ optional sint32 importance = 10;
}
message ListenersDisablingEffectsProto {
@@ -122,11 +122,11 @@ message RankingHelperProto {
// Default value is UNKNOWN_UID = USER_NULL = -10000.
optional int32 uid = 2;
// Default is IMPORTANCE_UNSPECIFIED (-1000).
- optional int32 importance = 3;
+ optional sint32 importance = 3;
// Default is PRIORITY_DEFAULT (0).
optional int32 priority = 4;
// Default is VISIBILITY_NO_OVERRIDE (-1000).
- optional int32 visibility = 5;
+ optional sint32 visibility = 5;
// Default is true.
optional bool show_badge = 6;
repeated android.app.NotificationChannelProto channels = 7;
diff --git a/libs/protoutil/Android.bp b/libs/protoutil/Android.bp
index 4f1d2d5a4fe5..7ad83ca79695 100644
--- a/libs/protoutil/Android.bp
+++ b/libs/protoutil/Android.bp
@@ -37,3 +37,20 @@ cc_library {
"liblog",
],
}
+
+cc_test {
+ name: "libprotoutil_test",
+
+ srcs: [
+ "tests/EncodedBuffer_test.cpp",
+ ],
+
+ shared_libs: [
+ "libcutils",
+ "libprotoutil",
+ ],
+
+ static_libs: [
+ "libgmock",
+ ],
+}
diff --git a/libs/protoutil/AndroidTest.xml b/libs/protoutil/AndroidTest.xml
new file mode 100644
index 000000000000..46d418e1bb0a
--- /dev/null
+++ b/libs/protoutil/AndroidTest.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 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.
+-->
+<configuration description="Config for libprotoutil_test">
+ <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
+ <option name="cleanup" value="true" />
+ <option name="push" value="libprotoutil_test->/data/nativetest/libprotoutil_test" />
+ </target_preparer>
+ <option name="test-suite-tag" value="apct" />
+ <test class="com.android.tradefed.testtype.GTest" >
+ <option name="native-test-device-path" value="/data/nativetest" />
+ <option name="module-name" value="libprotoutil_test" />
+ </test>
+</configuration>
diff --git a/libs/protoutil/src/EncodedBuffer.cpp b/libs/protoutil/src/EncodedBuffer.cpp
index 3a5e2e9ef5d0..c017851a1623 100644
--- a/libs/protoutil/src/EncodedBuffer.cpp
+++ b/libs/protoutil/src/EncodedBuffer.cpp
@@ -13,11 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#define LOG_TAG "libprotoutil"
+
+#include <stdlib.h>
#include <android/util/EncodedBuffer.h>
#include <android/util/protobuf.h>
-
-#include <stdlib.h>
+#include <cutils/log.h>
namespace android {
namespace util {
@@ -228,7 +230,7 @@ EncodedBuffer::readRawVarint()
size_t start = mEp.pos();
while (true) {
uint8_t byte = readRawByte();
- val += (byte & 0x7F) << shift;
+ val |= (UINT64_C(0x7F) & byte) << shift;
if ((byte & 0x80) == 0) break;
shift += 7;
}
@@ -345,7 +347,7 @@ EncodedBuffer::iterator::readRawVarint()
uint64_t val = 0, shift = 0;
while (true) {
uint8_t byte = next();
- val += (byte & 0x7F) << shift;
+ val |= (INT64_C(0x7F) & byte) << shift;
if ((byte & 0x80) == 0) break;
shift += 7;
}
diff --git a/libs/protoutil/tests/EncodedBuffer_test.cpp b/libs/protoutil/tests/EncodedBuffer_test.cpp
new file mode 100644
index 000000000000..615ab4ab29ed
--- /dev/null
+++ b/libs/protoutil/tests/EncodedBuffer_test.cpp
@@ -0,0 +1,25 @@
+// Copyright (C) 2018 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.
+#include <android/util/EncodedBuffer.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+using namespace android::util;
+
+TEST(EncodedBufferTest, ReadVarint) {
+ EncodedBuffer buffer;
+ uint64_t val = UINT64_C(1522865904593);
+ buffer.writeRawVarint64(val);
+ EXPECT_EQ(val, buffer.begin().readRawVarint());
+}