diff options
22 files changed, 403 insertions, 107 deletions
diff --git a/Android.bp b/Android.bp index 119c7ea5a4..ba55082248 100644 --- a/Android.bp +++ b/Android.bp @@ -42,6 +42,7 @@ cc_library_headers { export_include_dirs: [ "include/", ], + product_available: true, } ndk_headers { diff --git a/data/etc/android.hardware.bluetooth_le.channel_sounding.xml b/data/etc/android.hardware.bluetooth_le.channel_sounding.xml new file mode 100644 index 0000000000..f0ee5d999f --- /dev/null +++ b/data/etc/android.hardware.bluetooth_le.channel_sounding.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2024 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. +--> +<!-- Adds the feature indicating support for the BLE Channel sounding --> +<permissions> + <feature name="android.hardware.bluetooth_le.channel_sounding" /> +</permissions> diff --git a/include/android/OWNERS b/include/android/OWNERS index fad8c1b890..5b014d0425 100644 --- a/include/android/OWNERS +++ b/include/android/OWNERS @@ -3,3 +3,10 @@ per-file input.h,keycodes.h = file:platform/frameworks/base:/INPUT_OWNERS # Window manager per-file surface_control_input_receiver.h = file:platform/frameworks/base:/services/core/java/com/android/server/wm/OWNERS per-file input_transfer_token.h = file:platform/frameworks/base:/services/core/java/com/android/server/wm/OWNERS + +# CoGS +per-file *luts* = file:platform/frameworks/base:/graphics/java/android/graphics/OWNERS + +# ADPF +per-file performance_hint.h = file:platform/frameworks/base:/ADPF_OWNERS +per-file thermal.h = file:platform/frameworks/base:/ADPF_OWNERS diff --git a/include/powermanager/OWNERS b/include/powermanager/OWNERS new file mode 100644 index 0000000000..9f40e27a10 --- /dev/null +++ b/include/powermanager/OWNERS @@ -0,0 +1 @@ +file:platform/frameworks/base:/ADPF_OWNERS
\ No newline at end of file diff --git a/include/private/OWNERS b/include/private/OWNERS new file mode 100644 index 0000000000..37da96d488 --- /dev/null +++ b/include/private/OWNERS @@ -0,0 +1,3 @@ +# ADPF +per-file thermal_private.h = file:platform/frameworks/base:/ADPF_OWNERS +per-file performance_hint_private.h = file:platform/frameworks/base:/ADPF_OWNERS diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp index 2ef642a3a0..0a6117808a 100644 --- a/libs/binder/Android.bp +++ b/libs/binder/Android.bp @@ -829,6 +829,7 @@ aidl_interface { backend: { rust: { apex_available: [ + "//apex_available:platform", "com.android.virt", ], enabled: true, @@ -881,7 +882,6 @@ cc_library { ":__subpackages__", "//packages/modules/Virtualization:__subpackages__", "//device/google/cuttlefish/shared/minidroid:__subpackages__", - "//system/software_defined_vehicle:__subpackages__", "//visibility:any_system_partition", ], } diff --git a/libs/binder/ndk/Android.bp b/libs/binder/ndk/Android.bp index a7423b3d2a..5710bbfa9f 100644 --- a/libs/binder/ndk/Android.bp +++ b/libs/binder/ndk/Android.bp @@ -82,7 +82,6 @@ cc_library { llndk: { symbol_file: "libbinder_ndk.map.txt", - export_llndk_headers: ["libvendorsupport_llndk_headers"], }, cflags: [ @@ -110,11 +109,9 @@ cc_library { ], header_libs: [ - "libvendorsupport_llndk_headers", "jni_headers", ], export_header_lib_headers: [ - "libvendorsupport_llndk_headers", "jni_headers", ], diff --git a/libs/binder/ndk/binder_rpc.cpp b/libs/binder/ndk/binder_rpc.cpp index 53ab68e643..bb5989dec8 100644 --- a/libs/binder/ndk/binder_rpc.cpp +++ b/libs/binder/ndk/binder_rpc.cpp @@ -107,16 +107,20 @@ ABinderRpc_AccessorProvider* ABinderRpc_registerAccessorProvider( ABinderRpc_AccessorProvider_getAccessorCallback provider, const char* const* const instances, size_t numInstances, void* data, ABinderRpc_AccessorProviderUserData_deleteCallback onDelete) { - if (provider == nullptr) { - ALOGE("Null provider passed to ABinderRpc_registerAccessorProvider"); - return nullptr; - } if (data && onDelete == nullptr) { ALOGE("If a non-null data ptr is passed to ABinderRpc_registerAccessorProvider, then a " "ABinderRpc_AccessorProviderUserData_deleteCallback must also be passed to delete " "the data object once the ABinderRpc_AccessorProvider is removed."); return nullptr; } + // call the onDelete when the last reference of this goes away (when the + // last reference to the generate std::function goes away). + std::shared_ptr<OnDeleteProviderHolder> onDeleteHolder = + std::make_shared<OnDeleteProviderHolder>(data, onDelete); + if (provider == nullptr) { + ALOGE("Null provider passed to ABinderRpc_registerAccessorProvider"); + return nullptr; + } if (numInstances == 0 || instances == nullptr) { ALOGE("No instances passed to ABinderRpc_registerAccessorProvider. numInstances: %zu", numInstances); @@ -126,10 +130,6 @@ ABinderRpc_AccessorProvider* ABinderRpc_registerAccessorProvider( for (size_t i = 0; i < numInstances; i++) { instanceStrings.emplace(instances[i]); } - // call the onDelete when the last reference of this goes away (when the - // last reference to the generate std::function goes away). - std::shared_ptr<OnDeleteProviderHolder> onDeleteHolder = - std::make_shared<OnDeleteProviderHolder>(data, onDelete); android::RpcAccessorProvider generate = [provider, onDeleteHolder](const String16& name) -> sp<IBinder> { ABinderRpc_Accessor* accessor = provider(String8(name).c_str(), onDeleteHolder->mData); diff --git a/libs/binder/ndk/include_cpp/android/binder_interface_utils.h b/libs/binder/ndk/include_cpp/android/binder_interface_utils.h index 0ad110ee83..c6518d816f 100644 --- a/libs/binder/ndk/include_cpp/android/binder_interface_utils.h +++ b/libs/binder/ndk/include_cpp/android/binder_interface_utils.h @@ -30,16 +30,14 @@ #include <android/binder_auto_utils.h> #include <android/binder_ibinder.h> -#if defined(__ANDROID_VENDOR_API__) -#include <android/llndk-versioning.h> -#elif !defined(API_LEVEL_AT_LEAST) #if defined(__BIONIC__) -#define API_LEVEL_AT_LEAST(sdk_api_level, vendor_api_level) \ - (__builtin_available(android sdk_api_level, *)) +#define API_LEVEL_AT_LEAST(sdk_api_level) __builtin_available(android sdk_api_level, *) +#elif defined(TRUSTY_USERSPACE) +// TODO(b/349936395): set to true for Trusty +#define API_LEVEL_AT_LEAST(sdk_api_level) (false) #else -#define API_LEVEL_AT_LEAST(sdk_api_level, vendor_api_level) (true) +#define API_LEVEL_AT_LEAST(sdk_api_level) (true) #endif // __BIONIC__ -#endif // __ANDROID_VENDOR_API__ #if __has_include(<android/binder_shell.h>) #include <android/binder_shell.h> @@ -298,9 +296,8 @@ AIBinder_Class* ICInterface::defineClass(const char* interfaceDescriptor, #endif #if defined(__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__) || __ANDROID_API__ >= 36 - if API_LEVEL_AT_LEAST (36, 202504) { - if (codeToFunction != nullptr && - (&AIBinder_Class_setTransactionCodeToFunctionNameMap != nullptr)) { + if (API_LEVEL_AT_LEAST(36)) { + if (codeToFunction != nullptr) { AIBinder_Class_setTransactionCodeToFunctionNameMap(clazz, codeToFunction, functionCount); } diff --git a/libs/binder/ndk/include_cpp/android/persistable_bundle_aidl.h b/libs/binder/ndk/include_cpp/android/persistable_bundle_aidl.h index 83976b3771..f3f3c3802a 100644 --- a/libs/binder/ndk/include_cpp/android/persistable_bundle_aidl.h +++ b/libs/binder/ndk/include_cpp/android/persistable_bundle_aidl.h @@ -22,17 +22,14 @@ #include <set> #include <sstream> -// Include llndk-versioning.h only for non-system build as it is not available for NDK headers. -#if defined(__ANDROID_VENDOR_API__) -#include <android/llndk-versioning.h> -#elif !defined(API_LEVEL_AT_LEAST) #if defined(__BIONIC__) -#define API_LEVEL_AT_LEAST(sdk_api_level, vendor_api_level) \ - (__builtin_available(android sdk_api_level, *)) +#define API_LEVEL_AT_LEAST(sdk_api_level) __builtin_available(android sdk_api_level, *) +#elif defined(TRUSTY_USERSPACE) +// TODO(b/349936395): set to true for Trusty +#define API_LEVEL_AT_LEAST(sdk_api_level) (false) #else -#define API_LEVEL_AT_LEAST(sdk_api_level, vendor_api_level) (true) +#define API_LEVEL_AT_LEAST(sdk_api_level) (true) #endif // __BIONIC__ -#endif // __ANDROID_VENDOR_API__ namespace aidl::android::os { @@ -44,7 +41,7 @@ namespace aidl::android::os { class PersistableBundle { public: PersistableBundle() noexcept { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { mPBundle = APersistableBundle_new(); } } @@ -54,13 +51,13 @@ class PersistableBundle { PersistableBundle(PersistableBundle&& other) noexcept : mPBundle(other.release()) {} // duplicates, does not take ownership of the APersistableBundle* PersistableBundle(const PersistableBundle& other) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { mPBundle = APersistableBundle_dup(other.mPBundle); } } // duplicates, does not take ownership of the APersistableBundle* PersistableBundle& operator=(const PersistableBundle& other) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { mPBundle = APersistableBundle_dup(other.mPBundle); } return *this; @@ -70,7 +67,7 @@ class PersistableBundle { binder_status_t readFromParcel(const AParcel* _Nonnull parcel) { reset(); - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return APersistableBundle_readFromParcel(parcel, &mPBundle); } else { return STATUS_INVALID_OPERATION; @@ -81,7 +78,7 @@ class PersistableBundle { if (!mPBundle) { return STATUS_BAD_VALUE; } - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return APersistableBundle_writeToParcel(mPBundle, parcel); } else { return STATUS_INVALID_OPERATION; @@ -96,7 +93,7 @@ class PersistableBundle { */ void reset(APersistableBundle* _Nullable pBundle = nullptr) noexcept { if (mPBundle) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { APersistableBundle_delete(mPBundle); } mPBundle = nullptr; @@ -109,7 +106,7 @@ class PersistableBundle { * what should be used to check for equality. */ bool deepEquals(const PersistableBundle& rhs) const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return APersistableBundle_isEqual(get(), rhs.get()); } else { return false; @@ -148,7 +145,7 @@ class PersistableBundle { inline std::string toString() const { if (!mPBundle) { return "<PersistableBundle: null>"; - } else if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + } else if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { std::ostringstream os; os << "<PersistableBundle: "; os << "size: " << std::to_string(APersistableBundle_size(mPBundle)); @@ -159,7 +156,7 @@ class PersistableBundle { } int32_t size() const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return APersistableBundle_size(mPBundle); } else { return 0; @@ -167,7 +164,7 @@ class PersistableBundle { } int32_t erase(const std::string& key) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return APersistableBundle_erase(mPBundle, key.c_str()); } else { return 0; @@ -175,37 +172,37 @@ class PersistableBundle { } void putBoolean(const std::string& key, bool val) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { APersistableBundle_putBoolean(mPBundle, key.c_str(), val); } } void putInt(const std::string& key, int32_t val) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { APersistableBundle_putInt(mPBundle, key.c_str(), val); } } void putLong(const std::string& key, int64_t val) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { APersistableBundle_putLong(mPBundle, key.c_str(), val); } } void putDouble(const std::string& key, double val) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { APersistableBundle_putDouble(mPBundle, key.c_str(), val); } } void putString(const std::string& key, const std::string& val) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { APersistableBundle_putString(mPBundle, key.c_str(), val.c_str()); } } void putBooleanVector(const std::string& key, const std::vector<bool>& vec) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { // std::vector<bool> has no ::data(). int32_t num = vec.size(); if (num > 0) { @@ -222,7 +219,7 @@ class PersistableBundle { } void putIntVector(const std::string& key, const std::vector<int32_t>& vec) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { int32_t num = vec.size(); if (num > 0) { APersistableBundle_putIntVector(mPBundle, key.c_str(), vec.data(), num); @@ -230,7 +227,7 @@ class PersistableBundle { } } void putLongVector(const std::string& key, const std::vector<int64_t>& vec) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { int32_t num = vec.size(); if (num > 0) { APersistableBundle_putLongVector(mPBundle, key.c_str(), vec.data(), num); @@ -238,7 +235,7 @@ class PersistableBundle { } } void putDoubleVector(const std::string& key, const std::vector<double>& vec) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { int32_t num = vec.size(); if (num > 0) { APersistableBundle_putDoubleVector(mPBundle, key.c_str(), vec.data(), num); @@ -246,7 +243,7 @@ class PersistableBundle { } } void putStringVector(const std::string& key, const std::vector<std::string>& vec) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { int32_t num = vec.size(); if (num > 0) { char** inVec = (char**)malloc(num * sizeof(char*)); @@ -261,13 +258,13 @@ class PersistableBundle { } } void putPersistableBundle(const std::string& key, const PersistableBundle& pBundle) { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { APersistableBundle_putPersistableBundle(mPBundle, key.c_str(), pBundle.mPBundle); } } bool getBoolean(const std::string& key, bool* _Nonnull val) const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return APersistableBundle_getBoolean(mPBundle, key.c_str(), val); } else { return false; @@ -275,7 +272,7 @@ class PersistableBundle { } bool getInt(const std::string& key, int32_t* _Nonnull val) const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return APersistableBundle_getInt(mPBundle, key.c_str(), val); } else { return false; @@ -283,7 +280,7 @@ class PersistableBundle { } bool getLong(const std::string& key, int64_t* _Nonnull val) const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return APersistableBundle_getLong(mPBundle, key.c_str(), val); } else { return false; @@ -291,7 +288,7 @@ class PersistableBundle { } bool getDouble(const std::string& key, double* _Nonnull val) const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return APersistableBundle_getDouble(mPBundle, key.c_str(), val); } else { return false; @@ -303,7 +300,7 @@ class PersistableBundle { } bool getString(const std::string& key, std::string* _Nonnull val) const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { char* outString = nullptr; bool ret = APersistableBundle_getString(mPBundle, key.c_str(), &outString, &stringAllocator, nullptr); @@ -321,7 +318,7 @@ class PersistableBundle { const char* _Nonnull, T* _Nullable, int32_t), const APersistableBundle* _Nonnull pBundle, const char* _Nonnull key, std::vector<T>* _Nonnull vec) const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { int32_t bytes = 0; // call first with nullptr to get required size in bytes bytes = getVec(pBundle, key, nullptr, 0); @@ -343,28 +340,28 @@ class PersistableBundle { } bool getBooleanVector(const std::string& key, std::vector<bool>* _Nonnull vec) const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getVecInternal<bool>(&APersistableBundle_getBooleanVector, mPBundle, key.c_str(), vec); } return false; } bool getIntVector(const std::string& key, std::vector<int32_t>* _Nonnull vec) const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getVecInternal<int32_t>(&APersistableBundle_getIntVector, mPBundle, key.c_str(), vec); } return false; } bool getLongVector(const std::string& key, std::vector<int64_t>* _Nonnull vec) const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getVecInternal<int64_t>(&APersistableBundle_getLongVector, mPBundle, key.c_str(), vec); } return false; } bool getDoubleVector(const std::string& key, std::vector<double>* _Nonnull vec) const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getVecInternal<double>(&APersistableBundle_getDoubleVector, mPBundle, key.c_str(), vec); } @@ -389,7 +386,7 @@ class PersistableBundle { } bool getStringVector(const std::string& key, std::vector<std::string>* _Nonnull vec) const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { int32_t bytes = APersistableBundle_getStringVector(mPBundle, key.c_str(), nullptr, 0, &stringAllocator, nullptr); if (bytes > 0) { @@ -406,7 +403,7 @@ class PersistableBundle { } bool getPersistableBundle(const std::string& key, PersistableBundle* _Nonnull val) const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { APersistableBundle* bundle = nullptr; bool ret = APersistableBundle_getPersistableBundle(mPBundle, key.c_str(), &bundle); if (ret) { @@ -438,77 +435,77 @@ class PersistableBundle { } std::set<std::string> getBooleanKeys() const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getKeys(&APersistableBundle_getBooleanKeys, mPBundle); } else { return {}; } } std::set<std::string> getIntKeys() const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getKeys(&APersistableBundle_getIntKeys, mPBundle); } else { return {}; } } std::set<std::string> getLongKeys() const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getKeys(&APersistableBundle_getLongKeys, mPBundle); } else { return {}; } } std::set<std::string> getDoubleKeys() const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getKeys(&APersistableBundle_getDoubleKeys, mPBundle); } else { return {}; } } std::set<std::string> getStringKeys() const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getKeys(&APersistableBundle_getStringKeys, mPBundle); } else { return {}; } } std::set<std::string> getBooleanVectorKeys() const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getKeys(&APersistableBundle_getBooleanVectorKeys, mPBundle); } else { return {}; } } std::set<std::string> getIntVectorKeys() const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getKeys(&APersistableBundle_getIntVectorKeys, mPBundle); } else { return {}; } } std::set<std::string> getLongVectorKeys() const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getKeys(&APersistableBundle_getLongVectorKeys, mPBundle); } else { return {}; } } std::set<std::string> getDoubleVectorKeys() const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getKeys(&APersistableBundle_getDoubleVectorKeys, mPBundle); } else { return {}; } } std::set<std::string> getStringVectorKeys() const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getKeys(&APersistableBundle_getStringVectorKeys, mPBundle); } else { return {}; } } std::set<std::string> getPersistableBundleKeys() const { - if API_LEVEL_AT_LEAST(__ANDROID_API_V__, 202404) { + if (API_LEVEL_AT_LEAST(__ANDROID_API_V__)) { return getKeys(&APersistableBundle_getPersistableBundleKeys, mPBundle); } else { return {}; diff --git a/libs/binder/ndk/include_platform/android/binder_rpc.h b/libs/binder/ndk/include_platform/android/binder_rpc.h index 7d54e2dad9..13188894be 100644 --- a/libs/binder/ndk/include_platform/android/binder_rpc.h +++ b/libs/binder/ndk/include_platform/android/binder_rpc.h @@ -139,6 +139,8 @@ typedef void (*ABinderRpc_AccessorProviderUserData_deleteCallback)(void* _Nullab * registered. In the error case of duplicate instances, if data was * provided with a ABinderRpc_AccessorProviderUserData_deleteCallback, * the callback will be called to delete the data. + * If nullptr is returned, ABinderRpc_AccessorProviderUserData_deleteCallback + * will be called on data immediately. * Otherwise returns a pointer to the ABinderRpc_AccessorProvider that * can be used to remove with ABinderRpc_unregisterAccessorProvider. */ diff --git a/libs/binder/rust/rpcbinder/Android.bp b/libs/binder/rust/rpcbinder/Android.bp index 174fe8aba8..4036551ef3 100644 --- a/libs/binder/rust/rpcbinder/Android.bp +++ b/libs/binder/rust/rpcbinder/Android.bp @@ -27,7 +27,6 @@ rust_library { visibility: [ "//device/google/cuttlefish/shared/minidroid/sample", "//packages/modules/Virtualization:__subpackages__", - "//system/software_defined_vehicle:__subpackages__", ], apex_available: [ "//apex_available:platform", diff --git a/libs/binder/tests/binderRpcTest.cpp b/libs/binder/tests/binderRpcTest.cpp index 506fc716cd..da5a8e3881 100644 --- a/libs/binder/tests/binderRpcTest.cpp +++ b/libs/binder/tests/binderRpcTest.cpp @@ -1400,6 +1400,26 @@ TEST_F(BinderARpcNdk, ARpcProviderNewDelete) { EXPECT_TRUE(isDeleted); } +TEST_F(BinderARpcNdk, ARpcProviderDeleteOnError) { + bool isDeleted = false; + AccessorProviderData* data = new AccessorProviderData{{}, 0, &isDeleted}; + + ABinderRpc_AccessorProvider* provider = + ABinderRpc_registerAccessorProvider(getAccessor, kARpcSupportedServices, 0, data, + accessorProviderDataOnDelete); + + ASSERT_EQ(provider, nullptr); + EXPECT_TRUE(isDeleted); +} + +TEST_F(BinderARpcNdk, ARpcProvideOnErrorNoDeleteCbNoCrash) { + ABinderRpc_AccessorProvider* provider = + ABinderRpc_registerAccessorProvider(getAccessor, kARpcSupportedServices, 0, nullptr, + nullptr); + + ASSERT_EQ(provider, nullptr); +} + TEST_F(BinderARpcNdk, ARpcProviderDuplicateInstance) { const char* instance = "some.instance.name.IFoo/default"; const uint32_t numInstances = 2; diff --git a/libs/binder/tests/parcel_fuzzer/test_fuzzer/Android.bp b/libs/binder/tests/parcel_fuzzer/test_fuzzer/Android.bp index 690c39afc9..4008c56038 100644 --- a/libs/binder/tests/parcel_fuzzer/test_fuzzer/Android.bp +++ b/libs/binder/tests/parcel_fuzzer/test_fuzzer/Android.bp @@ -59,6 +59,11 @@ sh_test_host { darwin: { enabled: false, }, + host: { + data_libs: [ + "libc++", + ], + }, }, test_suites: ["general-tests"], } diff --git a/libs/binder/tests/parcel_fuzzer/test_fuzzer/run_fuzz_service_test.sh b/libs/binder/tests/parcel_fuzzer/test_fuzzer/run_fuzz_service_test.sh index 5d68fe172e..b623c5fbcd 100755 --- a/libs/binder/tests/parcel_fuzzer/test_fuzzer/run_fuzz_service_test.sh +++ b/libs/binder/tests/parcel_fuzzer/test_fuzzer/run_fuzz_service_test.sh @@ -39,6 +39,7 @@ for CRASH_TYPE in PLAIN KNOWN_UID AID_SYSTEM AID_ROOT BINDER DUMP SHELL_CMD; do else echo -e "${color_failed}Failed: Unable to find successful fuzzing output from test_service_fuzzer_should_crash" echo "${color_reset}" + cat "$FUZZER_OUT" exit 1 fi done diff --git a/libs/binder/trusty/RpcServerTrusty.cpp b/libs/binder/trusty/RpcServerTrusty.cpp index 17919c2a25..05800464ac 100644 --- a/libs/binder/trusty/RpcServerTrusty.cpp +++ b/libs/binder/trusty/RpcServerTrusty.cpp @@ -151,8 +151,10 @@ int RpcServerTrusty::handleMessage(const tipc_port* /*port*/, handle_t /*chan*/, int RpcServerTrusty::handleMessageInternal(void* ctx) { auto* channelContext = reinterpret_cast<ChannelContext*>(ctx); - LOG_ALWAYS_FATAL_IF(channelContext == nullptr, - "bad state: message received on uninitialized channel"); + if (channelContext == nullptr) { + LOG_RPC_DETAIL("bad state: message received on uninitialized channel"); + return ERR_BAD_STATE; + } auto& session = channelContext->session; auto& connection = channelContext->connection; diff --git a/libs/binder/trusty/ndk/include/android/llndk-versioning.h b/libs/binder/trusty/ndk/include/android/llndk-versioning.h deleted file mode 100644 index e955a34bdf..0000000000 --- a/libs/binder/trusty/ndk/include/android/llndk-versioning.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2024 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 - -// TODO(b/349936395): set to true for Trusty -#define API_LEVEL_AT_LEAST(sdk_api_level, vendor_api_level) (false) diff --git a/libs/gui/include/gui/IGraphicBufferProducer.h b/libs/gui/include/gui/IGraphicBufferProducer.h index 8fca9460aa..84a1730d7a 100644 --- a/libs/gui/include/gui/IGraphicBufferProducer.h +++ b/libs/gui/include/gui/IGraphicBufferProducer.h @@ -403,7 +403,7 @@ public: uint64_t nextFrameNumber{0}; FrameEventHistoryDelta frameTimestamps; bool bufferReplaced{false}; - int maxBufferCount{0}; + int maxBufferCount{BufferQueueDefs::NUM_BUFFER_SLOTS}; status_t result{NO_ERROR}; }; diff --git a/libs/nativewindow/rust/src/lib.rs b/libs/nativewindow/rust/src/lib.rs index 014c912a67..9876362cec 100644 --- a/libs/nativewindow/rust/src/lib.rs +++ b/libs/nativewindow/rust/src/lib.rs @@ -31,11 +31,13 @@ use binder::{ }; use ffi::{ AHardwareBuffer, AHardwareBuffer_Desc, AHardwareBuffer_readFromParcel, - AHardwareBuffer_writeToParcel, + AHardwareBuffer_writeToParcel, ARect, }; +use std::ffi::c_void; use std::fmt::{self, Debug, Formatter}; -use std::mem::ManuallyDrop; -use std::ptr::{self, null_mut, NonNull}; +use std::mem::{forget, ManuallyDrop}; +use std::os::fd::{AsRawFd, BorrowedFd, FromRawFd, OwnedFd}; +use std::ptr::{self, null, null_mut, NonNull}; /// Wrapper around a C `AHardwareBuffer_Desc`. #[derive(Clone, Debug, PartialEq, Eq)] @@ -267,10 +269,141 @@ impl HardwareBuffer { rfu0: 0, rfu1: 0, }; - // SAFETY: neither the buffer nor AHardwareBuffer_Desc pointers will be null. + // SAFETY: The `AHardwareBuffer` pointer we wrap is always valid, and the + // AHardwareBuffer_Desc pointer is valid because it comes from a reference. unsafe { ffi::AHardwareBuffer_describe(self.0.as_ref(), &mut buffer_desc) }; HardwareBufferDescription(buffer_desc) } + + /// Locks the hardware buffer for direct CPU access. + /// + /// # Safety + /// + /// - If `fence` is `None`, the caller must ensure that all writes to the buffer have completed + /// before calling this function. + /// - If the buffer has `AHARDWAREBUFFER_FORMAT_BLOB`, multiple threads or process may lock the + /// buffer simultaneously, but the caller must ensure that they don't access it simultaneously + /// and break Rust's aliasing rules, like any other shared memory. + /// - Otherwise if `usage` includes `AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY` or + /// `AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN`, the caller must ensure that no other threads or + /// processes lock the buffer simultaneously for any usage. + /// - Otherwise, the caller must ensure that no other threads lock the buffer for writing + /// simultaneously. + /// - If `rect` is not `None`, the caller must not modify the buffer outside of that rectangle. + pub unsafe fn lock<'a>( + &'a self, + usage: AHardwareBuffer_UsageFlags, + fence: Option<BorrowedFd>, + rect: Option<&ARect>, + ) -> Result<HardwareBufferGuard<'a>, StatusCode> { + let fence = if let Some(fence) = fence { fence.as_raw_fd() } else { -1 }; + let rect = rect.map(ptr::from_ref).unwrap_or(null()); + let mut address = null_mut(); + // SAFETY: The `AHardwareBuffer` pointer we wrap is always valid, and the buffer address out + // pointer is valid because it comes from a reference. Our caller promises that writes have + // completed and there will be no simultaneous read/write locks. + let status = unsafe { + ffi::AHardwareBuffer_lock(self.0.as_ptr(), usage.0, fence, rect, &mut address) + }; + status_result(status)?; + Ok(HardwareBufferGuard { + buffer: self, + address: NonNull::new(address) + .expect("AHardwareBuffer_lock set a null outVirtualAddress"), + }) + } + + /// Locks the hardware buffer for direct CPU access, returning information about the bytes per + /// pixel and stride as well. + /// + /// # Safety + /// + /// - If `fence` is `None`, the caller must ensure that all writes to the buffer have completed + /// before calling this function. + /// - If the buffer has `AHARDWAREBUFFER_FORMAT_BLOB`, multiple threads or process may lock the + /// buffer simultaneously, but the caller must ensure that they don't access it simultaneously + /// and break Rust's aliasing rules, like any other shared memory. + /// - Otherwise if `usage` includes `AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY` or + /// `AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN`, the caller must ensure that no other threads or + /// processes lock the buffer simultaneously for any usage. + /// - Otherwise, the caller must ensure that no other threads lock the buffer for writing + /// simultaneously. + pub unsafe fn lock_and_get_info<'a>( + &'a self, + usage: AHardwareBuffer_UsageFlags, + fence: Option<BorrowedFd>, + rect: Option<&ARect>, + ) -> Result<LockedBufferInfo<'a>, StatusCode> { + let fence = if let Some(fence) = fence { fence.as_raw_fd() } else { -1 }; + let rect = rect.map(ptr::from_ref).unwrap_or(null()); + let mut address = null_mut(); + let mut bytes_per_pixel = 0; + let mut stride = 0; + // SAFETY: The `AHardwareBuffer` pointer we wrap is always valid, and the various out + // pointers are valid because they come from references. Our caller promises that writes have + // completed and there will be no simultaneous read/write locks. + let status = unsafe { + ffi::AHardwareBuffer_lockAndGetInfo( + self.0.as_ptr(), + usage.0, + fence, + rect, + &mut address, + &mut bytes_per_pixel, + &mut stride, + ) + }; + status_result(status)?; + Ok(LockedBufferInfo { + guard: HardwareBufferGuard { + buffer: self, + address: NonNull::new(address) + .expect("AHardwareBuffer_lockAndGetInfo set a null outVirtualAddress"), + }, + bytes_per_pixel: bytes_per_pixel as u32, + stride: stride as u32, + }) + } + + /// Unlocks the hardware buffer from direct CPU access. + /// + /// Must be called after all changes to the buffer are completed by the caller. This will block + /// until the unlocking is complete and the buffer contents are updated. + fn unlock(&self) -> Result<(), StatusCode> { + // SAFETY: The `AHardwareBuffer` pointer we wrap is always valid. + let status = unsafe { ffi::AHardwareBuffer_unlock(self.0.as_ptr(), null_mut()) }; + status_result(status)?; + Ok(()) + } + + /// Unlocks the hardware buffer from direct CPU access. + /// + /// Must be called after all changes to the buffer are completed by the caller. + /// + /// This may not block until all work is completed, but rather will return a file descriptor + /// which will be signalled once the unlocking is complete and the buffer contents is updated. + /// If `Ok(None)` is returned then unlocking has already completed and no further waiting is + /// necessary. The file descriptor may be passed to a subsequent call to [`Self::lock`]. + pub fn unlock_with_fence( + &self, + guard: HardwareBufferGuard, + ) -> Result<Option<OwnedFd>, StatusCode> { + // Forget the guard so that its `Drop` implementation doesn't try to unlock the + // HardwareBuffer again. + forget(guard); + + let mut fence = -2; + // SAFETY: The `AHardwareBuffer` pointer we wrap is always valid. + let status = unsafe { ffi::AHardwareBuffer_unlock(self.0.as_ptr(), &mut fence) }; + let fence = if fence < 0 { + None + } else { + // SAFETY: `AHardwareBuffer_unlock` gives us ownership of the fence file descriptor. + Some(unsafe { OwnedFd::from_raw_fd(fence) }) + }; + status_result(status)?; + Ok(fence) + } } impl Drop for HardwareBuffer { @@ -346,6 +479,37 @@ unsafe impl Send for HardwareBuffer {} // according to the docs on the underlying gralloc calls) unsafe impl Sync for HardwareBuffer {} +/// A guard for when a `HardwareBuffer` is locked. +/// +/// The `HardwareBuffer` will be unlocked when this is dropped, or may be unlocked via +/// [`HardwareBuffer::unlock_with_fence`]. +#[derive(Debug)] +pub struct HardwareBufferGuard<'a> { + buffer: &'a HardwareBuffer, + /// The address of the buffer in memory. + pub address: NonNull<c_void>, +} + +impl<'a> Drop for HardwareBufferGuard<'a> { + fn drop(&mut self) { + self.buffer + .unlock() + .expect("Failed to unlock HardwareBuffer when dropping HardwareBufferGuard"); + } +} + +/// A guard for when a `HardwareBuffer` is locked, with additional information about the number of +/// bytes per pixel and stride. +#[derive(Debug)] +pub struct LockedBufferInfo<'a> { + /// The locked buffer guard. + pub guard: HardwareBufferGuard<'a>, + /// The number of bytes used for each pixel in the buffer. + pub bytes_per_pixel: u32, + /// The stride in bytes between rows in the buffer. + pub stride: u32, +} + #[cfg(test)] mod test { use super::*; @@ -499,4 +663,108 @@ mod test { assert_eq!(buffer.description(), buffer_description); assert_eq!(buffer2.description(), buffer_description); } + + #[test] + fn lock() { + let buffer = HardwareBuffer::new(&HardwareBufferDescription::new( + 1024, + 512, + 1, + AHardwareBuffer_Format::AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM, + AHardwareBuffer_UsageFlags::AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, + 0, + )) + .expect("Failed to create buffer"); + + // SAFETY: No other threads or processes have access to the buffer. + let guard = unsafe { + buffer.lock( + AHardwareBuffer_UsageFlags::AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, + None, + None, + ) + } + .unwrap(); + + drop(guard); + } + + #[test] + fn lock_with_rect() { + let buffer = HardwareBuffer::new(&HardwareBufferDescription::new( + 1024, + 512, + 1, + AHardwareBuffer_Format::AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM, + AHardwareBuffer_UsageFlags::AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, + 0, + )) + .expect("Failed to create buffer"); + let rect = ARect { left: 10, right: 20, top: 35, bottom: 45 }; + + // SAFETY: No other threads or processes have access to the buffer. + let guard = unsafe { + buffer.lock( + AHardwareBuffer_UsageFlags::AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, + None, + Some(&rect), + ) + } + .unwrap(); + + drop(guard); + } + + #[test] + fn unlock_with_fence() { + let buffer = HardwareBuffer::new(&HardwareBufferDescription::new( + 1024, + 512, + 1, + AHardwareBuffer_Format::AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM, + AHardwareBuffer_UsageFlags::AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, + 0, + )) + .expect("Failed to create buffer"); + + // SAFETY: No other threads or processes have access to the buffer. + let guard = unsafe { + buffer.lock( + AHardwareBuffer_UsageFlags::AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, + None, + None, + ) + } + .unwrap(); + + buffer.unlock_with_fence(guard).unwrap(); + } + + #[test] + fn lock_with_info() { + const WIDTH: u32 = 1024; + let buffer = HardwareBuffer::new(&HardwareBufferDescription::new( + WIDTH, + 512, + 1, + AHardwareBuffer_Format::AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM, + AHardwareBuffer_UsageFlags::AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, + 0, + )) + .expect("Failed to create buffer"); + + // SAFETY: No other threads or processes have access to the buffer. + let info = unsafe { + buffer.lock_and_get_info( + AHardwareBuffer_UsageFlags::AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN, + None, + None, + ) + } + .unwrap(); + + assert_eq!(info.bytes_per_pixel, 4); + assert_eq!(info.stride, WIDTH * 4); + drop(info); + } } diff --git a/libs/ui/Gralloc5.cpp b/libs/ui/Gralloc5.cpp index c9ec036186..2143f79f11 100644 --- a/libs/ui/Gralloc5.cpp +++ b/libs/ui/Gralloc5.cpp @@ -23,7 +23,6 @@ #include <aidlcommonsupport/NativeHandle.h> #include <android/binder_manager.h> #include <android/hardware/graphics/mapper/utils/IMapperMetadataTypes.h> -#include <android/llndk-versioning.h> #include <binder/IPCThreadState.h> #include <dlfcn.h> #include <ui/FatVector.h> @@ -91,7 +90,7 @@ static void *loadIMapperLibrary() { } void* so = nullptr; - if API_LEVEL_AT_LEAST (__ANDROID_API_V__, 202404) { + if (__builtin_available(android __ANDROID_API_V__, *)) { so = AServiceManager_openDeclaredPassthroughHal("mapper", mapperSuffix.c_str(), RTLD_LOCAL | RTLD_NOW); } else { diff --git a/services/gpuservice/gpuwork/bpfprogs/gpuWork.c b/services/gpuservice/gpuwork/bpfprogs/gpuWork.c index f4701896b6..94abc69426 100644 --- a/services/gpuservice/gpuwork/bpfprogs/gpuWork.c +++ b/services/gpuservice/gpuwork/bpfprogs/gpuWork.c @@ -20,11 +20,7 @@ #include <stddef.h> #include <stdint.h> -#ifdef MOCK_BPF -#include <test/mock_bpf_helpers.h> -#else #include <bpf_helpers.h> -#endif #define S_IN_NS (1000000000) #define SMALL_TIME_GAP_LIMIT_NS (S_IN_NS) diff --git a/services/surfaceflinger/tests/unittests/FrameTimelineTest.cpp b/services/surfaceflinger/tests/unittests/FrameTimelineTest.cpp index dac9265b71..fae236dfbb 100644 --- a/services/surfaceflinger/tests/unittests/FrameTimelineTest.cpp +++ b/services/surfaceflinger/tests/unittests/FrameTimelineTest.cpp @@ -158,6 +158,7 @@ public: a.presentTime == b.presentTime; } + NO_THREAD_SAFETY_ANALYSIS const std::map<int64_t, TimelineItem>& getPredictions() const { return mTokenManager->mPredictions; } |