• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <binder/Parcel.h>
18 #include <binder/RpcSession.h>
19 #include <binder/Status.h>
20 #include <gtest/gtest.h>
21 
22 #ifdef __ANDROID__
23 #include <android-base/properties.h>
24 #endif
25 
26 #include "../Debug.h"
27 #include "../Utils.h"
28 
29 namespace android {
30 
31 static const int32_t kInt32Array[] = {-1, 0, 17};
32 static const uint8_t kByteArray[] = {0, 17, 255};
33 enum EnumInt8 : int8_t { Int8A, Int8B };
34 enum EnumInt32 : int32_t { Int32A, Int32B };
35 enum EnumInt64 : int64_t { Int64A, Int64B };
36 struct AParcelable : Parcelable {
writeToParcelandroid::AParcelable37     status_t writeToParcel(Parcel* parcel) const { return parcel->writeInt32(37); }
readFromParcelandroid::AParcelable38     status_t readFromParcel(const Parcel*) { return OK; }
39 };
40 
41 // clang-format off
42 constexpr size_t kFillFunIndexLineBase = __LINE__ + 2;
43 static const std::vector<std::function<void(Parcel* p)>> kFillFuns {
__anon8de9214a0102(Parcel* p) 44     [](Parcel* p) { ASSERT_EQ(OK, p->writeInterfaceToken(String16(u"tok"))); },
__anon8de9214a0202(Parcel* p) 45     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32(-1)); },
__anon8de9214a0302(Parcel* p) 46     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32(0)); },
__anon8de9214a0402(Parcel* p) 47     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32(17)); },
__anon8de9214a0502(Parcel* p) 48     [](Parcel* p) { ASSERT_EQ(OK, p->writeUint32(0)); },
__anon8de9214a0602(Parcel* p) 49     [](Parcel* p) { ASSERT_EQ(OK, p->writeUint32(1)); },
__anon8de9214a0702(Parcel* p) 50     [](Parcel* p) { ASSERT_EQ(OK, p->writeUint32(10003)); },
__anon8de9214a0802(Parcel* p) 51     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt64(-1)); },
__anon8de9214a0902(Parcel* p) 52     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt64(0)); },
__anon8de9214a0a02(Parcel* p) 53     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt64(17)); },
__anon8de9214a0b02(Parcel* p) 54     [](Parcel* p) { ASSERT_EQ(OK, p->writeUint64(0)); },
__anon8de9214a0c02(Parcel* p) 55     [](Parcel* p) { ASSERT_EQ(OK, p->writeUint64(1)); },
__anon8de9214a0d02(Parcel* p) 56     [](Parcel* p) { ASSERT_EQ(OK, p->writeUint64(10003)); },
__anon8de9214a0e02(Parcel* p) 57     [](Parcel* p) { ASSERT_EQ(OK, p->writeFloat(0.0f)); },
__anon8de9214a0f02(Parcel* p) 58     [](Parcel* p) { ASSERT_EQ(OK, p->writeFloat(0.1f)); },
__anon8de9214a1002(Parcel* p) 59     [](Parcel* p) { ASSERT_EQ(OK, p->writeFloat(9.1f)); },
__anon8de9214a1102(Parcel* p) 60     [](Parcel* p) { ASSERT_EQ(OK, p->writeDouble(0.0)); },
__anon8de9214a1202(Parcel* p) 61     [](Parcel* p) { ASSERT_EQ(OK, p->writeDouble(0.1)); },
__anon8de9214a1302(Parcel* p) 62     [](Parcel* p) { ASSERT_EQ(OK, p->writeDouble(9.1)); },
__anon8de9214a1402(Parcel* p) 63     [](Parcel* p) { ASSERT_EQ(OK, p->writeCString("")); },
__anon8de9214a1502(Parcel* p) 64     [](Parcel* p) { ASSERT_EQ(OK, p->writeCString("a")); },
__anon8de9214a1602(Parcel* p) 65     [](Parcel* p) { ASSERT_EQ(OK, p->writeCString("baba")); },
__anon8de9214a1702(Parcel* p) 66     [](Parcel* p) { ASSERT_EQ(OK, p->writeString8(String8(""))); },
__anon8de9214a1802(Parcel* p) 67     [](Parcel* p) { ASSERT_EQ(OK, p->writeString8(String8("a"))); },
__anon8de9214a1902(Parcel* p) 68     [](Parcel* p) { ASSERT_EQ(OK, p->writeString8(String8("baba"))); },
__anon8de9214a1a02(Parcel* p) 69     [](Parcel* p) { ASSERT_EQ(OK, p->writeString16(String16(u""))); },
__anon8de9214a1b02(Parcel* p) 70     [](Parcel* p) { ASSERT_EQ(OK, p->writeString16(String16(u"a"))); },
__anon8de9214a1c02(Parcel* p) 71     [](Parcel* p) { ASSERT_EQ(OK, p->writeString16(String16(u"baba"))); },
__anon8de9214a1d02(Parcel* p) 72     [](Parcel* p) { ASSERT_EQ(OK, p->writeStrongBinder(nullptr)); },
__anon8de9214a1e02(Parcel* p) 73     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32Array(countof(kInt32Array), kInt32Array)); },
__anon8de9214a1f02(Parcel* p) 74     [](Parcel* p) { ASSERT_EQ(OK, p->writeByteArray(countof(kByteArray), kByteArray)); },
__anon8de9214a2002(Parcel* p) 75     [](Parcel* p) { ASSERT_EQ(OK, p->writeBool(true)); },
__anon8de9214a2102(Parcel* p) 76     [](Parcel* p) { ASSERT_EQ(OK, p->writeBool(false)); },
__anon8de9214a2202(Parcel* p) 77     [](Parcel* p) { ASSERT_EQ(OK, p->writeChar('a')); },
__anon8de9214a2302(Parcel* p) 78     [](Parcel* p) { ASSERT_EQ(OK, p->writeChar('?')); },
__anon8de9214a2402(Parcel* p) 79     [](Parcel* p) { ASSERT_EQ(OK, p->writeChar('\0')); },
__anon8de9214a2502(Parcel* p) 80     [](Parcel* p) { ASSERT_EQ(OK, p->writeByte(-128)); },
__anon8de9214a2602(Parcel* p) 81     [](Parcel* p) { ASSERT_EQ(OK, p->writeByte(0)); },
__anon8de9214a2702(Parcel* p) 82     [](Parcel* p) { ASSERT_EQ(OK, p->writeByte(127)); },
__anon8de9214a2802(Parcel* p) 83     [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8AsUtf16(std::string(""))); },
__anon8de9214a2902(Parcel* p) 84     [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8AsUtf16(std::string("a"))); },
__anon8de9214a2a02(Parcel* p) 85     [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8AsUtf16(std::string("abab"))); },
__anon8de9214a2b02(Parcel* p) 86     [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8AsUtf16(std::nullopt)); },
__anon8de9214a2c02(Parcel* p) 87     [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8AsUtf16(std::optional<std::string>(""))); },
__anon8de9214a2d02(Parcel* p) 88     [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8AsUtf16(std::optional<std::string>("a"))); },
__anon8de9214a2e02(Parcel* p) 89     [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8AsUtf16(std::optional<std::string>("abab"))); },
__anon8de9214a2f02(Parcel* p) 90     [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::optional<std::vector<int8_t>>(std::nullopt))); },
__anon8de9214a3002(Parcel* p) 91     [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::optional<std::vector<int8_t>>({-1, 0, 17}))); },
__anon8de9214a3102(Parcel* p) 92     [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::vector<int8_t>({}))); },
__anon8de9214a3202(Parcel* p) 93     [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::vector<int8_t>({-1, 0, 17}))); },
__anon8de9214a3302(Parcel* p) 94     [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::optional<std::vector<uint8_t>>(std::nullopt))); },
__anon8de9214a3402(Parcel* p) 95     [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::optional<std::vector<uint8_t>>({0, 1, 17}))); },
__anon8de9214a3502(Parcel* p) 96     [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::vector<uint8_t>({}))); },
__anon8de9214a3602(Parcel* p) 97     [](Parcel* p) { ASSERT_EQ(OK, p->writeByteVector(std::vector<uint8_t>({0, 1, 17}))); },
__anon8de9214a3702(Parcel* p) 98     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32Vector(std::optional<std::vector<int32_t>>(std::nullopt))); },
__anon8de9214a3802(Parcel* p) 99     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32Vector(std::optional<std::vector<int32_t>>({-1, 0, 17}))); },
__anon8de9214a3902(Parcel* p) 100     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32Vector(std::vector<int32_t>({}))); },
__anon8de9214a3a02(Parcel* p) 101     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt32Vector(std::vector<int32_t>({-1, 0, 17}))); },
__anon8de9214a3b02(Parcel* p) 102     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt64Vector(std::optional<std::vector<int64_t>>(std::nullopt))); },
__anon8de9214a3c02(Parcel* p) 103     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt64Vector(std::optional<std::vector<int64_t>>({-1, 0, 17}))); },
__anon8de9214a3d02(Parcel* p) 104     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt64Vector(std::vector<int64_t>({}))); },
__anon8de9214a3e02(Parcel* p) 105     [](Parcel* p) { ASSERT_EQ(OK, p->writeInt64Vector(std::vector<int64_t>({-1, 0, 17}))); },
__anon8de9214a3f02(Parcel* p) 106     [](Parcel* p) { ASSERT_EQ(OK, p->writeUint64Vector(std::optional<std::vector<uint64_t>>(std::nullopt))); },
__anon8de9214a4002(Parcel* p) 107     [](Parcel* p) { ASSERT_EQ(OK, p->writeUint64Vector(std::optional<std::vector<uint64_t>>({0, 1, 17}))); },
__anon8de9214a4102(Parcel* p) 108     [](Parcel* p) { ASSERT_EQ(OK, p->writeUint64Vector(std::vector<uint64_t>({}))); },
__anon8de9214a4202(Parcel* p) 109     [](Parcel* p) { ASSERT_EQ(OK, p->writeUint64Vector(std::vector<uint64_t>({0, 1, 17}))); },
__anon8de9214a4302(Parcel* p) 110     [](Parcel* p) { ASSERT_EQ(OK, p->writeFloatVector(std::optional<std::vector<float>>(std::nullopt))); },
__anon8de9214a4402(Parcel* p) 111     [](Parcel* p) { ASSERT_EQ(OK, p->writeFloatVector(std::optional<std::vector<float>>({0.0f, 0.1f, 9.1f}))); },
__anon8de9214a4502(Parcel* p) 112     [](Parcel* p) { ASSERT_EQ(OK, p->writeFloatVector(std::vector<float>({}))); },
__anon8de9214a4602(Parcel* p) 113     [](Parcel* p) { ASSERT_EQ(OK, p->writeFloatVector(std::vector<float>({0.0f, 0.1f, 9.1f}))); },
__anon8de9214a4702(Parcel* p) 114     [](Parcel* p) { ASSERT_EQ(OK, p->writeDoubleVector(std::optional<std::vector<double>>(std::nullopt))); },
__anon8de9214a4802(Parcel* p) 115     [](Parcel* p) { ASSERT_EQ(OK, p->writeDoubleVector(std::optional<std::vector<double>>({0.0, 0.1, 9.1}))); },
__anon8de9214a4902(Parcel* p) 116     [](Parcel* p) { ASSERT_EQ(OK, p->writeDoubleVector(std::vector<double>({}))); },
__anon8de9214a4a02(Parcel* p) 117     [](Parcel* p) { ASSERT_EQ(OK, p->writeDoubleVector(std::vector<double>({0.0, 0.1, 9.1}))); },
__anon8de9214a4b02(Parcel* p) 118     [](Parcel* p) { ASSERT_EQ(OK, p->writeBoolVector(std::optional<std::vector<bool>>(std::nullopt))); },
__anon8de9214a4c02(Parcel* p) 119     [](Parcel* p) { ASSERT_EQ(OK, p->writeBoolVector(std::optional<std::vector<bool>>({true, false}))); },
__anon8de9214a4d02(Parcel* p) 120     [](Parcel* p) { ASSERT_EQ(OK, p->writeBoolVector(std::vector<bool>({}))); },
__anon8de9214a4e02(Parcel* p) 121     [](Parcel* p) { ASSERT_EQ(OK, p->writeBoolVector(std::vector<bool>({true, false}))); },
__anon8de9214a4f02(Parcel* p) 122     [](Parcel* p) { ASSERT_EQ(OK, p->writeCharVector(std::optional<std::vector<char16_t>>(std::nullopt))); },
__anon8de9214a5002(Parcel* p) 123     [](Parcel* p) { ASSERT_EQ(OK, p->writeCharVector(std::optional<std::vector<char16_t>>({'a', '\0', '?'}))); },
__anon8de9214a5102(Parcel* p) 124     [](Parcel* p) { ASSERT_EQ(OK, p->writeCharVector(std::vector<char16_t>({}))); },
__anon8de9214a5202(Parcel* p) 125     [](Parcel* p) { ASSERT_EQ(OK, p->writeCharVector(std::vector<char16_t>({'a', '\0', '?'}))); },
__anon8de9214a5302(Parcel* p) 126     [](Parcel* p) { ASSERT_EQ(OK, p->writeString16Vector(std::optional<std::vector<std::optional<String16>>>(std::nullopt))); },
__anon8de9214a5402(Parcel* p) 127     [](Parcel* p) { ASSERT_EQ(OK, p->writeString16Vector(std::optional<std::vector<std::optional<String16>>>({std::nullopt, String16(), String16(u"a")}))); },
__anon8de9214a5502(Parcel* p) 128     [](Parcel* p) { ASSERT_EQ(OK, p->writeString16Vector(std::vector<std::optional<String16>>({}))); },
__anon8de9214a5602(Parcel* p) 129     [](Parcel* p) { ASSERT_EQ(OK, p->writeString16Vector(std::vector<std::optional<String16>>({std::nullopt, String16(), String16(u"a")}))); },
__anon8de9214a5702(Parcel* p) 130     [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8VectorAsUtf16Vector(std::optional<std::vector<std::optional<std::string>>>(std::nullopt))); },
__anon8de9214a5802(Parcel* p) 131     [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8VectorAsUtf16Vector(std::optional<std::vector<std::optional<std::string>>>({std::nullopt, std::string(), std::string("a")}))); },
__anon8de9214a5902(Parcel* p) 132     [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8VectorAsUtf16Vector(std::vector<std::optional<std::string>>({}))); },
__anon8de9214a5a02(Parcel* p) 133     [](Parcel* p) { ASSERT_EQ(OK, p->writeUtf8VectorAsUtf16Vector(std::vector<std::optional<std::string>>({std::nullopt, std::string(), std::string("a")}))); },
__anon8de9214a5b02(Parcel* p) 134     [](Parcel* p) { ASSERT_EQ(OK, p->writeStrongBinderVector(std::optional<std::vector<sp<IBinder>>>(std::nullopt))); },
__anon8de9214a5c02(Parcel* p) 135     [](Parcel* p) { ASSERT_EQ(OK, p->writeStrongBinderVector(std::optional<std::vector<sp<IBinder>>>({nullptr}))); },
__anon8de9214a5d02(Parcel* p) 136     [](Parcel* p) { ASSERT_EQ(OK, p->writeStrongBinderVector(std::vector<sp<IBinder>>({}))); },
__anon8de9214a5e02(Parcel* p) 137     [](Parcel* p) { ASSERT_EQ(OK, p->writeStrongBinderVector(std::vector<sp<IBinder>>({nullptr}))); },
__anon8de9214a5f02(Parcel* p) 138     [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::optional<std::vector<EnumInt8>>(std::nullopt))); },
__anon8de9214a6002(Parcel* p) 139     [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::optional<std::vector<EnumInt8>>({Int8A, Int8B}))); },
__anon8de9214a6102(Parcel* p) 140     [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::vector<EnumInt8>({Int8A, Int8B}))); },
__anon8de9214a6202(Parcel* p) 141     [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::optional<std::vector<EnumInt32>>(std::nullopt))); },
__anon8de9214a6302(Parcel* p) 142     [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::optional<std::vector<EnumInt32>>({Int32A, Int32B}))); },
__anon8de9214a6402(Parcel* p) 143     [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::vector<EnumInt32>({Int32A, Int32B}))); },
__anon8de9214a6502(Parcel* p) 144     [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::optional<std::vector<EnumInt64>>(std::nullopt))); },
__anon8de9214a6602(Parcel* p) 145     [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::optional<std::vector<EnumInt64>>({Int64A, Int64B}))); },
__anon8de9214a6702(Parcel* p) 146     [](Parcel* p) { ASSERT_EQ(OK, p->writeEnumVector(std::vector<EnumInt64>({Int64A, Int64B}))); },
__anon8de9214a6802(Parcel* p) 147     [](Parcel* p) { ASSERT_EQ(OK, p->writeParcelableVector(std::optional<std::vector<std::optional<AParcelable>>>(std::nullopt))); },
__anon8de9214a6902(Parcel* p) 148     [](Parcel* p) { ASSERT_EQ(OK, p->writeParcelableVector(std::optional<std::vector<std::optional<AParcelable>>>({AParcelable()}))); },
__anon8de9214a6a02(Parcel* p) 149     [](Parcel* p) { ASSERT_EQ(OK, p->writeParcelableVector(std::vector<AParcelable>({AParcelable()}))); },
__anon8de9214a6b02(Parcel* p) 150     [](Parcel* p) { ASSERT_EQ(OK, p->writeNullableParcelable(std::optional<AParcelable>(std::nullopt))); },
__anon8de9214a6c02(Parcel* p) 151     [](Parcel* p) { ASSERT_EQ(OK, p->writeNullableParcelable(std::optional<AParcelable>(AParcelable()))); },
__anon8de9214a6d02(Parcel* p) 152     [](Parcel* p) { ASSERT_EQ(OK, p->writeParcelable(AParcelable())); },
__anon8de9214a6e02(Parcel* p) 153     [](Parcel* p) { ASSERT_EQ(OK, p->writeVectorSize(std::vector<int32_t>({0, 1, 17}))); },
__anon8de9214a6f02(Parcel* p) 154     [](Parcel* p) { ASSERT_EQ(OK, p->writeVectorSize(std::vector<AParcelable>({}))); },
__anon8de9214a7002(Parcel* p) 155     [](Parcel* p) { ASSERT_EQ(OK, p->writeVectorSize(std::optional<std::vector<int32_t>>(std::nullopt))); },
__anon8de9214a7102(Parcel* p) 156     [](Parcel* p) { ASSERT_EQ(OK, p->writeVectorSize(std::optional<std::vector<int32_t>>({0, 1, 17}))); },
__anon8de9214a7202(Parcel* p) 157     [](Parcel* p) { ASSERT_EQ(OK, p->writeNoException()); },
__anon8de9214a7302(Parcel* p) 158     [](Parcel* p) { ASSERT_EQ(OK, binder::Status::ok().writeToParcel(p)); },
__anon8de9214a7402(Parcel* p) 159     [](Parcel* p) { ASSERT_EQ(OK, binder::Status::fromExceptionCode(7, ":D").writeToParcel(p)); },
__anon8de9214a7502(Parcel* p) 160     [](Parcel* p) { ASSERT_EQ(OK, binder::Status::fromServiceSpecificError(8, ":/").writeToParcel(p)); },
161 };
162 // clang-format on
163 
setParcelForRpc(Parcel * p,uint32_t version)164 static void setParcelForRpc(Parcel* p, uint32_t version) {
165     auto session = RpcSession::make();
166     EXPECT_TRUE(session->setProtocolVersion(version));
167     EXPECT_EQ(OK, session->addNullDebuggingClient());
168     p->markForRpc(session);
169 }
170 
buildRepr(uint32_t version)171 static std::string buildRepr(uint32_t version) {
172     std::string result;
173     for (size_t i = 0; i < kFillFuns.size(); i++) {
174         if (i != 0) result += "|";
175         Parcel p;
176         setParcelForRpc(&p, version);
177         kFillFuns[i](&p);
178 
179         result += HexString(p.data(), p.dataSize());
180     }
181     return result;
182 }
183 
184 // To be replaced with std::views::split (and std::views::zip) once C++ compilers catch up.
split(std::string_view s,char delimiter)185 static std::vector<std::string> split(std::string_view s, char delimiter) {
186     std::vector<std::string> result;
187     size_t pos = 0;
188     while (true) {
189         const auto found = s.find(delimiter, pos);
190         result.emplace_back(s.substr(pos, found - pos));
191         if (found == s.npos) return result;
192         pos = found + 1;
193     }
194 }
195 
checkRepr(const std::string & repr,uint32_t version)196 static void checkRepr(const std::string& repr, uint32_t version) {
197     const std::string actualRepr = buildRepr(version);
198 
199     auto expected = split(repr, '|');
200     ASSERT_EQ(expected.size(), kFillFuns.size());
201 
202     auto actual = split(actualRepr, '|');
203     ASSERT_EQ(actual.size(), kFillFuns.size());
204 
205     for (size_t i = 0; i < kFillFuns.size(); i++) {
206         EXPECT_EQ(expected[i], actual[i])
207                 << "Format mismatch, see " __FILE__ " line " << (kFillFunIndexLineBase + i);
208     }
209 
210     // same check as in the loop, but the above error is more clear to debug,
211     // and this error is more clear to be able to update the source file here.
212     EXPECT_EQ(repr, actualRepr);
213 }
214 
215 const std::string kCurrentRepr =
216         "0300000074006f006b000000|ffffffff|00000000|11000000|00000000|01000000|13270000|"
217         "ffffffffffffffff|0000000000000000|1100000000000000|0000000000000000|0100000000000000|"
218         "1327000000000000|00000000|cdcccc3d|9a991141|0000000000000000|9a9999999999b93f|"
219         "3333333333332240|00000000|61000000|6261626100000000|0000000000000000|0100000061000000|"
220         "040000006261626100000000|0000000000000000|0100000061000000|"
221         "04000000620061006200610000000000|0000000000000000|03000000ffffffff0000000011000000|"
222         "030000000011ff00|01000000|00000000|61000000|3f000000|00000000|80ffffff|00000000|7f000000|"
223         "0000000000000000|0100000061000000|04000000610062006100620000000000|ffffffff|"
224         "0000000000000000|0100000061000000|04000000610062006100620000000000|ffffffff|"
225         "03000000ff001100|00000000|03000000ff001100|ffffffff|0300000000011100|00000000|"
226         "0300000000011100|ffffffff|03000000ffffffff0000000011000000|00000000|"
227         "03000000ffffffff0000000011000000|ffffffff|"
228         "03000000ffffffffffffffff00000000000000001100000000000000|00000000|"
229         "03000000ffffffffffffffff00000000000000001100000000000000|ffffffff|"
230         "03000000000000000000000001000000000000001100000000000000|00000000|"
231         "03000000000000000000000001000000000000001100000000000000|ffffffff|"
232         "0300000000000000cdcccc3d9a991141|00000000|0300000000000000cdcccc3d9a991141|ffffffff|"
233         "0300000000000000000000009a9999999999b93f3333333333332240|00000000|"
234         "0300000000000000000000009a9999999999b93f3333333333332240|ffffffff|"
235         "020000000100000000000000|00000000|020000000100000000000000|ffffffff|"
236         "0300000061000000000000003f000000|00000000|0300000061000000000000003f000000|ffffffff|"
237         "03000000ffffffff00000000000000000100000061000000|00000000|"
238         "03000000ffffffff00000000000000000100000061000000|ffffffff|"
239         "03000000ffffffff00000000000000000100000061000000|00000000|"
240         "03000000ffffffff00000000000000000100000061000000|ffffffff|010000000000000000000000|"
241         "00000000|010000000000000000000000|ffffffff|0200000000010000|0200000000010000|ffffffff|"
242         "020000000000000001000000|020000000000000001000000|ffffffff|"
243         "0200000000000000000000000100000000000000|0200000000000000000000000100000000000000|"
244         "ffffffff|010000000100000025000000|010000000100000025000000|00000000|0100000025000000|"
245         "0100000025000000|03000000|00000000|ffffffff|03000000|00000000|00000000|"
246         "07000000020000003a0044000000000000000000|f8ffffff020000003a002f00000000000000000008000000";
247 
TEST(RpcWire,V0)248 TEST(RpcWire, V0) {
249     checkRepr(kCurrentRepr, 0);
250 }
251 
TEST(RpcWire,V1)252 TEST(RpcWire, V1) {
253     checkRepr(kCurrentRepr, 1);
254 }
255 
TEST(RpcWire,CurrentVersion)256 TEST(RpcWire, CurrentVersion) {
257     checkRepr(kCurrentRepr, RPC_WIRE_PROTOCOL_VERSION);
258 }
259 
260 static_assert(RPC_WIRE_PROTOCOL_VERSION == 1,
261               "If the binder wire protocol is updated, this test should test additional versions. "
262               "The binder wire protocol should only be updated on upstream AOSP.");
263 
TEST(RpcWire,NextIsPlusOneReminder)264 TEST(RpcWire, NextIsPlusOneReminder) {
265     if (RPC_WIRE_PROTOCOL_VERSION != RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL) {
266         EXPECT_EQ(RPC_WIRE_PROTOCOL_VERSION + 1, RPC_WIRE_PROTOCOL_VERSION_NEXT)
267                 << "Make sure to note what the next version should be.";
268     }
269 }
270 
TEST(RpcWire,ReleaseBranchHasFrozenRpcWireProtocol)271 TEST(RpcWire, ReleaseBranchHasFrozenRpcWireProtocol) {
272     if (RPC_WIRE_PROTOCOL_VERSION == RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL) {
273 #ifdef __ANDROID__
274         bool isRelease = base::GetProperty("ro.build.version.codename", "") == "REL";
275 #else
276         bool isRelease = true;
277 #endif
278         EXPECT_FALSE(isRelease)
279                 << "Binder RPC wire protocol must be frozen in release configuration!";
280     }
281 }
282 
283 } // namespace android
284