diff options
author | Xin Li <delphij@google.com> | 2019-03-13 02:26:03 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-03-13 02:26:03 +0000 |
commit | 88fdd29aaedbe257db10ccba75ebea7e03b88834 (patch) | |
tree | e69d6feb85a4dfdc6ed5547f55a6938895f77904 | |
parent | 76e4d108d076508e9f346aa73d708d35db54b2aa (diff) | |
parent | 4cf9c3b1a3f712df12390a3d036ab554b37d9ed3 (diff) | |
download | libhidl-88fdd29aaedbe257db10ccba75ebea7e03b88834.tar.gz |
Merge "DO NOT MERGE - Merge PPRL.190305.001 into master"android-q-preview-6android-q-preview-5android-q-preview-4android-q-preview-2.5android-q-preview-1android-o-mr1-iot-release-1.0.10
-rw-r--r-- | transport/HidlTransportSupport.cpp | 35 | ||||
-rw-r--r-- | transport/Static.cpp | 2 | ||||
-rw-r--r-- | transport/include/hidl/ConcurrentMap.h | 1 | ||||
-rw-r--r-- | transport/include/hidl/HidlTransportSupport.h | 12 | ||||
-rw-r--r-- | transport/include/hidl/Static.h | 1 |
5 files changed, 50 insertions, 1 deletions
diff --git a/transport/HidlTransportSupport.cpp b/transport/HidlTransportSupport.cpp index c9937f1..311504d 100644 --- a/transport/HidlTransportSupport.cpp +++ b/transport/HidlTransportSupport.cpp @@ -42,7 +42,24 @@ status_t handleTransportPoll(int /*fd*/) { return handleBinderPoll(); } -bool setMinSchedulerPolicy(const sp<IBase>& service, int policy, int priority) { +// TODO(b/122472540): only store one data item per object +template <typename V> +static void pruneMapLocked(ConcurrentMap<wp<::android::hidl::base::V1_0::IBase>, V>& map) { + using ::android::hidl::base::V1_0::IBase; + + std::vector<wp<IBase>> toDelete; + for (const auto& kv : map) { + if (kv.first.promote() == nullptr) { + toDelete.push_back(kv.first); + } + } + for (const auto& k : toDelete) { + map.eraseLocked(k); + } +} + +bool setMinSchedulerPolicy(const sp<::android::hidl::base::V1_0::IBase>& service, + int policy, int priority) { if (service->isRemote()) { LOG(ERROR) << "Can't set scheduler policy on remote service."; return false; @@ -89,6 +106,22 @@ bool setMinSchedulerPolicy(const sp<IBase>& service, int policy, int priority) { return true; } +bool setRequestingSid(const sp<::android::hidl::base::V1_0::IBase>& service, bool requesting) { + if (service->isRemote()) { + ALOGE("Can't set requesting sid on remote service."); + return false; + } + + // Due to ABI considerations, IBase cannot have a destructor to clean this up. + // So, because this API is so infrequently used, (expected to be usually only + // one time for a process, but it can be more), we are cleaning it up here. + std::unique_lock<std::mutex> lock = details::gServiceSidMap.lock(); + pruneMapLocked(details::gServiceSidMap); + details::gServiceSidMap.setLocked(service, requesting); + + return true; +} + bool interfacesEqual(const sp<IBase>& left, const sp<IBase>& right) { if (left == nullptr || right == nullptr || !left->isRemote() || !right->isRemote()) { return left == right; diff --git a/transport/Static.cpp b/transport/Static.cpp index 45ae27c..0bbd48d 100644 --- a/transport/Static.cpp +++ b/transport/Static.cpp @@ -33,7 +33,9 @@ BnConstructorMap gBnConstructorMap{}; ConcurrentMap<const ::android::hidl::base::V1_0::IBase*, wp<::android::hardware::BHwBinder>> gBnMap{}; +// TODO(b/122472540): replace with single, hidden map ConcurrentMap<wp<::android::hidl::base::V1_0::IBase>, SchedPrio> gServicePrioMap{}; +ConcurrentMap<wp<::android::hidl::base::V1_0::IBase>, bool> gServiceSidMap{}; // Deprecated; kept for ABI compatibility. Use getBsConstructorMap. BsConstructorMap gBsConstructorMap{}; diff --git a/transport/include/hidl/ConcurrentMap.h b/transport/include/hidl/ConcurrentMap.h index 54c1a32..1b06dfd 100644 --- a/transport/include/hidl/ConcurrentMap.h +++ b/transport/include/hidl/ConcurrentMap.h @@ -67,6 +67,7 @@ public: std::unique_lock<std::mutex> lock() { return std::unique_lock<std::mutex>(mMutex); } void setLocked(K&& k, V&& v) { mMap[std::forward<K>(k)] = std::forward<V>(v); } + void setLocked(K&& k, const V& v) { mMap[std::forward<K>(k)] = v; } const V& getLocked(const K& k, const V& def) const { const_iterator iter = mMap.find(k); diff --git a/transport/include/hidl/HidlTransportSupport.h b/transport/include/hidl/HidlTransportSupport.h index 69f3291..d29a3e4 100644 --- a/transport/include/hidl/HidlTransportSupport.h +++ b/transport/include/hidl/HidlTransportSupport.h @@ -92,6 +92,18 @@ bool setMinSchedulerPolicy(const sp<::android::hidl::base::V1_0::IBase>& service bool interfacesEqual(const sp<::android::hidl::base::V1_0::IBase>& left, const sp<::android::hidl::base::V1_0::IBase>& right); +/** + * Sets whether or not this object should request security contexts to be populatd for incoming + * calls (e.g. with getCallingSid). + * + * This method MUST be called before passing this service to another process + * and/or registering it with registerAsService(). + * + * @param service the service to set the policy for + * @param requesting whether or not to request sid (default is false) + */ +bool setRequestingSid(const sp<::android::hidl::base::V1_0::IBase>& service, bool requesting); + namespace details { // Return PID on userdebug / eng builds and IServiceManager::PidConstant::NO_PID on user builds. diff --git a/transport/include/hidl/Static.h b/transport/include/hidl/Static.h index b50c173..cc711b7 100644 --- a/transport/include/hidl/Static.h +++ b/transport/include/hidl/Static.h @@ -38,6 +38,7 @@ struct SchedPrio { }; extern ConcurrentMap<wp<::android::hidl::base::V1_0::IBase>, SchedPrio> gServicePrioMap; +extern ConcurrentMap<wp<::android::hidl::base::V1_0::IBase>, bool> gServiceSidMap; // For HidlBinderSupport and autogenerated code extern ConcurrentMap<const ::android::hidl::base::V1_0::IBase*, wp<::android::hardware::BHwBinder>> |