lin
2025-07-30 fcd736bf35fd93b563e9bbf594f2aa7b62028cc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
/*
 * Copyright (C) 2016, 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 "tests/test_data.h"
 
namespace android {
namespace aidl {
namespace test_data {
namespace string_constants {
 
const char kCanonicalName[] = "android.os.IStringConstants";
const char kInterfaceDefinition[] = R"(
package android.os;
 
interface IStringConstants {
  const String EXAMPLE_CONSTANT = "foo";
}
)";
 
const char kJavaOutputPath[] = "some/path/to/output.java";
const char kExpectedJavaOutput[] =
    R"(/*
 * This file is auto-generated.  DO NOT MODIFY.
 */
package android.os;
public interface IStringConstants extends android.os.IInterface
{
  /** Default implementation for IStringConstants. */
  public static class Default implements android.os.IStringConstants
  {
    @Override
    public android.os.IBinder asBinder() {
      return null;
    }
  }
  /** Local-side IPC implementation stub class. */
  public static abstract class Stub extends android.os.Binder implements android.os.IStringConstants
  {
    private static final java.lang.String DESCRIPTOR = "android.os.IStringConstants";
    /** Construct the stub at attach it to the interface. */
    public Stub()
    {
      this.attachInterface(this, DESCRIPTOR);
    }
    /**
     * Cast an IBinder object into an android.os.IStringConstants interface,
     * generating a proxy if needed.
     */
    public static android.os.IStringConstants asInterface(android.os.IBinder obj)
    {
      if ((obj==null)) {
        return null;
      }
      android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
      if (((iin!=null)&&(iin instanceof android.os.IStringConstants))) {
        return ((android.os.IStringConstants)iin);
      }
      return new android.os.IStringConstants.Stub.Proxy(obj);
    }
    @Override public android.os.IBinder asBinder()
    {
      return this;
    }
    @Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
    {
      java.lang.String descriptor = DESCRIPTOR;
      switch (code)
      {
        case INTERFACE_TRANSACTION:
        {
          reply.writeString(descriptor);
          return true;
        }
        default:
        {
          return super.onTransact(code, data, reply, flags);
        }
      }
    }
    private static class Proxy implements android.os.IStringConstants
    {
      private android.os.IBinder mRemote;
      Proxy(android.os.IBinder remote)
      {
        mRemote = remote;
      }
      @Override public android.os.IBinder asBinder()
      {
        return mRemote;
      }
      public java.lang.String getInterfaceDescriptor()
      {
        return DESCRIPTOR;
      }
      public static android.os.IStringConstants sDefaultImpl;
    }
    public static boolean setDefaultImpl(android.os.IStringConstants impl) {
      if (Stub.Proxy.sDefaultImpl == null && impl != null) {
        Stub.Proxy.sDefaultImpl = impl;
        return true;
      }
      return false;
    }
    public static android.os.IStringConstants getDefaultImpl() {
      return Stub.Proxy.sDefaultImpl;
    }
  }
  public static final String EXAMPLE_CONSTANT = "foo";
}
)";
 
const char kCppOutputPath[] = "some/path/to/output.cpp";
const char kGenHeaderDir[] = "output";
const char kGenInterfaceHeaderPath[] = "output/android/os/IStringConstants.h";
const char kExpectedIHeaderOutput[] =
    R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_STRING_CONSTANTS_H_
#define AIDL_GENERATED_ANDROID_OS_I_STRING_CONSTANTS_H_
 
#include <binder/IBinder.h>
#include <binder/IInterface.h>
#include <binder/Status.h>
#include <utils/String16.h>
#include <utils/StrongPointer.h>
 
namespace android {
 
namespace os {
 
class IStringConstants : public ::android::IInterface {
public:
  DECLARE_META_INTERFACE(StringConstants)
  static const ::android::String16& EXAMPLE_CONSTANT();
};  // class IStringConstants
 
class IStringConstantsDefault : public IStringConstants {
public:
  ::android::IBinder* onAsBinder() override;
  
};
 
}  // namespace os
 
}  // namespace android
 
#endif  // AIDL_GENERATED_ANDROID_OS_I_STRING_CONSTANTS_H_
)";
 
const char kExpectedCppOutput[] =
    R"(#include <android/os/IStringConstants.h>
#include <android/os/BpStringConstants.h>
 
