diff options
Diffstat (limited to 'native/android')
| -rw-r--r-- | native/android/Android.mk | 37 | ||||
| -rw-r--r-- | native/android/asset_manager.cpp | 210 | ||||
| -rw-r--r-- | native/android/configuration.cpp | 202 | ||||
| -rw-r--r-- | native/android/input.cpp | 275 | ||||
| -rw-r--r-- | native/android/looper.cpp | 82 | ||||
| -rw-r--r-- | native/android/native_activity.cpp | 39 | ||||
| -rw-r--r-- | native/android/native_window.cpp | 97 | ||||
| -rw-r--r-- | native/android/sensor.cpp | 155 | ||||
| -rw-r--r-- | native/android/storage_manager.cpp | 141 |
9 files changed, 1238 insertions, 0 deletions
diff --git a/native/android/Android.mk b/native/android/Android.mk new file mode 100644 index 000000000000..cc35a3adf4ae --- /dev/null +++ b/native/android/Android.mk @@ -0,0 +1,37 @@ +BASE_PATH := $(call my-dir) +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +# our source files +# +LOCAL_SRC_FILES:= \ + asset_manager.cpp \ + configuration.cpp \ + input.cpp \ + looper.cpp \ + native_activity.cpp \ + native_window.cpp \ + sensor.cpp \ + storage_manager.cpp + +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + libutils \ + libbinder \ + libui \ + libgui \ + libsurfaceflinger_client \ + libandroid_runtime + +LOCAL_STATIC_LIBRARIES := \ + libstorage + +LOCAL_C_INCLUDES += \ + frameworks/base/native/include \ + frameworks/base/core/jni/android \ + dalvik/libnativehelper/include/nativehelper + +LOCAL_MODULE:= libandroid + +include $(BUILD_SHARED_LIBRARY) diff --git a/native/android/asset_manager.cpp b/native/android/asset_manager.cpp new file mode 100644 index 000000000000..3f7c1b69af17 --- /dev/null +++ b/native/android/asset_manager.cpp @@ -0,0 +1,210 @@ +/* + * Copyright (C) 2010 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 "NAsset" +#include <utils/Log.h> + +#include <android/asset_manager_jni.h> +#include <utils/AssetManager.h> +#include <utils/AssetDir.h> +#include <utils/Asset.h> +#include <utils/threads.h> + +#include "jni.h" +#include "JNIHelp.h" + +using namespace android; + +// -------------------- Backing implementation of the public API -------------------- + +// AAssetManager is actually a secret typedef for an empty base class of AssetManager, +// but AAssetDir and AAsset are actual wrappers for isolation. + +// ----- +struct AAssetDir { + AssetDir* mAssetDir; + size_t mCurFileIndex; + String8 mCachedFileName; + + AAssetDir(AssetDir* dir) : mAssetDir(dir), mCurFileIndex(0) { } + ~AAssetDir() { delete mAssetDir; } +}; + + +// ----- +struct AAsset { + Asset* mAsset; + + AAsset(Asset* asset) : mAsset(asset) { } + ~AAsset() { delete mAsset; } +}; + +// -------------------- Public native C API -------------------- + +/** + * Supporting information + */ + +static struct assetmanager_offsets_t +{ + jfieldID mObject; +} gAssetManagerOffsets; + +static volatile bool gJNIConfigured = false; +static Mutex gMutex; + +/** + * Asset Manager functionality + */ +AAssetManager* AAssetManager_fromJava(JNIEnv* env, jobject assetManager) +{ + { + Mutex::Autolock _l(gMutex); + + if (gJNIConfigured == false) { + jclass amClass = env->FindClass("android/content/res/AssetManager"); + gAssetManagerOffsets.mObject = env->GetFieldID(amClass, "mObject", "I"); + gJNIConfigured = true; + } + } + + return (AAssetManager*) env->GetIntField(assetManager, gAssetManagerOffsets.mObject); +} + +AAsset* AAssetManager_open(AAssetManager* amgr, const char* filename, int mode) +{ + Asset::AccessMode amMode; + switch (mode) { + case AASSET_MODE_UNKNOWN: + amMode = Asset::ACCESS_UNKNOWN; + break; + case AASSET_MODE_RANDOM: + amMode = Asset::ACCESS_RANDOM; + break; + case AASSET_MODE_STREAMING: + amMode = Asset::ACCESS_STREAMING; + break; + case AASSET_MODE_BUFFER: + amMode = Asset::ACCESS_BUFFER; + break; + default: + return NULL; + } + + AssetManager* mgr = static_cast<AssetManager*>(amgr); + Asset* asset = mgr->open(filename, amMode); + if (asset == NULL) { + return NULL; + } + + return new AAsset(asset); +} + +AAssetDir* AAssetManager_openDir(AAssetManager* amgr, const char* dirName) +{ + AssetManager* mgr = static_cast<AssetManager*>(amgr); + return new AAssetDir(mgr->openDir(dirName)); +} + +/** + * AssetDir functionality + */ + +const char* AAssetDir_getNextFileName(AAssetDir* assetDir) +{ + const char* returnName = NULL; + size_t index = assetDir->mCurFileIndex; + const size_t max = assetDir->mAssetDir->getFileCount(); + + // Find the next regular file; explicitly don't report directories even if the + // underlying implementation changes to report them. At that point we can add + // a more general iterator to this native interface set if appropriate. + while ((index < max) && (assetDir->mAssetDir->getFileType(index) != kFileTypeRegular)) { + index++; + } + + // still in bounds? then the one at 'index' is the next to be reported; generate + // the string to return and advance the iterator for next time. + if (index < max) { + assetDir->mCachedFileName = assetDir->mAssetDir->getFileName(index); + returnName = assetDir->mCachedFileName.string(); + index++; + } + + assetDir->mCurFileIndex = index; + return returnName; +} + +void AAssetDir_rewind(AAssetDir* assetDir) +{ + assetDir->mCurFileIndex = 0; +} + +const char* AAssetDir_getFileName(AAssetDir* assetDir, int index) +{ + assetDir->mCachedFileName = assetDir->mAssetDir->getFileName(index); + return assetDir->mCachedFileName.string(); +} + +void AAssetDir_close(AAssetDir* assetDir) +{ + delete assetDir; +} + +/** + * Asset functionality + */ + +int AAsset_read(AAsset* asset, void* buf, size_t count) +{ + return asset->mAsset->read(buf, (size_t)count); +} + +off_t AAsset_seek(AAsset* asset, off_t offset, int whence) +{ + return asset->mAsset->seek(offset, whence); +} + +void AAsset_close(AAsset* asset) +{ + asset->mAsset->close(); + delete asset; +} + +const void* AAsset_getBuffer(AAsset* asset) +{ + return asset->mAsset->getBuffer(false); +} + +off_t AAsset_getLength(AAsset* asset) +{ + return asset->mAsset->getLength(); +} + +off_t AAsset_getRemainingLength(AAsset* asset) +{ + return asset->mAsset->getRemainingLength(); +} + +int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength) +{ + return asset->mAsset->openFileDescriptor(outStart, outLength); +} + +int AAsset_isAllocated(AAsset* asset) +{ + return asset->mAsset->isAllocated() ? 1 : 0; +} diff --git a/native/android/configuration.cpp b/native/android/configuration.cpp new file mode 100644 index 000000000000..d76164ff418e --- /dev/null +++ b/native/android/configuration.cpp @@ -0,0 +1,202 @@ +/* + * Copyright (C) 2010 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 "Configuration" +#include <utils/Log.h> + +#include <utils/AssetManager.h> + +#include <android_runtime/android_content_res_Configuration.h> + +using namespace android; + +AConfiguration* AConfiguration_new() { + AConfiguration* config = new AConfiguration; + memset(config, 0, sizeof(AConfiguration)); + return config; +} + +void AConfiguration_delete(AConfiguration* config) { + delete config; +} + +void AConfiguration_fromAssetManager(AConfiguration* out, AAssetManager* am) { + ((AssetManager*)am)->getConfiguration(out); +} + +void AConfiguration_copy(AConfiguration* dest, AConfiguration* src) { + *dest = *src; +} + +int32_t AConfiguration_getMcc(AConfiguration* config) { + return config->mcc; +} + +int32_t AConfiguration_getMnc(AConfiguration* config) { + return config->mnc; +} + +void AConfiguration_getLanguage(AConfiguration* config, char* outLanguage) { + outLanguage[0] = config->language[0]; + outLanguage[1] = config->language[1]; +} + +void AConfiguration_getCountry(AConfiguration* config, char* outCountry) { + outCountry[0] = config->country[0]; + outCountry[1] = config->country[1]; +} + +int32_t AConfiguration_getOrientation(AConfiguration* config) { + return config->orientation; +} + +int32_t AConfiguration_getTouchscreen(AConfiguration* config) { + return config->touchscreen; +} + +int32_t AConfiguration_getDensity(AConfiguration* config) { + return config->density; +} + +int32_t AConfiguration_getKeyboard(AConfiguration* config) { + return config->keyboard; +} + +int32_t AConfiguration_getNavigation(AConfiguration* config) { + return config->navigation; +} + +int32_t AConfiguration_getKeysHidden(AConfiguration* config) { + return config->inputFlags&ResTable_config::MASK_KEYSHIDDEN; +} + +int32_t AConfiguration_getNavHidden(AConfiguration* config) { + return (config->inputFlags&ResTable_config::MASK_NAVHIDDEN) + >> ResTable_config::SHIFT_NAVHIDDEN; +} + +int32_t AConfiguration_getSdkVersion(AConfiguration* config) { + return config->sdkVersion; +} + +int32_t AConfiguration_getScreenSize(AConfiguration* config) { + return config->screenLayout&ResTable_config::MASK_SCREENSIZE; +} + +int32_t AConfiguration_getScreenLong(AConfiguration* config) { + return (config->screenLayout&ResTable_config::MASK_SCREENLONG) + >> ResTable_config::SHIFT_SCREENLONG; +} + +int32_t AConfiguration_getUiModeType(AConfiguration* config) { + return config->uiMode&ResTable_config::MASK_UI_MODE_TYPE; +} + +int32_t AConfiguration_getUiModeNight(AConfiguration* config) { + return (config->uiMode&ResTable_config::MASK_UI_MODE_NIGHT) + >> ResTable_config::SHIFT_UI_MODE_NIGHT; + +} + +// ---------------------------------------------------------------------- + +void AConfiguration_setMcc(AConfiguration* config, int32_t mcc) { + config->mcc = mcc; +} + +void AConfiguration_setMnc(AConfiguration* config, int32_t mnc) { + config->mnc = mnc; +} + +void AConfiguration_setLanguage(AConfiguration* config, const char* language) { + config->language[0] = language[0]; + config->language[1] = language[1]; +} + +void AConfiguration_setCountry(AConfiguration* config, const char* country) { + config->country[0] = country[0]; + config->country[1] = country[1]; +} + +void AConfiguration_setOrientation(AConfiguration* config, int32_t orientation) { + config->orientation = orientation; +} + +void AConfiguration_setTouchscreen(AConfiguration* config, int32_t touchscreen) { + config->touchscreen = touchscreen; +} + +void AConfiguration_setDensity(AConfiguration* config, int32_t density) { + config->density = density; +} + +void AConfiguration_setKeyboard(AConfiguration* config, int32_t keyboard) { + config->keyboard = keyboard; +} + +void AConfiguration_setNavigation(AConfiguration* config, int32_t navigation) { + config->navigation = navigation; +} + +void AConfiguration_setKeysHidden(AConfiguration* config, int32_t keysHidden) { + config->inputFlags = (config->inputFlags&~ResTable_config::MASK_KEYSHIDDEN) + | (keysHidden&ResTable_config::MASK_KEYSHIDDEN); +} + +void AConfiguration_setNavHidden(AConfiguration* config, int32_t navHidden) { + config->inputFlags = (config->inputFlags&~ResTable_config::MASK_NAVHIDDEN) + | ((navHidden<<ResTable_config::SHIFT_NAVHIDDEN)&ResTable_config::MASK_NAVHIDDEN); +} + +void AConfiguration_setSdkVersion(AConfiguration* config, int32_t sdkVersion) { + config->sdkVersion = sdkVersion; +} + +void AConfiguration_setScreenSize(AConfiguration* config, int32_t screenSize) { + config->screenLayout = (config->screenLayout&~ResTable_config::MASK_SCREENSIZE) + | (screenSize&ResTable_config::MASK_SCREENSIZE); +} + +void AConfiguration_setScreenLong(AConfiguration* config, int32_t screenLong) { + config->screenLayout = (config->screenLayout&~ResTable_config::MASK_SCREENLONG) + | ((screenLong<<ResTable_config::SHIFT_SCREENLONG)&ResTable_config::MASK_SCREENLONG); +} + +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); +} + +void AConfiguration_setUiModeNight(AConfiguration* config, int32_t uiModeNight) { + config->uiMode = (config->uiMode&~ResTable_config::MASK_UI_MODE_NIGHT) + | ((uiModeNight<<ResTable_config::SHIFT_UI_MODE_NIGHT)&ResTable_config::MASK_UI_MODE_NIGHT); + +} + +// ---------------------------------------------------------------------- + +int32_t AConfiguration_diff(AConfiguration* config1, AConfiguration* config2) { + return (config1->diff(*config2)); +} + +int32_t AConfiguration_match(AConfiguration* base, AConfiguration* requested) { + return base->match(*requested); +} + +int32_t AConfiguration_isBetterThan(AConfiguration* base, AConfiguration* test, + AConfiguration* requested) { + return base->isBetterThan(*test, requested); +} diff --git a/native/android/input.cpp b/native/android/input.cpp new file mode 100644 index 000000000000..57f007264670 --- /dev/null +++ b/native/android/input.cpp @@ -0,0 +1,275 @@ +/* + * Copyright (C) 2009 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 "input" +#include <utils/Log.h> + +#include <android/input.h> +#include <ui/Input.h> +#include <ui/InputTransport.h> +#include <utils/PollLoop.h> +#include <utils/RefBase.h> +#include <utils/Vector.h> + +#include <android_runtime/android_app_NativeActivity.h> + +#include <poll.h> +#include <errno.h> + +using android::InputEvent; +using android::KeyEvent; +using android::MotionEvent; +using android::InputDeviceInfo; +using android::sp; +using android::Vector; + +int32_t AInputEvent_getType(const AInputEvent* event) { + return static_cast<const InputEvent*>(event)->getType(); +} + +int32_t AInputEvent_getDeviceId(const AInputEvent* event) { + return static_cast<const InputEvent*>(event)->getDeviceId(); +} + +int32_t AInputEvent_getSource(const AInputEvent* event) { + return static_cast<const InputEvent*>(event)->getSource(); +} + +int32_t AKeyEvent_getAction(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getAction(); +} + +int32_t AKeyEvent_getFlags(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getFlags(); +} + +int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getKeyCode(); +} + +int32_t AKeyEvent_getScanCode(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getScanCode(); +} + +int32_t AKeyEvent_getMetaState(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getMetaState(); +} +int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getRepeatCount(); +} + +int64_t AKeyEvent_getDownTime(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getDownTime(); +} + + +int64_t AKeyEvent_getEventTime(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getEventTime(); +} + +int32_t AMotionEvent_getAction(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getAction(); +} + +int32_t AMotionEvent_getFlags(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getFlags(); +} + +int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getMetaState(); +} + +int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event) { + return reinterpret_cast<const MotionEvent*>(motion_event)->getEdgeFlags(); +} + +int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getDownTime(); +} + +int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getEventTime(); +} + +float AMotionEvent_getXOffset(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getXOffset(); +} + +float AMotionEvent_getYOffset(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getYOffset(); +} + +float AMotionEvent_getXPrecision(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getXPrecision(); +} + +float AMotionEvent_getYPrecision(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getYPrecision(); +} + +size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getPointerCount(); +} + +int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getPointerId(pointer_index); +} + +float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getRawX(pointer_index); +} + +float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getRawY(pointer_index); +} + +float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getX(pointer_index); +} + +float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getY(pointer_index); +} + +float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getPressure(pointer_index); +} + +float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getSize(pointer_index); +} + +float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getTouchMajor(pointer_index); +} + +float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getTouchMinor(pointer_index); +} + +float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getToolMajor(pointer_index); +} + +float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getToolMinor(pointer_index); +} + +float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getOrientation(pointer_index); +} + +size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getHistorySize(); +} + +int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalEventTime( + history_index); +} + +float AMotionEvent_getHistoricalRawX(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawX( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalRawY(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawY( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalX( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalY( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalPressure( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalSize( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalTouchMajor(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMajor( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalTouchMinor(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMinor( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalToolMajor(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMajor( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalToolMinor(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMinor( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalOrientation(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalOrientation( + pointer_index, history_index); +} + + +void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper, + int ident, ALooper_callbackFunc* callback, void* data) { + queue->attachLooper(looper, ident, callback, data); +} + +void AInputQueue_detachLooper(AInputQueue* queue) { + queue->detachLooper(); +} + +int32_t AInputQueue_hasEvents(AInputQueue* queue) { + return queue->hasEvents(); +} + +int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent) { + return queue->getEvent(outEvent); +} + +int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event) { + return queue->preDispatchEvent(event) ? 1 : 0; +} + +void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled) { + queue->finishEvent(event, handled != 0); +} diff --git a/native/android/looper.cpp b/native/android/looper.cpp new file mode 100644 index 000000000000..0aeed7776efe --- /dev/null +++ b/native/android/looper.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2010 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 "ALooper" +#include <utils/Log.h> + +#include <android/looper.h> +#include <utils/PollLoop.h> + +using android::PollLoop; +using android::sp; + +ALooper* ALooper_forThread() { + return PollLoop::getForThread().get(); +} + +ALooper* ALooper_prepare(int32_t opts) { + bool allowFds = (opts&ALOOPER_PREPARE_ALLOW_NON_CALLBACKS) != 0; + sp<PollLoop> loop = PollLoop::getForThread(); + if (loop == NULL) { + loop = new PollLoop(allowFds); + PollLoop::setForThread(loop); + } + if (loop->getAllowNonCallbacks() != allowFds) { + LOGW("ALooper_prepare again with different ALOOPER_PREPARE_ALLOW_NON_CALLBACKS"); + } + return loop.get(); +} + +int32_t ALooper_pollOnce(int timeoutMillis, int* outEvents, void** outData) { + sp<PollLoop> loop = PollLoop::getForThread(); + if (loop == NULL) { + LOGW("ALooper_pollOnce: No looper for this thread!"); + return -1; + } + return loop->pollOnce(timeoutMillis, outEvents, outData); +} + +int32_t ALooper_pollAll(int timeoutMillis, int* outEvents, void** outData) { + sp<PollLoop> loop = PollLoop::getForThread(); + if (loop == NULL) { + LOGW("ALooper_pollOnce: No looper for this thread!"); + return -1; + } + + int32_t result; + while ((result = loop->pollOnce(timeoutMillis, outEvents, outData)) == ALOOPER_POLL_CALLBACK) { + ; + } + + return result; +} + +void ALooper_acquire(ALooper* looper) { + static_cast<PollLoop*>(looper)->incStrong((void*)ALooper_acquire); +} + +void ALooper_release(ALooper* looper) { + static_cast<PollLoop*>(looper)->decStrong((void*)ALooper_acquire); +} + +void ALooper_addFd(ALooper* looper, int fd, int ident, int events, + ALooper_callbackFunc* callback, void* data) { + static_cast<PollLoop*>(looper)->setLooperCallback(fd, ident, events, callback, data); +} + +int32_t ALooper_removeFd(ALooper* looper, int fd) { + return static_cast<PollLoop*>(looper)->removeCallback(fd) ? 1 : 0; +} diff --git a/native/android/native_activity.cpp b/native/android/native_activity.cpp new file mode 100644 index 000000000000..0c6823aef1b7 --- /dev/null +++ b/native/android/native_activity.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2010 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 "native_activity" +#include <utils/Log.h> + +#include <android_runtime/android_app_NativeActivity.h> + +using namespace android; + +void ANativeActivity_setWindowFormat(ANativeActivity* activity, int32_t format) { + android_NativeActivity_setWindowFormat(activity, format); +} + +void ANativeActivity_setWindowFlags(ANativeActivity* activity, + uint32_t addFlags, uint32_t removeFlags) { + android_NativeActivity_setWindowFlags(activity, addFlags, addFlags|removeFlags); +} + +void ANativeActivity_showSoftInput(ANativeActivity* activity, uint32_t flags) { + android_NativeActivity_showSoftInput(activity, flags); +} + +void ANativeActivity_hideSoftInput(ANativeActivity* activity, uint32_t flags) { + android_NativeActivity_hideSoftInput(activity, flags); +} diff --git a/native/android/native_window.cpp b/native/android/native_window.cpp new file mode 100644 index 000000000000..bada07839227 --- /dev/null +++ b/native/android/native_window.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2010 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 "Surface" +#include <utils/Log.h> + +#include <android/native_window_jni.h> +#include <surfaceflinger/Surface.h> +#include <android_runtime/android_view_Surface.h> + +using namespace android; + +ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface) { + sp<ANativeWindow> win = android_Surface_getNativeWindow(env, surface); + if (win != NULL) { + win->incStrong((void*)ANativeWindow_acquire); + } + return win.get(); +} + +void ANativeWindow_acquire(ANativeWindow* window) { + window->incStrong((void*)ANativeWindow_acquire); +} + +void ANativeWindow_release(ANativeWindow* window) { + window->decStrong((void*)ANativeWindow_acquire); +} + +static int32_t getWindowProp(ANativeWindow* window, int what) { + int value; + int res = window->query(window, what, &value); + return res < 0 ? res : value; +} + +int32_t ANativeWindow_getWidth(ANativeWindow* window) { + return getWindowProp(window, NATIVE_WINDOW_WIDTH); +} + +int32_t ANativeWindow_getHeight(ANativeWindow* window) { + return getWindowProp(window, NATIVE_WINDOW_HEIGHT); +} + +int32_t ANativeWindow_getFormat(ANativeWindow* window) { + return getWindowProp(window, NATIVE_WINDOW_FORMAT); +} + +int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, int32_t width, + int32_t height) { + native_window_set_buffers_geometry(window, width, height, 0); + return 0; +} + +int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer, + ARect* inOutDirtyBounds) { + Region dirtyRegion; + Region* dirtyParam = NULL; + if (inOutDirtyBounds != NULL) { + dirtyRegion.set(*(Rect*)inOutDirtyBounds); + dirtyParam = &dirtyRegion; + } + + Surface::SurfaceInfo info; + status_t res = static_cast<Surface*>(window)->lock(&info, dirtyParam); + if (res != OK) { + return -1; + } + + outBuffer->width = (int32_t)info.w; + outBuffer->height = (int32_t)info.h; + outBuffer->stride = (int32_t)info.s; + outBuffer->format = (int32_t)info.format; + outBuffer->bits = info.bits; + + if (inOutDirtyBounds != NULL) { + *inOutDirtyBounds = dirtyRegion.getBounds(); + } + + return 0; +} + +int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) { + status_t res = static_cast<Surface*>(window)->unlockAndPost(); + return res == android::OK ? 0 : -1; +} diff --git a/native/android/sensor.cpp b/native/android/sensor.cpp new file mode 100644 index 000000000000..cf7635d2027f --- /dev/null +++ b/native/android/sensor.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2009 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 "sensor" +#include <utils/Log.h> + +#include <android/looper.h> +#include <android/sensor.h> + +#include <utils/RefBase.h> +#include <utils/PollLoop.h> +#include <utils/Timers.h> + +#include <gui/Sensor.h> +#include <gui/SensorManager.h> +#include <gui/SensorEventQueue.h> + +#include <poll.h> + +using android::sp; +using android::Sensor; +using android::SensorManager; +using android::SensorEventQueue; +using android::String8; + +/*****************************************************************************/ + +ASensorManager* ASensorManager_getInstance() +{ + return &SensorManager::getInstance(); +} + +int ASensorManager_getSensorList(ASensorManager* manager, + ASensorList* list) +{ + Sensor const* const* l; + int c = static_cast<SensorManager*>(manager)->getSensorList(&l); + if (list) { + *list = reinterpret_cast<ASensorList>(l); + } + return c; +} + +ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type) +{ + return static_cast<SensorManager*>(manager)->getDefaultSensor(type); +} + +ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager, + ALooper* looper, int ident, ALooper_callbackFunc* callback, void* data) +{ + sp<SensorEventQueue> queue = + static_cast<SensorManager*>(manager)->createEventQueue(); + if (queue != 0) { + ALooper_addFd(looper, queue->getFd(), ident, POLLIN, callback, data); + queue->looper = looper; + queue->incStrong(manager); + } + return static_cast<ASensorEventQueue*>(queue.get()); +} + +int ASensorManager_destroyEventQueue(ASensorManager* manager, + ASensorEventQueue* inQueue) +{ + sp<SensorEventQueue> queue = static_cast<SensorEventQueue*>(inQueue); + ALooper_removeFd(queue->looper, queue->getFd()); + queue->decStrong(manager); + return 0; +} + +/*****************************************************************************/ + +int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor) +{ + return static_cast<SensorEventQueue*>(queue)->enableSensor( + static_cast<Sensor const*>(sensor)); +} + +int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor) +{ + return static_cast<SensorEventQueue*>(queue)->disableSensor( + static_cast<Sensor const*>(sensor)); +} + +int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, + int32_t usec) +{ + return static_cast<SensorEventQueue*>(queue)->setEventRate( + static_cast<Sensor const*>(sensor), us2ns(usec)); +} + +int ASensorEventQueue_hasEvents(ASensorEventQueue* queue) +{ + struct pollfd pfd; + pfd.fd = static_cast<SensorEventQueue*>(queue)->getFd(); + pfd.events = POLLIN; + pfd.revents = 0; + + int nfd = poll(&pfd, 1, 0); + + if (nfd < 0) + return -errno; + + if (pfd.revents != POLLIN) + return -1; + + return (nfd == 0) ? 0 : 1; +} + +ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, + ASensorEvent* events, size_t count) +{ + return static_cast<SensorEventQueue*>(queue)->read(events, count); +} + + +/*****************************************************************************/ + +const char* ASensor_getName(ASensor const* sensor) +{ + return static_cast<Sensor const*>(sensor)->getName().string(); +} + +const char* ASensor_getVendor(ASensor const* sensor) +{ + return static_cast<Sensor const*>(sensor)->getVendor().string(); +} + +int ASensor_getType(ASensor const* sensor) +{ + return static_cast<Sensor const*>(sensor)->getType(); +} + +float ASensor_getResolution(ASensor const* sensor) +{ + return static_cast<Sensor const*>(sensor)->getResolution(); +} + +int ASensor_getMinDelay(ASensor const* sensor) +{ + return static_cast<Sensor const*>(sensor)->getMinDelay(); +} diff --git a/native/android/storage_manager.cpp b/native/android/storage_manager.cpp new file mode 100644 index 000000000000..6dbe7463dd5e --- /dev/null +++ b/native/android/storage_manager.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2010 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 "NStorage" + +#include <android/storage_manager.h> +#include <storage/IMountService.h> + +#include <binder/Binder.h> +#include <binder/IServiceManager.h> +#include <utils/Log.h> +#include <utils/RefBase.h> +#include <utils/String8.h> +#include <utils/String16.h> + + +using namespace android; + +struct ObbActionListener : public BnObbActionListener { +private: + sp<AStorageManager> mStorageManager; + +public: + ObbActionListener(AStorageManager* mgr) : + mStorageManager(mgr) + {} + + virtual void onObbResult(const android::String16& filename, const android::String16& state) { + LOGD("Got obb result (%s, %s)\n", String8(filename).string(), String8(state).string()); + } +}; + +struct AStorageManager : public RefBase { +protected: + void* mObbCallback; + sp<ObbActionListener> mObbActionListener; + sp<IMountService> mMountService; + +public: + AStorageManager() : + mObbCallback(NULL) + { + } + + bool initialize() { + sp<IServiceManager> sm = defaultServiceManager(); + if (sm == NULL) { + LOGE("Couldn't get default ServiceManager\n"); + return false; + } + + mMountService = interface_cast<IMountService>(sm->getService(String16("mount"))); + if (mMountService == NULL) { + LOGE("Couldn't get connection to MountService\n"); + return false; + } + + mObbActionListener = new ObbActionListener(this); + + return true; + } + + void setObbCallback(void* cb) { + mObbCallback = cb; + } + + void mountObb(const char* filename, const char* key) { + String16 filename16(filename); + String16 key16(key); + mMountService->mountObb(filename16, key16, mObbActionListener); + } + + void unmountObb(const char* filename, const bool force) { + String16 filename16(filename); + mMountService->unmountObb(filename16, force); + } + + int isObbMounted(const char* filename) { + String16 filename16(filename); + return mMountService->isObbMounted(filename16); + } + + const char* getMountedObbPath(const char* filename) { + String16 filename16(filename); + String16 path16; + if (mMountService->getMountedObbPath(filename16, path16)) { + return String8(path16).string(); + } else { + return NULL; + } + } +}; + + +AStorageManager* AStorageManager_new() { + sp<AStorageManager> mgr = new AStorageManager(); + if (mgr == NULL || !mgr->initialize()) { + return NULL; + } + mgr->incStrong((void*)AStorageManager_new); + return static_cast<AStorageManager*>(mgr.get()); +} + +void AStorageManager_delete(AStorageManager* mgr) { + if (mgr) { + mgr->decStrong((void*)AStorageManager_new); + } +} + +void AStorageManager_setObbCallback(AStorageManager* mgr, void* cb) { + mgr->setObbCallback(cb); +} + +void AStorageManager_mountObb(AStorageManager* mgr, const char* filename, const char* key) { + mgr->mountObb(filename, key); +} + +void AStorageManager_unmountObb(AStorageManager* mgr, const char* filename, const int force) { + mgr->unmountObb(filename, force != 0); +} + +int AStorageManager_isObbMounted(AStorageManager* mgr, const char* filename) { + return mgr->isObbMounted(filename) != 0; +} + +const char* AStorageManager_getMountedObbPath(AStorageManager* mgr, const char* filename) { + return mgr->getMountedObbPath(filename); +} |
