Merge "Fix clang-tidy performance warnings in frameworks/native."
diff --git a/cmds/installd/Android.bp b/cmds/installd/Android.bp
index 94c3102..9d0d8ba 100644
--- a/cmds/installd/Android.bp
+++ b/cmds/installd/Android.bp
@@ -108,10 +108,8 @@
"-Wall",
"-Werror"
],
- clang: true,
- srcs: [
- "otapreopt_parameters.cpp"],
+ srcs: ["otapreopt_parameters.cpp"],
export_include_dirs: ["."],
@@ -123,4 +121,39 @@
],
}
-subdirs = ["tests"]
+//
+// OTA Executable
+//
+
+cc_binary {
+ name: "otapreopt",
+ cflags: [
+ "-Wall",
+ "-Werror"
+ ],
+
+ srcs: [
+ "dexopt.cpp",
+ "globals.cpp",
+ "otapreopt.cpp",
+ "utils.cpp",
+ ],
+
+ header_libs: ["dex2oat_headers"],
+
+ static_libs: [
+ "libartimagevalues",
+ "libdiskusage",
+ "libotapreoptparameters",
+ ],
+
+ shared_libs: [
+ "libbase",
+ "libcrypto",
+ "libcutils",
+ "liblog",
+ "liblogwrap",
+ "libselinux",
+ "libutils",
+ ],
+}
diff --git a/cmds/installd/Android.mk b/cmds/installd/Android.mk
index a4f95da..30de0b3 100644
--- a/cmds/installd/Android.mk
+++ b/cmds/installd/Android.mk
@@ -1,43 +1,5 @@
LOCAL_PATH := $(call my-dir)
-#
-# OTA Executable
-#
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := otapreopt
-LOCAL_CFLAGS := -Wall -Werror
-
-# Base & ASLR boundaries for boot image creation.
-ifndef LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA
- LOCAL_LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA := -0x1000000
-else
- LOCAL_LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA := $(LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA)
-endif
-ifndef LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA
- LOCAL_LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA := 0x1000000
-else
- LOCAL_LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA := $(LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA)
-endif
-LOCAL_CFLAGS += -DART_BASE_ADDRESS=$(LIBART_IMG_HOST_BASE_ADDRESS)
-LOCAL_CFLAGS += -DART_BASE_ADDRESS_MIN_DELTA=$(LOCAL_LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA)
-LOCAL_CFLAGS += -DART_BASE_ADDRESS_MAX_DELTA=$(LOCAL_LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA)
-
-LOCAL_SRC_FILES := otapreopt.cpp otapreopt_parameters.cpp globals.cpp utils.cpp dexopt.cpp
-LOCAL_HEADER_LIBRARIES := dex2oat_headers
-LOCAL_SHARED_LIBRARIES := \
- libbase \
- libcrypto \
- libcutils \
- liblog \
- liblogwrap \
- libselinux \
- libutils \
-
-LOCAL_STATIC_LIBRARIES := libdiskusage
-LOCAL_CLANG := true
-include $(BUILD_EXECUTABLE)
-
# OTA slot script
include $(CLEAR_VARS)
diff --git a/cmds/installd/art_helper/Android.bp b/cmds/installd/art_helper/Android.bp
new file mode 100644
index 0000000..c47dd72
--- /dev/null
+++ b/cmds/installd/art_helper/Android.bp
@@ -0,0 +1,12 @@
+// Inherit image values.
+art_global_defaults {
+ name: "libartimagevalues_defaults",
+}
+
+cc_library_static {
+ name: "libartimagevalues",
+ defaults: ["libartimagevalues_defaults"],
+ srcs: ["art_image_values.cpp"],
+ export_include_dirs: ["."],
+ cflags: ["-Wconversion"],
+}
diff --git a/cmds/installd/art_helper/art_image_values.cpp b/cmds/installd/art_helper/art_image_values.cpp
new file mode 100644
index 0000000..a139049
--- /dev/null
+++ b/cmds/installd/art_helper/art_image_values.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "art_image_values.h"
+
+namespace android {
+namespace installd {
+namespace art {
+
+uint32_t GetImageBaseAddress() {
+ return ART_BASE_ADDRESS;
+}
+int32_t GetImageMinBaseAddressDelta() {
+ return ART_BASE_ADDRESS_MIN_DELTA;
+}
+int32_t GetImageMaxBaseAddressDelta() {
+ return ART_BASE_ADDRESS_MAX_DELTA;
+}
+
+static_assert(ART_BASE_ADDRESS_MIN_DELTA < ART_BASE_ADDRESS_MAX_DELTA, "Inconsistent setup");
+
+} // namespace art
+} // namespace installd
+} // namespace android
diff --git a/cmds/installd/art_helper/art_image_values.h b/cmds/installd/art_helper/art_image_values.h
new file mode 100644
index 0000000..20c44c9
--- /dev/null
+++ b/cmds/installd/art_helper/art_image_values.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FRAMEWORKS_NATIVE_CMDS_INSTALLD_ART_HELPER_ART_IMAGE_VALUES_H
+#define FRAMEWORKS_NATIVE_CMDS_INSTALLD_ART_HELPER_ART_IMAGE_VALUES_H
+
+#include <cstdint>
+
+namespace android {
+namespace installd {
+namespace art {
+
+uint32_t GetImageBaseAddress();
+int32_t GetImageMinBaseAddressDelta();
+int32_t GetImageMaxBaseAddressDelta();
+
+} // namespace art
+} // namespace installd
+} // namespace android
+
+#endif // FRAMEWORKS_NATIVE_CMDS_INSTALLD_ART_HELPER_ART_IMAGE_VALUES_H
diff --git a/cmds/installd/otapreopt.cpp b/cmds/installd/otapreopt.cpp
index 7291ef3..73098f8 100644
--- a/cmds/installd/otapreopt.cpp
+++ b/cmds/installd/otapreopt.cpp
@@ -32,6 +32,7 @@
#include <android-base/macros.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
+#include <art_image_values.h>
#include <cutils/fs.h>
#include <cutils/properties.h>
#include <dex2oat_return_codes.h>
@@ -441,8 +442,8 @@
cmd.push_back(StringPrintf("--instruction-set=%s", isa));
- int32_t base_offset = ChooseRelocationOffsetDelta(ART_BASE_ADDRESS_MIN_DELTA,
- ART_BASE_ADDRESS_MAX_DELTA);
+ int32_t base_offset = ChooseRelocationOffsetDelta(art::GetImageMinBaseAddressDelta(),
+ art::GetImageMaxBaseAddressDelta());
cmd.push_back(StringPrintf("--base-offset-delta=%d", base_offset));
std::string error_msg;
@@ -466,9 +467,9 @@
}
cmd.push_back(StringPrintf("--oat-file=%s", oat_path.c_str()));
- int32_t base_offset = ChooseRelocationOffsetDelta(ART_BASE_ADDRESS_MIN_DELTA,
- ART_BASE_ADDRESS_MAX_DELTA);
- cmd.push_back(StringPrintf("--base=0x%x", ART_BASE_ADDRESS + base_offset));
+ int32_t base_offset = ChooseRelocationOffsetDelta(art::GetImageMinBaseAddressDelta(),
+ art::GetImageMaxBaseAddressDelta());
+ cmd.push_back(StringPrintf("--base=0x%x", art::GetImageBaseAddress() + base_offset));
cmd.push_back(StringPrintf("--instruction-set=%s", isa));
@@ -610,7 +611,7 @@
// If the dexopt failed, we may have a stale boot image from a previous OTA run.
// Then regenerate and retry.
if (WEXITSTATUS(dexopt_result) ==
- static_cast<int>(art::dex2oat::ReturnCode::kCreateRuntime)) {
+ static_cast<int>(::art::dex2oat::ReturnCode::kCreateRuntime)) {
if (!PrepareBootImage(/* force */ true)) {
LOG(ERROR) << "Forced boot image creating failed. Original error return was "
<< dexopt_result;
diff --git a/cmds/installd/otapreopt_parameters.cpp b/cmds/installd/otapreopt_parameters.cpp
index cf3de01..b1ad8db 100644
--- a/cmds/installd/otapreopt_parameters.cpp
+++ b/cmds/installd/otapreopt_parameters.cpp
@@ -16,6 +16,8 @@
#include "otapreopt_parameters.h"
+#include <cstring>
+
#include <android-base/logging.h>
#include "dexopt.h"
@@ -248,6 +250,8 @@
case 8: num_args_expected = 16; break;
// Version 9 adds a new dexopt flag: DEXOPT_GENERATE_APP_IMAGE
case 9: num_args_expected = 16; break;
+ // Version 10 is a compatibility bump.
+ case 10: num_args_expected = 16; break;
default:
LOG(ERROR) << "Don't know how to read arguments for version " << version;
return false;
@@ -360,6 +364,15 @@
}
}
+ if (version < 10) {
+ // Do not accept '&' as shared libraries from versions prior to 10. These may lead
+ // to runtime crashes. The server side of version 10+ should send the correct
+ // context in almost all cases (e.g., only for actual shared packages).
+ if (shared_libraries != nullptr && std::string("&") == shared_libraries) {
+ return false;
+ }
+ }
+
return true;
}
diff --git a/cmds/installd/tests/installd_otapreopt_test.cpp b/cmds/installd/tests/installd_otapreopt_test.cpp
index b518507..66dd51e 100644
--- a/cmds/installd/tests/installd_otapreopt_test.cpp
+++ b/cmds/installd/tests/installd_otapreopt_test.cpp
@@ -114,11 +114,14 @@
case 7: return "7";
case 8: return "8";
case 9: return "9";
+ case 10: return "10";
}
return nullptr;
}
- std::vector<const char*> getArgs(uint32_t version, bool versioned) {
+ std::vector<const char*> getArgs(uint32_t version,
+ bool versioned,
+ const char* shared_libs = "shared.lib") {
std::vector<const char*> args;
args.push_back("otapreopt"); // "otapreopt"
args.push_back("a"); // slot
@@ -135,7 +138,7 @@
args.push_back("0"); // dexopt_flags
args.push_back("speed"); // filter
args.push_back("!"); // volume
- args.push_back("shared.lib"); // libs
+ args.push_back(shared_libs); // libs
if (version > 1) {
args.push_back("!"); // seinfo
@@ -159,9 +162,11 @@
return args;
}
- void VerifyReadArguments(uint32_t version, bool versioned) {
+ void VerifyReadArguments(uint32_t version,
+ bool versioned,
+ const char* shared_libs = "shared.lib") {
OTAPreoptParameters params;
- std::vector<const char*> args = getArgs(version, versioned);
+ std::vector<const char*> args = getArgs(version, versioned, shared_libs);
ASSERT_TRUE(params.ReadArguments(args.size() - 1, args.data()));
verifyPackageParameters(params, version, versioned, args.data());
}
@@ -199,6 +204,18 @@
VerifyReadArguments(7, true);
}
+TEST_F(OTAPreoptTest, ReadArgumentsV9SharedLibsAmpersand) {
+ OTAPreoptParameters params;
+ std::vector<const char*> args = getArgs(9, true, "&");
+ ASSERT_FALSE(params.ReadArguments(args.size() - 1, args.data()));
+}
+
+TEST_F(OTAPreoptTest, ReadArgumentsV10SharedLibsAmpersand) {
+ OTAPreoptParameters params;
+ std::vector<const char*> args = getArgs(10, true, "&");
+ ASSERT_TRUE(params.ReadArguments(args.size() - 1, args.data()));
+}
+
TEST_F(OTAPreoptTest, ReadArgumentsFailToManyArgs) {
OTAPreoptParameters params;
std::vector<const char*> args = getArgs(5, true);
diff --git a/libs/binder/ndk/Android.bp b/libs/binder/ndk/Android.bp
index e5c68b5..3f3c4fa 100644
--- a/libs/binder/ndk/Android.bp
+++ b/libs/binder/ndk/Android.bp
@@ -27,6 +27,7 @@
"ibinder.cpp",
"parcel.cpp",
"process.cpp",
+ "status.cpp",
"service_manager.cpp",
],
@@ -36,3 +37,19 @@
"libutils",
],
}
+
+ndk_headers {
+ name: "libbinder_ndk_headers",
+ from: "include_ndk/android",
+ to: "android",
+ srcs: [
+ "include_ndk/android/*.h",
+ ],
+ license: "NOTICE",
+}
+
+ndk_library {
+ name: "libbinder_ndk",
+ symbol_file: "libbinder_ndk.map.txt",
+ first_version: "29",
+}
diff --git a/libs/binder/ndk/NOTICE b/libs/binder/ndk/NOTICE
new file mode 100644
index 0000000..d1ab54c
--- /dev/null
+++ b/libs/binder/ndk/NOTICE
@@ -0,0 +1,189 @@
+
+ Copyright (c) 2018, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/libs/binder/ndk/ibinder.cpp b/libs/binder/ndk/ibinder.cpp
index 8a1ec05..f16cde6 100644
--- a/libs/binder/ndk/ibinder.cpp
+++ b/libs/binder/ndk/ibinder.cpp
@@ -19,6 +19,7 @@
#include <android/binder_status.h>
#include "parcel_internal.h"
+#include "status_internal.h"
#include <android-base/logging.h>
@@ -27,6 +28,7 @@
using ::android::IBinder;
using ::android::Parcel;
using ::android::sp;
+using ::android::status_t;
using ::android::String16;
using ::android::wp;
@@ -116,17 +118,18 @@
return getClass()->getInterfaceDescriptor();
}
-binder_status_t ABBinder::onTransact(transaction_code_t code, const Parcel& data, Parcel* reply,
- binder_flags_t flags) {
+status_t ABBinder::onTransact(transaction_code_t code, const Parcel& data, Parcel* reply,
+ binder_flags_t flags) {
if (isUserCommand(code)) {
if (!data.checkInterface(this)) {
- return EX_ILLEGAL_STATE;
+ return STATUS_BAD_TYPE;
}
const AParcel in = AParcel::readOnly(this, &data);
AParcel out = AParcel(this, reply, false /*owns*/);
- return getClass()->onTransact(this, code, &in, &out);
+ binder_status_t status = getClass()->onTransact(this, code, &in, &out);
+ return PruneStatusT(status);
} else {
return BBinder::onTransact(code, data, reply, flags);
}
@@ -253,13 +256,13 @@
sp<TransferDeathRecipient> recipient =
new TransferDeathRecipient(binder->getBinder(), cookie, mOnDied);
- binder_status_t status = binder->getBinder()->linkToDeath(recipient, cookie, 0 /*flags*/);
- if (status != EX_NONE) {
- return status;
+ status_t status = binder->getBinder()->linkToDeath(recipient, cookie, 0 /*flags*/);
+ if (status != STATUS_OK) {
+ return PruneStatusT(status);
}
mDeathRecipients.push_back(recipient);
- return EX_NONE;
+ return STATUS_OK;
}
binder_status_t AIBinder_DeathRecipient::unlinkToDeath(AIBinder* binder, void* cookie) {
@@ -270,22 +273,19 @@
for (auto it = mDeathRecipients.rbegin(); it != mDeathRecipients.rend(); ++it) {
sp<TransferDeathRecipient> recipient = *it;
- if (recipient->getCookie() == cookie &&
-
- recipient->getWho() == binder->getBinder()) {
+ if (recipient->getCookie() == cookie && recipient->getWho() == binder->getBinder()) {
mDeathRecipients.erase(it.base() - 1);
- binder_status_t status =
- binder->getBinder()->unlinkToDeath(recipient, cookie, 0 /*flags*/);
- if (status != EX_NONE) {
+ status_t status = binder->getBinder()->unlinkToDeath(recipient, cookie, 0 /*flags*/);
+ if (status != ::android::OK) {
LOG(ERROR) << __func__
<< ": removed reference to death recipient but unlink failed.";
}
- return status;
+ return PruneStatusT(status);
}
}
- return -ENOENT;
+ return STATUS_NAME_NOT_FOUND;
}
// start of C-API methods
@@ -323,19 +323,20 @@
binder_status_t AIBinder_ping(AIBinder* binder) {
if (binder == nullptr) {
- return EX_NULL_POINTER;
+ return STATUS_UNEXPECTED_NULL;
}
- return binder->getBinder()->pingBinder();
+ return PruneStatusT(binder->getBinder()->pingBinder());
}
binder_status_t AIBinder_linkToDeath(AIBinder* binder, AIBinder_DeathRecipient* recipient,
void* cookie) {
if (binder == nullptr || recipient == nullptr) {
LOG(ERROR) << __func__ << ": Must provide binder and recipient.";
- return EX_NULL_POINTER;
+ return STATUS_UNEXPECTED_NULL;
}
+ // returns binder_status_t
return recipient->linkToDeath(binder, cookie);
}
@@ -343,9 +344,10 @@
void* cookie) {
if (binder == nullptr || recipient == nullptr) {
LOG(ERROR) << __func__ << ": Must provide binder and recipient.";
- return EX_NULL_POINTER;
+ return STATUS_UNEXPECTED_NULL;
}
+ // returns binder_status_t
return recipient->unlinkToDeath(binder, cookie);
}
@@ -406,14 +408,14 @@
binder_status_t AIBinder_prepareTransaction(AIBinder* binder, AParcel** in) {
if (binder == nullptr || in == nullptr) {
LOG(ERROR) << __func__ << ": requires non-null parameters.";
- return EX_NULL_POINTER;
+ return STATUS_UNEXPECTED_NULL;
}
const AIBinder_Class* clazz = binder->getClass();
if (clazz == nullptr) {
LOG(ERROR) << __func__
<< ": Class must be defined for a remote binder transaction. See "
"AIBinder_associateClass.";
- return EX_ILLEGAL_STATE;
+ return STATUS_INVALID_OPERATION;
}
if (!binder->isRemote()) {
@@ -424,20 +426,22 @@
}
*in = new AParcel(binder);
- binder_status_t status = (**in)->writeInterfaceToken(clazz->getInterfaceDescriptor());
- if (status != EX_NONE) {
+ status_t status = (*in)->get()->writeInterfaceToken(clazz->getInterfaceDescriptor());
+ binder_status_t ret = PruneStatusT(status);
+
+ if (ret != STATUS_OK) {
delete *in;
*in = nullptr;
}
- return status;
+ return ret;
}
binder_status_t AIBinder_transact(AIBinder* binder, transaction_code_t code, AParcel** in,
AParcel** out, binder_flags_t flags) {
if (in == nullptr) {
LOG(ERROR) << __func__ << ": requires non-null in parameter";
- return EX_NULL_POINTER;
+ return STATUS_UNEXPECTED_NULL;
}
using AutoParcelDestroyer = std::unique_ptr<AParcel*, void (*)(AParcel**)>;
@@ -447,36 +451,36 @@
if (!isUserCommand(code)) {
LOG(ERROR) << __func__ << ": Only user-defined transactions can be made from the NDK.";
- return EX_UNSUPPORTED_OPERATION;
+ return STATUS_UNKNOWN_TRANSACTION;
}
if ((flags & ~FLAG_ONEWAY) != 0) {
LOG(ERROR) << __func__ << ": Unrecognized flags sent: " << flags;
- return EX_ILLEGAL_ARGUMENT;
+ return STATUS_BAD_VALUE;
}
if (binder == nullptr || *in == nullptr || out == nullptr) {
LOG(ERROR) << __func__ << ": requires non-null parameters.";
- return EX_NULL_POINTER;
+ return STATUS_UNEXPECTED_NULL;
}
if ((*in)->getBinder() != binder) {
LOG(ERROR) << __func__ << ": parcel is associated with binder object " << binder
<< " but called with " << (*in)->getBinder();
- return EX_ILLEGAL_STATE;
+ return STATUS_BAD_VALUE;
}
*out = new AParcel(binder);
- binder_status_t parcelStatus =
- binder->getBinder()->transact(code, *(*in)->operator->(), (*out)->operator->(), flags);
+ status_t status = binder->getBinder()->transact(code, *(*in)->get(), (*out)->get(), flags);
+ binder_status_t ret = PruneStatusT(status);
- if (parcelStatus != EX_NONE) {
+ if (ret != STATUS_OK) {
delete *out;
*out = nullptr;
}
- return parcelStatus;
+ return ret;
}
AIBinder_DeathRecipient* AIBinder_DeathRecipient_new(
diff --git a/libs/binder/ndk/ibinder_internal.h b/libs/binder/ndk/ibinder_internal.h
index fcf1b0b..5b6bc94 100644
--- a/libs/binder/ndk/ibinder_internal.h
+++ b/libs/binder/ndk/ibinder_internal.h
@@ -66,8 +66,8 @@
ABBinder* asABBinder() override { return this; }
const ::android::String16& getInterfaceDescriptor() const override;
- binder_status_t onTransact(uint32_t code, const ::android::Parcel& data,
- ::android::Parcel* reply, binder_flags_t flags) override;
+ ::android::status_t onTransact(uint32_t code, const ::android::Parcel& data,
+ ::android::Parcel* reply, binder_flags_t flags) override;
private:
ABBinder(const AIBinder_Class* clazz, void* userData);
diff --git a/libs/binder/ndk/include_ndk/android/binder_ibinder.h b/libs/binder/ndk/include_ndk/android/binder_ibinder.h
index 7dca5a4..5081248 100644
--- a/libs/binder/ndk/include_ndk/android/binder_ibinder.h
+++ b/libs/binder/ndk/include_ndk/android/binder_ibinder.h
@@ -97,7 +97,7 @@
*
* If the process containing an AIBinder dies, it is possible to be holding a strong reference to
* an object which does not exist. In this case, transactions to this binder will return
- * EX_DEAD_OBJECT. See also AIBinder_linkToDeath, AIBinder_unlinkToDeath, and AIBinder_isAlive.
+ * STATUS_DEAD_OBJECT. See also AIBinder_linkToDeath, AIBinder_unlinkToDeath, and AIBinder_isAlive.
*
* Once an AIBinder is created, anywhere it is passed (remotely or locally), there is a 1-1
* correspondence between the address of an AIBinder and the object it represents. This means that
@@ -211,7 +211,7 @@
/**
* Stops registration for the associated binder dying. Does not delete the recipient. This function
* may return a binder transaction failure and in case the death recipient cannot be found, it
- * returns -ENOENT.
+ * returns STATUS_NAME_NOT_FOUND.
*/
binder_status_t AIBinder_unlinkToDeath(AIBinder* binder, AIBinder_DeathRecipient* recipient,
void* cookie);
diff --git a/libs/binder/ndk/include_ndk/android/binder_parcel.h b/libs/binder/ndk/include_ndk/android/binder_parcel.h
index e871ed1..8628025 100644
--- a/libs/binder/ndk/include_ndk/android/binder_parcel.h
+++ b/libs/binder/ndk/include_ndk/android/binder_parcel.h
@@ -66,6 +66,17 @@
*/
binder_status_t AParcel_readNullableStrongBinder(const AParcel* parcel, AIBinder** binder);
+/**
+ * Writes an AStatus object to the next location in a non-null parcel.
+ */
+binder_status_t AParcel_writeStatusHeader(AParcel* parcel, const AStatus* status);
+
+/**
+ * Reads an AStatus from the next location in a non-null parcel. Ownership is passed to the caller
+ * of this function.
+ */
+binder_status_t AParcel_readStatusHeader(const AParcel* parcel, AStatus** status);
+
// @START
/**
* Writes int32_t value to the next location in a non-null parcel.
diff --git a/libs/binder/ndk/include_ndk/android/binder_status.h b/libs/binder/ndk/include_ndk/android/binder_status.h
index e97e181..6389a1b 100644
--- a/libs/binder/ndk/include_ndk/android/binder_status.h
+++ b/libs/binder/ndk/include_ndk/android/binder_status.h
@@ -25,12 +25,42 @@
#pragma once
+#include <errno.h>
#include <stdint.h>
#include <sys/cdefs.h>
__BEGIN_DECLS
-// Keep the exception codes in sync with android/os/Parcel.java.
+enum {
+ STATUS_OK = 0,
+
+ STATUS_UNKNOWN_ERROR = (-2147483647 - 1), // INT32_MIN value
+ STATUS_NO_MEMORY = -ENOMEM,
+ STATUS_INVALID_OPERATION = -ENOSYS,
+ STATUS_BAD_VALUE = -EINVAL,
+ STATUS_BAD_TYPE = (STATUS_UNKNOWN_ERROR + 1),
+ STATUS_NAME_NOT_FOUND = -ENOENT,
+ STATUS_PERMISSION_DENIED = -EPERM,
+ STATUS_NO_INIT = -ENODEV,
+ STATUS_ALREADY_EXISTS = -EEXIST,
+ STATUS_DEAD_OBJECT = -EPIPE,
+ STATUS_FAILED_TRANSACTION = (STATUS_UNKNOWN_ERROR + 2),
+ STATUS_BAD_INDEX = -EOVERFLOW,
+ STATUS_NOT_ENOUGH_DATA = -ENODATA,
+ STATUS_WOULD_BLOCK = -EWOULDBLOCK,
+ STATUS_TIMED_OUT = -ETIMEDOUT,
+ STATUS_UNKNOWN_TRANSACTION = -EBADMSG,
+ STATUS_FDS_NOT_ALLOWED = (STATUS_UNKNOWN_ERROR + 7),
+ STATUS_UNEXPECTED_NULL = (STATUS_UNKNOWN_ERROR + 8),
+};
+
+/**
+ * One of the STATUS_* values.
+ *
+ * All unrecognized values are coerced into STATUS_UNKNOWN_ERROR.
+ */
+typedef int32_t binder_status_t;
+
enum {
EX_NONE = 0,
EX_SECURITY = -1,
@@ -44,12 +74,6 @@
EX_PARCELABLE = -9,
/**
- * This is special and Java specific; see Parcel.java.
- * This should be considered a success, and the next readInt32 bytes can be ignored.
- */
- EX_HAS_REPLY_HEADER = -128,
-
- /**
* This is special, and indicates to native binder proxies that the
* transaction has failed at a low level.
*/
@@ -57,10 +81,103 @@
};
/**
- * One of the above values or -errno.
- * By convention, positive values are considered to mean service-specific exceptions.
+ * One of the EXCEPTION_* types.
+ *
+ * All unrecognized values are coerced into EXCEPTION_TRANSACTION_FAILED.
+ *
+ * These exceptions values are used by the SDK for parcelables. Also see Parcel.java.
*/
-typedef int32_t binder_status_t;
+typedef int32_t binder_exception_t;
+
+/**
+ * This is a helper class that encapsulates a standard way to keep track of and chain binder errors
+ * along with service specific errors.
+ *
+ * It is not required to be used in order to parcel/receive transactions, but it is required in
+ * order to be compatible with standard AIDL transactions.
+ */
+struct AStatus;
+typedef struct AStatus AStatus;
+
+/**
+ * New status which is considered a success.
+ */
+__attribute__((warn_unused_result)) AStatus* AStatus_newOk();
+
+/**
+ * New status with exception code.
+ */
+__attribute__((warn_unused_result)) AStatus* AStatus_fromExceptionCode(
+ binder_exception_t exception);
+
+/**
+ * New status with exception code and message.
+ */
+__attribute__((warn_unused_result)) AStatus* AStatus_fromExceptionCodeWithMessage(
+ binder_exception_t exception, const char* message);
+
+/**
+ * New status with a service speciic error.
+ *
+ * This is considered to be EX_TRANSACTION_FAILED with extra information.
+ */
+__attribute__((warn_unused_result)) AStatus* AStatus_fromServiceSpecificError(
+ int32_t serviceSpecific);
+
+/**
+ * New status with a service specific error and message.
+ *
+ * This is considered to be EX_TRANSACTION_FAILED with extra information.
+ */
+__attribute__((warn_unused_result)) AStatus* AStatus_fromServiceSpecificErrorWithMessage(
+ int32_t serviceSpecific, const char* message);
+
+/**
+ * New status with binder_status_t. This is typically for low level failures when a binder_status_t
+ * is returned by an API on AIBinder or AParcel, and that is to be returned from a method returning
+ * an AStatus instance.
+ */
+__attribute__((warn_unused_result)) AStatus* AStatus_fromStatus(binder_status_t status);
+
+/**
+ * Whether this object represents a successful transaction. If this function returns true, then
+ * AStatus_getExceptionCode will return EX_NONE.
+ */
+bool AStatus_isOk(const AStatus* status);
+
+/**
+ * The exception that this status object represents.
+ */
+binder_exception_t AStatus_getExceptionCode(const AStatus* status);
+
+/**
+ * The service specific error if this object represents one. This function will only ever return a
+ * non-zero result if AStatus_getExceptionCode returns EX_SERVICE_SPECIFIC. If this function returns
+ * 0, the status object may still represent a different exception or status. To find out if this
+ * transaction as a whole is okay, use AStatus_isOk instead.
+ */
+int32_t AStatus_getServiceSpecificError(const AStatus* status);
+
+/**
+ * The status if this object represents one. This function will only ever return a non-zero result
+ * if AStatus_getExceptionCode returns EX_TRANSACTION_FAILED. If this function return 0, the status
+ * object may represent a different exception or a service specific error. To find out if this
+ * transaction as a whole is okay, use AStatus_isOk instead.
+ */
+binder_status_t AStatus_getStatus(const AStatus* status);
+
+/**
+ * If there is a message associated with this status, this will return that message. If there is no
+ * message, this will return an empty string.
+ *
+ * The returned string has the lifetime of the status object passed into this function.
+ */
+const char* AStatus_getMessage(const AStatus* status);
+
+/**
+ * Deletes memory associated with the status instance.
+ */
+void AStatus_delete(AStatus** status);
__END_DECLS
diff --git a/libs/binder/ndk/libbinder_ndk.map.txt b/libs/binder/ndk/libbinder_ndk.map.txt
new file mode 100644
index 0000000..14683b9
--- /dev/null
+++ b/libs/binder/ndk/libbinder_ndk.map.txt
@@ -0,0 +1,61 @@
+LIBBINDER_NDK { # introduced=29
+ global:
+ AIBinder_associateClass;
+ AIBinder_Class_define;
+ AIBinder_DeathRecipient_delete;
+ AIBinder_DeathRecipient_new;
+ AIBinder_debugGetRefCount;
+ AIBinder_decStrong;
+ AIBinder_getClass;
+ AIBinder_getUserData;
+ AIBinder_incStrong;
+ AIBinder_isAlive;
+ AIBinder_isRemote;
+ AIBinder_linkToDeath;
+ AIBinder_new;
+ AIBinder_ping;
+ AIBinder_prepareTransaction;
+ AIBinder_transact;
+ AIBinder_unlinkToDeath;
+ AIBinder_Weak_delete;
+ AIBinder_Weak_new;
+ AIBinder_Weak_promote;
+ AParcel_delete;
+ AParcel_readBool;
+ AParcel_readByte;
+ AParcel_readChar;
+ AParcel_readDouble;
+ AParcel_readFloat;
+ AParcel_readInt32;
+ AParcel_readInt64;
+ AParcel_readNullableStrongBinder;
+ AParcel_readStatusHeader;
+ AParcel_readStrongBinder;
+ AParcel_readUint32;
+ AParcel_readUint64;
+ AParcel_writeBool;
+ AParcel_writeByte;
+ AParcel_writeChar;
+ AParcel_writeDouble;
+ AParcel_writeFloat;
+ AParcel_writeInt32;
+ AParcel_writeInt64;
+ AParcel_writeStatusHeader;
+ AParcel_writeStrongBinder;
+ AParcel_writeUint32;
+ AParcel_writeUint64;
+ AStatus_delete;
+ AStatus_fromExceptionCode;
+ AStatus_fromExceptionCodeWithMessage;
+ AStatus_fromServiceSpecificError;
+ AStatus_fromServiceSpecificErrorWithMessage;
+ AStatus_fromStatus;
+ AStatus_getExceptionCode;
+ AStatus_getMessage;
+ AStatus_getServiceSpecificError;
+ AStatus_getStatus;
+ AStatus_isOk;
+ AStatus_newOk;
+ local:
+ *;
+};
diff --git a/libs/binder/ndk/parcel.cpp b/libs/binder/ndk/parcel.cpp
index ccdfc7b..a063657 100644
--- a/libs/binder/ndk/parcel.cpp
+++ b/libs/binder/ndk/parcel.cpp
@@ -18,12 +18,14 @@
#include "parcel_internal.h"
#include "ibinder_internal.h"
+#include "status_internal.h"
#include <binder/Parcel.h>
using ::android::IBinder;
using ::android::Parcel;
using ::android::sp;
+using ::android::status_t;
void AParcel_delete(AParcel** parcel) {
if (parcel == nullptr) {
@@ -36,104 +38,133 @@
binder_status_t AParcel_writeStrongBinder(AParcel* parcel, AIBinder* binder) {
sp<IBinder> writeBinder = binder != nullptr ? binder->getBinder() : nullptr;
- return (*parcel)->writeStrongBinder(writeBinder);
+ return parcel->get()->writeStrongBinder(writeBinder);
}
binder_status_t AParcel_readStrongBinder(const AParcel* parcel, AIBinder** binder) {
sp<IBinder> readBinder = nullptr;
- binder_status_t status = (*parcel)->readStrongBinder(&readBinder);
- if (status != EX_NONE) {
- return status;
+ status_t status = parcel->get()->readStrongBinder(&readBinder);
+ if (status != STATUS_OK) {
+ return PruneStatusT(status);
}
sp<AIBinder> ret = ABpBinder::lookupOrCreateFromBinder(readBinder);
AIBinder_incStrong(ret.get());
*binder = ret.get();
- return status;
+ return PruneStatusT(status);
}
binder_status_t AParcel_readNullableStrongBinder(const AParcel* parcel, AIBinder** binder) {
sp<IBinder> readBinder = nullptr;
- binder_status_t status = (*parcel)->readNullableStrongBinder(&readBinder);
- if (status != EX_NONE) {
- return status;
+ status_t status = parcel->get()->readNullableStrongBinder(&readBinder);
+ if (status != STATUS_OK) {
+ return PruneStatusT(status);
}
sp<AIBinder> ret = ABpBinder::lookupOrCreateFromBinder(readBinder);
AIBinder_incStrong(ret.get());
*binder = ret.get();
- return status;
+ return PruneStatusT(status);
+}
+binder_status_t AParcel_writeStatusHeader(AParcel* parcel, const AStatus* status) {
+ return PruneStatusT(status->get()->writeToParcel(parcel->get()));
+}
+binder_status_t AParcel_readStatusHeader(const AParcel* parcel, AStatus** status) {
+ ::android::binder::Status bstatus;
+ binder_status_t ret = PruneStatusT(bstatus.readFromParcel(*parcel->get()));
+ if (ret == EX_NONE) {
+ *status = new AStatus(std::move(bstatus));
+ }
+ return ret;
}
// See gen_parcel_helper.py. These auto-generated read/write methods use the same types for
// libbinder and this library.
// @START
binder_status_t AParcel_writeInt32(AParcel* parcel, int32_t value) {
- return (*parcel)->writeInt32(value);
+ status_t status = parcel->get()->writeInt32(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_writeUint32(AParcel* parcel, uint32_t value) {
- return (*parcel)->writeUint32(value);
+ status_t status = parcel->get()->writeUint32(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_writeInt64(AParcel* parcel, int64_t value) {
- return (*parcel)->writeInt64(value);
+ status_t status = parcel->get()->writeInt64(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_writeUint64(AParcel* parcel, uint64_t value) {
- return (*parcel)->writeUint64(value);
+ status_t status = parcel->get()->writeUint64(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_writeFloat(AParcel* parcel, float value) {
- return (*parcel)->writeFloat(value);
+ status_t status = parcel->get()->writeFloat(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_writeDouble(AParcel* parcel, double value) {
- return (*parcel)->writeDouble(value);
+ status_t status = parcel->get()->writeDouble(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_writeBool(AParcel* parcel, bool value) {
- return (*parcel)->writeBool(value);
+ status_t status = parcel->get()->writeBool(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_writeChar(AParcel* parcel, char16_t value) {
- return (*parcel)->writeChar(value);
+ status_t status = parcel->get()->writeChar(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_writeByte(AParcel* parcel, int8_t value) {
- return (*parcel)->writeByte(value);
+ status_t status = parcel->get()->writeByte(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_readInt32(const AParcel* parcel, int32_t* value) {
- return (*parcel)->readInt32(value);
+ status_t status = parcel->get()->readInt32(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_readUint32(const AParcel* parcel, uint32_t* value) {
- return (*parcel)->readUint32(value);
+ status_t status = parcel->get()->readUint32(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_readInt64(const AParcel* parcel, int64_t* value) {
- return (*parcel)->readInt64(value);
+ status_t status = parcel->get()->readInt64(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_readUint64(const AParcel* parcel, uint64_t* value) {
- return (*parcel)->readUint64(value);
+ status_t status = parcel->get()->readUint64(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_readFloat(const AParcel* parcel, float* value) {
- return (*parcel)->readFloat(value);
+ status_t status = parcel->get()->readFloat(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_readDouble(const AParcel* parcel, double* value) {
- return (*parcel)->readDouble(value);
+ status_t status = parcel->get()->readDouble(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_readBool(const AParcel* parcel, bool* value) {
- return (*parcel)->readBool(value);
+ status_t status = parcel->get()->readBool(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_readChar(const AParcel* parcel, char16_t* value) {
- return (*parcel)->readChar(value);
+ status_t status = parcel->get()->readChar(value);
+ return PruneStatusT(status);
}
binder_status_t AParcel_readByte(const AParcel* parcel, int8_t* value) {
- return (*parcel)->readByte(value);
+ status_t status = parcel->get()->readByte(value);
+ return PruneStatusT(status);
}
// @END
diff --git a/libs/binder/ndk/parcel_internal.h b/libs/binder/ndk/parcel_internal.h
index b6a9110..d69971f 100644
--- a/libs/binder/ndk/parcel_internal.h
+++ b/libs/binder/ndk/parcel_internal.h
@@ -24,8 +24,8 @@
#include "ibinder_internal.h"
struct AParcel {
- const ::android::Parcel* operator->() const { return mParcel; }
- ::android::Parcel* operator->() { return mParcel; }
+ const ::android::Parcel* get() const { return mParcel; }
+ ::android::Parcel* get() { return mParcel; }
AParcel(const AIBinder* binder) : AParcel(binder, new ::android::Parcel, true /*owns*/) {}
AParcel(const AIBinder* binder, ::android::Parcel* parcel, bool owns)
diff --git a/libs/binder/ndk/runtests.sh b/libs/binder/ndk/runtests.sh
index 6c8527d..2257eb2 100755
--- a/libs/binder/ndk/runtests.sh
+++ b/libs/binder/ndk/runtests.sh
@@ -37,4 +37,7 @@
adb wait-for-device
adb sync data
+# very simple unit tests, tests things outside of the NDK as well
run_libbinder_ndk_test
+
+atest android.binder.cts.NdkBinderTest
diff --git a/libs/binder/ndk/scripts/gen_parcel_helper.py b/libs/binder/ndk/scripts/gen_parcel_helper.py
index 794afe2..85ee755 100755
--- a/libs/binder/ndk/scripts/gen_parcel_helper.py
+++ b/libs/binder/ndk/scripts/gen_parcel_helper.py
@@ -68,7 +68,8 @@
header += " */\n"
header += "binder_status_t AParcel_write" + pretty + "(AParcel* parcel, " + cpp + " value);\n\n"
source += "binder_status_t AParcel_write" + pretty + "(AParcel* parcel, " + cpp + " value) {\n"
- source += " return (*parcel)->write" + pretty + "(value);\n"
+ source += " status_t status = parcel->get()->write" + pretty + "(value);\n"
+ source += " return PruneStatusT(status);\n"
source += "}\n\n"
for pretty, cpp in data_types:
@@ -77,7 +78,8 @@
header += " */\n"
header += "binder_status_t AParcel_read" + pretty + "(const AParcel* parcel, " + cpp + "* value);\n\n"
source += "binder_status_t AParcel_read" + pretty + "(const AParcel* parcel, " + cpp + "* value) {\n"
- source += " return (*parcel)->read" + pretty + "(value);\n"
+ source += " status_t status = parcel->get()->read" + pretty + "(value);\n"
+ source += " return PruneStatusT(status);\n"
source += "}\n\n"
replaceFileTags(ROOT + "include_ndk/android/binder_parcel.h", header)
diff --git a/libs/binder/ndk/scripts/init_map.sh b/libs/binder/ndk/scripts/init_map.sh
new file mode 100755
index 0000000..132144b
--- /dev/null
+++ b/libs/binder/ndk/scripts/init_map.sh
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+
+# Simple helper for ease of development until this API is frozen.
+
+echo "LIBBINDER_NDK { # introduced=29"
+echo " global:"
+{
+ grep -oP "AIBinder_[a-zA-Z0-9_]+(?=\()" include_ndk/android/binder_ibinder.h;
+ grep -oP "AParcel_[a-zA-Z0-9_]+(?=\()" include_ndk/android/binder_parcel.h;
+ grep -oP "AStatus_[a-zA-Z0-9_]+(?=\()" include_ndk/android/binder_status.h;
+} | sort | uniq | awk '{ print " " $0 ";"; }'
+echo " local:"
+echo " *;"
+echo "};"
diff --git a/libs/binder/ndk/service_manager.cpp b/libs/binder/ndk/service_manager.cpp
index 5bc69b0..9ddc555 100644
--- a/libs/binder/ndk/service_manager.cpp
+++ b/libs/binder/ndk/service_manager.cpp
@@ -15,7 +15,9 @@
*/
#include <android/binder_manager.h>
+
#include "ibinder_internal.h"
+#include "status_internal.h"
#include <binder/IServiceManager.h>
@@ -23,15 +25,17 @@
using ::android::IBinder;
using ::android::IServiceManager;
using ::android::sp;
+using ::android::status_t;
using ::android::String16;
binder_status_t AServiceManager_addService(AIBinder* binder, const char* instance) {
if (binder == nullptr || instance == nullptr) {
- return EX_NULL_POINTER;
+ return STATUS_UNEXPECTED_NULL;
}
sp<IServiceManager> sm = defaultServiceManager();
- return sm->addService(String16(instance), binder->getBinder());
+ status_t status = sm->addService(String16(instance), binder->getBinder());
+ return PruneStatusT(status);
}
AIBinder* AServiceManager_getService(const char* instance) {
if (instance == nullptr) {
diff --git a/libs/binder/ndk/status.cpp b/libs/binder/ndk/status.cpp
new file mode 100644
index 0000000..deb0392
--- /dev/null
+++ b/libs/binder/ndk/status.cpp
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <android/binder_status.h>
+#include "status_internal.h"
+
+#include <android-base/logging.h>
+
+using ::android::status_t;
+using ::android::binder::Status;
+
+AStatus* AStatus_newOk() {
+ return new AStatus();
+}
+
+AStatus* AStatus_fromExceptionCode(binder_exception_t exception) {
+ return new AStatus(Status::fromExceptionCode(exception));
+}
+
+AStatus* AStatus_fromExceptionCodeWithMessage(binder_exception_t exception, const char* message) {
+ return new AStatus(Status::fromExceptionCode(exception, message));
+}
+
+AStatus* AStatus_fromServiceSpecificError(int32_t serviceSpecific) {
+ return new AStatus(Status::fromServiceSpecificError(serviceSpecific));
+}
+
+AStatus* AStatus_fromServiceSpecificErrorWithMessage(int32_t serviceSpecific, const char* message) {
+ return new AStatus(Status::fromServiceSpecificError(serviceSpecific, message));
+}
+
+AStatus* AStatus_fromStatus(binder_status_t status) {
+ return new AStatus(Status::fromStatusT(status));
+}
+
+bool AStatus_isOk(const AStatus* status) {
+ return status->get()->isOk();
+}
+
+binder_exception_t AStatus_getExceptionCode(const AStatus* status) {
+ return PruneException(status->get()->exceptionCode());
+}
+
+int32_t AStatus_getServiceSpecificError(const AStatus* status) {
+ return status->get()->serviceSpecificErrorCode();
+}
+
+binder_status_t AStatus_getStatus(const AStatus* status) {
+ return PruneStatusT(status->get()->transactionError());
+}
+
+const char* AStatus_getMessage(const AStatus* status) {
+ return status->get()->exceptionMessage().c_str();
+}
+
+void AStatus_delete(AStatus** status) {
+ if (status == nullptr) {
+ return;
+ }
+
+ delete *status;
+ *status = nullptr;
+}
+
+binder_status_t PruneStatusT(status_t status) {
+ if (status > 0) return status;
+
+ switch (status) {
+ case ::android::OK:
+ return STATUS_OK;
+ case ::android::NO_MEMORY:
+ return STATUS_NO_MEMORY;
+ case ::android::INVALID_OPERATION:
+ return STATUS_INVALID_OPERATION;
+ case ::android::BAD_VALUE:
+ return STATUS_BAD_VALUE;
+ case ::android::BAD_TYPE:
+ return STATUS_BAD_TYPE;
+ case ::android::NAME_NOT_FOUND:
+ return STATUS_NAME_NOT_FOUND;
+ case ::android::PERMISSION_DENIED:
+ return STATUS_PERMISSION_DENIED;
+ case ::android::NO_INIT:
+ return STATUS_NO_INIT;
+ case ::android::ALREADY_EXISTS:
+ return STATUS_ALREADY_EXISTS;
+ case ::android::DEAD_OBJECT:
+ return STATUS_DEAD_OBJECT;
+ case ::android::FAILED_TRANSACTION:
+ return STATUS_FAILED_TRANSACTION;
+ case ::android::BAD_INDEX:
+ return STATUS_BAD_INDEX;
+ case ::android::NOT_ENOUGH_DATA:
+ return STATUS_NOT_ENOUGH_DATA;
+ case ::android::WOULD_BLOCK:
+ return STATUS_WOULD_BLOCK;
+ case ::android::TIMED_OUT:
+ return STATUS_TIMED_OUT;
+ case ::android::UNKNOWN_TRANSACTION:
+ return STATUS_UNKNOWN_TRANSACTION;
+ case ::android::FDS_NOT_ALLOWED:
+ return STATUS_FDS_NOT_ALLOWED;
+ case ::android::UNEXPECTED_NULL:
+ return STATUS_UNEXPECTED_NULL;
+ case ::android::UNKNOWN_ERROR:
+ return STATUS_UNKNOWN_ERROR;
+
+ default:
+ LOG(WARNING) << __func__
+ << ": Unknown status_t pruned into STATUS_UNKNOWN_ERROR: " << status;
+ return STATUS_UNKNOWN_ERROR;
+ }
+}
+
+binder_exception_t PruneException(int32_t exception) {
+ switch (exception) {
+ case Status::EX_NONE:
+ return EX_NONE;
+ case Status::EX_SECURITY:
+ return EX_SECURITY;
+ case Status::EX_BAD_PARCELABLE:
+ return EX_BAD_PARCELABLE;
+ case Status::EX_ILLEGAL_ARGUMENT:
+ return EX_ILLEGAL_ARGUMENT;
+ case Status::EX_NULL_POINTER:
+ return EX_NULL_POINTER;
+ case Status::EX_ILLEGAL_STATE:
+ return EX_ILLEGAL_STATE;
+ case Status::EX_NETWORK_MAIN_THREAD:
+ return EX_NETWORK_MAIN_THREAD;
+ case Status::EX_UNSUPPORTED_OPERATION:
+ return EX_UNSUPPORTED_OPERATION;
+ case Status::EX_SERVICE_SPECIFIC:
+ return EX_SERVICE_SPECIFIC;
+ case Status::EX_PARCELABLE:
+ return EX_PARCELABLE;
+ case Status::EX_TRANSACTION_FAILED:
+ return EX_TRANSACTION_FAILED;
+
+ default:
+ LOG(WARNING) << __func__
+ << ": Unknown status_t pruned into EX_TRANSACTION_FAILED: " << exception;
+ return EX_TRANSACTION_FAILED;
+ }
+}
diff --git a/libs/binder/ndk/status_internal.h b/libs/binder/ndk/status_internal.h
new file mode 100644
index 0000000..8c32baf
--- /dev/null
+++ b/libs/binder/ndk/status_internal.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <android/binder_status.h>
+
+#include <binder/Status.h>
+#include <utils/Errors.h>
+
+struct AStatus {
+ AStatus() {} // ok
+ AStatus(::android::binder::Status&& status) : mStatus(std::move(status)) {}
+
+ ::android::binder::Status* get() { return &mStatus; }
+ const ::android::binder::Status* get() const { return &mStatus; }
+
+private:
+ ::android::binder::Status mStatus;
+};
+
+// This collapses the statuses into the declared range.
+binder_status_t PruneStatusT(android::status_t status);
+
+// This collapses the exception into the declared range.
+binder_exception_t PruneException(int32_t exception);
diff --git a/libs/binder/ndk/test/iface.cpp b/libs/binder/ndk/test/iface.cpp
index a1aa0fa..80700df 100644
--- a/libs/binder/ndk/test/iface.cpp
+++ b/libs/binder/ndk/test/iface.cpp
@@ -41,7 +41,7 @@
binder_status_t IFoo_Class_onTransact(AIBinder* binder, transaction_code_t code, const AParcel* in,
AParcel* out) {
- binder_status_t stat = EX_UNSUPPORTED_OPERATION;
+ binder_status_t stat = STATUS_FAILED_TRANSACTION;
sp<IFoo> foo = static_cast<IFoo_Class_Data*>(AIBinder_getUserData(binder))->foo;
CHECK(foo != nullptr) << "Transaction made on already deleted object";
@@ -50,7 +50,7 @@
case IFoo::DOFOO: {
int32_t valueIn;
stat = AParcel_readInt32(in, &valueIn);
- if (stat != EX_NONE) break;
+ if (stat != STATUS_OK) break;
int32_t valueOut = foo->doubleNumber(valueIn);
stat = AParcel_writeInt32(out, valueOut);
break;
@@ -70,16 +70,16 @@
virtual int32_t doubleNumber(int32_t in) {
AParcel* parcelIn;
- CHECK(EX_NONE == AIBinder_prepareTransaction(mBinder, &parcelIn));
+ CHECK(STATUS_OK == AIBinder_prepareTransaction(mBinder, &parcelIn));
- CHECK(EX_NONE == AParcel_writeInt32(parcelIn, in));
+ CHECK(STATUS_OK == AParcel_writeInt32(parcelIn, in));
AParcel* parcelOut;
- CHECK(EX_NONE ==
+ CHECK(STATUS_OK ==
AIBinder_transact(mBinder, IFoo::DOFOO, &parcelIn, &parcelOut, 0 /*flags*/));
int32_t out;
- CHECK(EX_NONE == AParcel_readInt32(parcelOut, &out));
+ CHECK(STATUS_OK == AParcel_readInt32(parcelOut, &out));
AParcel_delete(&parcelOut);
diff --git a/libs/binder/ndk/test/main_client.cpp b/libs/binder/ndk/test/main_client.cpp
index b8518d7..2dcccfe 100644
--- a/libs/binder/ndk/test/main_client.cpp
+++ b/libs/binder/ndk/test/main_client.cpp
@@ -41,7 +41,7 @@
ASSERT_NE(nullptr, binder);
EXPECT_TRUE(AIBinder_isRemote(binder));
EXPECT_TRUE(AIBinder_isAlive(binder));
- EXPECT_EQ(EX_NONE, AIBinder_ping(binder));
+ EXPECT_EQ(STATUS_OK, AIBinder_ping(binder));
AIBinder_decStrong(binder);
}
@@ -60,9 +60,11 @@
AIBinder_DeathRecipient* recipient = AIBinder_DeathRecipient_new(OnBinderDeath);
ASSERT_NE(nullptr, recipient);
- EXPECT_EQ(EX_NONE, AIBinder_linkToDeath(binder, recipient, nullptr));
- EXPECT_EQ(EX_NONE, AIBinder_unlinkToDeath(binder, recipient, nullptr));
- EXPECT_EQ(-ENOENT, AIBinder_unlinkToDeath(binder, recipient, nullptr));
+ EXPECT_EQ(STATUS_OK, AIBinder_linkToDeath(binder, recipient, nullptr));
+ EXPECT_EQ(STATUS_OK, AIBinder_linkToDeath(binder, recipient, nullptr));
+ EXPECT_EQ(STATUS_OK, AIBinder_unlinkToDeath(binder, recipient, nullptr));
+ EXPECT_EQ(STATUS_OK, AIBinder_unlinkToDeath(binder, recipient, nullptr));
+ EXPECT_EQ(STATUS_NAME_NOT_FOUND, AIBinder_unlinkToDeath(binder, recipient, nullptr));
AIBinder_DeathRecipient_delete(&recipient);
AIBinder_decStrong(binder);
@@ -79,7 +81,7 @@
static const char* kInstanceName = "test-get-service-in-process";
sp<IFoo> foo = new MyTestFoo;
- EXPECT_EQ(EX_NONE, foo->addService(kInstanceName));
+ EXPECT_EQ(STATUS_OK, foo->addService(kInstanceName));
sp<IFoo> getFoo = IFoo::getService(kInstanceName);
EXPECT_EQ(foo.get(), getFoo.get());
@@ -119,7 +121,7 @@
static const char* kInstanceName1 = "test-multi-1";
static const char* kInstanceName2 = "test-multi-2";
sp<IFoo> foo = new MyTestFoo;
- EXPECT_EQ(EX_NONE, foo->addService(kInstanceName1));
- EXPECT_EQ(EX_NONE, foo->addService(kInstanceName2));
+ EXPECT_EQ(STATUS_OK, foo->addService(kInstanceName1));
+ EXPECT_EQ(STATUS_OK, foo->addService(kInstanceName2));
EXPECT_EQ(IFoo::getService(kInstanceName1), IFoo::getService(kInstanceName2));
}
diff --git a/libs/binder/ndk/test/main_server.cpp b/libs/binder/ndk/test/main_server.cpp
index f3da7da..0718a69 100644
--- a/libs/binder/ndk/test/main_server.cpp
+++ b/libs/binder/ndk/test/main_server.cpp
@@ -33,7 +33,7 @@
// Strong reference to MyFoo kept by service manager.
binder_status_t status = (new MyFoo)->addService(IFoo::kSomeInstanceName);
- if (status != EX_NONE) {
+ if (status != STATUS_OK) {
LOG(FATAL) << "Could not register: " << status;
}
diff --git a/libs/binder/ndk/update.sh b/libs/binder/ndk/update.sh
index 1eba892..49b4730 100755
--- a/libs/binder/ndk/update.sh
+++ b/libs/binder/ndk/update.sh
@@ -18,5 +18,6 @@
set -ex
# This script makes sure that the source code is in sync with the various scripts
+./scripts/init_map.sh > libbinder_ndk.map.txt
./scripts/gen_parcel_helper.py
./scripts/format.sh