summaryrefslogtreecommitdiff
path: root/native
diff options
context:
space:
mode:
Diffstat (limited to 'native')
-rw-r--r--native/android/Android.mk10
-rw-r--r--native/android/configuration.cpp9
-rw-r--r--native/android/net.c85
-rw-r--r--native/android/sensor.cpp15
-rw-r--r--native/graphics/jni/Android.mk5
-rw-r--r--native/graphics/jni/bitmap.cpp41
6 files changed, 142 insertions, 23 deletions
diff --git a/native/android/Android.mk b/native/android/Android.mk
index b3a74a87801f..12fdf71ba46d 100644
--- a/native/android/Android.mk
+++ b/native/android/Android.mk
@@ -12,9 +12,10 @@ LOCAL_SRC_FILES:= \
looper.cpp \
native_activity.cpp \
native_window.cpp \
+ net.c \
obb.cpp \
sensor.cpp \
- storage_manager.cpp
+ storage_manager.cpp \
LOCAL_SHARED_LIBRARIES := \
liblog \
@@ -25,14 +26,17 @@ LOCAL_SHARED_LIBRARIES := \
libbinder \
libui \
libgui \
- libandroid_runtime
+ libandroid_runtime \
+ libnetd_client \
LOCAL_STATIC_LIBRARIES := \
libstorage
LOCAL_C_INCLUDES += \
frameworks/base/native/include \
- frameworks/base/core/jni/android
+ frameworks/base/core/jni/android \
+ bionic/libc/dns/include \
+ system/netd/include \
LOCAL_MODULE := libandroid
diff --git a/native/android/configuration.cpp b/native/android/configuration.cpp
index 74cf80e1f4f2..77237ae97ff5 100644
--- a/native/android/configuration.cpp
+++ b/native/android/configuration.cpp
@@ -101,6 +101,10 @@ int32_t AConfiguration_getScreenLong(AConfiguration* config) {
>> ResTable_config::SHIFT_SCREENLONG;
}
+int32_t AConfiguration_getScreenRound(AConfiguration* config) {
+ return (config->screenLayout2&ResTable_config::MASK_SCREENROUND);
+}
+
int32_t AConfiguration_getUiModeType(AConfiguration* config) {
return config->uiMode&ResTable_config::MASK_UI_MODE_TYPE;
}
@@ -192,6 +196,11 @@ void AConfiguration_setScreenLong(AConfiguration* config, int32_t screenLong) {
| ((screenLong<<ResTable_config::SHIFT_SCREENLONG)&ResTable_config::MASK_SCREENLONG);
}
+void AConfiguration_setScreenRound(AConfiguration* config, int32_t screenRound) {
+ config->screenLayout2 = (config->screenLayout2&~ResTable_config::MASK_SCREENROUND)
+ | (screenRound&ResTable_config::MASK_SCREENROUND);
+}
+
void AConfiguration_setUiModeType(AConfiguration* config, int32_t uiModeType) {
config->uiMode = (config->uiMode&~ResTable_config::MASK_UI_MODE_TYPE)
| (uiModeType&ResTable_config::MASK_UI_MODE_TYPE);
diff --git a/native/android/net.c b/native/android/net.c
new file mode 100644
index 000000000000..de4b90cc1956
--- /dev/null
+++ b/native/android/net.c
@@ -0,0 +1,85 @@
+/*
+ * 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 <android/multinetwork.h>
+#include <errno.h>
+#include <NetdClient.h> // the functions that communicate with netd
+#include <resolv_netid.h> // android_getaddrinfofornet()
+#include <stdlib.h>
+#include <sys/limits.h>
+
+
+static int getnetidfromhandle(net_handle_t handle, unsigned *netid) {
+ static const uint32_t k32BitMask = 0xffffffff;
+ // This value MUST be kept in sync with the corresponding value in
+ // the android.net.Network#getNetworkHandle() implementation.
+ static const uint32_t kHandleMagic = 0xfacade;
+
+ // Check for minimum acceptable version of the API in the low bits.
+ if (handle != NETWORK_UNSPECIFIED &&
+ (handle & k32BitMask) != kHandleMagic) {
+ return 0;
+ }
+
+ if (netid != NULL) {
+ *netid = ((handle >> (CHAR_BIT * sizeof(k32BitMask))) & k32BitMask);
+ }
+ return 1;
+}
+
+
+int android_setsocknetwork(net_handle_t network, int fd) {
+ unsigned netid;
+ if (!getnetidfromhandle(network, &netid)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ int rval = setNetworkForSocket(netid, fd);
+ if (rval < 0) {
+ errno = -rval;
+ rval = -1;
+ }
+ return rval;
+}
+
+int android_setprocnetwork(net_handle_t network) {
+ unsigned netid;
+ if (!getnetidfromhandle(network, &netid)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ int rval = setNetworkForProcess(netid);
+ if (rval < 0) {
+ errno = -rval;
+ rval = -1;
+ }
+ return rval;
+}
+
+int android_getaddrinfofornetwork(net_handle_t network,
+ const char *node, const char *service,
+ const struct addrinfo *hints, struct addrinfo **res) {
+ unsigned netid;
+ if (!getnetidfromhandle(network, &netid)) {
+ errno = EINVAL;
+ return EAI_SYSTEM;
+ }
+
+ return android_getaddrinfofornet(node, service, hints, netid, 0, res);
+}
diff --git a/native/android/sensor.cpp b/native/android/sensor.cpp
index 73b52aa2c604..26b41e85fddd 100644
--- a/native/android/sensor.cpp
+++ b/native/android/sensor.cpp
@@ -35,12 +35,25 @@ using android::Sensor;
using android::SensorManager;
using android::SensorEventQueue;
using android::String8;
+using android::String16;
/*****************************************************************************/
+android::Mutex android::SensorManager::sLock;
+std::map<String16, SensorManager*> android::SensorManager::sPackageInstances;
+
ASensorManager* ASensorManager_getInstance()
{
- return &SensorManager::getInstance();
+ return ASensorManager_getInstanceForPackage(NULL);
+}
+
+ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName)
+{
+ if (packageName) {
+ return &SensorManager::getInstanceForPackage(String16(packageName));
+ } else {
+ return &SensorManager::getInstanceForPackage(String16());
+ }
}
int ASensorManager_getSensorList(ASensorManager* manager,
diff --git a/native/graphics/jni/Android.mk b/native/graphics/jni/Android.mk
index 91c9ac621be4..1b684bb4e28b 100644
--- a/native/graphics/jni/Android.mk
+++ b/native/graphics/jni/Android.mk
@@ -24,14 +24,15 @@ LOCAL_SHARED_LIBRARIES := \
LOCAL_C_INCLUDES += \
frameworks/base/native/include \
- frameworks/base/core/jni/android/graphics
+ frameworks/base/core/jni/android/graphics \
+ frameworks/base/libs/hwui
LOCAL_MODULE:= libjnigraphics
LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
# TODO: This is to work around b/19059885. Remove after root cause is fixed
-LOCAL_LDFLAGS_arm := -Wl,--hash-style=sysv
+LOCAL_LDFLAGS_arm := -Wl,--hash-style=both
include $(BUILD_SHARED_LIBRARY)
diff --git a/native/graphics/jni/bitmap.cpp b/native/graphics/jni/bitmap.cpp
index ea32edc9955e..6d2de98759c8 100644
--- a/native/graphics/jni/bitmap.cpp
+++ b/native/graphics/jni/bitmap.cpp
@@ -27,18 +27,16 @@ int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap,
return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
}
- SkBitmap* bm = GraphicsJNI::getNativeBitmap(env, jbitmap);
- if (NULL == bm) {
- return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
- }
+ SkBitmap bm;
+ GraphicsJNI::getSkBitmap(env, jbitmap, &bm);
if (info) {
- info->width = bm->width();
- info->height = bm->height();
- info->stride = bm->rowBytes();
+ info->width = bm.width();
+ info->height = bm.height();
+ info->stride = bm.rowBytes();
info->flags = 0;
- switch (bm->colorType()) {
+ switch (bm.colorType()) {
case kN32_SkColorType:
info->format = ANDROID_BITMAP_FORMAT_RGBA_8888;
break;
@@ -64,15 +62,16 @@ int AndroidBitmap_lockPixels(JNIEnv* env, jobject jbitmap, void** addrPtr) {
return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
}
- SkBitmap* bm = GraphicsJNI::getNativeBitmap(env, jbitmap);
- if (NULL == bm) {
+ SkPixelRef* pixelRef = GraphicsJNI::refSkPixelRef(env, jbitmap);
+ if (!pixelRef) {
return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
}
- bm->lockPixels();
- void* addr = bm->getPixels();
+ pixelRef->lockPixels();
+ void* addr = pixelRef->pixels();
if (NULL == addr) {
- bm->unlockPixels();
+ pixelRef->unlockPixels();
+ pixelRef->unref();
return ANDROID_BITMAP_RESULT_ALLOCATION_FAILED;
}
@@ -87,8 +86,8 @@ int AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap) {
return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
}
- SkBitmap* bm = GraphicsJNI::getNativeBitmap(env, jbitmap);
- if (NULL == bm) {
+ SkPixelRef* pixelRef = GraphicsJNI::refSkPixelRef(env, jbitmap);
+ if (!pixelRef) {
return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
}
@@ -96,9 +95,17 @@ int AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap) {
// bitmaps. Note that this will slow down read-only accesses to the
// bitmaps, but the NDK methods are primarily intended to be used for
// writes.
- bm->notifyPixelsChanged();
+ pixelRef->notifyPixelsChanged();
+
+ pixelRef->unlockPixels();
+ // Awkward in that we need to double-unref as the call to get the SkPixelRef
+ // did a ref(), so we need to unref() for the local ref and for the previous
+ // AndroidBitmap_lockPixels(). However this keeps GraphicsJNI a bit safer
+ // if others start using it without knowing about android::Bitmap's "fun"
+ // ref counting mechanism(s).
+ pixelRef->unref();
+ pixelRef->unref();
- bm->unlockPixels();
return ANDROID_BITMAP_RESULT_SUCCESS;
}