From 87bb7b2df144a9049f5e15f36d076feba2f50e09 Mon Sep 17 00:00:00 2001 From: Dakkshesh Date: Wed, 6 Aug 2025 13:14:12 +0530 Subject: [PATCH] cpp: external: Clean AOSP headers and resolve missing dependencies - To solve some dependency issues by removing redundant code. - Added missing headers Signed-off-by: Dakkshesh --- .../cpp/external/AOSP/include/binder/Common.h | 5 +- .../cpp/external/AOSP/include/binder/Parcel.h | 57 +----- .../external/AOSP/include/binder/Parcelable.h | 77 ++++++++ .../cpp/external/AOSP/include/binder/Status.h | 177 ++++++++++++++++++ .../cpp/external/AOSP/include/utils/RefBase.h | 2 +- .../AOSP/include/utils/StrongPointer.h | 2 +- .../cpp/external/AOSP/include/utils/Vector.h | 4 - 7 files changed, 260 insertions(+), 64 deletions(-) create mode 100644 app/src/main/cpp/external/AOSP/include/binder/Parcelable.h create mode 100644 app/src/main/cpp/external/AOSP/include/binder/Status.h diff --git a/app/src/main/cpp/external/AOSP/include/binder/Common.h b/app/src/main/cpp/external/AOSP/include/binder/Common.h index ed10154..b66ce03 100644 --- a/app/src/main/cpp/external/AOSP/include/binder/Common.h +++ b/app/src/main/cpp/external/AOSP/include/binder/Common.h @@ -39,11 +39,8 @@ // // For a more detailed explanation of this strategy, see // https://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html -#if BUILDING_LIBBINDER + #define LIBBINDER_EXPORTED __attribute__((__visibility__("default"))) -#else -#define LIBBINDER_EXPORTED -#endif // For stuff that is exported but probably shouldn't be. It behaves the exact // same way as LIBBINDER_EXPORTED, only exists to help track what we want diff --git a/app/src/main/cpp/external/AOSP/include/binder/Parcel.h b/app/src/main/cpp/external/AOSP/include/binder/Parcel.h index 6c4c6fe..ef9b0d6 100644 --- a/app/src/main/cpp/external/AOSP/include/binder/Parcel.h +++ b/app/src/main/cpp/external/AOSP/include/binder/Parcel.h @@ -26,9 +26,6 @@ #include #include -#ifndef BINDER_DISABLE_NATIVE_HANDLE -#include -#endif #include #include #include @@ -51,7 +48,6 @@ template class LightFlattenable; class IBinder; class IPCThreadState; class ProcessState; -class RpcSession; class String8; class TextOutput; namespace binder { @@ -63,7 +59,6 @@ class RecordedTransaction; class Parcel { friend class IPCThreadState; - friend class RpcState; public: class ReadableBlob; @@ -126,10 +121,6 @@ public: // is for an RPC transaction). LIBBINDER_EXPORTED void markForBinder(const sp& binder); - // Whenever possible, markForBinder should be preferred. This method is - // called automatically on reply Parcels for RPC transactions. - LIBBINDER_EXPORTED void markForRpc(const sp& session); - // Whether this Parcel is written for RPC transactions (after calls to // markForBinder or markForRpc). LIBBINDER_EXPORTED bool isForRpc() const; @@ -347,14 +338,6 @@ public: template status_t writeVectorSize(const std::unique_ptr>& val) __attribute__((deprecated("use std::optional version instead"))); -#ifndef BINDER_DISABLE_NATIVE_HANDLE - // Place a native_handle into the parcel (the native_handle's file- - // descriptors are dup'ed, so it is safe to delete the native_handle - // when this function returns). - // Doesn't take ownership of the native_handle. - LIBBINDER_EXPORTED status_t writeNativeHandle(const native_handle* handle); -#endif - // Place a file descriptor into the parcel. The given fd must remain // valid for the lifetime of the parcel. // The Parcel does not take ownership of the given fd unless you ask it to. @@ -601,14 +584,6 @@ public: // response headers rather than doing it by hand. LIBBINDER_EXPORTED int32_t readExceptionCode() const; -#ifndef BINDER_DISABLE_NATIVE_HANDLE - // Retrieve native_handle from the parcel. This returns a copy of the - // parcel's native_handle (the caller takes ownership). The caller - // must free the native_handle with native_handle_close() and - // native_handle_delete(). - LIBBINDER_EXPORTED native_handle* readNativeHandle() const; -#endif - // Retrieve a file descriptor from the parcel. This returns the raw fd // in the parcel, which you do not own -- use dup() to get your own copy. LIBBINDER_EXPORTED int readFileDescriptor() const; @@ -670,12 +645,6 @@ private: size_t ipcObjectsCount() const; void ipcSetDataReference(const uint8_t* data, size_t dataSize, const binder_size_t* objects, size_t objectsCount, release_func relFunc); - // Takes ownership even when an error is returned. - [[nodiscard]] status_t rpcSetDataReference( - const sp& session, const uint8_t* data, size_t dataSize, - const uint32_t* objectTable, size_t objectTableSize, - std::vector>&& ancillaryFds, - release_func relFunc); status_t finishWrite(size_t len); void releaseObjects(); @@ -1350,30 +1319,10 @@ private: mutable bool mFdsKnown = true; mutable bool mHasFds = false; }; - // Fields only needed when parcelling for RPC Binder. - struct RpcFields { - RpcFields(const sp& session); + + // TrickyStoreOSS stub + struct RpcFields {}; - // Should always be non-null. - const sp mSession; - - enum ObjectType : int32_t { - TYPE_BINDER_NULL = 0, - TYPE_BINDER = 1, - // FD to be passed via native transport (Trusty IPC or UNIX domain socket). - TYPE_NATIVE_FILE_DESCRIPTOR = 2, - }; - - // Sorted. - std::vector mObjectPositions; - - // File descriptors referenced by the parcel data. Should be indexed - // using the offsets in the parcel data. Don't assume the list is in the - // same order as `mObjectPositions`. - // - // Boxed to save space. Lazy allocated. - std::unique_ptr>> mFds; - }; std::variant mVariantFields; // Pointer to KernelFields in mVariantFields if present. diff --git a/app/src/main/cpp/external/AOSP/include/binder/Parcelable.h b/app/src/main/cpp/external/AOSP/include/binder/Parcelable.h new file mode 100644 index 0000000..0b707b3 --- /dev/null +++ b/app/src/main/cpp/external/AOSP/include/binder/Parcelable.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2015 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. + */ + +#pragma once + +#include + +#include +#include + +#include + +namespace android { + +class Parcel; + +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wweak-vtables" +#endif + +// Abstract interface of all parcelables. +class LIBBINDER_EXPORTED Parcelable { +public: + virtual ~Parcelable() = default; + + Parcelable() = default; + Parcelable(const Parcelable&) = default; + + // Write |this| parcelable to the given |parcel|. Keep in mind that + // implementations of writeToParcel must be manually kept in sync + // with readFromParcel and the Java equivalent versions of these methods. + // + // Returns android::OK on success and an appropriate error otherwise. + virtual status_t writeToParcel(Parcel* parcel) const = 0; + + // Read data from the given |parcel| into |this|. After readFromParcel + // completes, |this| should have equivalent state to the object that + // wrote itself to the parcel. + // + // Returns android::OK on success and an appropriate error otherwise. + virtual status_t readFromParcel(const Parcel* parcel) = 0; + + // WARNING: for use by auto-generated code only (AIDL). Should not be used + // manually, or there is a risk of breaking CTS, GTS, VTS, or CTS-on-GSI + // tests. + enum class Stability : int32_t { + STABILITY_LOCAL, + STABILITY_VINTF, // corresponds to @VintfStability + }; + + // 'Stable' means this parcelable is guaranteed to be stable for multiple + // years. + // It must be guaranteed by setting stability field in aidl_interface. + // WARNING: getStability() is only expected to be overridden by auto-generated + // code. Returns true if this parcelable is stable. + virtual Stability getStability() const { return Stability::STABILITY_LOCAL; } +}; // class Parcelable + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif + +} // namespace android diff --git a/app/src/main/cpp/external/AOSP/include/binder/Status.h b/app/src/main/cpp/external/AOSP/include/binder/Status.h new file mode 100644 index 0000000..d69f662 --- /dev/null +++ b/app/src/main/cpp/external/AOSP/include/binder/Status.h @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2015 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. + */ + +#ifndef ANDROID_BINDER_STATUS_H +#define ANDROID_BINDER_STATUS_H + +#include +#include // historical +#include + +#include +#include +#include +#include + +namespace android { +namespace binder { + +// An object similar in function to a status_t except that it understands +// how exceptions are encoded in the prefix of a Parcel. Used like: +// +// Parcel data; +// Parcel reply; +// status_t status; +// binder::Status remote_exception; +// if ((status = data.writeInterfaceToken(interface_descriptor)) != OK || +// (status = data.writeInt32(function_input)) != OK) { +// // We failed to write into the memory of our local parcel? +// } +// if ((status = remote()->transact(transaction, data, &reply)) != OK) { +// // Something has gone wrong in the binder driver or libbinder. +// } +// if ((status = remote_exception.readFromParcel(reply)) != OK) { +// // The remote didn't correctly write the exception header to the +// // reply. +// } +// if (!remote_exception.isOk()) { +// // The transaction went through correctly, but the remote reported an +// // exception during handling. +// } +// +class LIBBINDER_EXPORTED Status final { +public: + // Keep the exception codes in sync with android/os/Parcel.java. + enum Exception { + EX_NONE = 0, + EX_SECURITY = -1, + EX_BAD_PARCELABLE = -2, + EX_ILLEGAL_ARGUMENT = -3, + EX_NULL_POINTER = -4, + EX_ILLEGAL_STATE = -5, + EX_NETWORK_MAIN_THREAD = -6, + EX_UNSUPPORTED_OPERATION = -7, + EX_SERVICE_SPECIFIC = -8, + EX_PARCELABLE = -9, + + // See android/os/Parcel.java. We need to handle this in native code. + EX_HAS_NOTED_APPOPS_REPLY_HEADER = -127, + + // This is special and Java specific; see Parcel.java. + EX_HAS_REPLY_HEADER = -128, + // This is special, and indicates to C++ binder proxies that the + // transaction has failed at a low level. + EX_TRANSACTION_FAILED = -129, + }; + + // A more readable alias for the default constructor. + static Status ok(); + + // Authors should explicitly pick whether their integer is: + // - an exception code (EX_* above) + // - service specific error code + // - status_t + // + // Prefer a generic exception code when possible, then a service specific + // code, and finally a status_t for low level failures or legacy support. + // Exception codes and service specific errors map to nicer exceptions for + // Java clients. + static Status fromExceptionCode(int32_t exceptionCode); + static Status fromExceptionCode(int32_t exceptionCode, + const String8& message); + static Status fromExceptionCode(int32_t exceptionCode, + const char* message); + + // warning: this is still considered an error if it is constructed with a + // zero value error code. Please use Status::ok() instead and avoid zero + // error codes + static Status fromServiceSpecificError(int32_t serviceSpecificErrorCode); + static Status fromServiceSpecificError(int32_t serviceSpecificErrorCode, + const String8& message); + static Status fromServiceSpecificError(int32_t serviceSpecificErrorCode, + const char* message); + + static Status fromStatusT(status_t status); + + static std::string exceptionToString(status_t exceptionCode); + + Status() = default; + ~Status() = default; + + // Status objects are copyable and contain just simple data. + Status(const Status& status) = default; + Status(Status&& status) = default; + Status& operator=(const Status& status) = default; + + // Bear in mind that if the client or service is a Java endpoint, this + // is not the logic which will provide/interpret the data here. + status_t readFromParcel(const Parcel& parcel); + status_t writeToParcel(Parcel* parcel) const; + + // Convenience API to replace a Parcel with a status value, w/o requiring + // calling multiple APIs (makes generated code smaller). + status_t writeOverParcel(Parcel* parcel) const; + + // Set one of the pre-defined exception types defined above. + void setException(int32_t ex, const String8& message); + // Set a service specific exception with error code. + void setServiceSpecificError(int32_t errorCode, const String8& message); + // Setting a |status| != OK causes generated code to return |status| + // from Binder transactions, rather than writing an exception into the + // reply Parcel. This is the least preferable way of reporting errors. + void setFromStatusT(status_t status); + + // Get information about an exception. + int32_t exceptionCode() const { return mException; } + const String8& exceptionMessage() const { return mMessage; } + status_t transactionError() const { + return mException == EX_TRANSACTION_FAILED ? mErrorCode : OK; + } + int32_t serviceSpecificErrorCode() const { + return mException == EX_SERVICE_SPECIFIC ? mErrorCode : 0; + } + + bool isOk() const { return mException == EX_NONE; } + + // For logging. + String8 toString8() const; + +private: + Status(int32_t exceptionCode, int32_t errorCode); + Status(int32_t exceptionCode, int32_t errorCode, const String8& message); + + status_t skipUnusedHeader(const Parcel& parcel); + + // If |mException| == EX_TRANSACTION_FAILED, generated code will return + // |mErrorCode| as the result of the transaction rather than write an + // exception to the reply parcel. + // + // Otherwise, we always write |mException| to the parcel. + // If |mException| != EX_NONE, we write |mMessage| as well. + // If |mException| == EX_SERVICE_SPECIFIC we write |mErrorCode| as well. + int32_t mException = EX_NONE; + int32_t mErrorCode = 0; + String8 mMessage; +}; // class Status + +static inline std::ostream& operator<< (std::ostream& o, const Status& s) { + return o << s.toString8(); +} + +} // namespace binder +} // namespace android + +#endif // ANDROID_BINDER_STATUS_H diff --git a/app/src/main/cpp/external/AOSP/include/utils/RefBase.h b/app/src/main/cpp/external/AOSP/include/utils/RefBase.h index b6a8707..3170b82 100644 --- a/app/src/main/cpp/external/AOSP/include/utils/RefBase.h +++ b/app/src/main/cpp/external/AOSP/include/utils/RefBase.h @@ -221,7 +221,7 @@ // LightRefBase used to be declared in this header, so we have to include it #include -#include +#include "utils/StrongPointer.h" #include // --------------------------------------------------------------------------- diff --git a/app/src/main/cpp/external/AOSP/include/utils/StrongPointer.h b/app/src/main/cpp/external/AOSP/include/utils/StrongPointer.h index fb9b8e8..43c00c9 100644 --- a/app/src/main/cpp/external/AOSP/include/utils/StrongPointer.h +++ b/app/src/main/cpp/external/AOSP/include/utils/StrongPointer.h @@ -30,7 +30,7 @@ template class wp; template class sp { public: - inline constexpr sp() : m_ptr(nullptr) { } + inline sp() : m_ptr(nullptr) { } // The old way of using sp<> was like this. This is bad because it relies // on implicit conversion to sp<>, which we would like to remove (if an diff --git a/app/src/main/cpp/external/AOSP/include/utils/Vector.h b/app/src/main/cpp/external/AOSP/include/utils/Vector.h index d5db3cb..772cfd9 100644 --- a/app/src/main/cpp/external/AOSP/include/utils/Vector.h +++ b/app/src/main/cpp/external/AOSP/include/utils/Vector.h @@ -20,7 +20,6 @@ #include #include -#include #include #include #ifndef __has_attribute @@ -273,9 +272,6 @@ TYPE* Vector::editArray() { template inline const TYPE& Vector::operator[](size_t index) const { - LOG_FATAL_IF(index>=size(), - "%s: index=%u out of range (%u)", __PRETTY_FUNCTION__, - int(index), int(size())); return *(array() + index); }