Merge changes I4ebccfd0,I3507bdfd,Iaf02f55c am: acca0abaf1
am: f6ec7d5e3a
* commit 'f6ec7d5e3a55ee7eca4203dc386b6d0837b8e660':
Parcel: file descriptor leak
Parcel: include Android coding standard
Parcel: LOG_TAG cleanup
diff --git a/Android.mk b/Android.mk
index adb9674..14be920 100644
--- a/Android.mk
+++ b/Android.mk
@@ -23,10 +23,12 @@
IAppOpsService.cpp \
IBatteryStats.cpp \
IInterface.cpp \
+ IMediaResourceMonitor.cpp \
IMemory.cpp \
IPCThreadState.cpp \
IPermissionController.cpp \
IProcessInfoService.cpp \
+ IResultReceiver.cpp \
IServiceManager.cpp \
MemoryBase.cpp \
MemoryDealer.cpp \
diff --git a/Binder.cpp b/Binder.cpp
index e39093d..c4d47ca 100644
--- a/Binder.cpp
+++ b/Binder.cpp
@@ -20,6 +20,7 @@
#include <utils/misc.h>
#include <binder/BpBinder.h>
#include <binder/IInterface.h>
+#include <binder/IResultReceiver.h>
#include <binder/Parcel.h>
#include <stdio.h>
@@ -59,6 +60,24 @@
return false;
}
+
+status_t IBinder::shellCommand(const sp<IBinder>& target, int in, int out, int err,
+ Vector<String16>& args, const sp<IResultReceiver>& resultReceiver)
+{
+ Parcel send;
+ Parcel reply;
+ send.writeFileDescriptor(in);
+ send.writeFileDescriptor(out);
+ send.writeFileDescriptor(err);
+ const size_t numArgs = args.size();
+ send.writeInt32(numArgs);
+ for (size_t i = 0; i < numArgs; i++) {
+ send.writeString16(args[i]);
+ }
+ send.writeStrongBinder(resultReceiver != NULL ? IInterface::asBinder(resultReceiver) : NULL);
+ return target->transact(SHELL_COMMAND_TRANSACTION, send, &reply);
+}
+
// ---------------------------------------------------------------------------
class BBinder::Extras
@@ -129,7 +148,7 @@
return INVALID_OPERATION;
}
- status_t BBinder::dump(int /*fd*/, const Vector<String16>& /*args*/)
+status_t BBinder::dump(int /*fd*/, const Vector<String16>& /*args*/)
{
return NO_ERROR;
}
@@ -204,6 +223,25 @@
return dump(fd, args);
}
+ case SHELL_COMMAND_TRANSACTION: {
+ int in = data.readFileDescriptor();
+ int out = data.readFileDescriptor();
+ int err = data.readFileDescriptor();
+ int argc = data.readInt32();
+ Vector<String16> args;
+ for (int i = 0; i < argc && data.dataAvail() > 0; i++) {
+ args.add(data.readString16());
+ }
+ sp<IResultReceiver> resultReceiver = IResultReceiver::asInterface(
+ data.readStrongBinder());
+
+ // XXX can't add virtuals until binaries are updated.
+ //return shellCommand(in, out, err, args, resultReceiver);
+ if (resultReceiver != NULL) {
+ resultReceiver->send(INVALID_OPERATION);
+ }
+ }
+
case SYSPROPS_TRANSACTION: {
report_sysprop_change();
return NO_ERROR;
diff --git a/BpBinder.cpp b/BpBinder.cpp
index 345ba20..c0e0296 100644
--- a/BpBinder.cpp
+++ b/BpBinder.cpp
@@ -20,6 +20,7 @@
#include <binder/BpBinder.h>
#include <binder/IPCThreadState.h>
+#include <binder/IResultReceiver.h>
#include <utils/Log.h>
#include <stdio.h>
diff --git a/IMediaResourceMonitor.cpp b/IMediaResourceMonitor.cpp
new file mode 100644
index 0000000..e8deb4a
--- /dev/null
+++ b/IMediaResourceMonitor.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2016 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/IMediaResourceMonitor.h>
+#include <binder/Parcel.h>
+#include <utils/Errors.h>
+#include <sys/types.h>
+
+namespace android {
+
+// ----------------------------------------------------------------------
+
+class BpMediaResourceMonitor : public BpInterface<IMediaResourceMonitor> {
+public:
+ BpMediaResourceMonitor(const sp<IBinder>& impl)
+ : BpInterface<IMediaResourceMonitor>(impl) {}
+
+ virtual void notifyResourceGranted(/*in*/ int32_t pid, /*in*/ const String16& type,
+ /*in*/ const String16& subType, /*in*/ int64_t value)
+ {
+ Parcel data, reply;
+ data.writeInterfaceToken(IMediaResourceMonitor::getInterfaceDescriptor());
+ data.writeInt32(pid);
+ data.writeString16(type);
+ data.writeString16(subType);
+ data.writeInt64(value);
+ remote()->transact(NOTIFY_RESOURCE_GRANTED, data, &reply, IBinder::FLAG_ONEWAY);
+ }
+};
+
+IMPLEMENT_META_INTERFACE(MediaResourceMonitor, "android.media.IMediaResourceMonitor");
+
+// ----------------------------------------------------------------------
+
+status_t BnMediaResourceMonitor::onTransact( uint32_t code, const Parcel& data, Parcel* reply,
+ uint32_t flags) {
+ switch(code) {
+ case NOTIFY_RESOURCE_GRANTED: {
+ CHECK_INTERFACE(IMediaResourceMonitor, data, reply);
+ int32_t pid = data.readInt32();
+ const String16 type = data.readString16();
+ const String16 subType = data.readString16();
+ int64_t value = data.readInt64();
+ notifyResourceGranted(/*in*/ pid, /*in*/ type, /*in*/ subType, /*in*/ value);
+ return NO_ERROR;
+ } break;
+ default:
+ return BBinder::onTransact(code, data, reply, flags);
+ }
+}
+
+// ----------------------------------------------------------------------
+
+}; // namespace android
diff --git a/IProcessInfoService.cpp b/IProcessInfoService.cpp
index d86eb27..c37920d 100644
--- a/IProcessInfoService.cpp
+++ b/IProcessInfoService.cpp
@@ -49,6 +49,39 @@
return reply.readInt32();
}
+ virtual status_t getProcessStatesAndOomScoresFromPids(size_t length,
+ /*in*/ int32_t* pids, /*out*/ int32_t* states, /*out*/ int32_t* scores)
+ {
+ Parcel data, reply;
+ data.writeInterfaceToken(IProcessInfoService::getInterfaceDescriptor());
+ data.writeInt32Array(length, pids);
+ // write length of output arrays, used by java AIDL stubs
+ data.writeInt32(length);
+ data.writeInt32(length);
+ status_t err = remote()->transact(
+ GET_PROCESS_STATES_AND_OOM_SCORES_FROM_PIDS, data, &reply);
+ if (err != NO_ERROR
+ || ((err = reply.readExceptionCode()) != NO_ERROR)) {
+ return err;
+ }
+ int32_t replyLen = reply.readInt32();
+ if (static_cast<size_t>(replyLen) != length) {
+ return NOT_ENOUGH_DATA;
+ }
+ if (replyLen > 0 && (err = reply.read(
+ states, length * sizeof(*states))) != NO_ERROR) {
+ return err;
+ }
+ replyLen = reply.readInt32();
+ if (static_cast<size_t>(replyLen) != length) {
+ return NOT_ENOUGH_DATA;
+ }
+ if (replyLen > 0 && (err = reply.read(
+ scores, length * sizeof(*scores))) != NO_ERROR) {
+ return err;
+ }
+ return reply.readInt32();
+ }
};
IMPLEMENT_META_INTERFACE(ProcessInfoService, "android.os.IProcessInfoService");
@@ -84,6 +117,38 @@
reply->writeInt32(res);
return NO_ERROR;
} break;
+ case GET_PROCESS_STATES_AND_OOM_SCORES_FROM_PIDS: {
+ CHECK_INTERFACE(IProcessInfoService, data, reply);
+ int32_t arrayLen = data.readInt32();
+ if (arrayLen <= 0) {
+ reply->writeNoException();
+ reply->writeInt32(0);
+ reply->writeInt32(NOT_ENOUGH_DATA);
+ return NO_ERROR;
+ }
+
+ size_t len = static_cast<size_t>(arrayLen);
+ int32_t pids[len];
+ status_t res = data.read(pids, len * sizeof(*pids));
+
+ // Ignore output array length returned in the parcel here, as the
+ // states array must always be the same length as the input PIDs array.
+ int32_t states[len];
+ int32_t scores[len];
+ for (size_t i = 0; i < len; i++) {
+ states[i] = -1;
+ scores[i] = -10000;
+ }
+ if (res == NO_ERROR) {
+ res = getProcessStatesAndOomScoresFromPids(
+ len, /*in*/ pids, /*out*/ states, /*out*/ scores);
+ }
+ reply->writeNoException();
+ reply->writeInt32Array(len, states);
+ reply->writeInt32Array(len, scores);
+ reply->writeInt32(res);
+ return NO_ERROR;
+ } break;
default:
return BBinder::onTransact(code, data, reply, flags);
}
diff --git a/IResultReceiver.cpp b/IResultReceiver.cpp
new file mode 100644
index 0000000..2a22b69
--- /dev/null
+++ b/IResultReceiver.cpp
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "ResultReceiver"
+
+#include <binder/IResultReceiver.h>
+
+#include <utils/Log.h>
+#include <binder/Parcel.h>
+#include <utils/String8.h>
+
+#include <private/binder/Static.h>
+
+namespace android {
+
+// ----------------------------------------------------------------------
+
+class BpResultReceiver : public BpInterface<IResultReceiver>
+{
+public:
+ BpResultReceiver(const sp<IBinder>& impl)
+ : BpInterface<IResultReceiver>(impl)
+ {
+ }
+
+ virtual void send(int32_t resultCode) {
+ Parcel data;
+ data.writeInterfaceToken(IResultReceiver::getInterfaceDescriptor());
+ data.writeInt32(resultCode);
+ remote()->transact(OP_SEND, data, NULL, IBinder::FLAG_ONEWAY);
+ }
+};
+
+IMPLEMENT_META_INTERFACE(ResultReceiver, "com.android.internal.os.IResultReceiver");
+
+// ----------------------------------------------------------------------
+
+status_t BnResultReceiver::onTransact(
+ uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
+{
+ switch(code) {
+ case OP_SEND: {
+ CHECK_INTERFACE(IResultReceiver, data, reply);
+ int32_t resultCode = data.readInt32();
+ send(resultCode);
+ if (reply != NULL) {
+ reply->writeNoException();
+ }
+ return NO_ERROR;
+ } break;
+ default:
+ return BBinder::onTransact(code, data, reply, flags);
+ }
+}
+
+}; // namespace android
diff --git a/include/hwbinder/IBinder.h b/include/hwbinder/IBinder.h
index d98d4c5..5f1e87c 100644
--- a/include/hwbinder/IBinder.h
+++ b/include/hwbinder/IBinder.h
@@ -37,6 +37,7 @@
class BpBinder;
class IInterface;
class Parcel;
+class IResultReceiver;
/**
* Base class and low-level protocol for a remotable object.
@@ -54,6 +55,7 @@
PING_TRANSACTION = B_PACK_CHARS('_','P','N','G'),
DUMP_TRANSACTION = B_PACK_CHARS('_','D','M','P'),
+ SHELL_COMMAND_TRANSACTION = B_PACK_CHARS('_','C','M','D'),
INTERFACE_TRANSACTION = B_PACK_CHARS('_', 'N', 'T', 'F'),
SYSPROPS_TRANSACTION = B_PACK_CHARS('_', 'S', 'P', 'R'),
@@ -79,6 +81,9 @@
virtual bool isBinderAlive() const = 0;
virtual status_t pingBinder() = 0;
virtual status_t dump(int fd, const Vector<String16>& args) = 0;
+ static status_t shellCommand(const sp<IBinder>& target, int in, int out, int err,
+ Vector<String16>& args,
+ const sp<IResultReceiver>& resultReceiver);
virtual status_t transact( uint32_t code,
const Parcel& data,
diff --git a/include/hwbinder/IMediaResourceMonitor.h b/include/hwbinder/IMediaResourceMonitor.h
new file mode 100644
index 0000000..b7b9c50
--- /dev/null
+++ b/include/hwbinder/IMediaResourceMonitor.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2016 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_I_MEDIA_RESOURCE_MONITOR_H
+#define ANDROID_I_MEDIA_RESOURCE_MONITOR_H
+
+#include <binder/IInterface.h>
+
+namespace android {
+
+// ----------------------------------------------------------------------
+
+class IMediaResourceMonitor : public IInterface {
+public:
+ DECLARE_META_INTERFACE(MediaResourceMonitor);
+
+ virtual void notifyResourceGranted(/*in*/ int32_t pid, /*in*/ const String16& type,
+ /*in*/ const String16& subType, /*in*/ int64_t value) = 0;
+
+ enum {
+ NOTIFY_RESOURCE_GRANTED = IBinder::FIRST_CALL_TRANSACTION,
+ };
+};
+
+// ----------------------------------------------------------------------
+
+class BnMediaResourceMonitor : public BnInterface<IMediaResourceMonitor> {
+public:
+ virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
+ uint32_t flags = 0);
+};
+
+// ----------------------------------------------------------------------
+
+}; // namespace android
+
+#endif // ANDROID_I_MEDIA_RESOURCE_MONITOR_H
diff --git a/include/hwbinder/IProcessInfoService.h b/include/hwbinder/IProcessInfoService.h
index dc62f45..34ce0f0 100644
--- a/include/hwbinder/IProcessInfoService.h
+++ b/include/hwbinder/IProcessInfoService.h
@@ -31,8 +31,14 @@
/*in*/ int32_t* pids,
/*out*/ int32_t* states) = 0;
+ virtual status_t getProcessStatesAndOomScoresFromPids( size_t length,
+ /*in*/ int32_t* pids,
+ /*out*/ int32_t* states,
+ /*out*/ int32_t* scores) = 0;
+
enum {
GET_PROCESS_STATES_FROM_PIDS = IBinder::FIRST_CALL_TRANSACTION,
+ GET_PROCESS_STATES_AND_OOM_SCORES_FROM_PIDS,
};
};
diff --git a/include/hwbinder/IResultReceiver.h b/include/hwbinder/IResultReceiver.h
new file mode 100644
index 0000000..02dc6a6
--- /dev/null
+++ b/include/hwbinder/IResultReceiver.h
@@ -0,0 +1,55 @@
+/*
+ * 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_IRESULT_RECEIVER_H
+#define ANDROID_IRESULT_RECEIVER_H
+
+#include <binder/IInterface.h>
+
+namespace android {
+
+// ----------------------------------------------------------------------
+
+class IResultReceiver : public IInterface
+{
+public:
+ DECLARE_META_INTERFACE(ResultReceiver);
+
+ virtual void send(int32_t resultCode) = 0;
+
+ enum {
+ OP_SEND = IBinder::FIRST_CALL_TRANSACTION
+ };
+};
+
+// ----------------------------------------------------------------------
+
+class BnResultReceiver : public BnInterface<IResultReceiver>
+{
+public:
+ virtual status_t onTransact( uint32_t code,
+ const Parcel& data,
+ Parcel* reply,
+ uint32_t flags = 0);
+};
+
+// ----------------------------------------------------------------------
+
+}; // namespace android
+
+#endif // ANDROID_IRESULT_RECEIVER_H
+