namespace android {
 
namespace os {
 
IMPLEMENT_META_INTERFACE(StringConstants, "android.os.IStringConstants")
 
const ::android::String16& IStringConstants::EXAMPLE_CONSTANT() {
  static const ::android::String16 value(::android::String16("foo"));
  return value;
}
 
::android::IBinder* IStringConstantsDefault::onAsBinder() {
  return nullptr;
}
 
}  // namespace os
 
}  // namespace android
#include <android/os/BpStringConstants.h>
#include <binder/Parcel.h>
#include <android-base/macros.h>
 
namespace android {
 
namespace os {
 
BpStringConstants::BpStringConstants(const ::android::sp<::android::IBinder>& _aidl_impl)
    : BpInterface<IStringConstants>(_aidl_impl){
}
 
}  // namespace os
 
}  // namespace android
#include <android/os/BnStringConstants.h>
#include <binder/Parcel.h>
 
namespace android {
 
namespace os {
 
::android::status_t BnStringConstants::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) {
  ::android::status_t _aidl_ret_status = ::android::OK;
  switch (_aidl_code) {
  default:
  {
    _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
  }
  break;
  }
  if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
    _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
  }
  return _aidl_ret_status;
}
 
}  // namespace os
 
}  // namespace android
)";
 
const char kExpectedJavaOutputWithVersion[] =
    R"(/*
 * This file is auto-generated.  DO NOT MODIFY.
 */
package android.os;
public interface IStringConstants extends android.os.IInterface
{
  /**
   * The version of this interface that the caller is built against.
   * This might be different from what {@link #getInterfaceVersion()
   * getInterfaceVersion} returns as that is the version of the interface
   * that the remote object is implementing.
   */
  public static final int VERSION = 10;
  /** Default implementation for IStringConstants. */
  public static class Default implements android.os.IStringConstants
  {
    @Override
    public int getInterfaceVersion() {
      return -1;
    }
    @Override
    public android.os.IBinder asBinder() {
      return null;
    }
  }
  /** Local-side IPC implementation stub class. */
  public static abstract class Stub extends android.os.Binder implements android.os.IStringConstants
  {
    private static final java.lang.String DESCRIPTOR = "android.os.IStringConstants";
    /** Construct the stub at attach it to the interface. */
    public Stub()
    {
      this.attachInterface(this, DESCRIPTOR);
    }
    /**
     * Cast an IBinder object into an android.os.IStringConstants interface,
     * generating a proxy if needed.
     */
    public static android.os.IStringConstants asInterface(android.os.IBinder obj)
    {
      if ((obj==null)) {
        return null;
      }
      android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
      if (((iin!=null)&&(iin instanceof android.os.IStringConstants))) {
        return ((android.os.IStringConstants)iin);
      }
      return new android.os.IStringConstants.Stub.Proxy(obj);
    }
    @Override public android.os.IBinder asBinder()
    {
      return this;
    }
    @Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
    {
      java.lang.String descriptor = DESCRIPTOR;
      switch (code)
      {
        case INTERFACE_TRANSACTION:
        {
          reply.writeString(descriptor);
          return true;
        }
        case TRANSACTION_getInterfaceVersion:
        {
          data.enforceInterface(descriptor);
          reply.writeNoException();
          reply.writeInt(getInterfaceVersion());
          return true;
        }
        default:
        {
          return super.onTransact(code, data, reply, flags);
        }
      }
    }
    private static class Proxy implements android.os.IStringConstants
    {
      private android.os.IBinder mRemote;
      Proxy(android.os.IBinder remote)
      {
        mRemote = remote;
      }
      private int mCachedVersion = -1;
      @Override public android.os.IBinder asBinder()
      {
        return mRemote;
      }
      public java.lang.String getInterfaceDescriptor()
      {
        return DESCRIPTOR;
      }
      @Override
      public int getInterfaceVersion() throws android.os.RemoteException {
        if (mCachedVersion == -1) {
          android.os.Parcel data = android.os.Parcel.obtain();
          android.os.Parcel reply = android.os.Parcel.obtain();
          try {
            data.writeInterfaceToken(DESCRIPTOR);
            mRemote.transact(Stub.TRANSACTION_getInterfaceVersion, data, reply, 0);
            reply.readException();
            mCachedVersion = reply.readInt();
          } finally {
            reply.recycle();
            data.recycle();
          }
        }
        return mCachedVersion;
      }
      public static android.os.IStringConstants sDefaultImpl;
    }
    static final int TRANSACTION_getInterfaceVersion = (android.os.IBinder.FIRST_CALL_TRANSACTION + 16777214);
    public static boolean setDefaultImpl(android.os.IStringConstants impl) {
      if (Stub.Proxy.sDefaultImpl == null && impl != null) {
        Stub.Proxy.sDefaultImpl = impl;
        return true;
      }
      return false;
    }
    public static android.os.IStringConstants getDefaultImpl() {
      return Stub.Proxy.sDefaultImpl;
    }
  }
  public static final String EXAMPLE_CONSTANT = "foo";
  public int getInterfaceVersion() throws android.os.RemoteException;
}
)";
 
