├── .clang-format ├── ActivityManager.cpp ├── Android.bp ├── AppOpsManager.cpp ├── Binder.cpp ├── BpBinder.cpp ├── BufferedTextOutput.cpp ├── CMakeLists.txt ├── Debug.cpp ├── IActivityManager.cpp ├── IAppOpsCallback.cpp ├── IAppOpsService.cpp ├── IBatteryStats.cpp ├── IInterface.cpp ├── IMediaResourceMonitor.cpp ├── IMemory.cpp ├── IPCThreadState.cpp ├── IPermissionController.cpp ├── IProcessInfoService.cpp ├── IResultReceiver.cpp ├── IServiceManager.cpp ├── IShellCallback.cpp ├── IUidObserver.cpp ├── IpPrefix.cpp ├── MODULE_LICENSE_APACHE2 ├── MemoryBase.cpp ├── MemoryDealer.cpp ├── MemoryHeapBase.cpp ├── NOTICE ├── OWNERS ├── Parcel.cpp ├── ParcelFileDescriptor.cpp ├── PermissionCache.cpp ├── PermissionController.cpp ├── PersistableBundle.cpp ├── ProcessInfoService.cpp ├── ProcessState.cpp ├── Static.cpp ├── Status.cpp ├── TextOutput.cpp ├── Value.cpp ├── aidl └── android │ └── content │ └── pm │ ├── IPackageManagerNative.aidl │ └── OWNERS ├── include ├── binder │ ├── ActivityManager.h │ ├── AppOpsManager.h │ ├── Binder.h │ ├── BinderService.h │ ├── BpBinder.h │ ├── BufferedTextOutput.h │ ├── Debug.h │ ├── IActivityManager.h │ ├── IAppOpsCallback.h │ ├── IAppOpsService.h │ ├── IBatteryStats.h │ ├── IBinder.h │ ├── IInterface.h │ ├── IMediaResourceMonitor.h │ ├── IMemory.h │ ├── IPCThreadState.h │ ├── IPermissionController.h │ ├── IProcessInfoService.h │ ├── IResultReceiver.h │ ├── IServiceManager.h │ ├── IShellCallback.h │ ├── IUidObserver.h │ ├── IpPrefix.h │ ├── Map.h │ ├── MemoryBase.h │ ├── MemoryDealer.h │ ├── MemoryHeapBase.h │ ├── Parcel.h │ ├── ParcelFileDescriptor.h │ ├── Parcelable.h │ ├── PermissionCache.h │ ├── PermissionController.h │ ├── PersistableBundle.h │ ├── ProcessInfoService.h │ ├── ProcessState.h │ ├── SafeInterface.h │ ├── Status.h │ ├── TextOutput.h │ └── Value.h └── private │ └── binder │ ├── ParcelValTypes.h │ ├── Static.h │ └── binder_module.h ├── ndk ├── .clang-format ├── Android.bp ├── NOTICE ├── ibinder.cpp ├── ibinder_internal.h ├── ibinder_jni.cpp ├── include_apex │ └── android │ │ ├── binder_manager.h │ │ └── binder_process.h ├── include_ndk │ └── android │ │ ├── binder_auto_utils.h │ │ ├── binder_ibinder.h │ │ ├── binder_ibinder_jni.h │ │ ├── binder_interface_utils.h │ │ ├── binder_parcel.h │ │ ├── binder_parcel_utils.h │ │ └── binder_status.h ├── libbinder_ndk.map.txt ├── parcel.cpp ├── parcel_internal.h ├── process.cpp ├── runtests.sh ├── scripts │ ├── format.sh │ ├── gen_parcel_helper.py │ └── init_map.sh ├── service_manager.cpp ├── status.cpp ├── status_internal.h ├── test │ ├── Android.bp │ ├── iface.cpp │ ├── include │ │ └── iface │ │ │ └── iface.h │ ├── main_client.cpp │ └── main_server.cpp └── update.sh └── tests ├── Android.bp ├── CMakeLists.txt ├── binderDriverInterfaceTest.cpp ├── binderLibTest.cpp ├── binderSafeInterfaceTest.cpp ├── binderTextOutputTest.cpp ├── binderThroughputTest.cpp ├── binderValueTypeTest.cpp └── schd-dbg.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | 3 | AccessModifierOffset: -4 4 | AlignOperands: false 5 | AllowShortFunctionsOnASingleLine: Inline 6 | AlwaysBreakBeforeMultilineStrings: false 7 | ColumnLimit: 100 8 | CommentPragmas: NOLINT:.* 9 | ConstructorInitializerIndentWidth: 6 10 | ContinuationIndentWidth: 8 11 | IndentWidth: 4 12 | PenaltyBreakBeforeFirstCallParameter: 100000 13 | SpacesBeforeTrailingComments: 1 14 | -------------------------------------------------------------------------------- /ActivityManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 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 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | namespace android { 27 | 28 | ActivityManager::ActivityManager() 29 | { 30 | } 31 | 32 | sp ActivityManager::getService() 33 | { 34 | std::lock_guard scoped_lock(mLock); 35 | int64_t startTime = 0; 36 | sp service = mService; 37 | while (service == nullptr || !IInterface::asBinder(service)->isBinderAlive()) { 38 | sp binder = defaultServiceManager()->checkService(String16("activity")); 39 | if (binder == nullptr) { 40 | // Wait for the activity service to come back... 41 | if (startTime == 0) { 42 | startTime = uptimeMillis(); 43 | ALOGI("Waiting for activity service"); 44 | } else if ((uptimeMillis() - startTime) > 1000000) { 45 | ALOGW("Waiting too long for activity service, giving up"); 46 | service = nullptr; 47 | break; 48 | } 49 | usleep(25000); 50 | } else { 51 | service = interface_cast(binder); 52 | mService = service; 53 | } 54 | } 55 | return service; 56 | } 57 | 58 | int ActivityManager::openContentUri(const String16& stringUri) 59 | { 60 | sp service = getService(); 61 | return service != nullptr ? service->openContentUri(stringUri) : -1; 62 | } 63 | 64 | void ActivityManager::registerUidObserver(const sp& observer, 65 | const int32_t event, 66 | const int32_t cutpoint, 67 | const String16& callingPackage) 68 | { 69 | sp service = getService(); 70 | if (service != nullptr) { 71 | service->registerUidObserver(observer, event, cutpoint, callingPackage); 72 | } 73 | } 74 | 75 | void ActivityManager::unregisterUidObserver(const sp& observer) 76 | { 77 | sp service = getService(); 78 | if (service != nullptr) { 79 | service->unregisterUidObserver(observer); 80 | } 81 | } 82 | 83 | bool ActivityManager::isUidActive(const uid_t uid, const String16& callingPackage) 84 | { 85 | sp service = getService(); 86 | if (service != nullptr) { 87 | return service->isUidActive(uid, callingPackage); 88 | } 89 | return false; 90 | } 91 | 92 | int32_t ActivityManager::getUidProcessState(const uid_t uid, const String16& callingPackage) 93 | { 94 | sp service = getService(); 95 | if (service != nullptr) { 96 | return service->getUidProcessState(uid, callingPackage); 97 | } 98 | return PROCESS_STATE_UNKNOWN; 99 | } 100 | 101 | status_t ActivityManager::linkToDeath(const sp& recipient) { 102 | sp service = getService(); 103 | if (service != nullptr) { 104 | return IInterface::asBinder(service)->linkToDeath(recipient); 105 | } 106 | return INVALID_OPERATION; 107 | } 108 | 109 | status_t ActivityManager::unlinkToDeath(const sp& recipient) { 110 | sp service = getService(); 111 | if (service != nullptr) { 112 | return IInterface::asBinder(service)->unlinkToDeath(recipient); 113 | } 114 | return INVALID_OPERATION; 115 | } 116 | 117 | }; // namespace android 118 | -------------------------------------------------------------------------------- /Android.bp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009 The Android Open Source Project 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | cc_library_headers { 16 | name: "libbinder_headers", 17 | export_include_dirs: ["include"], 18 | vendor_available: true, 19 | header_libs: [ 20 | "libbase_headers", 21 | "libcutils_headers", 22 | "libutils_headers", 23 | ], 24 | export_header_lib_headers: [ 25 | "libbase_headers", 26 | "libcutils_headers", 27 | "libutils_headers", 28 | ], 29 | } 30 | 31 | cc_library_shared { 32 | name: "libbinder", 33 | 34 | // for vndbinder 35 | vendor_available: true, 36 | vndk: { 37 | enabled: true, 38 | }, 39 | double_loadable: true, 40 | 41 | srcs: [ 42 | "ActivityManager.cpp", 43 | "AppOpsManager.cpp", 44 | "Binder.cpp", 45 | "BpBinder.cpp", 46 | "BufferedTextOutput.cpp", 47 | "Debug.cpp", 48 | "IActivityManager.cpp", 49 | "IAppOpsCallback.cpp", 50 | "IAppOpsService.cpp", 51 | "IBatteryStats.cpp", 52 | "IInterface.cpp", 53 | "IMediaResourceMonitor.cpp", 54 | "IMemory.cpp", 55 | "IPCThreadState.cpp", 56 | "IPermissionController.cpp", 57 | "IProcessInfoService.cpp", 58 | "IResultReceiver.cpp", 59 | "IServiceManager.cpp", 60 | "IShellCallback.cpp", 61 | "IUidObserver.cpp", 62 | "MemoryBase.cpp", 63 | "MemoryDealer.cpp", 64 | "MemoryHeapBase.cpp", 65 | "Parcel.cpp", 66 | "ParcelFileDescriptor.cpp", 67 | "PermissionCache.cpp", 68 | "PermissionController.cpp", 69 | "PersistableBundle.cpp", 70 | "ProcessInfoService.cpp", 71 | "ProcessState.cpp", 72 | "Static.cpp", 73 | "Status.cpp", 74 | "TextOutput.cpp", 75 | "IpPrefix.cpp", 76 | "Value.cpp", 77 | ":libbinder_aidl", 78 | ], 79 | 80 | target: { 81 | vendor: { 82 | exclude_srcs: [ 83 | "ActivityManager.cpp", 84 | "AppOpsManager.cpp", 85 | "IActivityManager.cpp", 86 | "IAppOpsCallback.cpp", 87 | "IAppOpsService.cpp", 88 | "IBatteryStats.cpp", 89 | "IMediaResourceMonitor.cpp", 90 | "IPermissionController.cpp", 91 | "IProcessInfoService.cpp", 92 | "IUidObserver.cpp", 93 | "PermissionCache.cpp", 94 | "PermissionController.cpp", 95 | "ProcessInfoService.cpp", 96 | "IpPrefix.cpp", 97 | ":libbinder_aidl", 98 | ], 99 | }, 100 | }, 101 | 102 | aidl: { 103 | export_aidl_headers: true, 104 | }, 105 | 106 | cflags: [ 107 | "-Wall", 108 | "-Wextra", 109 | "-Werror", 110 | "-Wzero-as-null-pointer-constant", 111 | ], 112 | product_variables: { 113 | binder32bit: { 114 | cflags: ["-DBINDER_IPC_32BIT=1"], 115 | }, 116 | }, 117 | 118 | shared_libs: [ 119 | "libbase", 120 | "liblog", 121 | "libcutils", 122 | "libutils", 123 | "libbinderthreadstate", 124 | ], 125 | 126 | header_libs: [ 127 | "libbinder_headers", 128 | ], 129 | 130 | export_header_lib_headers: [ 131 | "libbinder_headers", 132 | ], 133 | 134 | clang: true, 135 | sanitize: { 136 | misc_undefined: ["integer"], 137 | }, 138 | } 139 | 140 | // AIDL interface between libbinder and framework.jar 141 | filegroup { 142 | name: "libbinder_aidl", 143 | srcs: [ 144 | "aidl/android/content/pm/IPackageManagerNative.aidl", 145 | ], 146 | } 147 | 148 | subdirs = ["tests"] 149 | -------------------------------------------------------------------------------- /AppOpsManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 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 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace android { 25 | 26 | namespace { 27 | 28 | #if defined(__BRILLO__) 29 | // Because Brillo has no application model, security policy is managed 30 | // statically (at build time) with SELinux controls. 31 | // As a consequence, it also never runs the AppOpsManager service. 32 | const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_ALLOWED; 33 | #else 34 | const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_IGNORED; 35 | #endif // defined(__BRILLO__) 36 | 37 | } // namespace 38 | 39 | static String16 _appops("appops"); 40 | static pthread_mutex_t gTokenMutex = PTHREAD_MUTEX_INITIALIZER; 41 | static sp gToken; 42 | 43 | static const sp& getToken(const sp& service) { 44 | pthread_mutex_lock(&gTokenMutex); 45 | if (gToken == nullptr || gToken->pingBinder() != NO_ERROR) { 46 | gToken = service->getToken(new BBinder()); 47 | } 48 | pthread_mutex_unlock(&gTokenMutex); 49 | return gToken; 50 | } 51 | 52 | AppOpsManager::AppOpsManager() 53 | { 54 | } 55 | 56 | #if defined(__BRILLO__) 57 | // There is no AppOpsService on Brillo 58 | sp AppOpsManager::getService() { return NULL; } 59 | #else 60 | sp AppOpsManager::getService() 61 | { 62 | 63 | std::lock_guard scoped_lock(mLock); 64 | int64_t startTime = 0; 65 | sp service = mService; 66 | while (service == nullptr || !IInterface::asBinder(service)->isBinderAlive()) { 67 | sp binder = defaultServiceManager()->checkService(_appops); 68 | if (binder == nullptr) { 69 | // Wait for the app ops service to come back... 70 | if (startTime == 0) { 71 | startTime = uptimeMillis(); 72 | ALOGI("Waiting for app ops service"); 73 | } else if ((uptimeMillis()-startTime) > 10000) { 74 | ALOGW("Waiting too long for app ops service, giving up"); 75 | service = nullptr; 76 | break; 77 | } 78 | sleep(1); 79 | } else { 80 | service = interface_cast(binder); 81 | mService = service; 82 | } 83 | } 84 | return service; 85 | } 86 | #endif // defined(__BRILLO__) 87 | 88 | int32_t AppOpsManager::checkOp(int32_t op, int32_t uid, const String16& callingPackage) 89 | { 90 | sp service = getService(); 91 | return service != nullptr 92 | ? service->checkOperation(op, uid, callingPackage) 93 | : APP_OPS_MANAGER_UNAVAILABLE_MODE; 94 | } 95 | 96 | int32_t AppOpsManager::checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t uid, 97 | const String16& callingPackage) { 98 | sp service = getService(); 99 | return service != nullptr 100 | ? service->checkAudioOperation(op, usage, uid, callingPackage) 101 | : APP_OPS_MANAGER_UNAVAILABLE_MODE; 102 | } 103 | 104 | int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage) { 105 | sp service = getService(); 106 | return service != nullptr 107 | ? service->noteOperation(op, uid, callingPackage) 108 | : APP_OPS_MANAGER_UNAVAILABLE_MODE; 109 | } 110 | 111 | int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, 112 | bool startIfModeDefault) { 113 | sp service = getService(); 114 | return service != nullptr 115 | ? service->startOperation(getToken(service), op, uid, callingPackage, 116 | startIfModeDefault) : APP_OPS_MANAGER_UNAVAILABLE_MODE; 117 | } 118 | 119 | void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPackage) { 120 | sp service = getService(); 121 | if (service != nullptr) { 122 | service->finishOperation(getToken(service), op, uid, callingPackage); 123 | } 124 | } 125 | 126 | void AppOpsManager::startWatchingMode(int32_t op, const String16& packageName, 127 | const sp& callback) { 128 | sp service = getService(); 129 | if (service != nullptr) { 130 | service->startWatchingMode(op, packageName, callback); 131 | } 132 | } 133 | 134 | void AppOpsManager::stopWatchingMode(const sp& callback) { 135 | sp service = getService(); 136 | if (service != nullptr) { 137 | service->stopWatchingMode(callback); 138 | } 139 | } 140 | 141 | int32_t AppOpsManager::permissionToOpCode(const String16& permission) { 142 | sp service = getService(); 143 | if (service != nullptr) { 144 | return service->permissionToOpCode(permission); 145 | } 146 | return -1; 147 | } 148 | 149 | 150 | }; // namespace android 151 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | ${CMAKE_CURRENT_SOURCE_DIR}/include 3 | ) 4 | 5 | add_library(binder SHARED 6 | "AppOpsManager.cpp" 7 | "Binder.cpp" 8 | "BpBinder.cpp" 9 | "BufferedTextOutput.cpp" 10 | "Debug.cpp" 11 | "IActivityManager.cpp" 12 | "IAppOpsCallback.cpp" 13 | "IAppOpsService.cpp" 14 | "IBatteryStats.cpp" 15 | "IInterface.cpp" 16 | "IMediaResourceMonitor.cpp" 17 | "IMemory.cpp" 18 | "IPCThreadState.cpp" 19 | "IPermissionController.cpp" 20 | "IProcessInfoService.cpp" 21 | "IResultReceiver.cpp" 22 | "IServiceManager.cpp" 23 | "IShellCallback.cpp" 24 | "MemoryBase.cpp" 25 | "MemoryDealer.cpp" 26 | "MemoryHeapBase.cpp" 27 | "Parcel.cpp" 28 | "PermissionCache.cpp" 29 | "PersistableBundle.cpp" 30 | "ProcessInfoService.cpp" 31 | "ProcessState.cpp" 32 | "Static.cpp" 33 | "Status.cpp" 34 | "TextOutput.cpp" 35 | "IpPrefix.cpp" 36 | "Value.cpp" 37 | ) 38 | target_link_libraries(binder utils binderthreadstate) 39 | 40 | add_subdirectory(tests) 41 | -------------------------------------------------------------------------------- /IActivityManager.cpp: -------------------------------------------------------------------------------- 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 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace android { 25 | 26 | // ------------------------------------------------------------------------------------ 27 | 28 | class BpActivityManager : public BpInterface 29 | { 30 | public: 31 | explicit BpActivityManager(const sp& impl) 32 | : BpInterface(impl) 33 | { 34 | } 35 | 36 | virtual int openContentUri(const String16& stringUri) 37 | { 38 | Parcel data, reply; 39 | data.writeInterfaceToken(IActivityManager::getInterfaceDescriptor()); 40 | data.writeString16(stringUri); 41 | status_t ret = remote()->transact(OPEN_CONTENT_URI_TRANSACTION, data, & reply); 42 | int fd = -1; 43 | if (ret == NO_ERROR) { 44 | int32_t exceptionCode = reply.readExceptionCode(); 45 | if (!exceptionCode) { 46 | // Success is indicated here by a nonzero int followed by the fd; 47 | // failure by a zero int with no data following. 48 | if (reply.readInt32() != 0) { 49 | fd = fcntl(reply.readParcelFileDescriptor(), F_DUPFD_CLOEXEC, 0); 50 | } 51 | } else { 52 | // An exception was thrown back; fall through to return failure 53 | ALOGD("openContentUri(%s) caught exception %d\n", 54 | String8(stringUri).string(), exceptionCode); 55 | } 56 | } 57 | return fd; 58 | } 59 | 60 | virtual void registerUidObserver(const sp& observer, 61 | const int32_t event, 62 | const int32_t cutpoint, 63 | const String16& callingPackage) 64 | { 65 | Parcel data, reply; 66 | data.writeInterfaceToken(IActivityManager::getInterfaceDescriptor()); 67 | data.writeStrongBinder(IInterface::asBinder(observer)); 68 | data.writeInt32(event); 69 | data.writeInt32(cutpoint); 70 | data.writeString16(callingPackage); 71 | remote()->transact(REGISTER_UID_OBSERVER_TRANSACTION, data, &reply); 72 | } 73 | 74 | virtual void unregisterUidObserver(const sp& observer) 75 | { 76 | Parcel data, reply; 77 | data.writeInterfaceToken(IActivityManager::getInterfaceDescriptor()); 78 | data.writeStrongBinder(IInterface::asBinder(observer)); 79 | remote()->transact(UNREGISTER_UID_OBSERVER_TRANSACTION, data, &reply); 80 | } 81 | 82 | virtual bool isUidActive(const uid_t uid, const String16& callingPackage) 83 | { 84 | Parcel data, reply; 85 | data.writeInterfaceToken(IActivityManager::getInterfaceDescriptor()); 86 | data.writeInt32(uid); 87 | data.writeString16(callingPackage); 88 | remote()->transact(IS_UID_ACTIVE_TRANSACTION, data, &reply); 89 | // fail on exception 90 | if (reply.readExceptionCode() != 0) return false; 91 | return reply.readInt32() == 1; 92 | } 93 | 94 | virtual int32_t getUidProcessState(const uid_t uid, const String16& callingPackage) 95 | { 96 | Parcel data, reply; 97 | data.writeInterfaceToken(IActivityManager::getInterfaceDescriptor()); 98 | data.writeInt32(uid); 99 | data.writeString16(callingPackage); 100 | remote()->transact(GET_UID_PROCESS_STATE_TRANSACTION, data, &reply); 101 | // fail on exception 102 | if (reply.readExceptionCode() != 0) { 103 | return ActivityManager::PROCESS_STATE_UNKNOWN; 104 | } 105 | return reply.readInt32(); 106 | } 107 | }; 108 | 109 | // ------------------------------------------------------------------------------------ 110 | 111 | IMPLEMENT_META_INTERFACE(ActivityManager, "android.app.IActivityManager"); 112 | 113 | }; // namespace android 114 | -------------------------------------------------------------------------------- /IAppOpsCallback.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 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_TAG "AppOpsCallback" 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | namespace android { 28 | 29 | // ---------------------------------------------------------------------- 30 | 31 | class BpAppOpsCallback : public BpInterface 32 | { 33 | public: 34 | explicit BpAppOpsCallback(const sp& impl) 35 | : BpInterface(impl) 36 | { 37 | } 38 | 39 | virtual void opChanged(int32_t op, const String16& packageName) { 40 | Parcel data, reply; 41 | data.writeInterfaceToken(IAppOpsCallback::getInterfaceDescriptor()); 42 | data.writeInt32(op); 43 | data.writeString16(packageName); 44 | remote()->transact(OP_CHANGED_TRANSACTION, data, &reply); 45 | } 46 | }; 47 | 48 | IMPLEMENT_META_INTERFACE(AppOpsCallback, "com.android.internal.app.IAppOpsCallback"); 49 | 50 | // ---------------------------------------------------------------------- 51 | 52 | // NOLINTNEXTLINE(google-default-arguments) 53 | status_t BnAppOpsCallback::onTransact( 54 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 55 | { 56 | switch(code) { 57 | case OP_CHANGED_TRANSACTION: { 58 | CHECK_INTERFACE(IAppOpsCallback, data, reply); 59 | int32_t op = data.readInt32(); 60 | String16 packageName; 61 | (void)data.readString16(&packageName); 62 | opChanged(op, packageName); 63 | reply->writeNoException(); 64 | return NO_ERROR; 65 | } break; 66 | default: 67 | return BBinder::onTransact(code, data, reply, flags); 68 | } 69 | } 70 | 71 | }; // namespace android 72 | -------------------------------------------------------------------------------- /IInterface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 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_TAG "IInterface" 18 | #include 19 | #include 20 | 21 | namespace android { 22 | 23 | // --------------------------------------------------------------------------- 24 | 25 | IInterface::IInterface() 26 | : RefBase() { 27 | } 28 | 29 | IInterface::~IInterface() { 30 | } 31 | 32 | // static 33 | sp IInterface::asBinder(const IInterface* iface) 34 | { 35 | if (iface == nullptr) return nullptr; 36 | return const_cast(iface)->onAsBinder(); 37 | } 38 | 39 | // static 40 | sp IInterface::asBinder(const sp& iface) 41 | { 42 | if (iface == nullptr) return nullptr; 43 | return iface->onAsBinder(); 44 | } 45 | 46 | 47 | // --------------------------------------------------------------------------- 48 | 49 | }; // namespace android 50 | -------------------------------------------------------------------------------- /IMediaResourceMonitor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 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 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace android { 23 | 24 | // ---------------------------------------------------------------------- 25 | 26 | class BpMediaResourceMonitor : public BpInterface { 27 | public: 28 | explicit BpMediaResourceMonitor(const sp& impl) 29 | : BpInterface(impl) {} 30 | 31 | virtual void notifyResourceGranted(/*in*/ int32_t pid, /*in*/ const int32_t type) 32 | { 33 | Parcel data, reply; 34 | data.writeInterfaceToken(IMediaResourceMonitor::getInterfaceDescriptor()); 35 | data.writeInt32(pid); 36 | data.writeInt32(type); 37 | remote()->transact(NOTIFY_RESOURCE_GRANTED, data, &reply, IBinder::FLAG_ONEWAY); 38 | } 39 | }; 40 | 41 | IMPLEMENT_META_INTERFACE(MediaResourceMonitor, "android.media.IMediaResourceMonitor"); 42 | 43 | // ---------------------------------------------------------------------- 44 | 45 | status_t BnMediaResourceMonitor::onTransact( uint32_t code, const Parcel& data, Parcel* reply, 46 | uint32_t flags) { 47 | switch(code) { 48 | case NOTIFY_RESOURCE_GRANTED: { 49 | CHECK_INTERFACE(IMediaResourceMonitor, data, reply); 50 | int32_t pid = data.readInt32(); 51 | const int32_t type = data.readInt32(); 52 | notifyResourceGranted(/*in*/ pid, /*in*/ type); 53 | return NO_ERROR; 54 | } break; 55 | default: 56 | return BBinder::onTransact(code, data, reply, flags); 57 | } 58 | } 59 | 60 | // ---------------------------------------------------------------------- 61 | 62 | }; // namespace android 63 | -------------------------------------------------------------------------------- /IProcessInfoService.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 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 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace android { 23 | 24 | // ---------------------------------------------------------------------- 25 | 26 | class BpProcessInfoService : public BpInterface { 27 | public: 28 | explicit BpProcessInfoService(const sp& impl) 29 | : BpInterface(impl) {} 30 | 31 | virtual status_t getProcessStatesFromPids(size_t length, /*in*/ int32_t* pids, 32 | /*out*/ int32_t* states) 33 | { 34 | Parcel data, reply; 35 | data.writeInterfaceToken(IProcessInfoService::getInterfaceDescriptor()); 36 | data.writeInt32Array(length, pids); 37 | data.writeInt32(length); // write length of output array, used by java AIDL stubs 38 | status_t err = remote()->transact(GET_PROCESS_STATES_FROM_PIDS, data, &reply); 39 | if (err != NO_ERROR || ((err = reply.readExceptionCode()) != NO_ERROR)) { 40 | return err; 41 | } 42 | int32_t replyLen = reply.readInt32(); 43 | if (static_cast(replyLen) != length) { 44 | return NOT_ENOUGH_DATA; 45 | } 46 | if (replyLen > 0 && (err = reply.read(states, length * sizeof(*states))) != NO_ERROR) { 47 | return err; 48 | } 49 | return reply.readInt32(); 50 | } 51 | 52 | virtual status_t getProcessStatesAndOomScoresFromPids(size_t length, 53 | /*in*/ int32_t* pids, /*out*/ int32_t* states, /*out*/ int32_t* scores) 54 | { 55 | Parcel data, reply; 56 | data.writeInterfaceToken(IProcessInfoService::getInterfaceDescriptor()); 57 | data.writeInt32Array(length, pids); 58 | // write length of output arrays, used by java AIDL stubs 59 | data.writeInt32(length); 60 | data.writeInt32(length); 61 | status_t err = remote()->transact( 62 | GET_PROCESS_STATES_AND_OOM_SCORES_FROM_PIDS, data, &reply); 63 | if (err != NO_ERROR 64 | || ((err = reply.readExceptionCode()) != NO_ERROR)) { 65 | return err; 66 | } 67 | int32_t replyLen = reply.readInt32(); 68 | if (static_cast(replyLen) != length) { 69 | return NOT_ENOUGH_DATA; 70 | } 71 | if (replyLen > 0 && (err = reply.read( 72 | states, length * sizeof(*states))) != NO_ERROR) { 73 | return err; 74 | } 75 | replyLen = reply.readInt32(); 76 | if (static_cast(replyLen) != length) { 77 | return NOT_ENOUGH_DATA; 78 | } 79 | if (replyLen > 0 && (err = reply.read( 80 | scores, length * sizeof(*scores))) != NO_ERROR) { 81 | return err; 82 | } 83 | return reply.readInt32(); 84 | } 85 | }; 86 | 87 | IMPLEMENT_META_INTERFACE(ProcessInfoService, "android.os.IProcessInfoService"); 88 | 89 | // ---------------------------------------------------------------------- 90 | 91 | }; // namespace android 92 | -------------------------------------------------------------------------------- /IResultReceiver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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_TAG "ResultReceiver" 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | namespace android { 28 | 29 | // ---------------------------------------------------------------------- 30 | 31 | class BpResultReceiver : public BpInterface 32 | { 33 | public: 34 | explicit BpResultReceiver(const sp& impl) 35 | : BpInterface(impl) 36 | { 37 | } 38 | 39 | virtual void send(int32_t resultCode) { 40 | Parcel data; 41 | data.writeInterfaceToken(IResultReceiver::getInterfaceDescriptor()); 42 | data.writeInt32(resultCode); 43 | remote()->transact(OP_SEND, data, nullptr, IBinder::FLAG_ONEWAY); 44 | } 45 | }; 46 | 47 | IMPLEMENT_META_INTERFACE(ResultReceiver, "com.android.internal.os.IResultReceiver"); 48 | 49 | // ---------------------------------------------------------------------- 50 | 51 | // NOLINTNEXTLINE(google-default-arguments) 52 | status_t BnResultReceiver::onTransact( 53 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 54 | { 55 | switch(code) { 56 | case OP_SEND: { 57 | CHECK_INTERFACE(IResultReceiver, data, reply); 58 | int32_t resultCode = data.readInt32(); 59 | send(resultCode); 60 | if (reply != nullptr) { 61 | reply->writeNoException(); 62 | } 63 | return NO_ERROR; 64 | } break; 65 | default: 66 | return BBinder::onTransact(code, data, reply, flags); 67 | } 68 | } 69 | 70 | }; // namespace android 71 | -------------------------------------------------------------------------------- /IShellCallback.cpp: -------------------------------------------------------------------------------- 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_TAG "ShellCallback" 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | namespace android { 31 | 32 | // ---------------------------------------------------------------------- 33 | 34 | class BpShellCallback : public BpInterface 35 | { 36 | public: 37 | explicit BpShellCallback(const sp& impl) 38 | : BpInterface(impl) 39 | { 40 | } 41 | 42 | virtual int openFile(const String16& path, const String16& seLinuxContext, 43 | const String16& mode) { 44 | Parcel data, reply; 45 | data.writeInterfaceToken(IShellCallback::getInterfaceDescriptor()); 46 | data.writeString16(path); 47 | data.writeString16(seLinuxContext); 48 | data.writeString16(mode); 49 | remote()->transact(OP_OPEN_OUTPUT_FILE, data, &reply, 0); 50 | reply.readExceptionCode(); 51 | int fd = reply.readParcelFileDescriptor(); 52 | return fd >= 0 ? fcntl(fd, F_DUPFD_CLOEXEC, 0) : fd; 53 | 54 | } 55 | }; 56 | 57 | IMPLEMENT_META_INTERFACE(ShellCallback, "com.android.internal.os.IShellCallback"); 58 | 59 | // ---------------------------------------------------------------------- 60 | 61 | // NOLINTNEXTLINE(google-default-arguments) 62 | status_t BnShellCallback::onTransact( 63 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 64 | { 65 | switch(code) { 66 | case OP_OPEN_OUTPUT_FILE: { 67 | CHECK_INTERFACE(IShellCallback, data, reply); 68 | String16 path(data.readString16()); 69 | String16 seLinuxContext(data.readString16()); 70 | String16 mode(data.readString16()); 71 | int fd = openFile(path, seLinuxContext, mode); 72 | if (reply != nullptr) { 73 | reply->writeNoException(); 74 | if (fd >= 0) { 75 | reply->writeInt32(1); 76 | reply->writeParcelFileDescriptor(fd, true); 77 | } else { 78 | reply->writeInt32(0); 79 | } 80 | } else if (fd >= 0) { 81 | close(fd); 82 | } 83 | return NO_ERROR; 84 | } break; 85 | default: 86 | return BBinder::onTransact(code, data, reply, flags); 87 | } 88 | } 89 | 90 | }; // namespace android 91 | -------------------------------------------------------------------------------- /IUidObserver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 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 | #include 18 | 19 | #include 20 | 21 | namespace android { 22 | 23 | // ------------------------------------------------------------------------------------ 24 | 25 | class BpUidObserver : public BpInterface 26 | { 27 | public: 28 | explicit BpUidObserver(const sp& impl) 29 | : BpInterface(impl) 30 | { 31 | } 32 | 33 | virtual void onUidGone(uid_t uid, bool disabled) 34 | { 35 | Parcel data, reply; 36 | data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor()); 37 | data.writeInt32((int32_t) uid); 38 | data.writeInt32(disabled ? 1 : 0); 39 | remote()->transact(ON_UID_GONE_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY); 40 | } 41 | 42 | virtual void onUidActive(uid_t uid) 43 | { 44 | Parcel data, reply; 45 | data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor()); 46 | data.writeInt32((int32_t) uid); 47 | remote()->transact(ON_UID_ACTIVE_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY); 48 | } 49 | 50 | virtual void onUidIdle(uid_t uid, bool disabled) 51 | { 52 | Parcel data, reply; 53 | data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor()); 54 | data.writeInt32((int32_t) uid); 55 | data.writeInt32(disabled ? 1 : 0); 56 | remote()->transact(ON_UID_IDLE_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY); 57 | } 58 | 59 | virtual void onUidStateChanged(uid_t uid, int32_t procState, int64_t procStateSeq) 60 | { 61 | Parcel data, reply; 62 | data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor()); 63 | data.writeInt32((int32_t) uid); 64 | data.writeInt32(procState); 65 | data.writeInt64(procStateSeq); 66 | remote()->transact(ON_UID_STATE_CHANGED_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY); 67 | } 68 | }; 69 | 70 | // ---------------------------------------------------------------------- 71 | 72 | IMPLEMENT_META_INTERFACE(UidObserver, "android.app.IUidObserver"); 73 | 74 | // ---------------------------------------------------------------------- 75 | 76 | status_t BnUidObserver::onTransact( 77 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 78 | { 79 | switch(code) { 80 | case ON_UID_GONE_TRANSACTION: { 81 | CHECK_INTERFACE(IUidObserver, data, reply); 82 | uid_t uid = data.readInt32(); 83 | bool disabled = data.readInt32() == 1; 84 | onUidGone(uid, disabled); 85 | return NO_ERROR; 86 | } break; 87 | 88 | case ON_UID_ACTIVE_TRANSACTION: { 89 | CHECK_INTERFACE(IUidObserver, data, reply); 90 | uid_t uid = data.readInt32(); 91 | onUidActive(uid); 92 | return NO_ERROR; 93 | } break; 94 | 95 | case ON_UID_IDLE_TRANSACTION: { 96 | CHECK_INTERFACE(IUidObserver, data, reply); 97 | uid_t uid = data.readInt32(); 98 | bool disabled = data.readInt32() == 1; 99 | onUidIdle(uid, disabled); 100 | return NO_ERROR; 101 | } break; 102 | case ON_UID_STATE_CHANGED_TRANSACTION: { 103 | CHECK_INTERFACE(IUidObserver, data, reply); 104 | uid_t uid = data.readInt32(); 105 | int32_t procState = data.readInt32(); 106 | int64_t procStateSeq = data.readInt64(); 107 | onUidStateChanged(uid, procState, procStateSeq); 108 | return NO_ERROR; 109 | } break; 110 | default: 111 | return BBinder::onTransact(code, data, reply, flags); 112 | } 113 | } 114 | 115 | }; // namespace android 116 | -------------------------------------------------------------------------------- /IpPrefix.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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_TAG "IpPrefix" 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | using android::BAD_TYPE; 28 | using android::BAD_VALUE; 29 | using android::NO_ERROR; 30 | using android::Parcel; 31 | using android::status_t; 32 | using android::UNEXPECTED_NULL; 33 | using namespace ::android::binder; 34 | 35 | namespace android { 36 | 37 | namespace net { 38 | 39 | #define RETURN_IF_FAILED(calledOnce) \ 40 | { \ 41 | status_t returnStatus = calledOnce; \ 42 | if (returnStatus) { \ 43 | ALOGE("Failed at %s:%d (%s)", __FILE__, __LINE__, __func__); \ 44 | return returnStatus; \ 45 | } \ 46 | } 47 | 48 | status_t IpPrefix::writeToParcel(Parcel* parcel) const { 49 | /* 50 | * Keep implementation in sync with writeToParcel() in 51 | * frameworks/base/core/java/android/net/IpPrefix.java. 52 | */ 53 | std::vector byte_vector; 54 | 55 | if (mIsIpv6) { 56 | const uint8_t* bytes = reinterpret_cast(&mUnion.mIn6Addr); 57 | byte_vector.insert(byte_vector.end(), bytes, bytes+sizeof(mUnion.mIn6Addr)); 58 | } else { 59 | const uint8_t* bytes = reinterpret_cast(&mUnion.mInAddr); 60 | byte_vector.insert(byte_vector.end(), bytes, bytes+sizeof(mUnion.mIn6Addr)); 61 | } 62 | 63 | RETURN_IF_FAILED(parcel->writeByteVector(byte_vector)); 64 | RETURN_IF_FAILED(parcel->writeInt32(static_cast(mPrefixLength))); 65 | 66 | return NO_ERROR; 67 | } 68 | 69 | status_t IpPrefix::readFromParcel(const Parcel* parcel) { 70 | /* 71 | * Keep implementation in sync with readFromParcel() in 72 | * frameworks/base/core/java/android/net/IpPrefix.java. 73 | */ 74 | std::vector byte_vector; 75 | 76 | RETURN_IF_FAILED(parcel->readByteVector(&byte_vector)); 77 | RETURN_IF_FAILED(parcel->readInt32(&mPrefixLength)); 78 | 79 | if (byte_vector.size() == 16) { 80 | mIsIpv6 = true; 81 | memcpy((void*)&mUnion.mIn6Addr, &byte_vector[0], sizeof(mUnion.mIn6Addr)); 82 | 83 | } else if (byte_vector.size() == 4) { 84 | mIsIpv6 = false; 85 | memcpy((void*)&mUnion.mInAddr, &byte_vector[0], sizeof(mUnion.mInAddr)); 86 | 87 | } else { 88 | ALOGE("Failed at %s:%d (%s)", __FILE__, __LINE__, __func__); \ 89 | return BAD_VALUE; 90 | } 91 | 92 | return NO_ERROR; 93 | } 94 | 95 | const struct in6_addr& IpPrefix::getAddressAsIn6Addr() const 96 | { 97 | return mUnion.mIn6Addr; 98 | } 99 | 100 | const struct in_addr& IpPrefix::getAddressAsInAddr() const 101 | { 102 | return mUnion.mInAddr; 103 | } 104 | 105 | bool IpPrefix::getAddressAsIn6Addr(struct in6_addr* addr) const 106 | { 107 | if (isIpv6()) { 108 | *addr = mUnion.mIn6Addr; 109 | return true; 110 | } 111 | return false; 112 | } 113 | 114 | bool IpPrefix::getAddressAsInAddr(struct in_addr* addr) const 115 | { 116 | if (isIpv4()) { 117 | *addr = mUnion.mInAddr; 118 | return true; 119 | } 120 | return false; 121 | } 122 | 123 | bool IpPrefix::isIpv6() const 124 | { 125 | return mIsIpv6; 126 | } 127 | 128 | bool IpPrefix::isIpv4() const 129 | { 130 | return !mIsIpv6; 131 | } 132 | 133 | int32_t IpPrefix::getPrefixLength() const 134 | { 135 | return mPrefixLength; 136 | } 137 | 138 | void IpPrefix::setAddress(const struct in6_addr& addr) 139 | { 140 | mUnion.mIn6Addr = addr; 141 | mIsIpv6 = true; 142 | } 143 | 144 | void IpPrefix::setAddress(const struct in_addr& addr) 145 | { 146 | mUnion.mInAddr = addr; 147 | mIsIpv6 = false; 148 | } 149 | 150 | void IpPrefix::setPrefixLength(int32_t prefix) 151 | { 152 | mPrefixLength = prefix; 153 | } 154 | 155 | bool operator==(const IpPrefix& lhs, const IpPrefix& rhs) 156 | { 157 | if (lhs.mIsIpv6 != rhs.mIsIpv6) { 158 | return false; 159 | } 160 | 161 | if (lhs.mPrefixLength != rhs.mPrefixLength) { 162 | return false; 163 | } 164 | 165 | if (lhs.mIsIpv6) { 166 | return 0 == memcmp(lhs.mUnion.mIn6Addr.s6_addr, rhs.mUnion.mIn6Addr.s6_addr, sizeof(struct in6_addr)); 167 | } 168 | 169 | return 0 == memcmp(&lhs.mUnion.mInAddr, &rhs.mUnion.mInAddr, sizeof(struct in_addr)); 170 | } 171 | 172 | } // namespace net 173 | 174 | } // namespace android 175 | -------------------------------------------------------------------------------- /MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/D-os/libbinder/754058efb7799a0a00b5908e051bbb4773a3f00d/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /MemoryBase.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | 24 | namespace android { 25 | 26 | // --------------------------------------------------------------------------- 27 | 28 | MemoryBase::MemoryBase(const sp& heap, 29 | ssize_t offset, size_t size) 30 | : mSize(size), mOffset(offset), mHeap(heap) 31 | { 32 | } 33 | 34 | sp MemoryBase::getMemory(ssize_t* offset, size_t* size) const 35 | { 36 | if (offset) *offset = mOffset; 37 | if (size) *size = mSize; 38 | return mHeap; 39 | } 40 | 41 | MemoryBase::~MemoryBase() 42 | { 43 | } 44 | 45 | // --------------------------------------------------------------------------- 46 | }; // namespace android 47 | -------------------------------------------------------------------------------- /MemoryHeapBase.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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_TAG "MemoryHeapBase" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | //#include 31 | #include 32 | #include 33 | 34 | namespace android { 35 | 36 | // --------------------------------------------------------------------------- 37 | 38 | MemoryHeapBase::MemoryHeapBase() 39 | : mFD(-1), mSize(0), mBase(MAP_FAILED), 40 | mDevice(nullptr), mNeedUnmap(false), mOffset(0) 41 | { 42 | } 43 | 44 | MemoryHeapBase::MemoryHeapBase(size_t size, uint32_t flags, char const * name) 45 | : mFD(-1), mSize(0), mBase(MAP_FAILED), mFlags(flags), 46 | mDevice(nullptr), mNeedUnmap(false), mOffset(0) 47 | { 48 | const size_t pagesize = getpagesize(); 49 | size = ((size + pagesize-1) & ~(pagesize-1)); 50 | int fd = -1;STUB;//ashmem_create_region(name == nullptr ? "MemoryHeapBase" : name, size); 51 | ALOGE_IF(fd<0, "error creating ashmem region: %s", strerror(errno)); 52 | if (fd >= 0) { 53 | if (mapfd(fd, size) == NO_ERROR) { 54 | if (flags & READ_ONLY) { 55 | STUB;//ashmem_set_prot_region(fd, PROT_READ); 56 | } 57 | } 58 | } 59 | } 60 | 61 | MemoryHeapBase::MemoryHeapBase(const char* device, size_t size, uint32_t flags) 62 | : mFD(-1), mSize(0), mBase(MAP_FAILED), mFlags(flags), 63 | mDevice(nullptr), mNeedUnmap(false), mOffset(0) 64 | { 65 | int open_flags = O_RDWR; 66 | if (flags & NO_CACHING) 67 | open_flags |= O_SYNC; 68 | 69 | int fd = open(device, open_flags); 70 | ALOGE_IF(fd<0, "error opening %s: %s", device, strerror(errno)); 71 | if (fd >= 0) { 72 | const size_t pagesize = getpagesize(); 73 | size = ((size + pagesize-1) & ~(pagesize-1)); 74 | if (mapfd(fd, size) == NO_ERROR) { 75 | mDevice = device; 76 | } 77 | } 78 | } 79 | 80 | MemoryHeapBase::MemoryHeapBase(int fd, size_t size, uint32_t flags, off_t offset) 81 | : mFD(-1), mSize(0), mBase(MAP_FAILED), mFlags(flags), 82 | mDevice(nullptr), mNeedUnmap(false), mOffset(0) 83 | { 84 | const size_t pagesize = getpagesize(); 85 | size = ((size + pagesize-1) & ~(pagesize-1)); 86 | mapfd(fcntl(fd, F_DUPFD_CLOEXEC, 0), size, offset); 87 | } 88 | 89 | status_t MemoryHeapBase::init(int fd, void *base, size_t size, int flags, const char* device) 90 | { 91 | if (mFD != -1) { 92 | return INVALID_OPERATION; 93 | } 94 | mFD = fd; 95 | mBase = base; 96 | mSize = size; 97 | mFlags = flags; 98 | mDevice = device; 99 | return NO_ERROR; 100 | } 101 | 102 | status_t MemoryHeapBase::mapfd(int fd, size_t size, off_t offset) 103 | { 104 | if (size == 0) { 105 | // try to figure out the size automatically 106 | struct stat sb; 107 | if (fstat(fd, &sb) == 0) { 108 | size = (size_t)sb.st_size; 109 | // sb.st_size is off_t which on ILP32 may be 64 bits while size_t is 32 bits. 110 | if ((off_t)size != sb.st_size) { 111 | ALOGE("%s: size of file %lld cannot fit in memory", 112 | __func__, (long long)sb.st_size); 113 | return INVALID_OPERATION; 114 | } 115 | } 116 | // if it didn't work, let mmap() fail. 117 | } 118 | 119 | if ((mFlags & DONT_MAP_LOCALLY) == 0) { 120 | void* base = (uint8_t*)mmap(nullptr, size, 121 | PROT_READ|PROT_WRITE, MAP_SHARED, fd, offset); 122 | if (base == MAP_FAILED) { 123 | ALOGE("mmap(fd=%d, size=%zu) failed (%s)", 124 | fd, size, strerror(errno)); 125 | close(fd); 126 | return -errno; 127 | } 128 | //ALOGD("mmap(fd=%d, base=%p, size=%zu)", fd, base, size); 129 | mBase = base; 130 | mNeedUnmap = true; 131 | } else { 132 | mBase = nullptr; // not MAP_FAILED 133 | mNeedUnmap = false; 134 | } 135 | mFD = fd; 136 | mSize = size; 137 | mOffset = offset; 138 | return NO_ERROR; 139 | } 140 | 141 | MemoryHeapBase::~MemoryHeapBase() 142 | { 143 | dispose(); 144 | } 145 | 146 | void MemoryHeapBase::dispose() 147 | { 148 | int fd = android_atomic_or(-1, &mFD); 149 | if (fd >= 0) { 150 | if (mNeedUnmap) { 151 | //ALOGD("munmap(fd=%d, base=%p, size=%zu)", fd, mBase, mSize); 152 | munmap(mBase, mSize); 153 | } 154 | mBase = nullptr; 155 | mSize = 0; 156 | close(fd); 157 | } 158 | } 159 | 160 | int MemoryHeapBase::getHeapID() const { 161 | return mFD; 162 | } 163 | 164 | void* MemoryHeapBase::getBase() const { 165 | return mBase; 166 | } 167 | 168 | size_t MemoryHeapBase::getSize() const { 169 | return mSize; 170 | } 171 | 172 | uint32_t MemoryHeapBase::getFlags() const { 173 | return mFlags; 174 | } 175 | 176 | const char* MemoryHeapBase::getDevice() const { 177 | return mDevice; 178 | } 179 | 180 | off_t MemoryHeapBase::getOffset() const { 181 | return mOffset; 182 | } 183 | 184 | // --------------------------------------------------------------------------- 185 | }; // namespace android 186 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | arve@google.com 2 | ctate@google.com 3 | hackbod@google.com 4 | maco@google.com 5 | smoreland@google.com 6 | -------------------------------------------------------------------------------- /ParcelFileDescriptor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | #include 18 | 19 | namespace android { 20 | namespace os { 21 | 22 | ParcelFileDescriptor::ParcelFileDescriptor() = default; 23 | 24 | ParcelFileDescriptor::ParcelFileDescriptor(android::base::unique_fd fd) : mFd(std::move(fd)) {} 25 | 26 | ParcelFileDescriptor::~ParcelFileDescriptor() = default; 27 | 28 | status_t ParcelFileDescriptor::writeToParcel(Parcel* parcel) const { 29 | return parcel->writeDupParcelFileDescriptor(mFd.get()); 30 | } 31 | 32 | status_t ParcelFileDescriptor::readFromParcel(const Parcel* parcel) { 33 | return parcel->readUniqueParcelFileDescriptor(&mFd); 34 | } 35 | 36 | } // namespace os 37 | } // namespace android 38 | -------------------------------------------------------------------------------- /PermissionCache.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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_TAG "PermissionCache" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace android { 27 | 28 | // ---------------------------------------------------------------------------- 29 | 30 | ANDROID_SINGLETON_STATIC_INSTANCE(PermissionCache) ; 31 | 32 | // ---------------------------------------------------------------------------- 33 | 34 | PermissionCache::PermissionCache() { 35 | } 36 | 37 | status_t PermissionCache::check(bool* granted, 38 | const String16& permission, uid_t uid) const { 39 | Mutex::Autolock _l(mLock); 40 | Entry e; 41 | e.name = permission; 42 | e.uid = uid; 43 | ssize_t index = mCache.indexOf(e); 44 | if (index >= 0) { 45 | *granted = mCache.itemAt(index).granted; 46 | return NO_ERROR; 47 | } 48 | return NAME_NOT_FOUND; 49 | } 50 | 51 | void PermissionCache::cache(const String16& permission, 52 | uid_t uid, bool granted) { 53 | Mutex::Autolock _l(mLock); 54 | Entry e; 55 | ssize_t index = mPermissionNamesPool.indexOf(permission); 56 | if (index > 0) { 57 | e.name = mPermissionNamesPool.itemAt(index); 58 | } else { 59 | mPermissionNamesPool.add(permission); 60 | e.name = permission; 61 | } 62 | // note, we don't need to store the pid, which is not actually used in 63 | // permission checks 64 | e.uid = uid; 65 | e.granted = granted; 66 | index = mCache.indexOf(e); 67 | if (index < 0) { 68 | mCache.add(e); 69 | } 70 | } 71 | 72 | void PermissionCache::purge() { 73 | Mutex::Autolock _l(mLock); 74 | mCache.clear(); 75 | } 76 | 77 | bool PermissionCache::checkCallingPermission(const String16& permission) { 78 | return PermissionCache::checkCallingPermission(permission, nullptr, nullptr); 79 | } 80 | 81 | bool PermissionCache::checkCallingPermission( 82 | const String16& permission, int32_t* outPid, int32_t* outUid) { 83 | IPCThreadState* ipcState = IPCThreadState::self(); 84 | pid_t pid = ipcState->getCallingPid(); 85 | uid_t uid = ipcState->getCallingUid(); 86 | if (outPid) *outPid = pid; 87 | if (outUid) *outUid = uid; 88 | return PermissionCache::checkPermission(permission, pid, uid); 89 | } 90 | 91 | bool PermissionCache::checkPermission( 92 | const String16& permission, pid_t pid, uid_t uid) { 93 | if ((uid == 0) || (pid == getpid())) { 94 | // root and ourselves is always okay 95 | return true; 96 | } 97 | 98 | PermissionCache& pc(PermissionCache::getInstance()); 99 | bool granted = false; 100 | if (pc.check(&granted, permission, uid) != NO_ERROR) { 101 | nsecs_t t = -systemTime(); 102 | granted = android::checkPermission(permission, pid, uid); 103 | t += systemTime(); 104 | ALOGD("checking %s for uid=%d => %s (%d us)", 105 | String8(permission).string(), uid, 106 | granted?"granted":"denied", (int)ns2us(t)); 107 | pc.cache(permission, uid, granted); 108 | } 109 | return granted; 110 | } 111 | 112 | // --------------------------------------------------------------------------- 113 | }; // namespace android 114 | -------------------------------------------------------------------------------- /PermissionController.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace android { 25 | 26 | PermissionController::PermissionController() 27 | { 28 | } 29 | 30 | sp PermissionController::getService() 31 | { 32 | std::lock_guard scoped_lock(mLock); 33 | int64_t startTime = 0; 34 | sp service = mService; 35 | while (service == nullptr || !IInterface::asBinder(service)->isBinderAlive()) { 36 | sp binder = defaultServiceManager()->checkService(String16("permission")); 37 | if (binder == nullptr) { 38 | // Wait for the activity service to come back... 39 | if (startTime == 0) { 40 | startTime = uptimeMillis(); 41 | ALOGI("Waiting for permission service"); 42 | } else if ((uptimeMillis() - startTime) > 10000) { 43 | ALOGW("Waiting too long for permission service, giving up"); 44 | service = nullptr; 45 | break; 46 | } 47 | sleep(1); 48 | } else { 49 | service = interface_cast(binder); 50 | mService = service; 51 | } 52 | } 53 | return service; 54 | } 55 | 56 | bool PermissionController::checkPermission(const String16& permission, int32_t pid, int32_t uid) 57 | { 58 | sp service = getService(); 59 | return service != nullptr ? service->checkPermission(permission, pid, uid) : false; 60 | } 61 | 62 | int32_t PermissionController::noteOp(const String16& op, int32_t uid, const String16& packageName) 63 | { 64 | sp service = getService(); 65 | return service != nullptr ? service->noteOp(op, uid, packageName) : MODE_ERRORED; 66 | } 67 | 68 | void PermissionController::getPackagesForUid(const uid_t uid, Vector &packages) 69 | { 70 | sp service = getService(); 71 | if (service != nullptr) { 72 | service->getPackagesForUid(uid, packages); 73 | } 74 | } 75 | 76 | bool PermissionController::isRuntimePermission(const String16& permission) 77 | { 78 | sp service = getService(); 79 | return service != nullptr ? service->isRuntimePermission(permission) : false; 80 | } 81 | 82 | int PermissionController::getPackageUid(const String16& package, int flags) 83 | { 84 | sp service = getService(); 85 | return service != nullptr ? service->getPackageUid(package, flags) : -1; 86 | } 87 | 88 | }; // namespace android 89 | -------------------------------------------------------------------------------- /ProcessInfoService.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 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 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | namespace android { 24 | 25 | ProcessInfoService::ProcessInfoService() { 26 | updateBinderLocked(); 27 | } 28 | 29 | status_t ProcessInfoService::getProcessStatesImpl(size_t length, /*in*/ int32_t* pids, 30 | /*out*/ int32_t* states) { 31 | status_t err = NO_ERROR; 32 | sp pis; 33 | mProcessInfoLock.lock(); 34 | pis = mProcessInfoService; 35 | mProcessInfoLock.unlock(); 36 | 37 | for (int i = 0; i < BINDER_ATTEMPT_LIMIT; i++) { 38 | 39 | if (pis != nullptr) { 40 | err = pis->getProcessStatesFromPids(length, /*in*/ pids, /*out*/ states); 41 | if (err == NO_ERROR) return NO_ERROR; // success 42 | if (IInterface::asBinder(pis)->isBinderAlive()) return err; 43 | } 44 | sleep(1); 45 | 46 | mProcessInfoLock.lock(); 47 | if (pis == mProcessInfoService) { 48 | updateBinderLocked(); 49 | } 50 | pis = mProcessInfoService; 51 | mProcessInfoLock.unlock(); 52 | } 53 | 54 | ALOGW("%s: Could not retrieve process states from ProcessInfoService after %d retries.", 55 | __FUNCTION__, BINDER_ATTEMPT_LIMIT); 56 | 57 | return TIMED_OUT; 58 | } 59 | 60 | status_t ProcessInfoService::getProcessStatesScoresImpl(size_t length, 61 | /*in*/ int32_t* pids, /*out*/ int32_t* states, 62 | /*out*/ int32_t *scores) { 63 | status_t err = NO_ERROR; 64 | sp pis; 65 | mProcessInfoLock.lock(); 66 | pis = mProcessInfoService; 67 | mProcessInfoLock.unlock(); 68 | 69 | for (int i = 0; i < BINDER_ATTEMPT_LIMIT; i++) { 70 | 71 | if (pis != nullptr) { 72 | err = pis->getProcessStatesAndOomScoresFromPids(length, 73 | /*in*/ pids, /*out*/ states, /*out*/ scores); 74 | if (err == NO_ERROR) return NO_ERROR; // success 75 | if (IInterface::asBinder(pis)->isBinderAlive()) return err; 76 | } 77 | sleep(1); 78 | 79 | mProcessInfoLock.lock(); 80 | if (pis == mProcessInfoService) { 81 | updateBinderLocked(); 82 | } 83 | pis = mProcessInfoService; 84 | mProcessInfoLock.unlock(); 85 | } 86 | 87 | ALOGW("%s: Could not retrieve process states and scores " 88 | "from ProcessInfoService after %d retries.", __FUNCTION__, 89 | BINDER_ATTEMPT_LIMIT); 90 | 91 | return TIMED_OUT; 92 | } 93 | 94 | void ProcessInfoService::updateBinderLocked() { 95 | const sp sm(defaultServiceManager()); 96 | if (sm != nullptr) { 97 | const String16 name("processinfo"); 98 | mProcessInfoService = interface_cast(sm->checkService(name)); 99 | } 100 | } 101 | 102 | ANDROID_SINGLETON_STATIC_INSTANCE(ProcessInfoService); 103 | 104 | }; // namespace android 105 | -------------------------------------------------------------------------------- /Static.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | // All static variables go here, to control initialization and 18 | // destruction order in the library. 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace android { 27 | 28 | // ------------ Text output streams 29 | 30 | Vector gTextBuffers; 31 | 32 | class LogTextOutput : public BufferedTextOutput 33 | { 34 | public: 35 | LogTextOutput() : BufferedTextOutput(MULTITHREADED) { } 36 | virtual ~LogTextOutput() { }; 37 | 38 | protected: 39 | virtual status_t writeLines(const struct iovec& vec, size_t N) 40 | { 41 | //android_writevLog(&vec, N); <-- this is now a no-op 42 | if (N != 1) ALOGI("WARNING: writeLines N=%zu\n", N); 43 | ALOGI("%.*s", (int)vec.iov_len, (const char*) vec.iov_base); 44 | return NO_ERROR; 45 | } 46 | }; 47 | 48 | class FdTextOutput : public BufferedTextOutput 49 | { 50 | public: 51 | explicit FdTextOutput(int fd) : BufferedTextOutput(MULTITHREADED), mFD(fd) { } 52 | virtual ~FdTextOutput() { }; 53 | 54 | protected: 55 | virtual status_t writeLines(const struct iovec& vec, size_t N) 56 | { 57 | writev(mFD, &vec, N); 58 | return NO_ERROR; 59 | } 60 | 61 | private: 62 | int mFD; 63 | }; 64 | 65 | static LogTextOutput gLogTextOutput; 66 | static FdTextOutput gStdoutTextOutput(STDOUT_FILENO); 67 | static FdTextOutput gStderrTextOutput(STDERR_FILENO); 68 | 69 | TextOutput& alog(gLogTextOutput); 70 | TextOutput& aout(gStdoutTextOutput); 71 | TextOutput& aerr(gStderrTextOutput); 72 | 73 | // ------------ ProcessState.cpp 74 | 75 | Mutex& gProcessMutex = *new Mutex; 76 | sp gProcess; 77 | 78 | // ------------ IServiceManager.cpp 79 | 80 | Mutex gDefaultServiceManagerLock; 81 | sp gDefaultServiceManager; 82 | #ifndef __ANDROID_VNDK__ 83 | sp gPermissionController; 84 | #endif 85 | bool gSystemBootCompleted = false; 86 | 87 | } // namespace android 88 | -------------------------------------------------------------------------------- /TextOutput.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 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 | #include 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace android { 29 | 30 | // --------------------------------------------------------------------------- 31 | 32 | TextOutput::TextOutput() { 33 | } 34 | 35 | TextOutput::~TextOutput() { 36 | } 37 | 38 | // --------------------------------------------------------------------------- 39 | 40 | static void textOutputPrinter(void* cookie, const char* txt) 41 | { 42 | ((TextOutput*)cookie)->print(txt, strlen(txt)); 43 | } 44 | 45 | TextOutput& operator<<(TextOutput& to, const TypeCode& val) 46 | { 47 | printTypeCode(val.typeCode(), textOutputPrinter, (void*)&to); 48 | return to; 49 | } 50 | 51 | HexDump::HexDump(const void *buf, size_t size, size_t bytesPerLine) 52 | : mBuffer(buf) 53 | , mSize(size) 54 | , mBytesPerLine(bytesPerLine) 55 | , mSingleLineCutoff(16) 56 | , mAlignment(4) 57 | , mCArrayStyle(false) 58 | { 59 | if (bytesPerLine >= 16) mAlignment = 4; 60 | else if (bytesPerLine >= 8) mAlignment = 2; 61 | else mAlignment = 1; 62 | } 63 | 64 | TextOutput& operator<<(TextOutput& to, const HexDump& val) 65 | { 66 | printHexData(0, val.buffer(), val.size(), val.bytesPerLine(), 67 | val.singleLineCutoff(), val.alignment(), val.carrayStyle(), 68 | textOutputPrinter, (void*)&to); 69 | return to; 70 | } 71 | 72 | }; // namespace android 73 | -------------------------------------------------------------------------------- /aidl/android/content/pm/IPackageManagerNative.aidl: -------------------------------------------------------------------------------- 1 | /* 2 | ** 3 | ** Copyright 2017, The Android Open Source Project 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | package android.content.pm; 19 | 20 | /** 21 | * Parallel implementation of certain {@link PackageManager} APIs that need to 22 | * be exposed to native code. 23 | *

These APIs are a parallel definition to the APIs in PackageManager, so, 24 | * they can technically diverge. However, it's good practice to keep these 25 | * APIs in sync with each other. 26 | *

Because these APIs are exposed to native code, it's possible they will 27 | * be exposed to privileged components [such as UID 0]. Care should be taken 28 | * to avoid exposing potential security holes for methods where permission 29 | * checks are bypassed based upon UID alone. 30 | * 31 | * @hide 32 | */ 33 | interface IPackageManagerNative { 34 | /** 35 | * Returns a set of names for the given UIDs. 36 | * IMPORTANT: Unlike the Java version of this API, unknown UIDs are 37 | * not represented by 'null's. Instead, they are represented by empty 38 | * strings. 39 | */ 40 | @utf8InCpp String[] getNamesForUids(in int[] uids); 41 | 42 | /** 43 | * Returns the name of the installer (a package) which installed the named 44 | * package. Preloaded packages return the string "preload". Sideloaded packages 45 | * return an empty string. Unknown or unknowable are returned as empty strings. 46 | */ 47 | 48 | @utf8InCpp String getInstallerForPackage(in String packageName); 49 | 50 | /** 51 | * Returns the version code of the named package. 52 | * Unknown or unknowable versions are returned as 0. 53 | */ 54 | 55 | long getVersionCodeForPackage(in String packageName); 56 | 57 | /** 58 | * Return if each app, identified by its package name allows its audio to be recorded. 59 | * Unknown packages are mapped to false. 60 | */ 61 | boolean[] isAudioPlaybackCaptureAllowed(in @utf8InCpp String[] packageNames); 62 | 63 | /* ApplicationInfo.isSystemApp() == true */ 64 | const int LOCATION_SYSTEM = 0x1; 65 | /* ApplicationInfo.isVendor() == true */ 66 | const int LOCATION_VENDOR = 0x2; 67 | /* ApplicationInfo.isProduct() == true */ 68 | const int LOCATION_PRODUCT = 0x4; 69 | 70 | /** 71 | * Returns a set of bitflags about package location. 72 | * LOCATION_SYSTEM: getApplicationInfo(packageName).isSystemApp() 73 | * LOCATION_VENDOR: getApplicationInfo(packageName).isVendor() 74 | * LOCATION_PRODUCT: getApplicationInfo(packageName).isProduct() 75 | */ 76 | int getLocationFlags(in @utf8InCpp String packageName); 77 | 78 | /** 79 | * Returns the target SDK version for the given package. 80 | * Unknown packages will cause the call to fail. The caller must check the 81 | * returned Status before using the result of this function. 82 | */ 83 | int getTargetSdkVersionForPackage(in String packageName); 84 | 85 | /** 86 | * Returns the name of module metadata package, or empty string if device doesn't have such 87 | * package. 88 | */ 89 | @utf8InCpp String getModuleMetadataPackageName(); 90 | } 91 | -------------------------------------------------------------------------------- /aidl/android/content/pm/OWNERS: -------------------------------------------------------------------------------- 1 | narayan@google.com 2 | patb@google.com 3 | svetoslavganov@google.com 4 | toddke@google.com -------------------------------------------------------------------------------- /include/binder/ActivityManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 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 | #ifndef ANDROID_ACTIVITY_MANAGER_H 18 | #define ANDROID_ACTIVITY_MANAGER_H 19 | 20 | #ifndef __ANDROID_VNDK__ 21 | 22 | #include 23 | 24 | #include 25 | 26 | // --------------------------------------------------------------------------- 27 | namespace android { 28 | 29 | class ActivityManager 30 | { 31 | public: 32 | 33 | enum { 34 | // Flag for registerUidObserver: report uid state changed 35 | UID_OBSERVER_PROCSTATE = 1<<0, 36 | // Flag for registerUidObserver: report uid gone 37 | UID_OBSERVER_GONE = 1<<1, 38 | // Flag for registerUidObserver: report uid has become idle 39 | UID_OBSERVER_IDLE = 1<<2, 40 | // Flag for registerUidObserver: report uid has become active 41 | UID_OBSERVER_ACTIVE = 1<<3 42 | }; 43 | 44 | enum { 45 | PROCESS_STATE_UNKNOWN = -1, 46 | PROCESS_STATE_PERSISTENT = 0, 47 | PROCESS_STATE_PERSISTENT_UI = 1, 48 | PROCESS_STATE_TOP = 2, 49 | PROCESS_STATE_FOREGROUND_SERVICE_LOCATION = 3, 50 | PROCESS_STATE_BOUND_TOP = 4, 51 | PROCESS_STATE_FOREGROUND_SERVICE = 5, 52 | PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 6, 53 | PROCESS_STATE_IMPORTANT_FOREGROUND = 7, 54 | PROCESS_STATE_IMPORTANT_BACKGROUND = 8, 55 | PROCESS_STATE_TRANSIENT_BACKGROUND = 9, 56 | PROCESS_STATE_BACKUP = 10, 57 | PROCESS_STATE_SERVICE = 11, 58 | PROCESS_STATE_RECEIVER = 12, 59 | PROCESS_STATE_TOP_SLEEPING = 13, 60 | PROCESS_STATE_HEAVY_WEIGHT = 14, 61 | PROCESS_STATE_HOME = 15, 62 | PROCESS_STATE_LAST_ACTIVITY = 16, 63 | PROCESS_STATE_CACHED_ACTIVITY = 17, 64 | PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 18, 65 | PROCESS_STATE_CACHED_RECENT = 19, 66 | PROCESS_STATE_CACHED_EMPTY = 20, 67 | PROCESS_STATE_NONEXISTENT = 21, 68 | }; 69 | 70 | ActivityManager(); 71 | 72 | int openContentUri(const String16& stringUri); 73 | void registerUidObserver(const sp& observer, 74 | const int32_t event, 75 | const int32_t cutpoint, 76 | const String16& callingPackage); 77 | void unregisterUidObserver(const sp& observer); 78 | bool isUidActive(const uid_t uid, const String16& callingPackage); 79 | int getUidProcessState(const uid_t uid, const String16& callingPackage); 80 | 81 | 82 | status_t linkToDeath(const sp& recipient); 83 | status_t unlinkToDeath(const sp& recipient); 84 | 85 | private: 86 | Mutex mLock; 87 | sp mService; 88 | sp getService(); 89 | }; 90 | 91 | 92 | }; // namespace android 93 | // --------------------------------------------------------------------------- 94 | #else // __ANDROID_VNDK__ 95 | #error "This header is not visible to vendors" 96 | #endif // __ANDROID_VNDK__ 97 | 98 | #endif // ANDROID_ACTIVITY_MANAGER_H 99 | -------------------------------------------------------------------------------- /include/binder/AppOpsManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 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 | #ifndef ANDROID_APP_OPS_MANAGER_H 18 | #define ANDROID_APP_OPS_MANAGER_H 19 | 20 | #ifndef __ANDROID_VNDK__ 21 | 22 | #include 23 | 24 | #include 25 | 26 | // --------------------------------------------------------------------------- 27 | namespace android { 28 | 29 | class AppOpsManager 30 | { 31 | public: 32 | enum { 33 | MODE_ALLOWED = IAppOpsService::MODE_ALLOWED, 34 | MODE_IGNORED = IAppOpsService::MODE_IGNORED, 35 | MODE_ERRORED = IAppOpsService::MODE_ERRORED 36 | }; 37 | 38 | enum { 39 | OP_NONE = -1, 40 | OP_COARSE_LOCATION = 0, 41 | OP_FINE_LOCATION = 1, 42 | OP_GPS = 2, 43 | OP_VIBRATE = 3, 44 | OP_READ_CONTACTS = 4, 45 | OP_WRITE_CONTACTS = 5, 46 | OP_READ_CALL_LOG = 6, 47 | OP_WRITE_CALL_LOG = 7, 48 | OP_READ_CALENDAR = 8, 49 | OP_WRITE_CALENDAR = 9, 50 | OP_WIFI_SCAN = 10, 51 | OP_POST_NOTIFICATION = 11, 52 | OP_NEIGHBORING_CELLS = 12, 53 | OP_CALL_PHONE = 13, 54 | OP_READ_SMS = 14, 55 | OP_WRITE_SMS = 15, 56 | OP_RECEIVE_SMS = 16, 57 | OP_RECEIVE_EMERGECY_SMS = 17, 58 | OP_RECEIVE_MMS = 18, 59 | OP_RECEIVE_WAP_PUSH = 19, 60 | OP_SEND_SMS = 20, 61 | OP_READ_ICC_SMS = 21, 62 | OP_WRITE_ICC_SMS = 22, 63 | OP_WRITE_SETTINGS = 23, 64 | OP_SYSTEM_ALERT_WINDOW = 24, 65 | OP_ACCESS_NOTIFICATIONS = 25, 66 | OP_CAMERA = 26, 67 | OP_RECORD_AUDIO = 27, 68 | OP_PLAY_AUDIO = 28, 69 | OP_READ_CLIPBOARD = 29, 70 | OP_WRITE_CLIPBOARD = 30, 71 | OP_TAKE_MEDIA_BUTTONS = 31, 72 | OP_TAKE_AUDIO_FOCUS = 32, 73 | OP_AUDIO_MASTER_VOLUME = 33, 74 | OP_AUDIO_VOICE_VOLUME = 34, 75 | OP_AUDIO_RING_VOLUME = 35, 76 | OP_AUDIO_MEDIA_VOLUME = 36, 77 | OP_AUDIO_ALARM_VOLUME = 37, 78 | OP_AUDIO_NOTIFICATION_VOLUME = 38, 79 | OP_AUDIO_BLUETOOTH_VOLUME = 39, 80 | OP_WAKE_LOCK = 40, 81 | OP_MONITOR_LOCATION = 41, 82 | OP_MONITOR_HIGH_POWER_LOCATION = 42, 83 | OP_GET_USAGE_STATS = 43, 84 | OP_MUTE_MICROPHONE = 44, 85 | OP_TOAST_WINDOW = 45, 86 | OP_PROJECT_MEDIA = 46, 87 | OP_ACTIVATE_VPN = 47, 88 | OP_WRITE_WALLPAPER = 48, 89 | OP_ASSIST_STRUCTURE = 49, 90 | OP_ASSIST_SCREENSHOT = 50, 91 | OP_READ_PHONE_STATE = 51, 92 | OP_ADD_VOICEMAIL = 52, 93 | OP_USE_SIP = 53, 94 | OP_PROCESS_OUTGOING_CALLS = 54, 95 | OP_USE_FINGERPRINT = 55, 96 | OP_BODY_SENSORS = 56, 97 | OP_AUDIO_ACCESSIBILITY_VOLUME = 64, 98 | OP_READ_PHONE_NUMBERS = 65, 99 | OP_REQUEST_INSTALL_PACKAGES = 66, 100 | OP_PICTURE_IN_PICTURE = 67, 101 | OP_INSTANT_APP_START_FOREGROUND = 68, 102 | OP_ANSWER_PHONE_CALLS = 69, 103 | OP_RUN_ANY_IN_BACKGROUND = 70, 104 | OP_CHANGE_WIFI_STATE = 71, 105 | OP_REQUEST_DELETE_PACKAGES = 72, 106 | OP_BIND_ACCESSIBILITY_SERVICE = 73, 107 | OP_ACCEPT_HANDOVER = 74, 108 | OP_MANAGE_IPSEC_TUNNELS = 75, 109 | OP_START_FOREGROUND = 76, 110 | OP_BLUETOOTH_SCAN = 77, 111 | OP_USE_BIOMETRIC = 78, 112 | }; 113 | 114 | AppOpsManager(); 115 | 116 | int32_t checkOp(int32_t op, int32_t uid, const String16& callingPackage); 117 | int32_t checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t uid, 118 | const String16& callingPackage); 119 | int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage); 120 | int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, 121 | bool startIfModeDefault); 122 | void finishOp(int32_t op, int32_t uid, const String16& callingPackage); 123 | void startWatchingMode(int32_t op, const String16& packageName, 124 | const sp& callback); 125 | void stopWatchingMode(const sp& callback); 126 | int32_t permissionToOpCode(const String16& permission); 127 | 128 | private: 129 | Mutex mLock; 130 | sp mService; 131 | 132 | sp getService(); 133 | }; 134 | 135 | 136 | }; // namespace android 137 | // --------------------------------------------------------------------------- 138 | #else // __ANDROID_VNDK__ 139 | #error "This header is not visible to vendors" 140 | #endif // __ANDROID_VNDK__ 141 | 142 | #endif // ANDROID_APP_OPS_MANAGER_H 143 | -------------------------------------------------------------------------------- /include/binder/Binder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_BINDER_H 18 | #define ANDROID_BINDER_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | // --------------------------------------------------------------------------- 25 | namespace android { 26 | 27 | class BBinder : public IBinder 28 | { 29 | public: 30 | BBinder(); 31 | 32 | virtual const String16& getInterfaceDescriptor() const; 33 | virtual bool isBinderAlive() const; 34 | virtual status_t pingBinder(); 35 | virtual status_t dump(int fd, const Vector& args); 36 | 37 | // NOLINTNEXTLINE(google-default-arguments) 38 | virtual status_t transact( uint32_t code, 39 | const Parcel& data, 40 | Parcel* reply, 41 | uint32_t flags = 0); 42 | 43 | // NOLINTNEXTLINE(google-default-arguments) 44 | virtual status_t linkToDeath(const sp& recipient, 45 | void* cookie = nullptr, 46 | uint32_t flags = 0); 47 | 48 | // NOLINTNEXTLINE(google-default-arguments) 49 | virtual status_t unlinkToDeath( const wp& recipient, 50 | void* cookie = nullptr, 51 | uint32_t flags = 0, 52 | wp* outRecipient = nullptr); 53 | 54 | virtual void attachObject( const void* objectID, 55 | void* object, 56 | void* cleanupCookie, 57 | object_cleanup_func func); 58 | virtual void* findObject(const void* objectID) const; 59 | virtual void detachObject(const void* objectID); 60 | 61 | virtual BBinder* localBinder(); 62 | 63 | bool isRequestingSid(); 64 | // This must be called before the object is sent to another process. Not thread safe. 65 | void setRequestingSid(bool requestSid); 66 | 67 | protected: 68 | virtual ~BBinder(); 69 | 70 | // NOLINTNEXTLINE(google-default-arguments) 71 | virtual status_t onTransact( uint32_t code, 72 | const Parcel& data, 73 | Parcel* reply, 74 | uint32_t flags = 0); 75 | 76 | private: 77 | BBinder(const BBinder& o); 78 | BBinder& operator=(const BBinder& o); 79 | 80 | class Extras; 81 | 82 | Extras* getOrCreateExtras(); 83 | 84 | std::atomic mExtras; 85 | void* mReserved0; 86 | }; 87 | 88 | // --------------------------------------------------------------------------- 89 | 90 | class BpRefBase : public virtual RefBase 91 | { 92 | protected: 93 | explicit BpRefBase(const sp& o); 94 | virtual ~BpRefBase(); 95 | virtual void onFirstRef(); 96 | virtual void onLastStrongRef(const void* id); 97 | virtual bool onIncStrongAttempted(uint32_t flags, const void* id); 98 | 99 | inline IBinder* remote() { return mRemote; } 100 | inline IBinder* remote() const { return mRemote; } 101 | 102 | private: 103 | BpRefBase(const BpRefBase& o); 104 | BpRefBase& operator=(const BpRefBase& o); 105 | 106 | IBinder* const mRemote; 107 | RefBase::weakref_type* mRefs; 108 | std::atomic mState; 109 | }; 110 | 111 | }; // namespace android 112 | 113 | // --------------------------------------------------------------------------- 114 | 115 | #endif // ANDROID_BINDER_H 116 | -------------------------------------------------------------------------------- /include/binder/BinderService.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 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 | #ifndef ANDROID_BINDER_SERVICE_H 18 | #define ANDROID_BINDER_SERVICE_H 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | // --------------------------------------------------------------------------- 31 | namespace android { 32 | 33 | template 34 | class BinderService 35 | { 36 | public: 37 | static status_t publish(bool allowIsolated = false, 38 | int dumpFlags = IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT) { 39 | sp sm(defaultServiceManager()); 40 | return sm->addService(String16(SERVICE::getServiceName()), new SERVICE(), allowIsolated, 41 | dumpFlags); 42 | } 43 | 44 | static void publishAndJoinThreadPool( 45 | bool allowIsolated = false, 46 | int dumpFlags = IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT) { 47 | publish(allowIsolated, dumpFlags); 48 | joinThreadPool(); 49 | } 50 | 51 | static void instantiate() { publish(); } 52 | 53 | static status_t shutdown() { return NO_ERROR; } 54 | 55 | private: 56 | static void joinThreadPool() { 57 | sp ps(ProcessState::self()); 58 | ps->startThreadPool(); 59 | ps->giveThreadPoolName(); 60 | IPCThreadState::self()->joinThreadPool(); 61 | } 62 | }; 63 | 64 | 65 | }; // namespace android 66 | // --------------------------------------------------------------------------- 67 | #endif // ANDROID_BINDER_SERVICE_H 68 | -------------------------------------------------------------------------------- /include/binder/BpBinder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 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 | #ifndef ANDROID_BPBINDER_H 18 | #define ANDROID_BPBINDER_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | // --------------------------------------------------------------------------- 27 | namespace android { 28 | 29 | using binder_proxy_limit_callback = void(*)(int); 30 | 31 | class BpBinder : public IBinder 32 | { 33 | public: 34 | static BpBinder* create(int32_t handle); 35 | 36 | inline int32_t handle() const { return mHandle; } 37 | 38 | virtual const String16& getInterfaceDescriptor() const; 39 | virtual bool isBinderAlive() const; 40 | virtual status_t pingBinder(); 41 | virtual status_t dump(int fd, const Vector& args); 42 | 43 | // NOLINTNEXTLINE(google-default-arguments) 44 | virtual status_t transact( uint32_t code, 45 | const Parcel& data, 46 | Parcel* reply, 47 | uint32_t flags = 0); 48 | 49 | // NOLINTNEXTLINE(google-default-arguments) 50 | virtual status_t linkToDeath(const sp& recipient, 51 | void* cookie = nullptr, 52 | uint32_t flags = 0); 53 | 54 | // NOLINTNEXTLINE(google-default-arguments) 55 | virtual status_t unlinkToDeath( const wp& recipient, 56 | void* cookie = nullptr, 57 | uint32_t flags = 0, 58 | wp* outRecipient = nullptr); 59 | 60 | virtual void attachObject( const void* objectID, 61 | void* object, 62 | void* cleanupCookie, 63 | object_cleanup_func func); 64 | virtual void* findObject(const void* objectID) const; 65 | virtual void detachObject(const void* objectID); 66 | 67 | virtual BpBinder* remoteBinder(); 68 | 69 | status_t setConstantData(const void* data, size_t size); 70 | void sendObituary(); 71 | 72 | static uint32_t getBinderProxyCount(uint32_t uid); 73 | static void getCountByUid(Vector& uids, Vector& counts); 74 | static void enableCountByUid(); 75 | static void disableCountByUid(); 76 | static void setCountByUidEnabled(bool enable); 77 | static void setLimitCallback(binder_proxy_limit_callback cb); 78 | static void setBinderProxyCountWatermarks(int high, int low); 79 | 80 | class ObjectManager 81 | { 82 | public: 83 | ObjectManager(); 84 | ~ObjectManager(); 85 | 86 | void attach( const void* objectID, 87 | void* object, 88 | void* cleanupCookie, 89 | IBinder::object_cleanup_func func); 90 | void* find(const void* objectID) const; 91 | void detach(const void* objectID); 92 | 93 | void kill(); 94 | 95 | private: 96 | ObjectManager(const ObjectManager&); 97 | ObjectManager& operator=(const ObjectManager&); 98 | 99 | struct entry_t 100 | { 101 | void* object; 102 | void* cleanupCookie; 103 | IBinder::object_cleanup_func func; 104 | }; 105 | 106 | KeyedVector mObjects; 107 | }; 108 | 109 | protected: 110 | BpBinder(int32_t handle,int32_t trackedUid); 111 | virtual ~BpBinder(); 112 | virtual void onFirstRef(); 113 | virtual void onLastStrongRef(const void* id); 114 | virtual bool onIncStrongAttempted(uint32_t flags, const void* id); 115 | 116 | private: 117 | const int32_t mHandle; 118 | 119 | struct Obituary { 120 | wp recipient; 121 | void* cookie; 122 | uint32_t flags; 123 | }; 124 | 125 | void reportOneDeath(const Obituary& obit); 126 | bool isDescriptorCached() const; 127 | 128 | mutable Mutex mLock; 129 | volatile int32_t mAlive; 130 | volatile int32_t mObitsSent; 131 | Vector* mObituaries; 132 | ObjectManager mObjects; 133 | Parcel* mConstantData; 134 | mutable String16 mDescriptorCache; 135 | int32_t mTrackedUid; 136 | 137 | static Mutex sTrackingLock; 138 | static std::unordered_map sTrackingMap; 139 | static int sNumTrackedUids; 140 | static std::atomic_bool sCountByUidEnabled; 141 | static binder_proxy_limit_callback sLimitCallback; 142 | static uint32_t sBinderProxyCountHighWatermark; 143 | static uint32_t sBinderProxyCountLowWatermark; 144 | static bool sBinderProxyThrottleCreate; 145 | }; 146 | 147 | }; // namespace android 148 | 149 | // --------------------------------------------------------------------------- 150 | 151 | #endif // ANDROID_BPBINDER_H 152 | -------------------------------------------------------------------------------- /include/binder/BufferedTextOutput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 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 | #ifndef ANDROID_BUFFEREDTEXTOUTPUT_H 18 | #define ANDROID_BUFFEREDTEXTOUTPUT_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | // --------------------------------------------------------------------------- 25 | namespace android { 26 | 27 | class BufferedTextOutput : public TextOutput 28 | { 29 | public: 30 | //** Flags for constructor */ 31 | enum { 32 | MULTITHREADED = 0x0001 33 | }; 34 | 35 | explicit BufferedTextOutput(uint32_t flags = 0); 36 | virtual ~BufferedTextOutput(); 37 | 38 | virtual status_t print(const char* txt, size_t len); 39 | virtual void moveIndent(int delta); 40 | 41 | virtual void pushBundle(); 42 | virtual void popBundle(); 43 | 44 | protected: 45 | virtual status_t writeLines(const struct iovec& vec, size_t N) = 0; 46 | 47 | private: 48 | struct BufferState; 49 | struct ThreadState; 50 | 51 | static ThreadState*getThreadState(); 52 | static void threadDestructor(void *st); 53 | 54 | BufferState*getBuffer() const; 55 | 56 | uint32_t mFlags; 57 | const int32_t mSeq; 58 | const int32_t mIndex; 59 | 60 | Mutex mLock; 61 | BufferState* mGlobalState; 62 | }; 63 | 64 | // --------------------------------------------------------------------------- 65 | }; // namespace android 66 | 67 | #endif // ANDROID_BUFFEREDTEXTOUTPUT_H 68 | -------------------------------------------------------------------------------- /include/binder/Debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 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 | #ifndef ANDROID_BINDER_DEBUG_H 18 | #define ANDROID_BINDER_DEBUG_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace android { 25 | // --------------------------------------------------------------------------- 26 | 27 | __BEGIN_DECLS 28 | 29 | const char* stringForIndent(int32_t indentLevel); 30 | 31 | typedef void (*debugPrintFunc)(void* cookie, const char* txt); 32 | 33 | void printTypeCode(uint32_t typeCode, 34 | debugPrintFunc func = nullptr, void* cookie = nullptr); 35 | 36 | void printHexData(int32_t indent, const void *buf, size_t length, 37 | size_t bytesPerLine=16, int32_t singleLineBytesCutoff=16, 38 | size_t alignment=0, bool cArrayStyle=false, 39 | debugPrintFunc func = nullptr, void* cookie = nullptr); 40 | 41 | 42 | ssize_t getBinderKernelReferences(size_t count, uintptr_t* buf); 43 | 44 | __END_DECLS 45 | 46 | // --------------------------------------------------------------------------- 47 | }; // namespace android 48 | 49 | #endif // ANDROID_BINDER_DEBUG_H 50 | 51 | #ifndef STUB 52 | #define STUB LOG_ALWAYS_FATAL("STUBBED @ %s:%d", __FILE__, __LINE__) 53 | #endif 54 | -------------------------------------------------------------------------------- /include/binder/IActivityManager.h: -------------------------------------------------------------------------------- 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 | #ifndef ANDROID_IACTIVITY_MANAGER_H 18 | #define ANDROID_IACTIVITY_MANAGER_H 19 | 20 | #ifndef __ANDROID_VNDK__ 21 | 22 | #include 23 | #include 24 | 25 | namespace android { 26 | 27 | // ------------------------------------------------------------------------------------ 28 | 29 | class IActivityManager : public IInterface 30 | { 31 | public: 32 | DECLARE_META_INTERFACE(ActivityManager) 33 | 34 | virtual int openContentUri(const String16& stringUri) = 0; 35 | virtual void registerUidObserver(const sp& observer, 36 | const int32_t event, 37 | const int32_t cutpoint, 38 | const String16& callingPackage) = 0; 39 | virtual void unregisterUidObserver(const sp& observer) = 0; 40 | virtual bool isUidActive(const uid_t uid, const String16& callingPackage) = 0; 41 | virtual int32_t getUidProcessState(const uid_t uid, const String16& callingPackage) = 0; 42 | 43 | enum { 44 | OPEN_CONTENT_URI_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION, 45 | REGISTER_UID_OBSERVER_TRANSACTION, 46 | UNREGISTER_UID_OBSERVER_TRANSACTION, 47 | IS_UID_ACTIVE_TRANSACTION, 48 | GET_UID_PROCESS_STATE_TRANSACTION 49 | }; 50 | }; 51 | 52 | // ------------------------------------------------------------------------------------ 53 | 54 | }; // namespace android 55 | 56 | #else // __ANDROID_VNDK__ 57 | #error "This header is not visible to vendors" 58 | #endif // __ANDROID_VNDK__ 59 | 60 | #endif // ANDROID_IACTIVITY_MANAGER_H 61 | -------------------------------------------------------------------------------- /include/binder/IAppOpsCallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 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 | // 18 | #ifndef ANDROID_IAPP_OPS_CALLBACK_H 19 | #define ANDROID_IAPP_OPS_CALLBACK_H 20 | 21 | #ifndef __ANDROID_VNDK__ 22 | 23 | #include 24 | 25 | namespace android { 26 | 27 | // ---------------------------------------------------------------------- 28 | 29 | class IAppOpsCallback : public IInterface 30 | { 31 | public: 32 | DECLARE_META_INTERFACE(AppOpsCallback) 33 | 34 | virtual void opChanged(int32_t op, const String16& packageName) = 0; 35 | 36 | enum { 37 | OP_CHANGED_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION 38 | }; 39 | }; 40 | 41 | // ---------------------------------------------------------------------- 42 | 43 | class BnAppOpsCallback : public BnInterface 44 | { 45 | public: 46 | // NOLINTNEXTLINE(google-default-arguments) 47 | virtual status_t onTransact( uint32_t code, 48 | const Parcel& data, 49 | Parcel* reply, 50 | uint32_t flags = 0); 51 | }; 52 | 53 | // ---------------------------------------------------------------------- 54 | 55 | }; // namespace android 56 | 57 | #else // __ANDROID_VNDK__ 58 | #error "This header is not visible to vendors" 59 | #endif // __ANDROID_VNDK__ 60 | 61 | #endif // ANDROID_IAPP_OPS_CALLBACK_H 62 | 63 | -------------------------------------------------------------------------------- /include/binder/IAppOpsService.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 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 | // 18 | #ifndef ANDROID_IAPP_OPS_SERVICE_H 19 | #define ANDROID_IAPP_OPS_SERVICE_H 20 | 21 | #ifndef __ANDROID_VNDK__ 22 | 23 | #include 24 | #include 25 | 26 | namespace android { 27 | 28 | // ---------------------------------------------------------------------- 29 | 30 | class IAppOpsService : public IInterface 31 | { 32 | public: 33 | DECLARE_META_INTERFACE(AppOpsService) 34 | 35 | virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) = 0; 36 | virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName) = 0; 37 | virtual int32_t startOperation(const sp& token, int32_t code, int32_t uid, 38 | const String16& packageName, bool startIfModeDefault) = 0; 39 | virtual void finishOperation(const sp& token, int32_t code, int32_t uid, 40 | const String16& packageName) = 0; 41 | virtual void startWatchingMode(int32_t op, const String16& packageName, 42 | const sp& callback) = 0; 43 | virtual void stopWatchingMode(const sp& callback) = 0; 44 | virtual sp getToken(const sp& clientToken) = 0; 45 | virtual int32_t permissionToOpCode(const String16& permission) = 0; 46 | virtual int32_t checkAudioOperation(int32_t code, int32_t usage,int32_t uid, 47 | const String16& packageName) = 0; 48 | 49 | enum { 50 | CHECK_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION, 51 | NOTE_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+1, 52 | START_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+2, 53 | FINISH_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+3, 54 | START_WATCHING_MODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+4, 55 | STOP_WATCHING_MODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+5, 56 | GET_TOKEN_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+6, 57 | PERMISSION_TO_OP_CODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+7, 58 | CHECK_AUDIO_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+8, 59 | }; 60 | 61 | enum { 62 | MODE_ALLOWED = 0, 63 | MODE_IGNORED = 1, 64 | MODE_ERRORED = 2 65 | }; 66 | }; 67 | 68 | // ---------------------------------------------------------------------- 69 | 70 | class BnAppOpsService : public BnInterface 71 | { 72 | public: 73 | // NOLINTNEXTLINE(google-default-arguments) 74 | virtual status_t onTransact( uint32_t code, 75 | const Parcel& data, 76 | Parcel* reply, 77 | uint32_t flags = 0); 78 | }; 79 | 80 | // ---------------------------------------------------------------------- 81 | 82 | }; // namespace android 83 | 84 | #else // __ANDROID_VNDK__ 85 | #error "This header is not visible to vendors" 86 | #endif // __ANDROID_VNDK__ 87 | 88 | #endif // ANDROID_IAPP_OPS_SERVICE_H 89 | -------------------------------------------------------------------------------- /include/binder/IBatteryStats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 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 | #ifndef ANDROID_IBATTERYSTATS_H 18 | #define ANDROID_IBATTERYSTATS_H 19 | 20 | #ifndef __ANDROID_VNDK__ 21 | 22 | #include 23 | 24 | namespace android { 25 | 26 | // ---------------------------------------------------------------------- 27 | 28 | class IBatteryStats : public IInterface 29 | { 30 | public: 31 | DECLARE_META_INTERFACE(BatteryStats) 32 | 33 | virtual void noteStartSensor(int uid, int sensor) = 0; 34 | virtual void noteStopSensor(int uid, int sensor) = 0; 35 | virtual void noteStartVideo(int uid) = 0; 36 | virtual void noteStopVideo(int uid) = 0; 37 | virtual void noteStartAudio(int uid) = 0; 38 | virtual void noteStopAudio(int uid) = 0; 39 | virtual void noteResetVideo() = 0; 40 | virtual void noteResetAudio() = 0; 41 | virtual void noteFlashlightOn(int uid) = 0; 42 | virtual void noteFlashlightOff(int uid) = 0; 43 | virtual void noteStartCamera(int uid) = 0; 44 | virtual void noteStopCamera(int uid) = 0; 45 | virtual void noteResetCamera() = 0; 46 | virtual void noteResetFlashlight() = 0; 47 | 48 | enum { 49 | NOTE_START_SENSOR_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION, 50 | NOTE_STOP_SENSOR_TRANSACTION, 51 | NOTE_START_VIDEO_TRANSACTION, 52 | NOTE_STOP_VIDEO_TRANSACTION, 53 | NOTE_START_AUDIO_TRANSACTION, 54 | NOTE_STOP_AUDIO_TRANSACTION, 55 | NOTE_RESET_VIDEO_TRANSACTION, 56 | NOTE_RESET_AUDIO_TRANSACTION, 57 | NOTE_FLASHLIGHT_ON_TRANSACTION, 58 | NOTE_FLASHLIGHT_OFF_TRANSACTION, 59 | NOTE_START_CAMERA_TRANSACTION, 60 | NOTE_STOP_CAMERA_TRANSACTION, 61 | NOTE_RESET_CAMERA_TRANSACTION, 62 | NOTE_RESET_FLASHLIGHT_TRANSACTION 63 | }; 64 | }; 65 | 66 | // ---------------------------------------------------------------------- 67 | 68 | class BnBatteryStats : public BnInterface 69 | { 70 | public: 71 | // NOLINTNEXTLINE(google-default-arguments) 72 | virtual status_t onTransact( uint32_t code, 73 | const Parcel& data, 74 | Parcel* reply, 75 | uint32_t flags = 0); 76 | }; 77 | 78 | // ---------------------------------------------------------------------- 79 | 80 | }; // namespace android 81 | 82 | #else // __ANDROID_VNDK__ 83 | #error "This header is not visible to vendors" 84 | #endif // __ANDROID_VNDK__ 85 | 86 | #endif // ANDROID_IBATTERYSTATS_H 87 | -------------------------------------------------------------------------------- /include/binder/IMediaResourceMonitor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 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 | #ifndef ANDROID_I_MEDIA_RESOURCE_MONITOR_H 18 | #define ANDROID_I_MEDIA_RESOURCE_MONITOR_H 19 | 20 | #ifndef __ANDROID_VNDK__ 21 | 22 | #include 23 | 24 | namespace android { 25 | 26 | // ---------------------------------------------------------------------- 27 | 28 | class IMediaResourceMonitor : public IInterface { 29 | public: 30 | DECLARE_META_INTERFACE(MediaResourceMonitor) 31 | 32 | // Values should be in sync with Intent.EXTRA_MEDIA_RESOURCE_TYPE_XXX. 33 | enum { 34 | TYPE_VIDEO_CODEC = 0, 35 | TYPE_AUDIO_CODEC = 1, 36 | }; 37 | 38 | virtual void notifyResourceGranted(/*in*/ int32_t pid, /*in*/ const int32_t type) = 0; 39 | 40 | enum { 41 | NOTIFY_RESOURCE_GRANTED = IBinder::FIRST_CALL_TRANSACTION, 42 | }; 43 | }; 44 | 45 | // ---------------------------------------------------------------------- 46 | 47 | class BnMediaResourceMonitor : public BnInterface { 48 | public: 49 | virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, 50 | uint32_t flags = 0); 51 | }; 52 | 53 | // ---------------------------------------------------------------------- 54 | 55 | }; // namespace android 56 | 57 | #else // __ANDROID_VNDK__ 58 | #error "This header is not visible to vendors" 59 | #endif // __ANDROID_VNDK__ 60 | 61 | #endif // ANDROID_I_MEDIA_RESOURCE_MONITOR_H 62 | -------------------------------------------------------------------------------- /include/binder/IMemory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 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 | #ifndef ANDROID_IMEMORY_H 18 | #define ANDROID_IMEMORY_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace android { 29 | 30 | // ---------------------------------------------------------------------------- 31 | 32 | class IMemoryHeap : public IInterface 33 | { 34 | public: 35 | DECLARE_META_INTERFACE(MemoryHeap) 36 | 37 | // flags returned by getFlags() 38 | enum { 39 | READ_ONLY = 0x00000001 40 | }; 41 | 42 | virtual int getHeapID() const = 0; 43 | virtual void* getBase() const = 0; 44 | virtual size_t getSize() const = 0; 45 | virtual uint32_t getFlags() const = 0; 46 | virtual off_t getOffset() const = 0; 47 | 48 | // these are there just for backward source compatibility 49 | int32_t heapID() const { return getHeapID(); } 50 | void* base() const { return getBase(); } 51 | size_t virtualSize() const { return getSize(); } 52 | }; 53 | 54 | class BnMemoryHeap : public BnInterface 55 | { 56 | public: 57 | // NOLINTNEXTLINE(google-default-arguments) 58 | virtual status_t onTransact( 59 | uint32_t code, 60 | const Parcel& data, 61 | Parcel* reply, 62 | uint32_t flags = 0); 63 | 64 | BnMemoryHeap(); 65 | protected: 66 | virtual ~BnMemoryHeap(); 67 | }; 68 | 69 | // ---------------------------------------------------------------------------- 70 | 71 | class IMemory : public IInterface 72 | { 73 | public: 74 | DECLARE_META_INTERFACE(Memory) 75 | 76 | // NOLINTNEXTLINE(google-default-arguments) 77 | virtual sp getMemory(ssize_t* offset=nullptr, size_t* size=nullptr) const = 0; 78 | 79 | // helpers 80 | void* fastPointer(const sp& heap, ssize_t offset) const; 81 | void* pointer() const; 82 | size_t size() const; 83 | ssize_t offset() const; 84 | }; 85 | 86 | class BnMemory : public BnInterface 87 | { 88 | public: 89 | // NOLINTNEXTLINE(google-default-arguments) 90 | virtual status_t onTransact( 91 | uint32_t code, 92 | const Parcel& data, 93 | Parcel* reply, 94 | uint32_t flags = 0); 95 | 96 | BnMemory(); 97 | protected: 98 | virtual ~BnMemory(); 99 | }; 100 | 101 | // ---------------------------------------------------------------------------- 102 | 103 | }; // namespace android 104 | 105 | #endif // ANDROID_IMEMORY_H 106 | -------------------------------------------------------------------------------- /include/binder/IPermissionController.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 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 | // 18 | #ifndef ANDROID_IPERMISSION_CONTROLLER_H 19 | #define ANDROID_IPERMISSION_CONTROLLER_H 20 | 21 | #ifndef __ANDROID_VNDK__ 22 | 23 | #include 24 | #include 25 | 26 | namespace android { 27 | 28 | // ---------------------------------------------------------------------- 29 | 30 | class IPermissionController : public IInterface 31 | { 32 | public: 33 | DECLARE_META_INTERFACE(PermissionController) 34 | 35 | virtual bool checkPermission(const String16& permission, int32_t pid, int32_t uid) = 0; 36 | 37 | virtual int32_t noteOp(const String16& op, int32_t uid, const String16& packageName) = 0; 38 | 39 | virtual void getPackagesForUid(const uid_t uid, Vector &packages) = 0; 40 | 41 | virtual bool isRuntimePermission(const String16& permission) = 0; 42 | 43 | virtual int getPackageUid(const String16& package, int flags) = 0; 44 | 45 | enum { 46 | CHECK_PERMISSION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION, 47 | NOTE_OP_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION + 1, 48 | GET_PACKAGES_FOR_UID_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION + 2, 49 | IS_RUNTIME_PERMISSION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION + 3, 50 | GET_PACKAGE_UID_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION + 4 51 | }; 52 | }; 53 | 54 | // ---------------------------------------------------------------------- 55 | 56 | class BnPermissionController : public BnInterface 57 | { 58 | public: 59 | // NOLINTNEXTLINE(google-default-arguments) 60 | virtual status_t onTransact( uint32_t code, 61 | const Parcel& data, 62 | Parcel* reply, 63 | uint32_t flags = 0); 64 | }; 65 | 66 | // ---------------------------------------------------------------------- 67 | 68 | }; // namespace android 69 | 70 | #else // __ANDROID_VNDK__ 71 | #error "This header is not visible to vendors" 72 | #endif // __ANDROID_VNDK__ 73 | 74 | #endif // ANDROID_IPERMISSION_CONTROLLER_H 75 | 76 | -------------------------------------------------------------------------------- /include/binder/IProcessInfoService.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 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 | #ifndef ANDROID_I_PROCESS_INFO_SERVICE_H 18 | #define ANDROID_I_PROCESS_INFO_SERVICE_H 19 | 20 | #ifndef __ANDROID_VNDK__ 21 | 22 | #include 23 | 24 | namespace android { 25 | 26 | // ---------------------------------------------------------------------- 27 | 28 | class IProcessInfoService : public IInterface { 29 | public: 30 | DECLARE_META_INTERFACE(ProcessInfoService) 31 | 32 | virtual status_t getProcessStatesFromPids( size_t length, 33 | /*in*/ int32_t* pids, 34 | /*out*/ int32_t* states) = 0; 35 | 36 | virtual status_t getProcessStatesAndOomScoresFromPids( size_t length, 37 | /*in*/ int32_t* pids, 38 | /*out*/ int32_t* states, 39 | /*out*/ int32_t* scores) = 0; 40 | 41 | enum { 42 | GET_PROCESS_STATES_FROM_PIDS = IBinder::FIRST_CALL_TRANSACTION, 43 | GET_PROCESS_STATES_AND_OOM_SCORES_FROM_PIDS, 44 | }; 45 | }; 46 | 47 | // ---------------------------------------------------------------------- 48 | 49 | }; // namespace android 50 | 51 | #else // __ANDROID_VNDK__ 52 | #error "This header is not visible to vendors" 53 | #endif // __ANDROID_VNDK__ 54 | 55 | #endif // ANDROID_I_PROCESS_INFO_SERVICE_H 56 | -------------------------------------------------------------------------------- /include/binder/IResultReceiver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | // 18 | #ifndef ANDROID_IRESULT_RECEIVER_H 19 | #define ANDROID_IRESULT_RECEIVER_H 20 | 21 | #include 22 | 23 | namespace android { 24 | 25 | // ---------------------------------------------------------------------- 26 | 27 | class IResultReceiver : public IInterface 28 | { 29 | public: 30 | DECLARE_META_INTERFACE(ResultReceiver) 31 | 32 | virtual void send(int32_t resultCode) = 0; 33 | 34 | enum { 35 | OP_SEND = IBinder::FIRST_CALL_TRANSACTION 36 | }; 37 | }; 38 | 39 | // ---------------------------------------------------------------------- 40 | 41 | class BnResultReceiver : public BnInterface 42 | { 43 | public: 44 | // NOLINTNEXTLINE(google-default-arguments) 45 | virtual status_t onTransact( uint32_t code, 46 | const Parcel& data, 47 | Parcel* reply, 48 | uint32_t flags = 0); 49 | }; 50 | 51 | // ---------------------------------------------------------------------- 52 | 53 | }; // namespace android 54 | 55 | #endif // ANDROID_IRESULT_RECEIVER_H 56 | 57 | -------------------------------------------------------------------------------- /include/binder/IServiceManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 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 | // 18 | #ifndef ANDROID_ISERVICE_MANAGER_H 19 | #define ANDROID_ISERVICE_MANAGER_H 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace android { 26 | 27 | // ---------------------------------------------------------------------- 28 | 29 | class IServiceManager : public IInterface 30 | { 31 | public: 32 | DECLARE_META_INTERFACE(ServiceManager) 33 | /** 34 | * Must match values in IServiceManager.java 35 | */ 36 | /* Allows services to dump sections according to priorities. */ 37 | static const int DUMP_FLAG_PRIORITY_CRITICAL = 1 << 0; 38 | static const int DUMP_FLAG_PRIORITY_HIGH = 1 << 1; 39 | static const int DUMP_FLAG_PRIORITY_NORMAL = 1 << 2; 40 | /** 41 | * Services are by default registered with a DEFAULT dump priority. DEFAULT priority has the 42 | * same priority as NORMAL priority but the services are not called with dump priority 43 | * arguments. 44 | */ 45 | static const int DUMP_FLAG_PRIORITY_DEFAULT = 1 << 3; 46 | static const int DUMP_FLAG_PRIORITY_ALL = DUMP_FLAG_PRIORITY_CRITICAL | 47 | DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PRIORITY_DEFAULT; 48 | static const int DUMP_FLAG_PROTO = 1 << 4; 49 | 50 | /** 51 | * Retrieve an existing service, blocking for a few seconds 52 | * if it doesn't yet exist. 53 | */ 54 | virtual sp getService( const String16& name) const = 0; 55 | 56 | /** 57 | * Retrieve an existing service, non-blocking. 58 | */ 59 | virtual sp checkService( const String16& name) const = 0; 60 | 61 | /** 62 | * Register a service. 63 | */ 64 | // NOLINTNEXTLINE(google-default-arguments) 65 | virtual status_t addService(const String16& name, const sp& service, 66 | bool allowIsolated = false, 67 | int dumpsysFlags = DUMP_FLAG_PRIORITY_DEFAULT) = 0; 68 | 69 | /** 70 | * Return list of all existing services. 71 | */ 72 | // NOLINTNEXTLINE(google-default-arguments) 73 | virtual Vector listServices(int dumpsysFlags = DUMP_FLAG_PRIORITY_ALL) = 0; 74 | 75 | enum { 76 | GET_SERVICE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION, 77 | CHECK_SERVICE_TRANSACTION, 78 | ADD_SERVICE_TRANSACTION, 79 | LIST_SERVICES_TRANSACTION, 80 | }; 81 | }; 82 | 83 | sp defaultServiceManager(); 84 | 85 | template 86 | status_t getService(const String16& name, sp* outService) 87 | { 88 | const sp sm = defaultServiceManager(); 89 | if (sm != nullptr) { 90 | *outService = interface_cast(sm->getService(name)); 91 | if ((*outService) != nullptr) return NO_ERROR; 92 | } 93 | return NAME_NOT_FOUND; 94 | } 95 | 96 | bool checkCallingPermission(const String16& permission); 97 | bool checkCallingPermission(const String16& permission, 98 | int32_t* outPid, int32_t* outUid); 99 | bool checkPermission(const String16& permission, pid_t pid, uid_t uid); 100 | 101 | }; // namespace android 102 | 103 | #endif // ANDROID_ISERVICE_MANAGER_H 104 | 105 | -------------------------------------------------------------------------------- /include/binder/IShellCallback.h: -------------------------------------------------------------------------------- 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 | // 18 | #ifndef ANDROID_ISHELL_CALLBACK_H 19 | #define ANDROID_ISHELL_CALLBACK_H 20 | 21 | #include 22 | 23 | namespace android { 24 | 25 | // ---------------------------------------------------------------------- 26 | 27 | class IShellCallback : public IInterface 28 | { 29 | public: 30 | DECLARE_META_INTERFACE(ShellCallback); 31 | 32 | virtual int openFile(const String16& path, const String16& seLinuxContext, 33 | const String16& mode) = 0; 34 | 35 | enum { 36 | OP_OPEN_OUTPUT_FILE = IBinder::FIRST_CALL_TRANSACTION 37 | }; 38 | }; 39 | 40 | // ---------------------------------------------------------------------- 41 | 42 | class BnShellCallback : public BnInterface 43 | { 44 | public: 45 | // NOLINTNEXTLINE(google-default-arguments) 46 | virtual status_t onTransact( uint32_t code, 47 | const Parcel& data, 48 | Parcel* reply, 49 | uint32_t flags = 0); 50 | }; 51 | 52 | // ---------------------------------------------------------------------- 53 | 54 | }; // namespace android 55 | 56 | #endif // ANDROID_ISHELL_CALLBACK_H 57 | 58 | -------------------------------------------------------------------------------- /include/binder/IUidObserver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 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 | // 18 | #ifndef ANDROID_IUID_OBSERVER_H 19 | #define ANDROID_IUID_OBSERVER_H 20 | 21 | #ifndef __ANDROID_VNDK__ 22 | 23 | #include 24 | 25 | namespace android { 26 | 27 | // ---------------------------------------------------------------------- 28 | 29 | class IUidObserver : public IInterface 30 | { 31 | public: 32 | DECLARE_META_INTERFACE(UidObserver) 33 | 34 | virtual void onUidGone(uid_t uid, bool disabled) = 0; 35 | virtual void onUidActive(uid_t uid) = 0; 36 | virtual void onUidIdle(uid_t uid, bool disabled) = 0; 37 | virtual void onUidStateChanged(uid_t uid, int32_t procState, int64_t procStateSeq) = 0; 38 | 39 | enum { 40 | ON_UID_GONE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION, 41 | ON_UID_ACTIVE_TRANSACTION, 42 | ON_UID_IDLE_TRANSACTION, 43 | ON_UID_STATE_CHANGED_TRANSACTION 44 | }; 45 | }; 46 | 47 | // ---------------------------------------------------------------------- 48 | 49 | class BnUidObserver : public BnInterface 50 | { 51 | public: 52 | // NOLINTNEXTLINE(google-default-arguments) 53 | virtual status_t onTransact(uint32_t code, 54 | const Parcel& data, 55 | Parcel* reply, 56 | uint32_t flags = 0); 57 | }; 58 | 59 | // ---------------------------------------------------------------------- 60 | 61 | }; // namespace android 62 | 63 | #else // __ANDROID_VNDK__ 64 | #error "This header is not visible to vendors" 65 | #endif // __ANDROID_VNDK__ 66 | 67 | #endif // ANDROID_IUID_OBSERVER_H 68 | -------------------------------------------------------------------------------- /include/binder/IpPrefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | #ifndef ANDROID_IP_PREFIX_H 18 | #define ANDROID_IP_PREFIX_H 19 | 20 | #ifndef __ANDROID_VNDK__ 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace android { 29 | 30 | namespace net { 31 | 32 | /* 33 | * C++ implementation of the Java class android.net.IpPrefix 34 | */ 35 | class IpPrefix : public Parcelable { 36 | public: 37 | IpPrefix() = default; 38 | virtual ~IpPrefix() = default; 39 | IpPrefix(const IpPrefix& prefix) = default; 40 | 41 | IpPrefix(const struct in6_addr& addr, int32_t plen): 42 | mUnion(addr), mPrefixLength(plen), mIsIpv6(true) { } 43 | 44 | IpPrefix(const struct in_addr& addr, int32_t plen): 45 | mUnion(addr), mPrefixLength(plen), mIsIpv6(false) { } 46 | 47 | bool getAddressAsIn6Addr(struct in6_addr* addr) const; 48 | bool getAddressAsInAddr(struct in_addr* addr) const; 49 | 50 | const struct in6_addr& getAddressAsIn6Addr() const; 51 | const struct in_addr& getAddressAsInAddr() const; 52 | 53 | bool isIpv6() const; 54 | bool isIpv4() const; 55 | 56 | int32_t getPrefixLength() const; 57 | 58 | void setAddress(const struct in6_addr& addr); 59 | void setAddress(const struct in_addr& addr); 60 | 61 | void setPrefixLength(int32_t prefix); 62 | 63 | friend bool operator==(const IpPrefix& lhs, const IpPrefix& rhs); 64 | 65 | friend bool operator!=(const IpPrefix& lhs, const IpPrefix& rhs) { 66 | return !(lhs == rhs); 67 | } 68 | 69 | public: 70 | // Overrides 71 | status_t writeToParcel(Parcel* parcel) const override; 72 | status_t readFromParcel(const Parcel* parcel) override; 73 | 74 | private: 75 | union InternalUnion { 76 | InternalUnion() = default; 77 | explicit InternalUnion(const struct in6_addr &addr):mIn6Addr(addr) { }; 78 | explicit InternalUnion(const struct in_addr &addr):mInAddr(addr) { }; 79 | struct in6_addr mIn6Addr; 80 | struct in_addr mInAddr; 81 | } mUnion; 82 | int32_t mPrefixLength; 83 | bool mIsIpv6; 84 | }; 85 | 86 | } // namespace net 87 | 88 | } // namespace android 89 | 90 | #else // __ANDROID_VNDK__ 91 | #error "This header is not visible to vendors" 92 | #endif // __ANDROID_VNDK__ 93 | 94 | #endif // ANDROID_IP_PREFIX_H 95 | -------------------------------------------------------------------------------- /include/binder/Map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 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 | #ifndef ANDROID_MAP_H 18 | #define ANDROID_MAP_H 19 | 20 | #include 21 | #include 22 | 23 | // --------------------------------------------------------------------------- 24 | namespace android { 25 | namespace binder { 26 | 27 | class Value; 28 | 29 | /** 30 | * Convenience typedef for ::std::map<::std::string,::android::binder::Value> 31 | */ 32 | typedef ::std::map<::std::string, Value> Map; 33 | 34 | } // namespace binder 35 | } // namespace android 36 | 37 | // --------------------------------------------------------------------------- 38 | 39 | #endif // ANDROID_MAP_H 40 | -------------------------------------------------------------------------------- /include/binder/MemoryBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_MEMORY_BASE_H 18 | #define ANDROID_MEMORY_BASE_H 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | 26 | namespace android { 27 | 28 | // --------------------------------------------------------------------------- 29 | 30 | class MemoryBase : public BnMemory 31 | { 32 | public: 33 | MemoryBase(const sp& heap, ssize_t offset, size_t size); 34 | virtual ~MemoryBase(); 35 | virtual sp getMemory(ssize_t* offset, size_t* size) const; 36 | 37 | protected: 38 | size_t getSize() const { return mSize; } 39 | ssize_t getOffset() const { return mOffset; } 40 | const sp& getHeap() const { return mHeap; } 41 | 42 | private: 43 | size_t mSize; 44 | ssize_t mOffset; 45 | sp mHeap; 46 | }; 47 | 48 | // --------------------------------------------------------------------------- 49 | }; // namespace android 50 | 51 | #endif // ANDROID_MEMORY_BASE_H 52 | -------------------------------------------------------------------------------- /include/binder/MemoryDealer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 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 | #ifndef ANDROID_MEMORY_DEALER_H 18 | #define ANDROID_MEMORY_DEALER_H 19 | 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | namespace android { 28 | // ---------------------------------------------------------------------------- 29 | 30 | class SimpleBestFitAllocator; 31 | 32 | // ---------------------------------------------------------------------------- 33 | 34 | class MemoryDealer : public RefBase 35 | { 36 | public: 37 | explicit MemoryDealer(size_t size, const char* name = nullptr, 38 | uint32_t flags = 0 /* or bits such as MemoryHeapBase::READ_ONLY */ ); 39 | 40 | virtual sp allocate(size_t size); 41 | virtual void deallocate(size_t offset); 42 | virtual void dump(const char* what) const; 43 | 44 | // allocations are aligned to some value. return that value so clients can account for it. 45 | static size_t getAllocationAlignment(); 46 | 47 | sp getMemoryHeap() const { return heap(); } 48 | 49 | protected: 50 | virtual ~MemoryDealer(); 51 | 52 | private: 53 | const sp& heap() const; 54 | SimpleBestFitAllocator* allocator() const; 55 | 56 | sp mHeap; 57 | SimpleBestFitAllocator* mAllocator; 58 | }; 59 | 60 | 61 | // ---------------------------------------------------------------------------- 62 | }; // namespace android 63 | 64 | #endif // ANDROID_MEMORY_DEALER_H 65 | -------------------------------------------------------------------------------- /include/binder/MemoryHeapBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef ANDROID_MEMORY_HEAP_BASE_H 18 | #define ANDROID_MEMORY_HEAP_BASE_H 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | 26 | namespace android { 27 | 28 | // --------------------------------------------------------------------------- 29 | 30 | class MemoryHeapBase : public virtual BnMemoryHeap 31 | { 32 | public: 33 | enum { 34 | READ_ONLY = IMemoryHeap::READ_ONLY, 35 | // memory won't be mapped locally, but will be mapped in the remote 36 | // process. 37 | DONT_MAP_LOCALLY = 0x00000100, 38 | NO_CACHING = 0x00000200 39 | }; 40 | 41 | /* 42 | * maps the memory referenced by fd. but DOESN'T take ownership 43 | * of the filedescriptor (it makes a copy with dup() 44 | */ 45 | MemoryHeapBase(int fd, size_t size, uint32_t flags = 0, off_t offset = 0); 46 | 47 | /* 48 | * maps memory from the given device 49 | */ 50 | explicit MemoryHeapBase(const char* device, size_t size = 0, uint32_t flags = 0); 51 | 52 | /* 53 | * maps memory from ashmem, with the given name for debugging 54 | */ 55 | explicit MemoryHeapBase(size_t size, uint32_t flags = 0, char const* name = nullptr); 56 | 57 | virtual ~MemoryHeapBase(); 58 | 59 | /* implement IMemoryHeap interface */ 60 | virtual int getHeapID() const; 61 | 62 | /* virtual address of the heap. returns MAP_FAILED in case of error */ 63 | virtual void* getBase() const; 64 | 65 | virtual size_t getSize() const; 66 | virtual uint32_t getFlags() const; 67 | off_t getOffset() const override; 68 | 69 | const char* getDevice() const; 70 | 71 | /* this closes this heap -- use carefully */ 72 | void dispose(); 73 | 74 | /* this is only needed as a workaround, use only if you know 75 | * what you are doing */ 76 | status_t setDevice(const char* device) { 77 | if (mDevice == nullptr) 78 | mDevice = device; 79 | return mDevice ? NO_ERROR : ALREADY_EXISTS; 80 | } 81 | 82 | protected: 83 | MemoryHeapBase(); 84 | // init() takes ownership of fd 85 | status_t init(int fd, void *base, size_t size, 86 | int flags = 0, const char* device = nullptr); 87 | 88 | private: 89 | status_t mapfd(int fd, size_t size, off_t offset = 0); 90 | 91 | int mFD; 92 | size_t mSize; 93 | void* mBase; 94 | uint32_t mFlags; 95 | const char* mDevice; 96 | bool mNeedUnmap; 97 | off_t mOffset; 98 | }; 99 | 100 | // --------------------------------------------------------------------------- 101 | }; // namespace android 102 | 103 | #endif // ANDROID_MEMORY_HEAP_BASE_H 104 | -------------------------------------------------------------------------------- /include/binder/ParcelFileDescriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | #ifndef ANDROID_PARCEL_FILE_DESCRIPTOR_H_ 18 | #define ANDROID_PARCEL_FILE_DESCRIPTOR_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace android { 25 | namespace os { 26 | 27 | /* 28 | * C++ implementation of the Java class android.os.ParcelFileDescriptor 29 | */ 30 | class ParcelFileDescriptor : public android::Parcelable { 31 | public: 32 | ParcelFileDescriptor(); 33 | explicit ParcelFileDescriptor(android::base::unique_fd fd); 34 | ParcelFileDescriptor(ParcelFileDescriptor&& other) : mFd(std::move(other.mFd)) { } 35 | ~ParcelFileDescriptor() override; 36 | 37 | int get() const { return mFd.get(); } 38 | android::base::unique_fd release() { return std::move(mFd); } 39 | void reset(android::base::unique_fd fd = android::base::unique_fd()) { mFd = std::move(fd); } 40 | 41 | // android::Parcelable override: 42 | android::status_t writeToParcel(android::Parcel* parcel) const override; 43 | android::status_t readFromParcel(const android::Parcel* parcel) override; 44 | 45 | private: 46 | android::base::unique_fd mFd; 47 | }; 48 | 49 | } // namespace os 50 | } // namespace android 51 | 52 | #endif // ANDROID_OS_PARCEL_FILE_DESCRIPTOR_H_ 53 | -------------------------------------------------------------------------------- /include/binder/Parcelable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | #ifndef ANDROID_PARCELABLE_H 18 | #define ANDROID_PARCELABLE_H 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | namespace android { 26 | 27 | class Parcel; 28 | 29 | #if defined(__clang__) 30 | #pragma clang diagnostic push 31 | #pragma clang diagnostic ignored "-Wweak-vtables" 32 | #endif 33 | 34 | // Abstract interface of all parcelables. 35 | class Parcelable { 36 | public: 37 | virtual ~Parcelable() = default; 38 | 39 | Parcelable() = default; 40 | Parcelable(const Parcelable&) = default; 41 | 42 | // Write |this| parcelable to the given |parcel|. Keep in mind that 43 | // implementations of writeToParcel must be manually kept in sync 44 | // with readFromParcel and the Java equivalent versions of these methods. 45 | // 46 | // Returns android::OK on success and an appropriate error otherwise. 47 | virtual status_t writeToParcel(Parcel* parcel) const = 0; 48 | 49 | // Read data from the given |parcel| into |this|. After readFromParcel 50 | // completes, |this| should have equivalent state to the object that 51 | // wrote itself to the parcel. 52 | // 53 | // Returns android::OK on success and an appropriate error otherwise. 54 | virtual status_t readFromParcel(const Parcel* parcel) = 0; 55 | }; // class Parcelable 56 | 57 | #if defined(__clang__) 58 | #pragma clang diagnostic pop 59 | #endif 60 | 61 | } // namespace android 62 | 63 | #endif // ANDROID_PARCELABLE_H 64 | -------------------------------------------------------------------------------- /include/binder/PermissionCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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 | #ifndef BINDER_PERMISSION_H 18 | #define BINDER_PERMISSION_H 19 | 20 | #ifndef __ANDROID_VNDK__ 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | namespace android { 30 | // --------------------------------------------------------------------------- 31 | 32 | /* 33 | * PermissionCache caches permission checks for a given uid. 34 | * 35 | * Currently the cache is not updated when there is a permission change, 36 | * for instance when an application is uninstalled. 37 | * 38 | * IMPORTANT: for the reason stated above, only system permissions are safe 39 | * to cache. This restriction may be lifted at a later time. 40 | * 41 | */ 42 | 43 | class PermissionCache : Singleton { 44 | struct Entry { 45 | String16 name; 46 | uid_t uid; 47 | bool granted; 48 | inline bool operator < (const Entry& e) const { 49 | return (uid == e.uid) ? (name < e.name) : (uid < e.uid); 50 | } 51 | }; 52 | mutable Mutex mLock; 53 | // we pool all the permission names we see, as many permissions checks 54 | // will have identical names 55 | SortedVector< String16 > mPermissionNamesPool; 56 | // this is our cache per say. it stores pooled names. 57 | SortedVector< Entry > mCache; 58 | 59 | // free the whole cache, but keep the permission name pool 60 | void purge(); 61 | 62 | status_t check(bool* granted, 63 | const String16& permission, uid_t uid) const; 64 | 65 | void cache(const String16& permission, uid_t uid, bool granted); 66 | 67 | public: 68 | PermissionCache(); 69 | 70 | static bool checkCallingPermission(const String16& permission); 71 | 72 | static bool checkCallingPermission(const String16& permission, 73 | int32_t* outPid, int32_t* outUid); 74 | 75 | static bool checkPermission(const String16& permission, 76 | pid_t pid, uid_t uid); 77 | }; 78 | 79 | // --------------------------------------------------------------------------- 80 | }; // namespace android 81 | 82 | #else // __ANDROID_VNDK__ 83 | #error "This header is not visible to vendors" 84 | #endif // __ANDROID_VNDK__ 85 | 86 | #endif /* BINDER_PERMISSION_H */ 87 | -------------------------------------------------------------------------------- /include/binder/PermissionController.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | #ifndef ANDROID_PERMISSION_CONTROLLER_H 18 | #define ANDROID_PERMISSION_CONTROLLER_H 19 | 20 | #ifndef __ANDROID_VNDK__ 21 | 22 | #include 23 | 24 | #include 25 | 26 | // --------------------------------------------------------------------------- 27 | namespace android { 28 | 29 | class PermissionController 30 | { 31 | public: 32 | 33 | enum { 34 | MATCH_SYSTEM_ONLY = 1<<16, 35 | MATCH_UNINSTALLED_PACKAGES = 1<<13, 36 | MATCH_FACTORY_ONLY = 1<<21, 37 | MATCH_INSTANT = 1<<23 38 | }; 39 | 40 | enum { 41 | MODE_ALLOWED = 0, 42 | MODE_IGNORED = 1, 43 | MODE_ERRORED = 2, 44 | MODE_DEFAULT = 3, 45 | }; 46 | 47 | PermissionController(); 48 | 49 | bool checkPermission(const String16& permission, int32_t pid, int32_t uid); 50 | int32_t noteOp(const String16& op, int32_t uid, const String16& packageName); 51 | void getPackagesForUid(const uid_t uid, Vector& packages); 52 | bool isRuntimePermission(const String16& permission); 53 | int getPackageUid(const String16& package, int flags); 54 | 55 | private: 56 | Mutex mLock; 57 | sp mService; 58 | 59 | sp getService(); 60 | }; 61 | 62 | 63 | }; // namespace android 64 | // --------------------------------------------------------------------------- 65 | #else // __ANDROID_VNDK__ 66 | #error "This header is not visible to vendors" 67 | #endif // __ANDROID_VNDK__ 68 | 69 | #endif // ANDROID_PERMISSION_CONTROLLER_H 70 | -------------------------------------------------------------------------------- /include/binder/PersistableBundle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 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 | #ifndef ANDROID_PERSISTABLE_BUNDLE_H 18 | #define ANDROID_PERSISTABLE_BUNDLE_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace android { 29 | 30 | namespace os { 31 | 32 | /* 33 | * C++ implementation of PersistableBundle, a mapping from String values to 34 | * various types that can be saved to persistent and later restored. 35 | */ 36 | class PersistableBundle : public Parcelable { 37 | public: 38 | PersistableBundle() = default; 39 | virtual ~PersistableBundle() = default; 40 | PersistableBundle(const PersistableBundle& bundle) = default; 41 | 42 | status_t writeToParcel(Parcel* parcel) const override; 43 | status_t readFromParcel(const Parcel* parcel) override; 44 | 45 | bool empty() const; 46 | size_t size() const; 47 | size_t erase(const String16& key); 48 | 49 | /* 50 | * Setters for PersistableBundle. Adds a a key-value pair instantiated with 51 | * |key| and |value| into the member map appropriate for the type of |value|. 52 | * If there is already an existing value for |key|, |value| will replace it. 53 | */ 54 | void putBoolean(const String16& key, bool value); 55 | void putInt(const String16& key, int32_t value); 56 | void putLong(const String16& key, int64_t value); 57 | void putDouble(const String16& key, double value); 58 | void putString(const String16& key, const String16& value); 59 | void putBooleanVector(const String16& key, const std::vector& value); 60 | void putIntVector(const String16& key, const std::vector& value); 61 | void putLongVector(const String16& key, const std::vector& value); 62 | void putDoubleVector(const String16& key, const std::vector& value); 63 | void putStringVector(const String16& key, const std::vector& value); 64 | void putPersistableBundle(const String16& key, const PersistableBundle& value); 65 | 66 | /* 67 | * Getters for PersistableBundle. If |key| exists, these methods write the 68 | * value associated with |key| into |out|, and return true. Otherwise, these 69 | * methods return false. 70 | */ 71 | bool getBoolean(const String16& key, bool* out) const; 72 | bool getInt(const String16& key, int32_t* out) const; 73 | bool getLong(const String16& key, int64_t* out) const; 74 | bool getDouble(const String16& key, double* out) const; 75 | bool getString(const String16& key, String16* out) const; 76 | bool getBooleanVector(const String16& key, std::vector* out) const; 77 | bool getIntVector(const String16& key, std::vector* out) const; 78 | bool getLongVector(const String16& key, std::vector* out) const; 79 | bool getDoubleVector(const String16& key, std::vector* out) const; 80 | bool getStringVector(const String16& key, std::vector* out) const; 81 | bool getPersistableBundle(const String16& key, PersistableBundle* out) const; 82 | 83 | /* Getters for all keys for each value type */ 84 | std::set getBooleanKeys() const; 85 | std::set getIntKeys() const; 86 | std::set getLongKeys() const; 87 | std::set getDoubleKeys() const; 88 | std::set getStringKeys() const; 89 | std::set getBooleanVectorKeys() const; 90 | std::set getIntVectorKeys() const; 91 | std::set getLongVectorKeys() const; 92 | std::set getDoubleVectorKeys() const; 93 | std::set getStringVectorKeys() const; 94 | std::set getPersistableBundleKeys() const; 95 | 96 | friend bool operator==(const PersistableBundle& lhs, const PersistableBundle& rhs) { 97 | return (lhs.mBoolMap == rhs.mBoolMap && lhs.mIntMap == rhs.mIntMap && 98 | lhs.mLongMap == rhs.mLongMap && lhs.mDoubleMap == rhs.mDoubleMap && 99 | lhs.mStringMap == rhs.mStringMap && lhs.mBoolVectorMap == rhs.mBoolVectorMap && 100 | lhs.mIntVectorMap == rhs.mIntVectorMap && 101 | lhs.mLongVectorMap == rhs.mLongVectorMap && 102 | lhs.mDoubleVectorMap == rhs.mDoubleVectorMap && 103 | lhs.mStringVectorMap == rhs.mStringVectorMap && 104 | lhs.mPersistableBundleMap == rhs.mPersistableBundleMap); 105 | } 106 | 107 | friend bool operator!=(const PersistableBundle& lhs, const PersistableBundle& rhs) { 108 | return !(lhs == rhs); 109 | } 110 | 111 | private: 112 | status_t writeToParcelInner(Parcel* parcel) const; 113 | status_t readFromParcelInner(const Parcel* parcel, size_t length); 114 | 115 | std::map mBoolMap; 116 | std::map mIntMap; 117 | std::map mLongMap; 118 | std::map mDoubleMap; 119 | std::map mStringMap; 120 | std::map> mBoolVectorMap; 121 | std::map> mIntVectorMap; 122 | std::map> mLongVectorMap; 123 | std::map> mDoubleVectorMap; 124 | std::map> mStringVectorMap; 125 | std::map mPersistableBundleMap; 126 | }; 127 | 128 | } // namespace os 129 | 130 | } // namespace android 131 | 132 | #endif // ANDROID_PERSISTABLE_BUNDLE_H 133 | -------------------------------------------------------------------------------- /include/binder/ProcessInfoService.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 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 | #ifndef ANDROID_PROCESS_INFO_SERVICE_H 18 | #define ANDROID_PROCESS_INFO_SERVICE_H 19 | 20 | #ifndef __ANDROID_VNDK__ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace android { 28 | 29 | // ---------------------------------------------------------------------- 30 | 31 | class ProcessInfoService : public Singleton { 32 | 33 | friend class Singleton; 34 | sp mProcessInfoService; 35 | Mutex mProcessInfoLock; 36 | 37 | ProcessInfoService(); 38 | 39 | status_t getProcessStatesImpl(size_t length, /*in*/ int32_t* pids, /*out*/ int32_t* states); 40 | status_t getProcessStatesScoresImpl(size_t length, /*in*/ int32_t* pids, 41 | /*out*/ int32_t* states, /*out*/ int32_t *scores); 42 | void updateBinderLocked(); 43 | 44 | static const int BINDER_ATTEMPT_LIMIT = 5; 45 | 46 | public: 47 | 48 | /** 49 | * For each PID in the given "pids" input array, write the current process state 50 | * for that process into the "states" output array, or 51 | * ActivityManager.PROCESS_STATE_NONEXISTENT * to indicate that no process with the given PID 52 | * exists. 53 | * 54 | * Returns NO_ERROR if this operation was successful, or a negative error code otherwise. 55 | */ 56 | static status_t getProcessStatesFromPids(size_t length, /*in*/ int32_t* pids, 57 | /*out*/ int32_t* states) { 58 | return ProcessInfoService::getInstance().getProcessStatesImpl(length, /*in*/ pids, 59 | /*out*/ states); 60 | } 61 | 62 | /** 63 | * For each PID in the given "pids" input array, write the current process state 64 | * for that process into the "states" output array, or 65 | * ActivityManager.PROCESS_STATE_NONEXISTENT * to indicate that no process with the given PID 66 | * exists. OoM scores will also be written in the "scores" output array. 67 | * Please also note that clients calling this method need to have 68 | * "GET_PROCESS_STATE_AND_OOM_SCORE" permission. 69 | * 70 | * Returns NO_ERROR if this operation was successful, or a negative error code otherwise. 71 | */ 72 | static status_t getProcessStatesScoresFromPids(size_t length, /*in*/ int32_t* pids, 73 | /*out*/ int32_t* states, /*out*/ int32_t *scores) { 74 | return ProcessInfoService::getInstance().getProcessStatesScoresImpl( 75 | length, /*in*/ pids, /*out*/ states, /*out*/ scores); 76 | } 77 | }; 78 | 79 | // ---------------------------------------------------------------------- 80 | 81 | }; // namespace android 82 | 83 | #else // __ANDROID_VNDK__ 84 | #error "This header is not visible to vendors" 85 | #endif // __ANDROID_VNDK__ 86 | 87 | #endif // ANDROID_PROCESS_INFO_SERVICE_H 88 | 89 | -------------------------------------------------------------------------------- /include/binder/ProcessState.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 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 | #ifndef ANDROID_PROCESS_STATE_H 18 | #define ANDROID_PROCESS_STATE_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | // --------------------------------------------------------------------------- 29 | namespace android { 30 | 31 | class IPCThreadState; 32 | 33 | class ProcessState : public virtual RefBase 34 | { 35 | public: 36 | static sp self(); 37 | static sp selfOrNull(); 38 | 39 | /* initWithDriver() can be used to configure libbinder to use 40 | * a different binder driver dev node. It must be called *before* 41 | * any call to ProcessState::self(). The default is /dev/vndbinder 42 | * for processes built with the VNDK and /dev/binder for those 43 | * which are not. 44 | */ 45 | static sp initWithDriver(const char *driver); 46 | 47 | void setContextObject(const sp& object); 48 | sp getContextObject(const sp& caller); 49 | 50 | void setContextObject(const sp& object, 51 | const String16& name); 52 | sp getContextObject(const String16& name, 53 | const sp& caller); 54 | 55 | void startThreadPool(); 56 | 57 | typedef bool (*context_check_func)(const String16& name, 58 | const sp& caller, 59 | void* userData); 60 | 61 | bool isContextManager(void) const; 62 | bool becomeContextManager( 63 | context_check_func checkFunc, 64 | void* userData); 65 | 66 | sp getStrongProxyForHandle(int32_t handle); 67 | wp getWeakProxyForHandle(int32_t handle); 68 | void expungeHandle(int32_t handle, IBinder* binder); 69 | 70 | void spawnPooledThread(bool isMain); 71 | 72 | status_t setThreadPoolMaxThreadCount(size_t maxThreads); 73 | void giveThreadPoolName(); 74 | 75 | String8 getDriverName(); 76 | 77 | ssize_t getKernelReferences(size_t count, uintptr_t* buf); 78 | 79 | enum class CallRestriction { 80 | // all calls okay 81 | NONE, 82 | // log when calls are blocking 83 | ERROR_IF_NOT_ONEWAY, 84 | // abort process on blocking calls 85 | FATAL_IF_NOT_ONEWAY, 86 | }; 87 | // Sets calling restrictions for all transactions in this process. This must be called 88 | // before any threads are spawned. 89 | void setCallRestriction(CallRestriction restriction); 90 | 91 | private: 92 | friend class IPCThreadState; 93 | 94 | explicit ProcessState(const char* driver); 95 | ~ProcessState(); 96 | 97 | ProcessState(const ProcessState& o); 98 | ProcessState& operator=(const ProcessState& o); 99 | String8 makeBinderThreadName(); 100 | 101 | struct handle_entry { 102 | IBinder* binder; 103 | RefBase::weakref_type* refs; 104 | }; 105 | 106 | handle_entry* lookupHandleLocked(int32_t handle); 107 | 108 | String8 mDriverName; 109 | int mDriverFD; 110 | void* mVMStart; 111 | 112 | // Protects thread count variable below. 113 | pthread_mutex_t mThreadCountLock; 114 | pthread_cond_t mThreadCountDecrement; 115 | // Number of binder threads current executing a command. 116 | size_t mExecutingThreadsCount; 117 | // Maximum number for binder threads allowed for this process. 118 | size_t mMaxThreads; 119 | // Time when thread pool was emptied 120 | int64_t mStarvationStartTimeMs; 121 | 122 | mutable Mutex mLock; // protects everything below. 123 | 124 | VectormHandleToObject; 125 | 126 | bool mManagesContexts; 127 | context_check_func mBinderContextCheckFunc; 128 | void* mBinderContextUserData; 129 | 130 | KeyedVector > 131 | mContexts; 132 | 133 | 134 | String8 mRootDir; 135 | bool mThreadPoolStarted; 136 | volatile int32_t mThreadPoolSeq; 137 | 138 | CallRestriction mCallRestriction; 139 | }; 140 | 141 | }; // namespace android 142 | 143 | // --------------------------------------------------------------------------- 144 | 145 | #endif // ANDROID_PROCESS_STATE_H 146 | -------------------------------------------------------------------------------- /include/private/binder/ParcelValTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | namespace android { 18 | namespace binder { 19 | 20 | // Keep in sync with frameworks/base/core/java/android/os/Parcel.java. 21 | enum { 22 | VAL_NULL = -1, 23 | VAL_STRING = 0, 24 | VAL_INTEGER = 1, 25 | VAL_MAP = 2, 26 | VAL_BUNDLE = 3, 27 | VAL_PARCELABLE = 4, 28 | VAL_SHORT = 5, 29 | VAL_LONG = 6, 30 | VAL_DOUBLE = 8, 31 | VAL_BOOLEAN = 9, 32 | VAL_BYTEARRAY = 13, 33 | VAL_STRINGARRAY = 14, 34 | VAL_IBINDER = 15, 35 | VAL_INTARRAY = 18, 36 | VAL_LONGARRAY = 19, 37 | VAL_BYTE = 20, 38 | VAL_SERIALIZABLE = 21, 39 | VAL_BOOLEANARRAY = 23, 40 | VAL_PERSISTABLEBUNDLE = 25, 41 | VAL_DOUBLEARRAY = 28, 42 | }; 43 | 44 | } // namespace binder 45 | } // namespace android 46 | -------------------------------------------------------------------------------- /include/private/binder/Static.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | // All static variables go here, to control initialization and 18 | // destruction order in the library. 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #ifndef __ANDROID_VNDK__ 25 | #include 26 | #endif 27 | #include 28 | 29 | namespace android { 30 | 31 | // For TextStream.cpp 32 | extern Vector gTextBuffers; 33 | 34 | // For ProcessState.cpp 35 | extern Mutex& gProcessMutex; 36 | extern sp gProcess; 37 | 38 | // For IServiceManager.cpp 39 | extern Mutex gDefaultServiceManagerLock; 40 | extern sp gDefaultServiceManager; 41 | #ifndef __ANDROID_VNDK__ 42 | extern sp gPermissionController; 43 | #endif 44 | extern bool gSystemBootCompleted; 45 | 46 | } // namespace android 47 | -------------------------------------------------------------------------------- /include/private/binder/binder_module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 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 | #ifndef _BINDER_MODULE_H_ 18 | #define _BINDER_MODULE_H_ 19 | 20 | #ifdef __cplusplus 21 | namespace android { 22 | #endif 23 | 24 | /* obtain structures and constants from the kernel header */ 25 | 26 | #include 27 | #include 28 | 29 | #ifdef __cplusplus 30 | } // namespace android 31 | #endif 32 | 33 | #endif // _BINDER_MODULE_H_ 34 | -------------------------------------------------------------------------------- /ndk/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | ColumnLimit: 100 3 | IndentWidth: 4 4 | ContinuationIndentWidth: 8 5 | PointerAlignment: Left 6 | TabWidth: 4 7 | AllowShortFunctionsOnASingleLine: Inline 8 | PointerAlignment: Left 9 | TabWidth: 4 10 | UseTab: Never 11 | -------------------------------------------------------------------------------- /ndk/Android.bp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | cc_library { 18 | name: "libbinder_ndk", 19 | vendor_available: true, 20 | 21 | export_include_dirs: [ 22 | "include_ndk", 23 | "include_apex", 24 | ], 25 | 26 | cflags: [ 27 | "-Wall", 28 | "-Wextra", 29 | "-Werror", 30 | ], 31 | 32 | srcs: [ 33 | "ibinder.cpp", 34 | "ibinder_jni.cpp", 35 | "parcel.cpp", 36 | "process.cpp", 37 | "status.cpp", 38 | "service_manager.cpp", 39 | ], 40 | 41 | shared_libs: [ 42 | "libandroid_runtime_lazy", 43 | "libbase", 44 | "libbinder", 45 | "libutils", 46 | ], 47 | 48 | header_libs: [ 49 | "jni_headers", 50 | ], 51 | export_header_lib_headers: [ 52 | "jni_headers", 53 | ], 54 | 55 | version_script: "libbinder_ndk.map.txt", 56 | stubs: { 57 | symbol_file: "libbinder_ndk.map.txt", 58 | versions: ["29"], 59 | }, 60 | } 61 | 62 | ndk_headers { 63 | name: "libbinder_ndk_headers", 64 | from: "include_ndk/android", 65 | to: "android", 66 | srcs: [ 67 | "include_ndk/android/*.h", 68 | ], 69 | license: "NOTICE", 70 | } 71 | 72 | ndk_library { 73 | name: "libbinder_ndk", 74 | symbol_file: "libbinder_ndk.map.txt", 75 | first_version: "29", 76 | } 77 | -------------------------------------------------------------------------------- /ndk/ibinder_jni.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | #include 18 | #include "ibinder_internal.h" 19 | 20 | #include 21 | 22 | using ::android::IBinder; 23 | using ::android::ibinderForJavaObject; 24 | using ::android::javaObjectForIBinder; 25 | using ::android::sp; 26 | 27 | AIBinder* AIBinder_fromJavaBinder(JNIEnv* env, jobject binder) { 28 | if (binder == nullptr) { 29 | return nullptr; 30 | } 31 | 32 | sp ibinder = ibinderForJavaObject(env, binder); 33 | sp cbinder = ABpBinder::lookupOrCreateFromBinder(ibinder); 34 | AIBinder_incStrong(cbinder.get()); 35 | 36 | return cbinder.get(); 37 | } 38 | 39 | jobject AIBinder_toJavaBinder(JNIEnv* env, AIBinder* binder) { 40 | if (binder == nullptr) { 41 | return nullptr; 42 | } 43 | 44 | return javaObjectForIBinder(env, binder->getBinder()); 45 | } 46 | -------------------------------------------------------------------------------- /ndk/include_apex/android/binder_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | __BEGIN_DECLS 23 | 24 | /** 25 | * This registers the service with the default service manager under this instance name. This does 26 | * not take ownership of binder. 27 | * 28 | * \param binder object to register globally with the service manager. 29 | * \param instance identifier of the service. This will be used to lookup the service. 30 | * 31 | * \return STATUS_OK on success. 32 | */ 33 | binder_status_t AServiceManager_addService(AIBinder* binder, const char* instance); 34 | 35 | /** 36 | * Gets a binder object with this specific instance name. Will return nullptr immediately if the 37 | * service is not available This also implicitly calls AIBinder_incStrong (so the caller of this 38 | * function is responsible for calling AIBinder_decStrong). 39 | * 40 | * \param instance identifier of the service used to lookup the service. 41 | */ 42 | __attribute__((warn_unused_result)) AIBinder* AServiceManager_checkService(const char* instance); 43 | 44 | /** 45 | * Gets a binder object with this specific instance name. Blocks for a couple of seconds waiting on 46 | * it. This also implicitly calls AIBinder_incStrong (so the caller of this function is responsible 47 | * for calling AIBinder_decStrong). 48 | * 49 | * \param instance identifier of the service used to lookup the service. 50 | */ 51 | __attribute__((warn_unused_result)) AIBinder* AServiceManager_getService(const char* instance); 52 | 53 | __END_DECLS 54 | -------------------------------------------------------------------------------- /ndk/include_apex/android/binder_process.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | __BEGIN_DECLS 23 | 24 | /** 25 | * This creates a threadpool for incoming binder transactions if it has not already been created. 26 | */ 27 | void ABinderProcess_startThreadPool(); 28 | /** 29 | * This sets the maximum number of threads that can be started in the threadpool. By default, after 30 | * startThreadPool is called, this is one. If it is called additional times, it will only prevent 31 | * the kernel from starting new threads and will not delete already existing threads. 32 | */ 33 | bool ABinderProcess_setThreadPoolMaxThreadCount(uint32_t numThreads); 34 | /** 35 | * This adds the current thread to the threadpool. This may cause the threadpool to exceed the 36 | * maximum size. 37 | */ 38 | void ABinderProcess_joinThreadPool(); 39 | 40 | __END_DECLS 41 | -------------------------------------------------------------------------------- /ndk/include_ndk/android/binder_ibinder_jni.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | /** 18 | * @addtogroup NdkBinder 19 | * @{ 20 | */ 21 | 22 | /** 23 | * @file binder_ibinder_jni.h 24 | * @brief Conversions between AIBinder and android.os.IBinder 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | #include 32 | 33 | __BEGIN_DECLS 34 | #if __ANDROID_API__ >= __ANDROID_API_Q__ 35 | 36 | /** 37 | * Converts an android.os.IBinder object into an AIBinder* object. 38 | * 39 | * If either env or the binder is null, null is returned. If this binder object was originally an 40 | * AIBinder object, the original object is returned. The returned object has one refcount 41 | * associated with it, and so this should be accompanied with an AIBinder_decStrong call. 42 | * 43 | * \param env Java environment. 44 | * \param binder android.os.IBinder java object. 45 | * 46 | * \return an AIBinder object representing the Java binder object. If either parameter is null, or 47 | * the Java object is of the wrong type, this will return null. 48 | */ 49 | __attribute__((warn_unused_result)) AIBinder* AIBinder_fromJavaBinder(JNIEnv* env, jobject binder) 50 | __INTRODUCED_IN(29); 51 | 52 | /** 53 | * Converts an AIBinder* object into an android.os.IBinder object. 54 | * 55 | * If either env or the binder is null, null is returned. If this binder object was originally an 56 | * IBinder object, the original java object will be returned. 57 | * 58 | * \param env Java environment. 59 | * \param binder the object to convert. 60 | * 61 | * \return an android.os.IBinder object or null if the parameters were null. 62 | */ 63 | __attribute__((warn_unused_result)) jobject AIBinder_toJavaBinder(JNIEnv* env, AIBinder* binder) 64 | __INTRODUCED_IN(29); 65 | 66 | #endif //__ANDROID_API__ >= __ANDROID_API_Q__ 67 | __END_DECLS 68 | 69 | /** @} */ 70 | -------------------------------------------------------------------------------- /ndk/libbinder_ndk.map.txt: -------------------------------------------------------------------------------- 1 | LIBBINDER_NDK { # introduced=29 2 | global: 3 | AIBinder_associateClass; 4 | AIBinder_Class_define; 5 | AIBinder_Class_setOnDump; 6 | AIBinder_DeathRecipient_delete; 7 | AIBinder_DeathRecipient_new; 8 | AIBinder_debugGetRefCount; 9 | AIBinder_decStrong; 10 | AIBinder_dump; 11 | AIBinder_fromJavaBinder; 12 | AIBinder_getCallingPid; 13 | AIBinder_getCallingUid; 14 | AIBinder_getClass; 15 | AIBinder_getUserData; 16 | AIBinder_incStrong; 17 | AIBinder_isAlive; 18 | AIBinder_isRemote; 19 | AIBinder_linkToDeath; 20 | AIBinder_new; 21 | AIBinder_ping; 22 | AIBinder_prepareTransaction; 23 | AIBinder_toJavaBinder; 24 | AIBinder_transact; 25 | AIBinder_unlinkToDeath; 26 | AIBinder_Weak_delete; 27 | AIBinder_Weak_new; 28 | AIBinder_Weak_promote; 29 | AParcel_delete; 30 | AParcel_getDataPosition; 31 | AParcel_readBool; 32 | AParcel_readBoolArray; 33 | AParcel_readByte; 34 | AParcel_readByteArray; 35 | AParcel_readChar; 36 | AParcel_readCharArray; 37 | AParcel_readDouble; 38 | AParcel_readDoubleArray; 39 | AParcel_readFloat; 40 | AParcel_readFloatArray; 41 | AParcel_readInt32; 42 | AParcel_readInt32Array; 43 | AParcel_readInt64; 44 | AParcel_readInt64Array; 45 | AParcel_readParcelableArray; 46 | AParcel_readParcelFileDescriptor; 47 | AParcel_readStatusHeader; 48 | AParcel_readString; 49 | AParcel_readStringArray; 50 | AParcel_readStrongBinder; 51 | AParcel_readUint32; 52 | AParcel_readUint32Array; 53 | AParcel_readUint64; 54 | AParcel_readUint64Array; 55 | AParcel_setDataPosition; 56 | AParcel_writeBool; 57 | AParcel_writeBoolArray; 58 | AParcel_writeByte; 59 | AParcel_writeByteArray; 60 | AParcel_writeChar; 61 | AParcel_writeCharArray; 62 | AParcel_writeDouble; 63 | AParcel_writeDoubleArray; 64 | AParcel_writeFloat; 65 | AParcel_writeFloatArray; 66 | AParcel_writeInt32; 67 | AParcel_writeInt32Array; 68 | AParcel_writeInt64; 69 | AParcel_writeInt64Array; 70 | AParcel_writeParcelableArray; 71 | AParcel_writeParcelFileDescriptor; 72 | AParcel_writeStatusHeader; 73 | AParcel_writeString; 74 | AParcel_writeStringArray; 75 | AParcel_writeStrongBinder; 76 | AParcel_writeUint32; 77 | AParcel_writeUint32Array; 78 | AParcel_writeUint64; 79 | AParcel_writeUint64Array; 80 | AStatus_delete; 81 | AStatus_fromExceptionCode; 82 | AStatus_fromExceptionCodeWithMessage; 83 | AStatus_fromServiceSpecificError; 84 | AStatus_fromServiceSpecificErrorWithMessage; 85 | AStatus_fromStatus; 86 | AStatus_getExceptionCode; 87 | AStatus_getMessage; 88 | AStatus_getServiceSpecificError; 89 | AStatus_getStatus; 90 | AStatus_isOk; 91 | AStatus_newOk; 92 | ABinderProcess_joinThreadPool; # apex 93 | ABinderProcess_setThreadPoolMaxThreadCount; # apex 94 | ABinderProcess_startThreadPool; # apex 95 | AServiceManager_addService; # apex 96 | AServiceManager_checkService; # apex 97 | AServiceManager_getService; # apex 98 | local: 99 | *; 100 | }; 101 | -------------------------------------------------------------------------------- /ndk/parcel_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | #pragma once 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include 24 | #include "ibinder_internal.h" 25 | 26 | struct AParcel { 27 | const ::android::Parcel* get() const { return mParcel; } 28 | ::android::Parcel* get() { return mParcel; } 29 | 30 | explicit AParcel(const AIBinder* binder) 31 | : AParcel(binder, new ::android::Parcel, true /*owns*/) {} 32 | AParcel(const AIBinder* binder, ::android::Parcel* parcel, bool owns) 33 | : mBinder(binder), mParcel(parcel), mOwns(owns) {} 34 | 35 | ~AParcel() { 36 | if (mOwns) { 37 | delete mParcel; 38 | } 39 | } 40 | 41 | static const AParcel readOnly(const AIBinder* binder, const ::android::Parcel* parcel) { 42 | return AParcel(binder, const_cast<::android::Parcel*>(parcel), false); 43 | } 44 | 45 | const AIBinder* getBinder() { return mBinder; } 46 | 47 | private: 48 | // This object is associated with a calls to a specific AIBinder object. This is used for sanity 49 | // checking to make sure that a parcel is one that is expected. 50 | const AIBinder* mBinder; 51 | 52 | ::android::Parcel* mParcel; 53 | bool mOwns; 54 | }; 55 | -------------------------------------------------------------------------------- /ndk/process.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | #include 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | using ::android::IPCThreadState; 25 | using ::android::ProcessState; 26 | 27 | void ABinderProcess_startThreadPool() { 28 | ProcessState::self()->startThreadPool(); 29 | ProcessState::self()->giveThreadPoolName(); 30 | } 31 | bool ABinderProcess_setThreadPoolMaxThreadCount(uint32_t numThreads) { 32 | return ProcessState::self()->setThreadPoolMaxThreadCount(numThreads) == 0; 33 | } 34 | void ABinderProcess_joinThreadPool() { 35 | IPCThreadState::self()->joinThreadPool(); 36 | } 37 | -------------------------------------------------------------------------------- /ndk/runtests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright (C) 2018 The Android Open Source Project 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | if [ -z $ANDROID_BUILD_TOP ]; then 18 | echo "You need to source and lunch before you can use this script" 19 | exit 1 20 | fi 21 | 22 | set -ex 23 | 24 | function run_libbinder_ndk_test() { 25 | adb shell /data/nativetest64/libbinder_ndk_test_server/libbinder_ndk_test_server & 26 | 27 | # avoid getService 1s delay for most runs, non-critical 28 | sleep 0.1 29 | 30 | adb shell /data/nativetest64/libbinder_ndk_test_client/libbinder_ndk_test_client; \ 31 | adb shell killall libbinder_ndk_test_server 32 | } 33 | 34 | [ "$1" != "--skip-build" ] && $ANDROID_BUILD_TOP/build/soong/soong_ui.bash --make-mode \ 35 | MODULES-IN-frameworks-native-libs-binder-ndk 36 | 37 | adb root 38 | adb wait-for-device 39 | adb sync data 40 | 41 | # very simple unit tests, tests things outside of the NDK as well 42 | run_libbinder_ndk_test 43 | 44 | # CTS tests (much more comprehensive, new tests should ideally go here) 45 | atest android.binder.cts 46 | -------------------------------------------------------------------------------- /ndk/scripts/format.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright (C) 2018 The Android Open Source Project 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | 19 | echo "Formatting code" 20 | 21 | bpfmt -w $(find $ANDROID_BUILD_TOP/frameworks/native/libs/binder/ndk/ -name "Android.bp") 22 | clang-format -i $(find $ANDROID_BUILD_TOP/frameworks/native/libs/binder/ndk/ -\( -name "*.cpp" -o -name "*.h" -\)) 23 | -------------------------------------------------------------------------------- /ndk/scripts/init_map.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Simple helper for ease of development until this API is frozen. 4 | 5 | echo "LIBBINDER_NDK { # introduced=29" 6 | echo " global:" 7 | { 8 | grep -oP "AIBinder_[a-zA-Z0-9_]+(?=\()" include_ndk/android/binder_ibinder.h; 9 | grep -oP "AIBinder_[a-zA-Z0-9_]+(?=\()" include_ndk/android/binder_ibinder_jni.h; 10 | grep -oP "AParcel_[a-zA-Z0-9_]+(?=\()" include_ndk/android/binder_parcel.h; 11 | grep -oP "AStatus_[a-zA-Z0-9_]+(?=\()" include_ndk/android/binder_status.h; 12 | } | sort | uniq | awk '{ print " " $0 ";"; }' 13 | { 14 | grep -oP "AServiceManager_[a-zA-Z0-9_]+(?=\()" include_apex/android/binder_manager.h; 15 | grep -oP "ABinderProcess_[a-zA-Z0-9_]+(?=\()" include_apex/android/binder_process.h; 16 | } | sort | uniq | awk '{ print " " $0 "; # apex"; }' 17 | echo " local:" 18 | echo " *;" 19 | echo "};" 20 | -------------------------------------------------------------------------------- /ndk/service_manager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | #include 18 | 19 | #include "ibinder_internal.h" 20 | #include "status_internal.h" 21 | 22 | #include 23 | 24 | using ::android::defaultServiceManager; 25 | using ::android::IBinder; 26 | using ::android::IServiceManager; 27 | using ::android::sp; 28 | using ::android::status_t; 29 | using ::android::String16; 30 | 31 | binder_status_t AServiceManager_addService(AIBinder* binder, const char* instance) { 32 | if (binder == nullptr || instance == nullptr) { 33 | return STATUS_UNEXPECTED_NULL; 34 | } 35 | 36 | sp sm = defaultServiceManager(); 37 | status_t status = sm->addService(String16(instance), binder->getBinder()); 38 | return PruneStatusT(status); 39 | } 40 | AIBinder* AServiceManager_checkService(const char* instance) { 41 | if (instance == nullptr) { 42 | return nullptr; 43 | } 44 | 45 | sp sm = defaultServiceManager(); 46 | sp binder = sm->checkService(String16(instance)); 47 | 48 | sp ret = ABpBinder::lookupOrCreateFromBinder(binder); 49 | AIBinder_incStrong(ret.get()); 50 | return ret.get(); 51 | } 52 | AIBinder* AServiceManager_getService(const char* instance) { 53 | if (instance == nullptr) { 54 | return nullptr; 55 | } 56 | 57 | sp sm = defaultServiceManager(); 58 | sp binder = sm->getService(String16(instance)); 59 | 60 | sp ret = ABpBinder::lookupOrCreateFromBinder(binder); 61 | AIBinder_incStrong(ret.get()); 62 | return ret.get(); 63 | } 64 | -------------------------------------------------------------------------------- /ndk/status.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | #include 18 | #include "status_internal.h" 19 | 20 | #include 21 | 22 | using ::android::status_t; 23 | using ::android::binder::Status; 24 | 25 | AStatus* AStatus_newOk() { 26 | return new AStatus(); 27 | } 28 | 29 | AStatus* AStatus_fromExceptionCode(binder_exception_t exception) { 30 | return new AStatus(Status::fromExceptionCode(PruneException(exception))); 31 | } 32 | 33 | AStatus* AStatus_fromExceptionCodeWithMessage(binder_exception_t exception, const char* message) { 34 | return new AStatus(Status::fromExceptionCode(PruneException(exception), message)); 35 | } 36 | 37 | AStatus* AStatus_fromServiceSpecificError(int32_t serviceSpecific) { 38 | return new AStatus(Status::fromServiceSpecificError(serviceSpecific)); 39 | } 40 | 41 | AStatus* AStatus_fromServiceSpecificErrorWithMessage(int32_t serviceSpecific, const char* message) { 42 | return new AStatus(Status::fromServiceSpecificError(serviceSpecific, message)); 43 | } 44 | 45 | AStatus* AStatus_fromStatus(binder_status_t status) { 46 | return new AStatus(Status::fromStatusT(PruneStatusT(status))); 47 | } 48 | 49 | bool AStatus_isOk(const AStatus* status) { 50 | return status->get()->isOk(); 51 | } 52 | 53 | binder_exception_t AStatus_getExceptionCode(const AStatus* status) { 54 | return PruneException(status->get()->exceptionCode()); 55 | } 56 | 57 | int32_t AStatus_getServiceSpecificError(const AStatus* status) { 58 | return status->get()->serviceSpecificErrorCode(); 59 | } 60 | 61 | binder_status_t AStatus_getStatus(const AStatus* status) { 62 | return PruneStatusT(status->get()->transactionError()); 63 | } 64 | 65 | const char* AStatus_getMessage(const AStatus* status) { 66 | return status->get()->exceptionMessage().c_str(); 67 | } 68 | 69 | void AStatus_delete(AStatus* status) { 70 | delete status; 71 | } 72 | 73 | binder_status_t PruneStatusT(status_t status) { 74 | switch (status) { 75 | case ::android::OK: 76 | return STATUS_OK; 77 | case ::android::NO_MEMORY: 78 | return STATUS_NO_MEMORY; 79 | case ::android::INVALID_OPERATION: 80 | return STATUS_INVALID_OPERATION; 81 | case ::android::BAD_VALUE: 82 | return STATUS_BAD_VALUE; 83 | case ::android::BAD_TYPE: 84 | return STATUS_BAD_TYPE; 85 | case ::android::NAME_NOT_FOUND: 86 | return STATUS_NAME_NOT_FOUND; 87 | case ::android::PERMISSION_DENIED: 88 | return STATUS_PERMISSION_DENIED; 89 | case ::android::NO_INIT: 90 | return STATUS_NO_INIT; 91 | case ::android::ALREADY_EXISTS: 92 | return STATUS_ALREADY_EXISTS; 93 | case ::android::DEAD_OBJECT: 94 | return STATUS_DEAD_OBJECT; 95 | case ::android::FAILED_TRANSACTION: 96 | return STATUS_FAILED_TRANSACTION; 97 | case ::android::BAD_INDEX: 98 | return STATUS_BAD_INDEX; 99 | case ::android::NOT_ENOUGH_DATA: 100 | return STATUS_NOT_ENOUGH_DATA; 101 | case ::android::WOULD_BLOCK: 102 | return STATUS_WOULD_BLOCK; 103 | case ::android::TIMED_OUT: 104 | return STATUS_TIMED_OUT; 105 | case ::android::UNKNOWN_TRANSACTION: 106 | return STATUS_UNKNOWN_TRANSACTION; 107 | case ::android::FDS_NOT_ALLOWED: 108 | return STATUS_FDS_NOT_ALLOWED; 109 | case ::android::UNEXPECTED_NULL: 110 | return STATUS_UNEXPECTED_NULL; 111 | case ::android::UNKNOWN_ERROR: 112 | return STATUS_UNKNOWN_ERROR; 113 | 114 | default: 115 | LOG(WARNING) << __func__ 116 | << ": Unknown status_t pruned into STATUS_UNKNOWN_ERROR: " << status; 117 | return STATUS_UNKNOWN_ERROR; 118 | } 119 | } 120 | 121 | binder_exception_t PruneException(int32_t exception) { 122 | switch (exception) { 123 | case Status::EX_NONE: 124 | return EX_NONE; 125 | case Status::EX_SECURITY: 126 | return EX_SECURITY; 127 | case Status::EX_BAD_PARCELABLE: 128 | return EX_BAD_PARCELABLE; 129 | case Status::EX_ILLEGAL_ARGUMENT: 130 | return EX_ILLEGAL_ARGUMENT; 131 | case Status::EX_NULL_POINTER: 132 | return EX_NULL_POINTER; 133 | case Status::EX_ILLEGAL_STATE: 134 | return EX_ILLEGAL_STATE; 135 | case Status::EX_NETWORK_MAIN_THREAD: 136 | return EX_NETWORK_MAIN_THREAD; 137 | case Status::EX_UNSUPPORTED_OPERATION: 138 | return EX_UNSUPPORTED_OPERATION; 139 | case Status::EX_SERVICE_SPECIFIC: 140 | return EX_SERVICE_SPECIFIC; 141 | case Status::EX_PARCELABLE: 142 | return EX_PARCELABLE; 143 | case Status::EX_TRANSACTION_FAILED: 144 | return EX_TRANSACTION_FAILED; 145 | 146 | default: 147 | LOG(WARNING) << __func__ 148 | << ": Unknown status_t pruned into EX_TRANSACTION_FAILED: " << exception; 149 | return EX_TRANSACTION_FAILED; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /ndk/status_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | #pragma once 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | struct AStatus { 25 | AStatus() {} // ok 26 | explicit AStatus(::android::binder::Status&& status) : mStatus(std::move(status)) {} 27 | 28 | ::android::binder::Status* get() { return &mStatus; } 29 | const ::android::binder::Status* get() const { return &mStatus; } 30 | 31 | private: 32 | ::android::binder::Status mStatus; 33 | }; 34 | 35 | // This collapses the statuses into the declared range. 36 | binder_status_t PruneStatusT(android::status_t status); 37 | 38 | // This collapses the exception into the declared range. 39 | binder_exception_t PruneException(int32_t exception); 40 | -------------------------------------------------------------------------------- /ndk/test/Android.bp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | cc_defaults { 18 | name: "test_libbinder_ndk_defaults", 19 | shared_libs: [ 20 | "libbase", 21 | ], 22 | strip: { 23 | none: true, 24 | }, 25 | cflags: [ 26 | "-O0", 27 | "-g", 28 | ], 29 | } 30 | 31 | cc_library_static { 32 | name: "test_libbinder_ndk_library", 33 | defaults: ["test_libbinder_ndk_defaults"], 34 | export_include_dirs: ["include"], 35 | shared_libs: ["libbinder_ndk"], 36 | export_shared_lib_headers: ["libbinder_ndk"], 37 | srcs: ["iface.cpp"], 38 | } 39 | 40 | cc_defaults { 41 | name: "test_libbinder_ndk_test_defaults", 42 | defaults: ["test_libbinder_ndk_defaults"], 43 | shared_libs: [ 44 | "libandroid_runtime_lazy", 45 | "libbase", 46 | "libbinder", 47 | "libutils", 48 | ], 49 | static_libs: [ 50 | "libbinder_ndk", 51 | "test_libbinder_ndk_library", 52 | ], 53 | } 54 | 55 | // This test is a unit test of the low-level API that is presented here, 56 | // specifically the parts which are outside of the NDK. Actual users should 57 | // also instead use AIDL to generate these stubs. See android.binder.cts. 58 | cc_test { 59 | name: "libbinder_ndk_test_client", 60 | defaults: ["test_libbinder_ndk_test_defaults"], 61 | srcs: ["main_client.cpp"], 62 | } 63 | 64 | cc_test { 65 | name: "libbinder_ndk_test_server", 66 | defaults: ["test_libbinder_ndk_test_defaults"], 67 | srcs: ["main_server.cpp"], 68 | gtest: false, 69 | } 70 | -------------------------------------------------------------------------------- /ndk/test/include/iface/iface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | // warning: it is recommended to use AIDL output instead of this. binder_ibinder_utils.h and some of 23 | // the other niceties make sure that, for instance, binder proxies are always the same. They also 24 | // don't use internal Android APIs like refbase which are used here only for convenience. 25 | 26 | class IFoo : public virtual ::android::RefBase { 27 | public: 28 | static const char* kSomeInstanceName; 29 | static const char* kInstanceNameToDieFor; 30 | 31 | static AIBinder_Class* kClass; 32 | 33 | // Takes ownership of IFoo 34 | binder_status_t addService(const char* instance); 35 | static ::android::sp getService(const char* instance, AIBinder** outBinder = nullptr); 36 | 37 | enum Call { 38 | DOFOO = FIRST_CALL_TRANSACTION + 0, 39 | DIE = FIRST_CALL_TRANSACTION + 1, 40 | }; 41 | 42 | virtual ~IFoo(); 43 | 44 | virtual binder_status_t doubleNumber(int32_t in, int32_t* out) = 0; 45 | virtual binder_status_t die() = 0; 46 | 47 | private: 48 | // this variable is only when IFoo is local (since this test combines 'IFoo' and 'BnFoo'), not 49 | // for BpFoo. 50 | AIBinder_Weak* mWeakBinder = nullptr; 51 | }; 52 | -------------------------------------------------------------------------------- /ndk/test/main_server.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 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 | #include 18 | #include 19 | #include 20 | 21 | using ::android::sp; 22 | 23 | class MyFoo : public IFoo { 24 | binder_status_t doubleNumber(int32_t in, int32_t* out) override { 25 | *out = 2 * in; 26 | LOG(INFO) << "doubleNumber (" << in << ") => " << *out; 27 | return STATUS_OK; 28 | } 29 | 30 | binder_status_t die() override { 31 | LOG(FATAL) << "IFoo::die called!"; 32 | return STATUS_UNKNOWN_ERROR; 33 | } 34 | }; 35 | 36 | int service(const char* instance) { 37 | ABinderProcess_setThreadPoolMaxThreadCount(0); 38 | 39 | // Strong reference to MyFoo kept by service manager. 40 | binder_status_t status = (new MyFoo)->addService(instance); 41 | 42 | if (status != STATUS_OK) { 43 | LOG(FATAL) << "Could not register: " << status << " " << instance; 44 | } 45 | 46 | ABinderProcess_joinThreadPool(); 47 | 48 | return 1; // should not return 49 | } 50 | 51 | int main() { 52 | if (fork() == 0) { 53 | return service(IFoo::kInstanceNameToDieFor); 54 | } 55 | 56 | return service(IFoo::kSomeInstanceName); 57 | } 58 | -------------------------------------------------------------------------------- /ndk/update.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright (C) 2018 The Android Open Source Project 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | set -ex 19 | 20 | # This script makes sure that the source code is in sync with the various scripts 21 | ./scripts/gen_parcel_helper.py 22 | ./scripts/format.sh 23 | ./scripts/init_map.sh > libbinder_ndk.map.txt 24 | -------------------------------------------------------------------------------- /tests/Android.bp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2014 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 | cc_defaults { 18 | name: "binder_test_defaults", 19 | cflags: [ 20 | "-Wall", 21 | "-Werror", 22 | "-Wno-unused-private-field", 23 | "-Wno-unused-variable", 24 | ], 25 | } 26 | 27 | cc_test { 28 | name: "binderDriverInterfaceTest_IPC_32", 29 | srcs: ["binderDriverInterfaceTest.cpp"], 30 | defaults: ["binder_test_defaults"], 31 | compile_multilib: "32", 32 | cflags: ["-DBINDER_IPC_32BIT=1"], 33 | } 34 | 35 | cc_test { 36 | product_variables: { 37 | binder32bit: { 38 | cflags: ["-DBINDER_IPC_32BIT=1"], 39 | }, 40 | }, 41 | 42 | name: "binderDriverInterfaceTest", 43 | srcs: ["binderDriverInterfaceTest.cpp"], 44 | defaults: ["binder_test_defaults"], 45 | } 46 | 47 | cc_test { 48 | name: "binderValueTypeTest", 49 | srcs: ["binderValueTypeTest.cpp"], 50 | defaults: ["binder_test_defaults"], 51 | shared_libs: [ 52 | "libbinder", 53 | "libutils", 54 | ], 55 | } 56 | 57 | cc_test { 58 | name: "binderLibTest_IPC_32", 59 | srcs: ["binderLibTest.cpp"], 60 | defaults: ["binder_test_defaults"], 61 | shared_libs: [ 62 | "libbinder", 63 | "libutils", 64 | ], 65 | compile_multilib: "32", 66 | cflags: ["-DBINDER_IPC_32BIT=1"], 67 | } 68 | 69 | cc_test { 70 | product_variables: { 71 | binder32bit: { 72 | cflags: ["-DBINDER_IPC_32BIT=1"], 73 | }, 74 | }, 75 | 76 | defaults: ["binder_test_defaults"], 77 | name: "binderLibTest", 78 | srcs: ["binderLibTest.cpp"], 79 | shared_libs: [ 80 | "libbinder", 81 | "libutils", 82 | ], 83 | } 84 | 85 | cc_test { 86 | name: "binderThroughputTest", 87 | srcs: ["binderThroughputTest.cpp"], 88 | defaults: ["binder_test_defaults"], 89 | shared_libs: [ 90 | "libbinder", 91 | "libutils", 92 | ], 93 | clang: true, 94 | cflags: [ 95 | "-g", 96 | "-Wno-missing-field-initializers", 97 | "-Wno-sign-compare", 98 | "-O3", 99 | ], 100 | } 101 | 102 | cc_test { 103 | name: "binderTextOutputTest", 104 | srcs: ["binderTextOutputTest.cpp"], 105 | defaults: ["binder_test_defaults"], 106 | shared_libs: [ 107 | "libbinder", 108 | "libutils", 109 | "libbase", 110 | ], 111 | } 112 | 113 | cc_test { 114 | name: "schd-dbg", 115 | srcs: ["schd-dbg.cpp"], 116 | defaults: ["binder_test_defaults"], 117 | shared_libs: [ 118 | "libbinder", 119 | "libutils", 120 | "libbase", 121 | ], 122 | } 123 | 124 | cc_test { 125 | name: "binderSafeInterfaceTest", 126 | srcs: ["binderSafeInterfaceTest.cpp"], 127 | defaults: ["binder_test_defaults"], 128 | 129 | cppflags: [ 130 | "-Weverything", 131 | "-Wno-c++98-compat", 132 | "-Wno-c++98-compat-pedantic", 133 | "-Wno-global-constructors", 134 | "-Wno-padded", 135 | "-Wno-weak-vtables", 136 | ], 137 | 138 | cpp_std: "experimental", 139 | gnu_extensions: false, 140 | 141 | shared_libs: [ 142 | "libbinder", 143 | "libcutils", 144 | "liblog", 145 | "libutils", 146 | ], 147 | } 148 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | "${EXTERNAL_GOOGLETEST_DIR}/googletest/include" 3 | "${EXTERNAL_GOOGLETEST_DIR}/googlemock/include" 4 | ) 5 | 6 | add_executable(binderDriverInterfaceTest "binderDriverInterfaceTest.cpp") 7 | target_link_libraries(binderDriverInterfaceTest gtest) 8 | 9 | add_executable(binderLibTest "binderLibTest.cpp") 10 | target_link_libraries(binderLibTest binder gtest) 11 | 12 | add_executable(binderThroughputTest "binderThroughputTest.cpp") 13 | target_link_libraries(binderThroughputTest binder utils gtest) 14 | 15 | gtest_discover_tests(binderDriverInterfaceTest binderLibTest binderThroughputTest) 16 | -------------------------------------------------------------------------------- /tests/binderTextOutputTest.cpp: -------------------------------------------------------------------------------- 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 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "android-base/file.h" 24 | #include "android-base/test_utils.h" 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | static void CheckMessage(CapturedStderr& cap, 32 | const char* expected, 33 | bool singleline) { 34 | cap.Stop(); 35 | std::string output = cap.str(); 36 | if (singleline) 37 | output.erase(std::remove(output.begin(), output.end(), '\n')); 38 | ASSERT_EQ(output, expected); 39 | } 40 | 41 | #define CHECK_LOG_(input, expect, singleline) \ 42 | { \ 43 | CapturedStderr cap; \ 44 | android::aerr << input << android::endl; \ 45 | CheckMessage(cap, expect, singleline); \ 46 | } \ 47 | 48 | #define CHECK_VAL_(val, singleline) \ 49 | { \ 50 | std::stringstream ss; \ 51 | ss << val; \ 52 | std::string s = ss.str(); \ 53 | CHECK_LOG_(val, s.c_str(), singleline); \ 54 | } \ 55 | 56 | #define CHECK_LOG(input, expect) CHECK_LOG_(input, expect, true) 57 | #define CHECK_VAL(val) CHECK_VAL_(val, true) 58 | 59 | TEST(TextOutput, HandlesStdEndl) { 60 | CapturedStderr cap; 61 | android::aerr << "foobar" << std::endl; 62 | cap.Stop(); 63 | ASSERT_EQ(cap.str(), "foobar\n"); 64 | } 65 | 66 | TEST(TextOutput, HandlesCEndl) { 67 | CapturedStderr cap; 68 | android::aerr << "foobar" << "\n"; 69 | cap.Stop(); 70 | ASSERT_EQ(cap.str(), "foobar\n"); 71 | } 72 | 73 | TEST(TextOutput, HandlesAndroidEndl) { 74 | CapturedStderr cap; 75 | android::aerr << "foobar" << android::endl; 76 | cap.Stop(); 77 | ASSERT_EQ(cap.str(), "foobar\n"); 78 | } 79 | 80 | TEST(TextOutput, HandleEmptyString) { 81 | CHECK_LOG("", ""); 82 | } 83 | 84 | TEST(TextOutput, HandleString) { 85 | CHECK_LOG("foobar", "foobar"); 86 | } 87 | 88 | TEST(TextOutput, HandleNum) { 89 | CHECK_LOG(12345, "12345"); 90 | } 91 | 92 | TEST(TextOutput, HandleBool) { 93 | CHECK_LOG(false, "false"); 94 | } 95 | 96 | TEST(TextOutput, HandleChar) { 97 | CHECK_LOG('T', "T"); 98 | } 99 | 100 | TEST(TextOutput, HandleParcel) { 101 | android::Parcel val; 102 | CHECK_LOG(val, "Parcel(NULL)"); 103 | } 104 | 105 | TEST(TextOutput, HandleHexDump) { 106 | const char buf[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; 107 | android::HexDump val(buf, sizeof(buf)); 108 | CHECK_LOG(val, "03020100 07060504 0b0a0908 0f0e0d0c '................'"); 109 | } 110 | 111 | TEST(TextOutput, HandleHexDumpCustom) { 112 | const char buf[4] = {0x11,0x22,0x33,0x44}; 113 | android::HexDump val(buf, sizeof(buf), 4); 114 | CHECK_LOG(val, "11 22 33 44 '.\"3D'"); 115 | } 116 | 117 | TEST(TextOutput, HandleTypeCode) { 118 | android::TypeCode val(1234); 119 | CHECK_LOG(val, "'\\x04\\xd2'"); 120 | } 121 | 122 | TEST(TextOutput, HandleCookie) { 123 | int32_t val = 321; //0x141 124 | CHECK_LOG((void*)(long)val, "0x141"); 125 | } 126 | 127 | TEST(TextOutput, HandleString8) { 128 | android::String8 val("foobar"); 129 | CHECK_LOG(val, "foobar"); 130 | } 131 | 132 | TEST(TextOutput, HandleString16) { 133 | android::String16 val("foobar"); 134 | CHECK_LOG(val, "foobar"); 135 | } 136 | 137 | template 138 | class TextTest : public testing::Test {}; 139 | 140 | typedef testing::Types TestTypes; 145 | TYPED_TEST_CASE(TextTest, TestTypes); 146 | 147 | TYPED_TEST(TextTest, TextMax) 148 | { 149 | TypeParam max = std::numeric_limits::max(); 150 | CHECK_VAL(max); 151 | } 152 | 153 | TYPED_TEST(TextTest, TestMin) 154 | { 155 | TypeParam min = std::numeric_limits::min(); 156 | CHECK_VAL(min); 157 | } 158 | 159 | TYPED_TEST(TextTest, TestDenom) 160 | { 161 | TypeParam min = std::numeric_limits::denorm_min(); 162 | CHECK_VAL(min); 163 | } 164 | 165 | TYPED_TEST(TextTest, TestEpsilon) 166 | { 167 | TypeParam eps = std::numeric_limits::epsilon(); 168 | CHECK_VAL(eps); 169 | } 170 | -------------------------------------------------------------------------------- /tests/binderValueTypeTest.cpp: -------------------------------------------------------------------------------- 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 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "android-base/file.h" 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | using ::android::binder::Value; 32 | using ::android::os::PersistableBundle; 33 | using ::android::String16; 34 | using ::std::vector; 35 | 36 | #define VALUE_TYPE_TEST(T, TYPENAME, VAL) \ 37 | TEST(ValueType, Handles ## TYPENAME) { \ 38 | T x = VAL; \ 39 | T y = T(); \ 40 | Value value = VAL; \ 41 | ASSERT_FALSE(value.empty()); \ 42 | ASSERT_TRUE(value.is ## TYPENAME ()); \ 43 | ASSERT_TRUE(value.get ## TYPENAME (&y)); \ 44 | ASSERT_EQ(x, y); \ 45 | ASSERT_EQ(value, Value(y)); \ 46 | value.put ## TYPENAME (x); \ 47 | ASSERT_EQ(value, Value(y)); \ 48 | value = Value(); \ 49 | ASSERT_TRUE(value.empty()); \ 50 | ASSERT_NE(value, Value(y)); \ 51 | value = y; \ 52 | ASSERT_EQ(value, Value(x)); \ 53 | } 54 | 55 | #define VALUE_TYPE_VECTOR_TEST(T, TYPENAME, VAL) \ 56 | TEST(ValueType, Handles ## TYPENAME ## Vector) { \ 57 | vector x; \ 58 | vector y; \ 59 | x.push_back(VAL); \ 60 | x.push_back(T()); \ 61 | Value value(x); \ 62 | ASSERT_FALSE(value.empty()); \ 63 | ASSERT_TRUE(value.is ## TYPENAME ## Vector()); \ 64 | ASSERT_TRUE(value.get ## TYPENAME ## Vector(&y)); \ 65 | ASSERT_EQ(x, y); \ 66 | ASSERT_EQ(value, Value(y)); \ 67 | value.put ## TYPENAME ## Vector(x); \ 68 | ASSERT_EQ(value, Value(y)); \ 69 | value = Value(); \ 70 | ASSERT_TRUE(value.empty()); \ 71 | ASSERT_NE(value, Value(y)); \ 72 | value = y; \ 73 | ASSERT_EQ(value, Value(x)); \ 74 | } 75 | 76 | VALUE_TYPE_TEST(bool, Boolean, true) 77 | VALUE_TYPE_TEST(int32_t, Int, 31337) 78 | VALUE_TYPE_TEST(int64_t, Long, 13370133701337L) 79 | VALUE_TYPE_TEST(double, Double, 3.14159265358979323846) 80 | VALUE_TYPE_TEST(String16, String, String16("Lovely")) 81 | 82 | VALUE_TYPE_VECTOR_TEST(bool, Boolean, true) 83 | VALUE_TYPE_VECTOR_TEST(int32_t, Int, 31337) 84 | VALUE_TYPE_VECTOR_TEST(int64_t, Long, 13370133701337L) 85 | VALUE_TYPE_VECTOR_TEST(double, Double, 3.14159265358979323846) 86 | VALUE_TYPE_VECTOR_TEST(String16, String, String16("Lovely")) 87 | 88 | VALUE_TYPE_TEST(PersistableBundle, PersistableBundle, PersistableBundle()) 89 | 90 | TEST(ValueType, HandlesClear) { 91 | Value value; 92 | ASSERT_TRUE(value.empty()); 93 | value.putInt(31337); 94 | ASSERT_FALSE(value.empty()); 95 | value.clear(); 96 | ASSERT_TRUE(value.empty()); 97 | } 98 | 99 | TEST(ValueType, HandlesSwap) { 100 | Value value_a, value_b; 101 | int32_t int_x; 102 | value_a.putInt(31337); 103 | ASSERT_FALSE(value_a.empty()); 104 | ASSERT_TRUE(value_b.empty()); 105 | value_a.swap(value_b); 106 | ASSERT_FALSE(value_b.empty()); 107 | ASSERT_TRUE(value_a.empty()); 108 | ASSERT_TRUE(value_b.getInt(&int_x)); 109 | ASSERT_EQ(31337, int_x); 110 | } 111 | --------------------------------------------------------------------------------