Increase raft timeout to 10min so we get complete logs from older devices. am: 804339a59e
am: 7126caa17f
* commit '7126caa17f4b76632335daa8090ba9e37db35102':
Increase raft timeout to 10min so we get complete logs from older devices.
diff --git a/cmds/dumpstate/dumpstate.c b/cmds/dumpstate/dumpstate.c
index b88b605..6093e08 100644
--- a/cmds/dumpstate/dumpstate.c
+++ b/cmds/dumpstate/dumpstate.c
@@ -337,17 +337,28 @@
if (timeout < 20000) {
timeout = 20000;
}
- run_command("SYSTEM LOG", timeout / 1000, "logcat", "-v", "threadtime", "-d", "*:v", NULL);
+ run_command("SYSTEM LOG", timeout / 1000, "logcat", "-v", "threadtime",
+ "-v", "printable",
+ "-d",
+ "*:v", NULL);
timeout = logcat_timeout("events");
if (timeout < 20000) {
timeout = 20000;
}
- run_command("EVENT LOG", timeout / 1000, "logcat", "-b", "events", "-v", "threadtime", "-d", "*:v", NULL);
+ run_command("EVENT LOG", timeout / 1000, "logcat", "-b", "events",
+ "-v", "threadtime",
+ "-v", "printable",
+ "-d",
+ "*:v", NULL);
timeout = logcat_timeout("radio");
if (timeout < 20000) {
timeout = 20000;
}
- run_command("RADIO LOG", timeout / 1000, "logcat", "-b", "radio", "-v", "threadtime", "-d", "*:v", NULL);
+ run_command("RADIO LOG", timeout / 1000, "logcat", "-b", "radio",
+ "-v", "threadtime",
+ "-v", "printable",
+ "-d",
+ "*:v", NULL);
run_command("LOG STATISTICS", 10, "logcat", "-b", "all", "-S", NULL);
@@ -419,8 +430,12 @@
}
/* kernels must set CONFIG_PSTORE_PMSG, slice up pstore with device tree */
- run_command("LAST LOGCAT", 10, "logcat", "-L", "-v", "threadtime",
- "-b", "all", "-d", "*:v", NULL);
+ run_command("LAST LOGCAT", 10, "logcat", "-L",
+ "-b", "all",
+ "-v", "threadtime",
+ "-v", "printable",
+ "-d",
+ "*:v", NULL);
/* The following have a tendency to get wedged when wifi drivers/fw goes belly-up. */
diff --git a/cmds/installd/commands.cpp b/cmds/installd/commands.cpp
index c05a3d3..fac8ddd 100644
--- a/cmds/installd/commands.cpp
+++ b/cmds/installd/commands.cpp
@@ -746,7 +746,7 @@
static void run_dex2oat(int zip_fd, int oat_fd, const char* input_file_name,
const char* output_file_name, int swap_fd, const char *pkgname, const char *instruction_set,
- bool vm_safe_mode, bool debuggable, bool post_bootcomplete)
+ bool vm_safe_mode, bool debuggable, bool post_bootcomplete, bool use_jit)
{
static const unsigned int MAX_INSTRUCTION_SET_LEN = 7;
@@ -807,7 +807,6 @@
(strcmp(vold_decrypt, "trigger_restart_min_framework") == 0 ||
(strcmp(vold_decrypt, "1") == 0)));
- bool use_jit = check_boolean_property("debug.usejit");
bool generate_debug_info = check_boolean_property("debug.generate-debug-info");
static const char* DEX2OAT_BIN = "/system/bin/dex2oat";
@@ -861,6 +860,8 @@
}
}
+ // use the JIT if either it's specified as a dexopt flag or if the property is set
+ use_jit = use_jit || check_boolean_property("debug.usejit");
if (have_dex2oat_Xms_flag) {
sprintf(dex2oat_Xms_arg, "-Xms%s", dex2oat_Xms_flag);
}
@@ -1081,9 +1082,8 @@
}
}
-int dexopt(const char *apk_path, uid_t uid, bool is_public,
- const char *pkgname, const char *instruction_set, int dexopt_needed,
- bool vm_safe_mode, bool debuggable, const char* oat_dir, bool boot_complete)
+int dexopt(const char *apk_path, uid_t uid, const char *pkgname, const char *instruction_set,
+ int dexopt_needed, const char* oat_dir, int dexopt_flags)
{
struct utimbuf ut;
struct stat input_stat;
@@ -1092,6 +1092,15 @@
const char *input_file;
char in_odex_path[PKG_PATH_MAX];
int res, input_fd=-1, out_fd=-1, swap_fd=-1;
+ bool is_public = (dexopt_flags & DEXOPT_PUBLIC) != 0;
+ bool vm_safe_mode = (dexopt_flags & DEXOPT_SAFEMODE) != 0;
+ bool debuggable = (dexopt_flags & DEXOPT_DEBUGGABLE) != 0;
+ bool boot_complete = (dexopt_flags & DEXOPT_BOOTCOMPLETE) != 0;
+ bool use_jit = (dexopt_flags & DEXOPT_USEJIT) != 0;
+
+ if ((dexopt_flags & ~DEXOPT_MASK) != 0) {
+ LOG_FATAL("dexopt flags contains unknown fields\n");
+ }
// Early best-effort check whether we can fit the the path into our buffers.
// Note: the cache path will require an additional 5 bytes for ".swap", but we'll try to run
@@ -1231,7 +1240,7 @@
input_file_name++;
}
run_dex2oat(input_fd, out_fd, input_file_name, out_path, swap_fd, pkgname,
- instruction_set, vm_safe_mode, debuggable, boot_complete);
+ instruction_set, vm_safe_mode, debuggable, boot_complete, use_jit);
} else {
ALOGE("Invalid dexopt needed: %d\n", dexopt_needed);
exit(73);
diff --git a/cmds/installd/installd.cpp b/cmds/installd/installd.cpp
index f67e838..7a16150 100644
--- a/cmds/installd/installd.cpp
+++ b/cmds/installd/installd.cpp
@@ -47,10 +47,9 @@
static int do_dexopt(char **arg, char reply[REPLY_MAX] __unused)
{
- /* apk_path, uid, is_public, pkgname, instruction_set,
- * dexopt_needed, vm_safe_mode, debuggable, oat_dir, boot_complete */
- return dexopt(arg[0], atoi(arg[1]), atoi(arg[2]), arg[3], arg[4], atoi(arg[5]),
- atoi(arg[6]), atoi(arg[7]), arg[8], atoi(arg[9]));
+ /* apk_path, uid, pkgname, instruction_set, dexopt_needed, oat_dir, dexopt_flags */
+ return dexopt(arg[0], atoi(arg[1]), arg[2], arg[3], atoi(arg[4]),
+ arg[5], atoi(arg[6]));
}
static int do_mark_boot_complete(char **arg, char reply[REPLY_MAX] __unused)
@@ -194,7 +193,7 @@
struct cmdinfo cmds[] = {
{ "ping", 0, do_ping },
{ "install", 5, do_install },
- { "dexopt", 10, do_dexopt },
+ { "dexopt", 7, do_dexopt },
{ "markbootcomplete", 1, do_mark_boot_complete },
{ "movedex", 3, do_move_dex },
{ "rmdex", 2, do_rm_dex },
diff --git a/cmds/installd/installd.h b/cmds/installd/installd.h
index 24b9084..df13fe4 100644
--- a/cmds/installd/installd.h
+++ b/cmds/installd/installd.h
@@ -90,6 +90,24 @@
#define DEXOPT_PATCHOAT_NEEDED 2
#define DEXOPT_SELF_PATCHOAT_NEEDED 3
+/****************************************************************************
+ * IMPORTANT: These values are passed from Java code. Keep them in sync with
+ * frameworks/base/services/core/java/com/android/server/pm/Installer.java
+ ***************************************************************************/
+constexpr int DEXOPT_PUBLIC = 1 << 1;
+constexpr int DEXOPT_SAFEMODE = 1 << 2;
+constexpr int DEXOPT_DEBUGGABLE = 1 << 3;
+constexpr int DEXOPT_BOOTCOMPLETE = 1 << 4;
+constexpr int DEXOPT_USEJIT = 1 << 5;
+
+/* all known values for dexopt flags */
+constexpr int DEXOPT_MASK =
+ DEXOPT_PUBLIC
+ | DEXOPT_SAFEMODE
+ | DEXOPT_DEBUGGABLE
+ | DEXOPT_BOOTCOMPLETE
+ | DEXOPT_USEJIT;
+
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
/* data structures */
@@ -241,9 +259,8 @@
const char *instruction_set, int64_t *codesize, int64_t *datasize,
int64_t *cachesize, int64_t *asecsize);
int free_cache(const char *uuid, int64_t free_size);
-int dexopt(const char *apk_path, uid_t uid, bool is_public, const char *pkgName,
- const char *instruction_set, int dexopt_needed, bool vm_safe_mode,
- bool debuggable, const char* oat_dir, bool boot_complete);
+int dexopt(const char *apk_path, uid_t uid, const char *pkgName, const char *instruction_set,
+ int dexopt_needed, const char* oat_dir, int dexopt_flags);
int mark_boot_complete(const char *instruction_set);
int movefiles();
int linklib(const char* uuid, const char* pkgname, const char* asecLibDir, int userId);
diff --git a/include/batteryservice/BatteryService.h b/include/batteryservice/BatteryService.h
index f0a2790..12d15ba 100644
--- a/include/batteryservice/BatteryService.h
+++ b/include/batteryservice/BatteryService.h
@@ -58,6 +58,7 @@
bool chargerUsbOnline;
bool chargerWirelessOnline;
int maxChargingCurrent;
+ int maxChargingVoltage;
int batteryStatus;
int batteryHealth;
bool batteryPresent;
diff --git a/include/binder/Binder.h b/include/binder/Binder.h
index 86628a0..f849fd4 100644
--- a/include/binder/Binder.h
+++ b/include/binder/Binder.h
@@ -17,7 +17,7 @@
#ifndef ANDROID_BINDER_H
#define ANDROID_BINDER_H
-#include <stdatomic.h>
+#include <atomic>
#include <stdint.h>
#include <binder/IBinder.h>
@@ -71,7 +71,7 @@
class Extras;
- atomic_uintptr_t mExtras; // should be atomic<Extras *>
+ std::atomic<Extras*> mExtras;
void* mReserved0;
};
@@ -95,7 +95,7 @@
IBinder* const mRemote;
RefBase::weakref_type* mRefs;
- volatile int32_t mState;
+ std::atomic<int32_t> mState;
};
}; // namespace android
diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h
index 16cd6cf..430c3ff 100644
--- a/include/binder/Parcel.h
+++ b/include/binder/Parcel.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_PARCEL_H
#define ANDROID_PARCEL_H
+#include <vector>
+
#include <cutils/native_handle.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>
@@ -25,6 +27,8 @@
#include <utils/Flattenable.h>
#include <linux/binder.h>
+#include <binder/IInterface.h>
+
// ---------------------------------------------------------------------------
namespace android {
@@ -108,6 +112,20 @@
status_t writeWeakBinder(const wp<IBinder>& val);
status_t writeInt32Array(size_t len, const int32_t *val);
status_t writeByteArray(size_t len, const uint8_t *val);
+ status_t writeBool(bool val);
+ status_t writeChar(char16_t val);
+ status_t writeByte(int8_t val);
+
+ status_t writeByteVector(const std::vector<int8_t>& val);
+ status_t writeInt32Vector(const std::vector<int32_t>& val);
+ status_t writeInt64Vector(const std::vector<int64_t>& val);
+ status_t writeFloatVector(const std::vector<float>& val);
+ status_t writeDoubleVector(const std::vector<double>& val);
+ status_t writeBoolVector(const std::vector<bool>& val);
+ status_t writeCharVector(const std::vector<char16_t>& val);
+ status_t writeString16Vector(const std::vector<String16>& val);
+
+ status_t writeStrongBinderVector(const std::vector<sp<IBinder>>& val);
template<typename T>
status_t write(const Flattenable<T>& val);
@@ -118,7 +136,7 @@
// Place a native_handle into the parcel (the native_handle's file-
// descriptors are dup'ed, so it is safe to delete the native_handle
- // when this function returns).
+ // when this function returns).
// Doesn't take ownership of the native_handle.
status_t writeNativeHandle(const native_handle* handle);
@@ -169,15 +187,37 @@
status_t readDouble(double *pArg) const;
intptr_t readIntPtr() const;
status_t readIntPtr(intptr_t *pArg) const;
+ bool readBool() const;
+ status_t readBool(bool *pArg) const;
+ char16_t readChar() const;
+ status_t readChar(char16_t *pArg) const;
+ int8_t readByte() const;
+ status_t readByte(int8_t *pArg) const;
const char* readCString() const;
String8 readString8() const;
String16 readString16() const;
+ status_t readString16(String16* pArg) const;
const char16_t* readString16Inplace(size_t* outLen) const;
sp<IBinder> readStrongBinder() const;
+ status_t readStrongBinder(sp<IBinder>* val) const;
wp<IBinder> readWeakBinder() const;
template<typename T>
+ status_t readStrongBinder(sp<T>* val) const;
+
+ status_t readStrongBinderVector(std::vector<sp<IBinder>>* val) const;
+
+ status_t readByteVector(std::vector<int8_t>* val) const;
+ status_t readInt32Vector(std::vector<int32_t>* val) const;
+ status_t readInt64Vector(std::vector<int64_t>* val) const;
+ status_t readFloatVector(std::vector<float>* val) const;
+ status_t readDoubleVector(std::vector<double>* val) const;
+ status_t readBoolVector(std::vector<bool>* val) const;
+ status_t readCharVector(std::vector<char16_t>* val) const;
+ status_t readString16Vector(std::vector<String16>* val) const;
+
+ template<typename T>
status_t read(Flattenable<T>& val) const;
template<typename T>
@@ -402,6 +442,22 @@
return NO_ERROR;
}
+template<typename T>
+status_t Parcel::readStrongBinder(sp<T>* val) const {
+ sp<IBinder> tmp;
+ status_t ret = readStrongBinder(&tmp);
+
+ if (ret == OK) {
+ *val = interface_cast<T>(tmp);
+
+ if (val->get() == nullptr) {
+ return UNKNOWN_ERROR;
+ }
+ }
+
+ return ret;
+}
+
// ---------------------------------------------------------------------------
inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel)
diff --git a/include/binder/Status.h b/include/binder/Status.h
new file mode 100644
index 0000000..04738f8
--- /dev/null
+++ b/include/binder/Status.h
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2015 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 ANDROID_BINDER_STATUS_H
+#define ANDROID_BINDER_STATUS_H
+
+#include <cstdint>
+
+#include <binder/Parcel.h>
+#include <utils/String8.h>
+
+namespace android {
+namespace binder {
+
+// An object similar in function to a status_t except that it understands
+// how exceptions are encoded in the prefix of a Parcel. Used like:
+//
+// Parcel data;
+// Parcel reply;
+// status_t status;
+// binder::Status remote_exception;
+// if ((status = data.writeInterfaceToken(interface_descriptor)) != OK ||
+// (status = data.writeInt32(function_input)) != OK) {
+// // We failed to write into the memory of our local parcel?
+// }
+// if ((status = remote()->transact(transaction, data, &reply)) != OK) {
+// // Something has gone wrong in the binder driver or libbinder.
+// }
+// if ((status = remote_exception.readFromParcel(reply)) != OK) {
+// // The remote didn't correctly write the exception header to the
+// // reply.
+// }
+// if (!remote_exception.isOk()) {
+// // The transaction went through correctly, but the remote reported an
+// // exception during handling.
+// }
+//
+class Status final {
+public:
+ // Keep the exception codes in sync with android/os/Parcel.java.
+ enum Exception {
+ EX_NONE = 0,
+ EX_SECURITY = -1,
+ EX_BAD_PARCELABLE = -2,
+ EX_ILLEGAL_ARGUMENT = -3,
+ EX_NULL_POINTER = -4,
+ EX_ILLEGAL_STATE = -5,
+ EX_NETWORK_MAIN_THREAD = -6,
+ EX_UNSUPPORTED_OPERATION = -7,
+ EX_TRANSACTION_FAILED = -8,
+
+ // This is special and Java specific; see Parcel.java.
+ EX_HAS_REPLY_HEADER = -128,
+ };
+
+ // Allow authors to explicitly pick whether their integer is a status_t or
+ // exception code.
+ static Status fromExceptionCode(int32_t exception_code);
+ static Status fromStatusT(status_t status);
+ // A more readable alias for the default constructor.
+ static Status ok();
+
+ Status() = default;
+ Status(int32_t exception_code, const String8& message);
+ Status(int32_t exception_code, const char* message);
+
+
+ // Status objects are copyable and contain just simple data.
+ Status(const Status& status) = default;
+ Status(Status&& status) = default;
+ Status& operator=(const Status& status) = default;
+
+ ~Status() = default;
+
+ // Bear in mind that if the client or service is a Java endpoint, this
+ // is not the logic which will provide/interpret the data here.
+ status_t readFromParcel(const Parcel& parcel);
+ status_t writeToParcel(Parcel* parcel) const;
+
+ // Set one of the pre-defined exception types defined above.
+ void setException(int32_t ex, const String8& message);
+ // A few of the status_t values map to exception codes, but most of them
+ // simply map to "transaction failed."
+ void setFromStatusT(status_t status);
+
+ // Get information about an exception.
+ // Any argument may be given as nullptr.
+ void getException(int32_t* returned_exception,
+ String8* returned_message) const;
+ int32_t exceptionCode() const { return mException; }
+ const String8& exceptionMessage() const { return mMessage; }
+
+ bool isOk() const { return mException == EX_NONE; }
+
+ // For logging.
+ String8 toString8() const;
+
+private:
+ // We always write |mException| to the parcel.
+ // If |mException| != EX_NONE, we write message as well.
+ int32_t mException = EX_NONE;
+ String8 mMessage;
+}; // class Status
+
+} // namespace binder
+} // namespace android
+
+#endif // ANDROID_BINDER_STATUS_H
diff --git a/libs/binder/Android.mk b/libs/binder/Android.mk
index d5860ef..bd432f3 100644
--- a/libs/binder/Android.mk
+++ b/libs/binder/Android.mk
@@ -36,6 +36,7 @@
PermissionCache.cpp \
ProcessState.cpp \
Static.cpp \
+ Status.cpp \
TextOutput.cpp \
LOCAL_PATH:= $(call my-dir)
diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp
index 9d200fb..e39093d 100644
--- a/libs/binder/Binder.cpp
+++ b/libs/binder/Binder.cpp
@@ -16,7 +16,7 @@
#include <binder/Binder.h>
-#include <stdatomic.h>
+#include <atomic>
#include <utils/misc.h>
#include <binder/BpBinder.h>
#include <binder/IInterface.h>
@@ -70,9 +70,8 @@
// ---------------------------------------------------------------------------
-BBinder::BBinder()
+BBinder::BBinder() : mExtras(nullptr)
{
- atomic_init(&mExtras, static_cast<uintptr_t>(0));
}
bool BBinder::isBinderAlive() const
@@ -139,19 +138,16 @@
const void* objectID, void* object, void* cleanupCookie,
object_cleanup_func func)
{
- Extras* e = reinterpret_cast<Extras*>(
- atomic_load_explicit(&mExtras, memory_order_acquire));
+ Extras* e = mExtras.load(std::memory_order_acquire);
if (!e) {
e = new Extras;
- uintptr_t expected = 0;
- if (!atomic_compare_exchange_strong_explicit(
- &mExtras, &expected,
- reinterpret_cast<uintptr_t>(e),
- memory_order_release,
- memory_order_acquire)) {
+ Extras* expected = nullptr;
+ if (!mExtras.compare_exchange_strong(expected, e,
+ std::memory_order_release,
+ std::memory_order_acquire)) {
delete e;
- e = reinterpret_cast<Extras*>(expected); // Filled in by CAS
+ e = expected; // Filled in by CAS
}
if (e == 0) return; // out of memory
}
@@ -160,18 +156,9 @@
e->mObjects.attach(objectID, object, cleanupCookie, func);
}
-// The C11 standard doesn't allow atomic loads from const fields,
-// though C++11 does. Fudge it until standards get straightened out.
-static inline uintptr_t load_const_atomic(const atomic_uintptr_t* p,
- memory_order mo) {
- atomic_uintptr_t* non_const_p = const_cast<atomic_uintptr_t*>(p);
- return atomic_load_explicit(non_const_p, mo);
-}
-
void* BBinder::findObject(const void* objectID) const
{
- Extras* e = reinterpret_cast<Extras*>(
- load_const_atomic(&mExtras, memory_order_acquire));
+ Extras* e = mExtras.load(std::memory_order_acquire);
if (!e) return NULL;
AutoMutex _l(e->mLock);
@@ -180,8 +167,7 @@
void BBinder::detachObject(const void* objectID)
{
- Extras* e = reinterpret_cast<Extras*>(
- atomic_load_explicit(&mExtras, memory_order_acquire));
+ Extras* e = mExtras.load(std::memory_order_acquire);
if (!e) return;
AutoMutex _l(e->mLock);
@@ -195,8 +181,7 @@
BBinder::~BBinder()
{
- Extras* e = reinterpret_cast<Extras*>(
- atomic_load_explicit(&mExtras, memory_order_relaxed));
+ Extras* e = mExtras.load(std::memory_order_relaxed);
if (e) delete e;
}
@@ -252,7 +237,7 @@
BpRefBase::~BpRefBase()
{
if (mRemote) {
- if (!(mState&kRemoteAcquired)) {
+ if (!(mState.load(std::memory_order_relaxed)&kRemoteAcquired)) {
mRemote->decStrong(this);
}
mRefs->decWeak(this);
@@ -261,7 +246,7 @@
void BpRefBase::onFirstRef()
{
- android_atomic_or(kRemoteAcquired, &mState);
+ mState.fetch_or(kRemoteAcquired, std::memory_order_relaxed);
}
void BpRefBase::onLastStrongRef(const void* /*id*/)
diff --git a/libs/binder/Debug.cpp b/libs/binder/Debug.cpp
index bdb7182..a8f2da5 100644
--- a/libs/binder/Debug.cpp
+++ b/libs/binder/Debug.cpp
@@ -138,7 +138,7 @@
*pos = 0;
return pos;
}
-
+
if( fullContext ) {
*pos++ = '0';
*pos++ = 'x';
@@ -167,21 +167,21 @@
if (func == NULL) func = defaultPrintFunc;
size_t offset;
-
+
unsigned char *pos = (unsigned char *)buf;
-
+
if (pos == NULL) {
if (singleLineBytesCutoff < 0) func(cookie, "\n");
func(cookie, "(NULL)");
return;
}
-
+
if (length == 0) {
if (singleLineBytesCutoff < 0) func(cookie, "\n");
func(cookie, "(empty)");
return;
}
-
+
if ((int32_t)length < 0) {
if (singleLineBytesCutoff < 0) func(cookie, "\n");
char buf[64];
@@ -189,12 +189,12 @@
func(cookie, buf);
return;
}
-
+
char buffer[256];
static const size_t maxBytesPerLine = (sizeof(buffer)-1-11-4)/(3+1);
-
+
if (bytesPerLine > maxBytesPerLine) bytesPerLine = maxBytesPerLine;
-
+
const bool oneLine = (int32_t)length <= singleLineBytesCutoff;
bool newLine = false;
if (cStyle) {
@@ -205,7 +205,7 @@
func(cookie, "\n");
newLine = true;
}
-
+
for (offset = 0; ; offset += bytesPerLine, pos += bytesPerLine) {
long remain = length;
@@ -217,21 +217,20 @@
size_t index;
size_t word;
-
+
for (word = 0; word < bytesPerLine; ) {
const size_t startIndex = word+(alignment-(alignment?1:0));
- const ssize_t dir = -1;
for (index = 0; index < alignment || (alignment == 0 && index < bytesPerLine); index++) {
-
+
if (!cStyle) {
if (index == 0 && word > 0 && alignment > 0) {
*c++ = ' ';
}
-
+
if (remain-- > 0) {
- const unsigned char val = *(pos+startIndex+(index*dir));
+ const unsigned char val = *(pos+startIndex-index);
*c++ = makehexdigit(val>>4);
*c++ = makehexdigit(val);
} else if (!oneLine) {
@@ -248,14 +247,14 @@
*c++ = '0';
*c++ = 'x';
}
- const unsigned char val = *(pos+startIndex+(index*dir));
+ const unsigned char val = *(pos+startIndex-index);
*c++ = makehexdigit(val>>4);
*c++ = makehexdigit(val);
remain--;
}
}
}
-
+
word += index;
}
@@ -272,7 +271,7 @@
*c++ = ' ';
}
}
-
+
*c++ = '\'';
if (length > bytesPerLine) *c++ = '\n';
} else {
@@ -284,7 +283,7 @@
*c = 0;
func(cookie, buffer);
newLine = true;
-
+
if (length <= bytesPerLine) break;
length -= bytesPerLine;
}
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 22d7ef3..1d6ec9e 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -23,6 +23,7 @@
#include <binder/Binder.h>
#include <binder/BpBinder.h>
#include <binder/ProcessState.h>
+#include <binder/Status.h>
#include <binder/TextOutput.h>
#include <errno.h>
@@ -69,9 +70,6 @@
// Note: must be kept in sync with android/os/StrictMode.java's PENALTY_GATHER
#define STRICT_MODE_PENALTY_GATHER (0x40 << 16)
-// Note: must be kept in sync with android/os/Parcel.java's EX_HAS_REPLY_HEADER
-#define EX_HAS_REPLY_HEADER -128
-
// XXX This can be made public if we want to provide
// support for typed data.
struct small_flat_data
@@ -338,6 +336,39 @@
return BAD_TYPE;
}
+namespace {
+
+template<typename T>
+status_t readTypedVector(std::vector<T>* val, const Parcel* p,
+ status_t(Parcel::*read_func)(T*) const) {
+ val->clear();
+
+ int32_t size;
+ status_t status = p->readInt32(&size);
+
+ if (status != OK) {
+ return status;
+ }
+
+ if (size < 0) {
+ return UNEXPECTED_NULL;
+ }
+
+ val->resize(size);
+
+ for (auto& v: *val) {
+ status = (p->*read_func)(&v);
+
+ if (status != OK) {
+ return status;
+ }
+ }
+
+ return OK;
+}
+
+} // namespace
+
// ---------------------------------------------------------------------------
Parcel::Parcel()
@@ -378,13 +409,11 @@
size_t Parcel::dataAvail() const
{
- // TODO: decide what to do about the possibility that this can
- // report an available-data size that exceeds a Java int's max
- // positive value, causing havoc. Fortunately this will only
- // happen if someone constructs a Parcel containing more than two
- // gigabytes of data, which on typical phone hardware is simply
- // not possible.
- return dataSize() - dataPosition();
+ size_t result = dataSize() - dataPosition();
+ if (result > INT32_MAX) {
+ abort();
+ }
+ return result;
}
size_t Parcel::dataPosition() const
@@ -745,6 +774,104 @@
return NULL;
}
+namespace {
+
+template<typename T, typename U>
+status_t unsafeWriteTypedVector(const std::vector<T>& val, Parcel* p,
+ status_t(Parcel::*write_func)(U)) {
+ if (val.size() > std::numeric_limits<int32_t>::max()) {
+ return BAD_VALUE;
+ }
+
+ status_t status = p->writeInt32(val.size());
+
+ if (status != OK) {
+ return status;
+ }
+
+ for (const auto& item : val) {
+ status = (p->*write_func)(item);
+
+ if (status != OK) {
+ return status;
+ }
+ }
+
+ return OK;
+}
+
+template<typename T>
+status_t writeTypedVector(const std::vector<T>& val, Parcel* p,
+ status_t(Parcel::*write_func)(const T&)) {
+ return unsafeWriteTypedVector(val, p, write_func);
+}
+
+template<typename T>
+status_t writeTypedVector(const std::vector<T>& val, Parcel* p,
+ status_t(Parcel::*write_func)(T)) {
+ return unsafeWriteTypedVector(val, p, write_func);
+}
+
+} // namespace
+
+status_t Parcel::writeByteVector(const std::vector<int8_t>& val)
+{
+ status_t status;
+ if (val.size() > std::numeric_limits<int32_t>::max()) {
+ status = BAD_VALUE;
+ return status;
+ }
+
+ status = writeInt32(val.size());
+ if (status != OK) {
+ return status;
+ }
+
+ void* data = writeInplace(val.size());
+ if (!data) {
+ status = BAD_VALUE;
+ return status;
+ }
+
+ memcpy(data, val.data(), val.size());
+ return status;
+}
+
+status_t Parcel::writeInt32Vector(const std::vector<int32_t>& val)
+{
+ return writeTypedVector(val, this, &Parcel::writeInt32);
+}
+
+status_t Parcel::writeInt64Vector(const std::vector<int64_t>& val)
+{
+ return writeTypedVector(val, this, &Parcel::writeInt64);
+}
+
+status_t Parcel::writeFloatVector(const std::vector<float>& val)
+{
+ return writeTypedVector(val, this, &Parcel::writeFloat);
+}
+
+status_t Parcel::writeDoubleVector(const std::vector<double>& val)
+{
+ return writeTypedVector(val, this, &Parcel::writeDouble);
+}
+
+status_t Parcel::writeBoolVector(const std::vector<bool>& val)
+{
+ return writeTypedVector(val, this, &Parcel::writeBool);
+}
+
+status_t Parcel::writeCharVector(const std::vector<char16_t>& val)
+{
+ return writeTypedVector(val, this, &Parcel::writeChar);
+}
+
+status_t Parcel::writeString16Vector(const std::vector<String16>& val)
+{
+ return writeTypedVector(val, this, &Parcel::writeString16);
+}
+
status_t Parcel::writeInt32(int32_t val)
{
return writeAligned(val);
@@ -788,6 +915,21 @@
return ret;
}
+status_t Parcel::writeBool(bool val)
+{
+ return writeInt32(int32_t(val));
+}
+
+status_t Parcel::writeChar(char16_t val)
+{
+ return writeInt32(int32_t(val));
+}
+
+status_t Parcel::writeByte(int8_t val)
+{
+ return writeInt32(int32_t(val));
+}
+
status_t Parcel::writeInt64(int64_t val)
{
return writeAligned(val);
@@ -874,6 +1016,15 @@
return flatten_binder(ProcessState::self(), val, this);
}
+status_t Parcel::writeStrongBinderVector(const std::vector<sp<IBinder>>& val)
+{
+ return writeTypedVector(val, this, &Parcel::writeStrongBinder);
+}
+
+status_t Parcel::readStrongBinderVector(std::vector<sp<IBinder>>* val) const {
+ return readTypedVector(val, this, &Parcel::readStrongBinder);
+}
+
status_t Parcel::writeWeakBinder(const wp<IBinder>& val)
{
return flatten_binder(ProcessState::self(), val, this);
@@ -1077,7 +1228,8 @@
status_t Parcel::writeNoException()
{
- return writeInt32(0);
+ binder::Status status;
+ return status.writeToParcel(this);
}
void Parcel::remove(size_t /*start*/, size_t /*amt*/)
@@ -1160,6 +1312,93 @@
return err;
}
+status_t Parcel::readByteVector(std::vector<int8_t>* val) const {
+ val->clear();
+
+ int32_t size;
+ status_t status = readInt32(&size);
+
+ if (status != OK) {
+ return status;
+ }
+
+ if (size < 0) {
+ status = UNEXPECTED_NULL;
+ return status;
+ }
+ if (size_t(size) > dataAvail()) {
+ status = BAD_VALUE;
+ return status;
+ }
+
+ const void* data = readInplace(size);
+ if (!data) {
+ status = BAD_VALUE;
+ return status;
+ }
+ val->resize(size);
+ memcpy(val->data(), data, size);
+
+ return status;
+}
+
+status_t Parcel::readInt32Vector(std::vector<int32_t>* val) const {
+ return readTypedVector(val, this, &Parcel::readInt32);
+}
+
+status_t Parcel::readInt64Vector(std::vector<int64_t>* val) const {
+ return readTypedVector(val, this, &Parcel::readInt64);
+}
+
+status_t Parcel::readFloatVector(std::vector<float>* val) const {
+ return readTypedVector(val, this, &Parcel::readFloat);
+}
+
+status_t Parcel::readDoubleVector(std::vector<double>* val) const {
+ return readTypedVector(val, this, &Parcel::readDouble);
+}
+
+status_t Parcel::readBoolVector(std::vector<bool>* val) const {
+ val->clear();
+
+ int32_t size;
+ status_t status = readInt32(&size);
+
+ if (status != OK) {
+ return status;
+ }
+
+ if (size < 0) {
+ return UNEXPECTED_NULL;
+ }
+
+ val->resize(size);
+
+ /* C++ bool handling means a vector of bools isn't necessarily addressable
+ * (we might use individual bits)
+ */
+ bool data;
+ for (int32_t i = 0; i < size; ++i) {
+ status = readBool(&data);
+ (*val)[i] = data;
+
+ if (status != OK) {
+ return status;
+ }
+ }
+
+ return OK;
+}
+
+status_t Parcel::readCharVector(std::vector<char16_t>* val) const {
+ return readTypedVector(val, this, &Parcel::readChar);
+}
+
+status_t Parcel::readString16Vector(std::vector<String16>* val) const {
+ return readTypedVector(val, this, &Parcel::readString16);
+}
+
+
status_t Parcel::readInt32(int32_t *pArg) const
{
return readAligned(pArg);
@@ -1278,6 +1517,44 @@
return readAligned<intptr_t>();
}
+status_t Parcel::readBool(bool *pArg) const
+{
+ int32_t tmp;
+ status_t ret = readInt32(&tmp);
+ *pArg = (tmp != 0);
+ return ret;
+}
+
+bool Parcel::readBool() const
+{
+ return readInt32() != 0;
+}
+
+status_t Parcel::readChar(char16_t *pArg) const
+{
+ int32_t tmp;
+ status_t ret = readInt32(&tmp);
+ *pArg = char16_t(tmp);
+ return ret;
+}
+
+char16_t Parcel::readChar() const
+{
+ return char16_t(readInt32());
+}
+
+status_t Parcel::readByte(int8_t *pArg) const
+{
+ int32_t tmp;
+ status_t ret = readInt32(&tmp);
+ *pArg = int8_t(tmp);
+ return ret;
+}
+
+int8_t Parcel::readByte() const
+{
+ return int8_t(readInt32());
+}
const char* Parcel::readCString() const
{
@@ -1316,6 +1593,19 @@
return String16();
}
+status_t Parcel::readString16(String16* pArg) const
+{
+ size_t len;
+ const char16_t* str = readString16Inplace(&len);
+ if (str) {
+ pArg->setTo(str, len);
+ return 0;
+ } else {
+ *pArg = String16();
+ return UNEXPECTED_NULL;
+ }
+}
+
const char16_t* Parcel::readString16Inplace(size_t* outLen) const
{
int32_t size = readInt32();
@@ -1331,10 +1621,15 @@
return NULL;
}
+status_t Parcel::readStrongBinder(sp<IBinder>* val) const
+{
+ return unflatten_binder(ProcessState::self(), *this, val);
+}
+
sp<IBinder> Parcel::readStrongBinder() const
{
sp<IBinder> val;
- unflatten_binder(ProcessState::self(), *this, &val);
+ readStrongBinder(&val);
return val;
}
@@ -1347,18 +1642,9 @@
int32_t Parcel::readExceptionCode() const
{
- int32_t exception_code = readAligned<int32_t>();
- if (exception_code == EX_HAS_REPLY_HEADER) {
- int32_t header_start = dataPosition();
- int32_t header_size = readAligned<int32_t>();
- // Skip over fat responses headers. Not used (or propagated) in
- // native code
- setDataPosition(header_start + header_size);
- // And fat response headers are currently only used when there are no
- // exceptions, so return no error:
- return 0;
- }
- return exception_code;
+ binder::Status status;
+ status.readFromParcel(*this);
+ return status.exceptionCode();
}
native_handle* Parcel::readNativeHandle() const
@@ -1671,8 +1957,14 @@
if (mData) {
LOG_ALLOC("Parcel %p: freeing with %zu capacity", this, mDataCapacity);
pthread_mutex_lock(&gParcelGlobalAllocSizeLock);
- gParcelGlobalAllocSize -= mDataCapacity;
- gParcelGlobalAllocCount--;
+ if (mDataCapacity <= gParcelGlobalAllocSize) {
+ gParcelGlobalAllocSize = gParcelGlobalAllocSize - mDataCapacity;
+ } else {
+ gParcelGlobalAllocSize = 0;
+ }
+ if (gParcelGlobalAllocCount > 0) {
+ gParcelGlobalAllocCount--;
+ }
pthread_mutex_unlock(&gParcelGlobalAllocSizeLock);
free(mData);
}
@@ -1851,6 +2143,7 @@
pthread_mutex_lock(&gParcelGlobalAllocSizeLock);
gParcelGlobalAllocSize += desired;
gParcelGlobalAllocSize -= mDataCapacity;
+ gParcelGlobalAllocCount++;
pthread_mutex_unlock(&gParcelGlobalAllocSizeLock);
mData = data;
mDataCapacity = desired;
diff --git a/libs/binder/Status.cpp b/libs/binder/Status.cpp
new file mode 100644
index 0000000..41fff3d
--- /dev/null
+++ b/libs/binder/Status.cpp
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2015 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 <binder/Status.h>
+
+namespace android {
+namespace binder {
+
+Status Status::fromExceptionCode(int32_t exception_code) {
+ return Status(exception_code, "");
+}
+
+Status Status::fromStatusT(status_t status) {
+ Status ret;
+ ret.setFromStatusT(status);
+ return ret;
+}
+
+Status Status::ok() {
+ return Status();
+}
+
+Status::Status(int32_t exception_code, const String8& message)
+ : mException(exception_code),
+ mMessage(message) {}
+
+Status::Status(int32_t exception_code, const char* message)
+ : mException(exception_code),
+ mMessage(message) {}
+
+status_t Status::readFromParcel(const Parcel& parcel) {
+ status_t status = parcel.readInt32(&mException);
+ if (status != OK) {
+ setFromStatusT(status);
+ return status;
+ }
+
+ // Skip over fat response headers. Not used (or propagated) in native code.
+ if (mException == EX_HAS_REPLY_HEADER) {
+ // Note that the header size includes the 4 byte size field.
+ const int32_t header_start = parcel.dataPosition();
+ int32_t header_size;
+ status = parcel.readInt32(&header_size);
+ if (status != OK) {
+ setFromStatusT(status);
+ return status;
+ }
+ parcel.setDataPosition(header_start + header_size);
+ // And fat response headers are currently only used when there are no
+ // exceptions, so act like there was no error.
+ mException = EX_NONE;
+ }
+
+ if (mException == EX_NONE) {
+ return status;
+ }
+
+ // The remote threw an exception. Get the message back.
+ mMessage = String8(parcel.readString16());
+
+ return status;
+}
+
+status_t Status::writeToParcel(Parcel* parcel) const {
+ status_t status = parcel->writeInt32(mException);
+ if (status != OK) { return status; }
+ if (mException == EX_NONE) {
+ // We have no more information to write.
+ return status;
+ }
+ status = parcel->writeString16(String16(mMessage));
+ return status;
+}
+
+void Status::setFromStatusT(status_t status) {
+ switch (status) {
+ case NO_ERROR:
+ mException = EX_NONE;
+ mMessage.clear();
+ break;
+ case UNEXPECTED_NULL:
+ mException = EX_NULL_POINTER;
+ mMessage.setTo("Unexpected null reference in Parcel");
+ break;
+ default:
+ mException = EX_TRANSACTION_FAILED;
+ mMessage.setTo("Transaction failed");
+ break;
+ }
+}
+
+void Status::setException(int32_t ex, const String8& message) {
+ mException = ex;
+ mMessage.setTo(message);
+}
+
+void Status::getException(int32_t* returned_exception,
+ String8* returned_message) const {
+ if (returned_exception) {
+ *returned_exception = mException;
+ }
+ if (returned_message) {
+ returned_message->setTo(mMessage);
+ }
+}
+
+String8 Status::toString8() const {
+ String8 ret;
+ if (mException == EX_NONE) {
+ ret.append("No error");
+ } else {
+ ret.appendFormat("Status(%d): '", mException);
+ ret.append(String8(mMessage));
+ ret.append("'");
+ }
+ return ret;
+}
+
+} // namespace binder
+} // namespace android
diff --git a/services/batteryservice/BatteryProperties.cpp b/services/batteryservice/BatteryProperties.cpp
index f13d6e8..07cc797 100644
--- a/services/batteryservice/BatteryProperties.cpp
+++ b/services/batteryservice/BatteryProperties.cpp
@@ -34,6 +34,7 @@
chargerUsbOnline = p->readInt32() == 1 ? true : false;
chargerWirelessOnline = p->readInt32() == 1 ? true : false;
maxChargingCurrent = p->readInt32();
+ maxChargingVoltage = p->readInt32();
batteryStatus = p->readInt32();
batteryHealth = p->readInt32();
batteryPresent = p->readInt32() == 1 ? true : false;
@@ -49,6 +50,7 @@
p->writeInt32(chargerUsbOnline ? 1 : 0);
p->writeInt32(chargerWirelessOnline ? 1 : 0);
p->writeInt32(maxChargingCurrent);
+ p->writeInt32(maxChargingVoltage);
p->writeInt32(batteryStatus);
p->writeInt32(batteryHealth);
p->writeInt32(batteryPresent ? 1 : 0);