Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "android_os_HwBinder" |
| 19 | #include <android-base/logging.h> |
| 20 | |
| 21 | #include "android_os_HwBinder.h" |
| 22 | |
| 23 | #include "android_os_HwParcel.h" |
| 24 | #include "android_os_HwRemoteBinder.h" |
| 25 | |
Steven Moreland | afe95a9 | 2017-05-23 12:45:16 -0700 | [diff] [blame] | 26 | #include <cstring> |
| 27 | |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 28 | #include <nativehelper/JNIHelp.h> |
Steven Moreland | a813686 | 2016-10-24 13:44:41 -0700 | [diff] [blame] | 29 | #include <android/hidl/manager/1.0/IServiceManager.h> |
Yifan Hong | bae1b55 | 2016-12-01 10:25:05 -0800 | [diff] [blame] | 30 | #include <android/hidl/base/1.0/IBase.h> |
Yifan Hong | 90b6a37 | 2017-01-09 17:58:33 -0800 | [diff] [blame] | 31 | #include <android/hidl/base/1.0/BpHwBase.h> |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 32 | #include <android_runtime/AndroidRuntime.h> |
Steven Moreland | a813686 | 2016-10-24 13:44:41 -0700 | [diff] [blame] | 33 | #include <hidl/ServiceManagement.h> |
Martijn Coenen | aa2c32f | 2016-09-01 01:37:05 +0200 | [diff] [blame] | 34 | #include <hidl/Status.h> |
Martijn Coenen | 1298711 | 2016-12-08 10:48:19 +0100 | [diff] [blame] | 35 | #include <hidl/HidlTransportSupport.h> |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 36 | #include <hwbinder/ProcessState.h> |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 37 | #include <nativehelper/ScopedLocalRef.h> |
Andreas Gampe | 63c0193 | 2017-10-25 13:03:24 -0700 | [diff] [blame] | 38 | #include <nativehelper/ScopedUtfChars.h> |
Yifan Hong | 0382be2 | 2017-02-06 12:43:08 -0800 | [diff] [blame] | 39 | #include <vintf/parse_string.h> |
Sundong Ahn | 28cc6e8 | 2017-07-13 16:34:01 +0900 | [diff] [blame] | 40 | #include <utils/misc.h> |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 41 | |
| 42 | #include "core_jni_helpers.h" |
| 43 | |
| 44 | using android::AndroidRuntime; |
Steven Moreland | f3c5349 | 2016-11-03 15:17:04 -0700 | [diff] [blame] | 45 | using android::hardware::hidl_vec; |
| 46 | using android::hardware::hidl_string; |
Timur Iskhakov | b6a6283 | 2017-07-10 10:08:38 -0700 | [diff] [blame] | 47 | using android::hardware::IPCThreadState; |
| 48 | using android::hardware::ProcessState; |
Steven Moreland | c0631d0 | 2017-01-04 10:37:59 -0800 | [diff] [blame] | 49 | template<typename T> |
| 50 | using Return = android::hardware::Return<T>; |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 51 | |
| 52 | #define PACKAGE_PATH "android/os" |
| 53 | #define CLASS_NAME "HwBinder" |
| 54 | #define CLASS_PATH PACKAGE_PATH "/" CLASS_NAME |
| 55 | |
| 56 | namespace android { |
| 57 | |
Steven Moreland | e62b1f3 | 2016-12-20 15:55:48 -0800 | [diff] [blame] | 58 | static jclass gErrorClass; |
| 59 | |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 60 | static struct fields_t { |
| 61 | jfieldID contextID; |
| 62 | jmethodID onTransactID; |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 63 | } gFields; |
| 64 | |
Andreas Huber | 56bdb8a | 2017-06-16 14:56:12 -0700 | [diff] [blame] | 65 | struct JHwBinderHolder : public RefBase { |
| 66 | JHwBinderHolder() {} |
| 67 | |
| 68 | sp<JHwBinder> get(JNIEnv *env, jobject obj) { |
| 69 | Mutex::Autolock autoLock(mLock); |
| 70 | |
| 71 | sp<JHwBinder> binder = mBinder.promote(); |
| 72 | |
| 73 | if (binder == NULL) { |
| 74 | binder = new JHwBinder(env, obj); |
| 75 | mBinder = binder; |
| 76 | } |
| 77 | |
| 78 | return binder; |
| 79 | } |
| 80 | |
| 81 | private: |
| 82 | Mutex mLock; |
| 83 | wp<JHwBinder> mBinder; |
| 84 | |
| 85 | DISALLOW_COPY_AND_ASSIGN(JHwBinderHolder); |
| 86 | }; |
| 87 | |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 88 | // static |
| 89 | void JHwBinder::InitClass(JNIEnv *env) { |
| 90 | ScopedLocalRef<jclass> clazz( |
| 91 | env, FindClassOrDie(env, CLASS_PATH)); |
| 92 | |
| 93 | gFields.contextID = |
| 94 | GetFieldIDOrDie(env, clazz.get(), "mNativeContext", "J"); |
| 95 | |
| 96 | gFields.onTransactID = |
| 97 | GetMethodIDOrDie( |
| 98 | env, |
| 99 | clazz.get(), |
| 100 | "onTransact", |
| 101 | "(IL" PACKAGE_PATH "/HwParcel;L" PACKAGE_PATH "/HwParcel;I)V"); |
| 102 | } |
| 103 | |
| 104 | // static |
Andreas Huber | 56bdb8a | 2017-06-16 14:56:12 -0700 | [diff] [blame] | 105 | sp<JHwBinderHolder> JHwBinder::SetNativeContext( |
| 106 | JNIEnv *env, jobject thiz, const sp<JHwBinderHolder> &context) { |
| 107 | sp<JHwBinderHolder> old = |
| 108 | (JHwBinderHolder *)env->GetLongField(thiz, gFields.contextID); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 109 | |
| 110 | if (context != NULL) { |
| 111 | context->incStrong(NULL /* id */); |
| 112 | } |
| 113 | |
| 114 | if (old != NULL) { |
| 115 | old->decStrong(NULL /* id */); |
| 116 | } |
| 117 | |
| 118 | env->SetLongField(thiz, gFields.contextID, (long)context.get()); |
| 119 | |
| 120 | return old; |
| 121 | } |
| 122 | |
| 123 | // static |
Andreas Huber | 56bdb8a | 2017-06-16 14:56:12 -0700 | [diff] [blame] | 124 | sp<JHwBinder> JHwBinder::GetNativeBinder( |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 125 | JNIEnv *env, jobject thiz) { |
Andreas Huber | 56bdb8a | 2017-06-16 14:56:12 -0700 | [diff] [blame] | 126 | JHwBinderHolder *holder = |
| 127 | reinterpret_cast<JHwBinderHolder *>( |
| 128 | env->GetLongField(thiz, gFields.contextID)); |
| 129 | |
| 130 | return holder->get(env, thiz); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | JHwBinder::JHwBinder(JNIEnv *env, jobject thiz) { |
| 134 | jclass clazz = env->GetObjectClass(thiz); |
| 135 | CHECK(clazz != NULL); |
| 136 | |
Andreas Huber | 56bdb8a | 2017-06-16 14:56:12 -0700 | [diff] [blame] | 137 | mObject = env->NewGlobalRef(thiz); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | JHwBinder::~JHwBinder() { |
| 141 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 142 | |
Andreas Huber | 56bdb8a | 2017-06-16 14:56:12 -0700 | [diff] [blame] | 143 | env->DeleteGlobalRef(mObject); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 144 | mObject = NULL; |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | status_t JHwBinder::onTransact( |
| 148 | uint32_t code, |
| 149 | const hardware::Parcel &data, |
| 150 | hardware::Parcel *reply, |
| 151 | uint32_t flags, |
| 152 | TransactCallback callback) { |
| 153 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
Martijn Coenen | 60bf84a | 2017-02-08 10:22:28 +0100 | [diff] [blame] | 154 | bool isOneway = (flags & TF_ONE_WAY) != 0; |
| 155 | ScopedLocalRef<jobject> replyObj(env, nullptr); |
| 156 | sp<JHwParcel> replyContext = nullptr; |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 157 | |
| 158 | ScopedLocalRef<jobject> requestObj(env, JHwParcel::NewObject(env)); |
| 159 | JHwParcel::GetNativeContext(env, requestObj.get())->setParcel( |
| 160 | const_cast<hardware::Parcel *>(&data), false /* assumeOwnership */); |
| 161 | |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 162 | |
Martijn Coenen | 60bf84a | 2017-02-08 10:22:28 +0100 | [diff] [blame] | 163 | if (!isOneway) { |
| 164 | replyObj.reset(JHwParcel::NewObject(env)); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 165 | |
Martijn Coenen | 60bf84a | 2017-02-08 10:22:28 +0100 | [diff] [blame] | 166 | replyContext = JHwParcel::GetNativeContext(env, replyObj.get()); |
| 167 | |
| 168 | replyContext->setParcel(reply, false /* assumeOwnership */); |
| 169 | replyContext->setTransactCallback(callback); |
| 170 | } |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 171 | |
| 172 | env->CallVoidMethod( |
| 173 | mObject, |
| 174 | gFields.onTransactID, |
| 175 | code, |
| 176 | requestObj.get(), |
| 177 | replyObj.get(), |
| 178 | flags); |
| 179 | |
Steven Moreland | e62b1f3 | 2016-12-20 15:55:48 -0800 | [diff] [blame] | 180 | if (env->ExceptionCheck()) { |
| 181 | jthrowable excep = env->ExceptionOccurred(); |
| 182 | env->ExceptionDescribe(); |
Aurimas Liutikas | f0aa0f1 | 2017-02-10 14:52:59 -0800 | [diff] [blame] | 183 | env->ExceptionClear(); |
Steven Moreland | e62b1f3 | 2016-12-20 15:55:48 -0800 | [diff] [blame] | 184 | |
Aurimas Liutikas | f0aa0f1 | 2017-02-10 14:52:59 -0800 | [diff] [blame] | 185 | // It is illegal to call IsInstanceOf if there is a pending exception. |
| 186 | // Attempting to do so results in a JniAbort which crashes the entire process. |
Steven Moreland | e62b1f3 | 2016-12-20 15:55:48 -0800 | [diff] [blame] | 187 | if (env->IsInstanceOf(excep, gErrorClass)) { |
| 188 | /* It's an error */ |
| 189 | LOG(ERROR) << "Forcefully exiting"; |
| 190 | exit(1); |
| 191 | } else { |
Steven Moreland | e62b1f3 | 2016-12-20 15:55:48 -0800 | [diff] [blame] | 192 | LOG(ERROR) << "Uncaught exception!"; |
| 193 | } |
| 194 | |
| 195 | env->DeleteLocalRef(excep); |
| 196 | } |
| 197 | |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 198 | status_t err = OK; |
| 199 | |
Martijn Coenen | 60bf84a | 2017-02-08 10:22:28 +0100 | [diff] [blame] | 200 | if (!isOneway) { |
| 201 | if (!replyContext->wasSent()) { |
| 202 | // The implementation never finished the transaction. |
| 203 | err = UNKNOWN_ERROR; // XXX special error code instead? |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 204 | |
Martijn Coenen | 60bf84a | 2017-02-08 10:22:28 +0100 | [diff] [blame] | 205 | reply->setDataPosition(0 /* pos */); |
| 206 | } |
| 207 | |
| 208 | // Release all temporary storage now that scatter-gather data |
| 209 | // has been consolidated, either by calling the TransactCallback, |
| 210 | // if wasSent() == true or clearing the reply parcel (setDataOffset above). |
| 211 | replyContext->getStorage()->release(env); |
| 212 | |
| 213 | // We cannot permanently pass ownership of "data" and "reply" over to their |
| 214 | // Java object wrappers (we don't own them ourselves). |
| 215 | replyContext->setParcel( |
| 216 | NULL /* parcel */, false /* assumeOwnership */); |
| 217 | |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 220 | JHwParcel::GetNativeContext(env, requestObj.get())->setParcel( |
| 221 | NULL /* parcel */, false /* assumeOwnership */); |
| 222 | |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 223 | return err; |
| 224 | } |
| 225 | |
| 226 | } // namespace android |
| 227 | |
| 228 | //////////////////////////////////////////////////////////////////////////////// |
| 229 | |
| 230 | using namespace android; |
| 231 | |
| 232 | static void releaseNativeContext(void *nativeContext) { |
Andreas Huber | 56bdb8a | 2017-06-16 14:56:12 -0700 | [diff] [blame] | 233 | sp<JHwBinderHolder> context = static_cast<JHwBinderHolder *>(nativeContext); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 234 | |
Andreas Huber | 56bdb8a | 2017-06-16 14:56:12 -0700 | [diff] [blame] | 235 | if (context != NULL) { |
| 236 | context->decStrong(NULL /* id */); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
| 240 | static jlong JHwBinder_native_init(JNIEnv *env) { |
| 241 | JHwBinder::InitClass(env); |
| 242 | |
| 243 | return reinterpret_cast<jlong>(&releaseNativeContext); |
| 244 | } |
| 245 | |
| 246 | static void JHwBinder_native_setup(JNIEnv *env, jobject thiz) { |
Andreas Huber | 56bdb8a | 2017-06-16 14:56:12 -0700 | [diff] [blame] | 247 | sp<JHwBinderHolder> context = new JHwBinderHolder; |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 248 | JHwBinder::SetNativeContext(env, thiz, context); |
| 249 | } |
| 250 | |
| 251 | static void JHwBinder_native_transact( |
| 252 | JNIEnv * /* env */, |
| 253 | jobject /* thiz */, |
| 254 | jint /* code */, |
| 255 | jobject /* requestObj */, |
| 256 | jobject /* replyObj */, |
| 257 | jint /* flags */) { |
| 258 | CHECK(!"Should not be here"); |
| 259 | } |
| 260 | |
| 261 | static void JHwBinder_native_registerService( |
Andreas Huber | 35eb799 | 2016-10-25 13:29:30 -0700 | [diff] [blame] | 262 | JNIEnv *env, |
| 263 | jobject thiz, |
Steven Moreland | f3c5349 | 2016-11-03 15:17:04 -0700 | [diff] [blame] | 264 | jstring serviceNameObj) { |
Andreas Gampe | 63c0193 | 2017-10-25 13:03:24 -0700 | [diff] [blame] | 265 | ScopedUtfChars str(env, serviceNameObj); |
| 266 | if (str.c_str() == nullptr) { |
| 267 | return; // NPE will be pending. |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Andreas Huber | 56bdb8a | 2017-06-16 14:56:12 -0700 | [diff] [blame] | 270 | sp<hardware::IBinder> binder = JHwBinder::GetNativeBinder(env, thiz); |
Steven Moreland | 520d12c | 2016-12-15 15:50:17 -0800 | [diff] [blame] | 271 | |
Martijn Coenen | 1298711 | 2016-12-08 10:48:19 +0100 | [diff] [blame] | 272 | /* TODO(b/33440494) this is not right */ |
Yifan Hong | 90b6a37 | 2017-01-09 17:58:33 -0800 | [diff] [blame] | 273 | sp<hidl::base::V1_0::IBase> base = new hidl::base::V1_0::BpHwBase(binder); |
Steven Moreland | 520d12c | 2016-12-15 15:50:17 -0800 | [diff] [blame] | 274 | |
| 275 | auto manager = hardware::defaultServiceManager(); |
| 276 | |
| 277 | if (manager == nullptr) { |
| 278 | LOG(ERROR) << "Could not get hwservicemanager."; |
Steven Moreland | c0631d0 | 2017-01-04 10:37:59 -0800 | [diff] [blame] | 279 | signalExceptionForError(env, UNKNOWN_ERROR, true /* canThrowRemoteException */); |
Steven Moreland | 520d12c | 2016-12-15 15:50:17 -0800 | [diff] [blame] | 280 | return; |
| 281 | } |
| 282 | |
Andreas Gampe | 63c0193 | 2017-10-25 13:03:24 -0700 | [diff] [blame] | 283 | Return<bool> ret = manager->add(str.c_str(), base); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 284 | |
Steven Moreland | c0631d0 | 2017-01-04 10:37:59 -0800 | [diff] [blame] | 285 | bool ok = ret.isOk() && ret; |
| 286 | |
Steven Moreland | a813686 | 2016-10-24 13:44:41 -0700 | [diff] [blame] | 287 | if (ok) { |
Andreas Gampe | 63c0193 | 2017-10-25 13:03:24 -0700 | [diff] [blame] | 288 | LOG(INFO) << "HwBinder: Starting thread pool for " << str.c_str(); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 289 | ::android::hardware::ProcessState::self()->startThreadPool(); |
| 290 | } |
| 291 | |
Steven Moreland | c0631d0 | 2017-01-04 10:37:59 -0800 | [diff] [blame] | 292 | signalExceptionForError(env, (ok ? OK : UNKNOWN_ERROR), true /* canThrowRemoteException */); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | static jobject JHwBinder_native_getService( |
Andreas Huber | 35eb799 | 2016-10-25 13:29:30 -0700 | [diff] [blame] | 296 | JNIEnv *env, |
| 297 | jclass /* clazzObj */, |
Steven Moreland | f3c5349 | 2016-11-03 15:17:04 -0700 | [diff] [blame] | 298 | jstring ifaceNameObj, |
Steven Moreland | ec5eb7e | 2017-10-25 04:50:46 +0000 | [diff] [blame] | 299 | jstring serviceNameObj, |
| 300 | jboolean retry) { |
Steven Moreland | f3c5349 | 2016-11-03 15:17:04 -0700 | [diff] [blame] | 301 | |
Steven Moreland | f8202e4 | 2017-04-06 09:28:32 -0700 | [diff] [blame] | 302 | using ::android::hidl::base::V1_0::IBase; |
Steven Moreland | c4bfdef | 2017-10-18 23:19:43 -0700 | [diff] [blame] | 303 | using ::android::hardware::details::getRawServiceInternal; |
Yifan Hong | 0382be2 | 2017-02-06 12:43:08 -0800 | [diff] [blame] | 304 | |
Andreas Gampe | 63c0193 | 2017-10-25 13:03:24 -0700 | [diff] [blame] | 305 | std::string ifaceName; |
| 306 | { |
| 307 | ScopedUtfChars str(env, ifaceNameObj); |
| 308 | if (str.c_str() == nullptr) { |
| 309 | return nullptr; // NPE will be pending. |
| 310 | } |
| 311 | ifaceName = str.c_str(); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Andreas Gampe | 63c0193 | 2017-10-25 13:03:24 -0700 | [diff] [blame] | 314 | std::string serviceName; |
| 315 | { |
| 316 | ScopedUtfChars str(env, serviceNameObj); |
| 317 | if (str.c_str() == nullptr) { |
| 318 | return nullptr; // NPE will be pending. |
| 319 | } |
| 320 | serviceName = str.c_str(); |
Andreas Huber | 35eb799 | 2016-10-25 13:29:30 -0700 | [diff] [blame] | 321 | } |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 322 | |
Steven Moreland | ec5eb7e | 2017-10-25 04:50:46 +0000 | [diff] [blame] | 323 | sp<IBase> ret = getRawServiceInternal(ifaceName, serviceName, retry /* retry */, false /* getStub */); |
Steven Moreland | 72be156 | 2017-07-21 19:29:54 +0000 | [diff] [blame] | 324 | sp<hardware::IBinder> service = hardware::toBinder<hidl::base::V1_0::IBase>(ret); |
Steven Moreland | 2f379ca | 2017-02-01 09:58:00 -0800 | [diff] [blame] | 325 | |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 326 | if (service == NULL) { |
| 327 | signalExceptionForError(env, NAME_NOT_FOUND); |
| 328 | return NULL; |
| 329 | } |
| 330 | |
Andreas Gampe | 63c0193 | 2017-10-25 13:03:24 -0700 | [diff] [blame] | 331 | LOG(INFO) << "HwBinder: Starting thread pool for " << serviceName << "::" << ifaceName; |
Andreas Huber | 781c083 | 2016-10-05 11:10:26 -0700 | [diff] [blame] | 332 | ::android::hardware::ProcessState::self()->startThreadPool(); |
| 333 | |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 334 | return JHwRemoteBinder::NewObject(env, service); |
| 335 | } |
| 336 | |
Yifan Hong | 029b08c | 2017-10-25 13:19:22 -0700 | [diff] [blame] | 337 | void JHwBinder_native_configureRpcThreadpool(JNIEnv *, jclass, |
| 338 | jlong maxThreads, jboolean callerWillJoin) { |
Timur Iskhakov | b6a6283 | 2017-07-10 10:08:38 -0700 | [diff] [blame] | 339 | CHECK(maxThreads > 0); |
| 340 | ProcessState::self()->setThreadPoolConfiguration(maxThreads, callerWillJoin /*callerJoinsPool*/); |
| 341 | } |
| 342 | |
| 343 | void JHwBinder_native_joinRpcThreadpool() { |
| 344 | IPCThreadState::self()->joinThreadPool(); |
| 345 | } |
| 346 | |
Yifan Hong | 029b08c | 2017-10-25 13:19:22 -0700 | [diff] [blame] | 347 | static void JHwBinder_report_sysprop_change(JNIEnv * /*env*/, jclass /*clazz*/) |
Sundong Ahn | 28cc6e8 | 2017-07-13 16:34:01 +0900 | [diff] [blame] | 348 | { |
| 349 | report_sysprop_change(); |
| 350 | } |
| 351 | |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 352 | static JNINativeMethod gMethods[] = { |
| 353 | { "native_init", "()J", (void *)JHwBinder_native_init }, |
| 354 | { "native_setup", "()V", (void *)JHwBinder_native_setup }, |
| 355 | |
| 356 | { "transact", |
| 357 | "(IL" PACKAGE_PATH "/HwParcel;L" PACKAGE_PATH "/HwParcel;I)V", |
| 358 | (void *)JHwBinder_native_transact }, |
| 359 | |
Martijn Coenen | 85d12da | 2017-03-06 13:07:53 +0100 | [diff] [blame] | 360 | { "registerService", "(Ljava/lang/String;)V", |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 361 | (void *)JHwBinder_native_registerService }, |
| 362 | |
Steven Moreland | ec5eb7e | 2017-10-25 04:50:46 +0000 | [diff] [blame] | 363 | { "getService", "(Ljava/lang/String;Ljava/lang/String;Z)L" PACKAGE_PATH "/IHwBinder;", |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 364 | (void *)JHwBinder_native_getService }, |
Timur Iskhakov | b6a6283 | 2017-07-10 10:08:38 -0700 | [diff] [blame] | 365 | |
| 366 | { "configureRpcThreadpool", "(JZ)V", |
| 367 | (void *)JHwBinder_native_configureRpcThreadpool }, |
| 368 | |
| 369 | { "joinRpcThreadpool", "()V", |
| 370 | (void *)JHwBinder_native_joinRpcThreadpool }, |
Sundong Ahn | 28cc6e8 | 2017-07-13 16:34:01 +0900 | [diff] [blame] | 371 | |
| 372 | { "native_report_sysprop_change", "()V", |
| 373 | (void *)JHwBinder_report_sysprop_change }, |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 374 | }; |
| 375 | |
| 376 | namespace android { |
| 377 | |
| 378 | int register_android_os_HwBinder(JNIEnv *env) { |
Steven Moreland | e62b1f3 | 2016-12-20 15:55:48 -0800 | [diff] [blame] | 379 | jclass errorClass = FindClassOrDie(env, "java/lang/Error"); |
| 380 | gErrorClass = MakeGlobalRefOrDie(env, errorClass); |
| 381 | |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 382 | return RegisterMethodsOrDie(env, CLASS_PATH, gMethods, NELEM(gMethods)); |
| 383 | } |
| 384 | |
| 385 | } // namespace android |