const char kExpectedIHeaderOutputWithVersion[] =
R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_STRING_CONSTANTS_H_
#define AIDL_GENERATED_ANDROID_OS_I_STRING_CONSTANTS_H_
 
#include <binder/IBinder.h>
#include <binder/IInterface.h>
#include <binder/Status.h>
#include <utils/String16.h>
#include <utils/StrongPointer.h>
 
namespace android {
 
namespace os {
 
class IStringConstants : public ::android::IInterface {
public:
  DECLARE_META_INTERFACE(StringConstants)
  const int32_t VERSION = 10;
  static const ::android::String16& EXAMPLE_CONSTANT();
  virtual int32_t getInterfaceVersion() = 0;
};  // class IStringConstants
 
class IStringConstantsDefault : public IStringConstants {
public:
  ::android::IBinder* onAsBinder() override;
  int32_t getInterfaceVersion() override;
 
};
 
}  // namespace os
 
}  // namespace android
 
#endif  // AIDL_GENERATED_ANDROID_OS_I_STRING_CONSTANTS_H_
)";
 
const char kExpectedCppOutputWithVersion[] =
    R"(#include <android/os/IStringConstants.h>
#include <android/os/BpStringConstants.h>
 
namespace android {
 
namespace os {
 
IMPLEMENT_META_INTERFACE(StringConstants, "android.os.IStringConstants")
 
const ::android::String16& IStringConstants::EXAMPLE_CONSTANT() {
  static const ::android::String16 value(::android::String16("foo"));
  return value;
}
 
::android::IBinder* IStringConstantsDefault::onAsBinder() {
  return nullptr;
}
 
int32_t IStringConstantsDefault::getInterfaceVersion() {
  return 0;
}
 
}  // namespace os
 
}  // namespace android
#include <android/os/BpStringConstants.h>
#include <binder/Parcel.h>
#include <android-base/macros.h>
 
namespace android {
 
namespace os {
 
BpStringConstants::BpStringConstants(const ::android::sp<::android::IBinder>& _aidl_impl)
    : BpInterface<IStringConstants>(_aidl_impl){
}
 
int32_t BpStringConstants::getInterfaceVersion() {
  if (cached_version_ == -1) {
    ::android::Parcel data;
    ::android::Parcel reply;
    data.writeInterfaceToken(getInterfaceDescriptor());
    ::android::status_t err = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 16777214 /* getInterfaceVersion */, data, &reply);
    if (err == ::android::OK) {
      ::android::binder::Status _aidl_status;
      err = _aidl_status.readFromParcel(reply);
      if (err == ::android::OK && _aidl_status.isOk()) {
        cached_version_ = reply.readInt32();
      }
    }
  }
  return cached_version_;
}
 
}  // namespace os
 
}  // namespace android
#include <android/os/BnStringConstants.h>
#include <binder/Parcel.h>
 
namespace android {
 
namespace os {
 
::android::status_t BnStringConstants::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) {
  ::android::status_t _aidl_ret_status = ::android::OK;
  switch (_aidl_code) {
  case ::android::IBinder::FIRST_CALL_TRANSACTION + 16777214 /* getInterfaceVersion */:
  {
    _aidl_data.checkInterface(this);
    _aidl_reply->writeNoException();
    _aidl_reply->writeInt32(IStringConstants::VERSION);
  }
  break;
  default:
  {
    _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
  }
  break;
  }
  if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
    _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
  }
  return _aidl_ret_status;
}
 
int32_t BnStringConstants::getInterfaceVersion() {
  return IStringConstants::VERSION;
}
 
}  // namespace os
 
}  // namespace android
)";
 
}  // namespace string_constants
}  // namespace test_data
}  // namespace aidl
}  // namespace android