Merge "More native work." into gingerbread

This commit is contained in:
Dianne Hackborn
2010-08-11 00:45:44 -07:00
committed by Android (Google) Code Review
23 changed files with 995 additions and 82 deletions

View File

@ -26460,6 +26460,17 @@
<parameter name="holder" type="android.view.SurfaceHolder">
</parameter>
</method>
<field name="KEY_NATIVE_SAVED_STATE"
type="java.lang.String"
transient="false"
volatile="false"
value="&quot;android:native_state&quot;"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="META_DATA_LIB_NAME"
type="java.lang.String"
transient="false"

View File

@ -10,6 +10,7 @@ import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.os.Build;
import android.os.Bundle;
@ -32,12 +33,27 @@ import java.lang.ref.WeakReference;
/**
* Convenience for implementing an activity that will be implemented
* purely in native code. That is, a game (or game-like thing).
* purely in native code. That is, a game (or game-like thing). There
* is no need to derive from this class; you can simply declare it in your
* manifest, and use the NDK APIs from there.
*
* <p>A typical manifest would look like:
*
* {@sample development/ndk/platforms/android-9/samples/native-activity/AndroidManifest.xml
* manifest}
*
* <p>A very simple example of native code that is run by NativeActivity
* follows. This reads input events from the user and uses OpenGLES to
* draw into the native activity's window.
*
* {@sample development/ndk/platforms/android-9/samples/native-activity/jni/main.c all}
*/
public class NativeActivity extends Activity implements SurfaceHolder.Callback2,
InputQueue.Callback, OnGlobalLayoutListener {
public static final String META_DATA_LIB_NAME = "android.app.lib_name";
public static final String KEY_NATIVE_SAVED_STATE = "android:native_state";
private NativeContentView mNativeContentView;
private InputMethodManager mIMM;
private InputMethodCallback mInputMethodCallback;
@ -59,14 +75,15 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback2,
private native int loadNativeCode(String path, MessageQueue queue,
String internalDataPath, String externalDataPath, int sdkVersion,
AssetManager assetMgr);
AssetManager assetMgr, byte[] savedState);
private native void unloadNativeCode(int handle);
private native void onStartNative(int handle);
private native void onResumeNative(int handle);
private native void onSaveInstanceStateNative(int handle);
private native byte[] onSaveInstanceStateNative(int handle);
private native void onPauseNative(int handle);
private native void onStopNative(int handle);
private native void onConfigurationChangedNative(int handle);
private native void onLowMemoryNative(int handle);
private native void onWindowFocusChangedNative(int handle, boolean focused);
private native void onSurfaceCreatedNative(int handle, Surface surface);
@ -165,10 +182,13 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback2,
throw new IllegalArgumentException("Unable to find native library: " + libname);
}
byte[] nativeSavedState = savedInstanceState != null
? savedInstanceState.getByteArray(KEY_NATIVE_SAVED_STATE) : null;
mNativeHandle = loadNativeCode(path, Looper.myQueue(),
getFilesDir().toString(),
Environment.getExternalStorageAppFilesDirectory(ai.packageName).toString(),
Build.VERSION.SDK_INT, getAssets());
Build.VERSION.SDK_INT, getAssets(), nativeSavedState);
if (mNativeHandle == 0) {
throw new IllegalArgumentException("Unable to load native library: " + path);
@ -206,7 +226,10 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback2,
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
onSaveInstanceStateNative(mNativeHandle);
byte[] state = onSaveInstanceStateNative(mNativeHandle);
if (state != null) {
outState.putByteArray(KEY_NATIVE_SAVED_STATE, state);
}
}
@Override
@ -221,6 +244,14 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback2,
onStopNative(mNativeHandle);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (!mDestroyed) {
onConfigurationChangedNative(mNativeHandle);
}
}
@Override
public void onLowMemory() {
super.onLowMemory();

View File

@ -1288,7 +1288,7 @@ public class Resources {
height = mMetrics.widthPixels;
}
int keyboardHidden = mConfiguration.keyboardHidden;
if (keyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO
if (keyboardHidden == Configuration.KEYBOARDHIDDEN_NO
&& mConfiguration.hardKeyboardHidden
== Configuration.HARDKEYBOARDHIDDEN_YES) {
keyboardHidden = Configuration.KEYBOARDHIDDEN_SOFT;

View File

@ -0,0 +1,34 @@
/*
* 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.
*/
package com.android.internal.app;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class PlatLogoActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImageView content = new ImageView(this);
content.setImageResource(com.android.internal.R.drawable.platlogo);
content.setScaleType(ImageView.ScaleType.FIT_CENTER);
setContentView(content);
}
}

View File

@ -135,7 +135,8 @@ LOCAL_SRC_FILES:= \
android_backup_BackupDataOutput.cpp \
android_backup_FileBackupHelperBase.cpp \
android_backup_BackupHelperDispatcher.cpp \
android_content_res_ObbScanner.cpp
android_content_res_ObbScanner.cpp \
android_content_res_Configuration.cpp
LOCAL_C_INCLUDES += \
$(JNI_H_INCLUDE) \

View File

@ -167,6 +167,7 @@ extern int register_android_view_InputQueue(JNIEnv* env);
extern int register_android_view_KeyEvent(JNIEnv* env);
extern int register_android_view_MotionEvent(JNIEnv* env);
extern int register_android_content_res_ObbScanner(JNIEnv* env);
extern int register_android_content_res_Configuration(JNIEnv* env);
static AndroidRuntime* gCurRuntime = NULL;
@ -1340,6 +1341,7 @@ static const RegJNIRec gRegJNI[] = {
REG_JNI(register_android_view_MotionEvent),
REG_JNI(register_android_content_res_ObbScanner),
REG_JNI(register_android_content_res_Configuration),
};
/*

View File

@ -600,7 +600,7 @@ static bool mainWorkCallback(int fd, int events, void* data) {
static jint
loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jobject messageQueue,
jstring internalDataDir, jstring externalDataDir, int sdkVersion,
jobject jAssetMgr)
jobject jAssetMgr, jbyteArray savedState)
{
LOG_TRACE("loadNativeCode_native");
@ -666,7 +666,18 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jobject messageQ
code->assetManager = assetManagerForJavaObject(env, jAssetMgr);
code->createActivityFunc(code, NULL, 0);
jbyte* rawSavedState = NULL;
jsize rawSavedSize = 0;
if (savedState != NULL) {
rawSavedState = env->GetByteArrayElements(savedState, NULL);
rawSavedSize = env->GetArrayLength(savedState);
}
code->createActivityFunc(code, rawSavedState, rawSavedSize);
if (rawSavedState != NULL) {
env->ReleaseByteArrayElements(savedState, rawSavedState, 0);
}
}
return (jint)code;
@ -706,17 +717,31 @@ onResume_native(JNIEnv* env, jobject clazz, jint handle)
}
}
static void
static jbyteArray
onSaveInstanceState_native(JNIEnv* env, jobject clazz, jint handle)
{
LOG_TRACE("onSaveInstanceState_native");
jbyteArray array = NULL;
if (handle != 0) {
NativeCode* code = (NativeCode*)handle;
if (code->callbacks.onSaveInstanceState != NULL) {
size_t len = 0;
code->callbacks.onSaveInstanceState(code, &len);
jbyte* state = (jbyte*)code->callbacks.onSaveInstanceState(code, &len);
if (len > 0) {
array = env->NewByteArray(len);
if (array != NULL) {
env->SetByteArrayRegion(array, 0, len, state);
}
}
if (state != NULL) {
free(state);
}
}
}
return array;
}
static void
@ -743,6 +768,18 @@ onStop_native(JNIEnv* env, jobject clazz, jint handle)
}
}
static void
onConfigurationChanged_native(JNIEnv* env, jobject clazz, jint handle)
{
LOG_TRACE("onConfigurationChanged_native");
if (handle != 0) {
NativeCode* code = (NativeCode*)handle;
if (code->callbacks.onConfigurationChanged != NULL) {
code->callbacks.onConfigurationChanged(code);
}
}
}
static void
onLowMemory_native(JNIEnv* env, jobject clazz, jint handle)
{
@ -934,14 +971,15 @@ finishPreDispatchKeyEvent_native(JNIEnv* env, jobject clazz, jint handle,
}
static const JNINativeMethod g_methods[] = {
{ "loadNativeCode", "(Ljava/lang/String;Landroid/os/MessageQueue;Ljava/lang/String;Ljava/lang/String;ILandroid/content/res/AssetManager;)I",
{ "loadNativeCode", "(Ljava/lang/String;Landroid/os/MessageQueue;Ljava/lang/String;Ljava/lang/String;ILandroid/content/res/AssetManager;[B)I",
(void*)loadNativeCode_native },
{ "unloadNativeCode", "(I)V", (void*)unloadNativeCode_native },
{ "onStartNative", "(I)V", (void*)onStart_native },
{ "onResumeNative", "(I)V", (void*)onResume_native },
{ "onSaveInstanceStateNative", "(I)V", (void*)onSaveInstanceState_native },
{ "onSaveInstanceStateNative", "(I)[B", (void*)onSaveInstanceState_native },
{ "onPauseNative", "(I)V", (void*)onPause_native },
{ "onStopNative", "(I)V", (void*)onStop_native },
{ "onConfigurationChangedNative", "(I)V", (void*)onConfigurationChanged_native },
{ "onLowMemoryNative", "(I)V", (void*)onLowMemory_native },
{ "onWindowFocusChangedNative", "(IZ)V", (void*)onWindowFocusChanged_native },
{ "onSurfaceCreatedNative", "(ILandroid/view/Surface;)V", (void*)onSurfaceCreated_native },

View File

@ -0,0 +1,118 @@
/*
* Copyright 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/misc.h"
#include "jni.h"
#include <android_runtime/android_content_res_Configuration.h>
#include "android_runtime/AndroidRuntime.h"
namespace android {
static struct {
jclass clazz;
jfieldID mcc;
jfieldID mnc;
jfieldID locale;
jfieldID screenLayout;
jfieldID touchscreen;
jfieldID keyboard;
jfieldID keyboardHidden;
jfieldID hardKeyboardHidden;
jfieldID navigation;
jfieldID navigationHidden;
jfieldID orientation;
jfieldID uiMode;
} gConfigurationClassInfo;
void android_Configuration_getFromJava(
JNIEnv* env, jobject clazz, struct AConfiguration* out) {
out->mcc = env->GetIntField(clazz, gConfigurationClassInfo.mcc);
out->mnc = env->GetIntField(clazz, gConfigurationClassInfo.mnc);
out->screenLayout = env->GetIntField(clazz, gConfigurationClassInfo.screenLayout);
out->touchscreen = env->GetIntField(clazz, gConfigurationClassInfo.touchscreen);
out->keyboard = env->GetIntField(clazz, gConfigurationClassInfo.keyboard);
out->navigation = env->GetIntField(clazz, gConfigurationClassInfo.navigation);
out->inputFlags = env->GetIntField(clazz, gConfigurationClassInfo.keyboardHidden);
int hardKeyboardHidden = env->GetIntField(clazz, gConfigurationClassInfo.hardKeyboardHidden);
if (out->inputFlags == ACONFIGURATION_KEYSHIDDEN_NO
&& hardKeyboardHidden == 2) {
out->inputFlags = ACONFIGURATION_KEYSHIDDEN_SOFT;
}
out->inputFlags |= env->GetIntField(clazz, gConfigurationClassInfo.navigationHidden)
<< ResTable_config::SHIFT_NAVHIDDEN;
out->orientation = env->GetIntField(clazz, gConfigurationClassInfo.orientation);
out->uiMode = env->GetIntField(clazz, gConfigurationClassInfo.uiMode);
}
/*
* JNI registration.
*/
static JNINativeMethod gMethods[] = {
/* name, signature, funcPtr */
//{ "getObbInfo_native", "(Ljava/lang/String;Landroid/content/res/ObbInfo;)Z",
// (void*) android_content_res_ObbScanner_getObbInfo },
};
#define FIND_CLASS(var, className) \
var = env->FindClass(className); \
LOG_FATAL_IF(! var, "Unable to find class " className); \
var = jclass(env->NewGlobalRef(var));
#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
LOG_FATAL_IF(! var, "Unable to find field " fieldName);
int register_android_content_res_Configuration(JNIEnv* env)
{
FIND_CLASS(gConfigurationClassInfo.clazz, "android/content/res/Configuration");
GET_FIELD_ID(gConfigurationClassInfo.mcc, gConfigurationClassInfo.clazz,
"mcc", "I");
GET_FIELD_ID(gConfigurationClassInfo.mnc, gConfigurationClassInfo.clazz,
"mnc", "I");
GET_FIELD_ID(gConfigurationClassInfo.locale, gConfigurationClassInfo.clazz,
"locale", "Ljava/util/Locale;");
GET_FIELD_ID(gConfigurationClassInfo.screenLayout, gConfigurationClassInfo.clazz,
"screenLayout", "I");
GET_FIELD_ID(gConfigurationClassInfo.touchscreen, gConfigurationClassInfo.clazz,
"touchscreen", "I");
GET_FIELD_ID(gConfigurationClassInfo.keyboard, gConfigurationClassInfo.clazz,
"keyboard", "I");
GET_FIELD_ID(gConfigurationClassInfo.keyboardHidden, gConfigurationClassInfo.clazz,
"keyboardHidden", "I");
GET_FIELD_ID(gConfigurationClassInfo.hardKeyboardHidden, gConfigurationClassInfo.clazz,
"hardKeyboardHidden", "I");
GET_FIELD_ID(gConfigurationClassInfo.navigation, gConfigurationClassInfo.clazz,
"navigation", "I");
GET_FIELD_ID(gConfigurationClassInfo.navigationHidden, gConfigurationClassInfo.clazz,
"navigationHidden", "I");
GET_FIELD_ID(gConfigurationClassInfo.orientation, gConfigurationClassInfo.clazz,
"orientation", "I");
GET_FIELD_ID(gConfigurationClassInfo.uiMode, gConfigurationClassInfo.clazz,
"uiMode", "I");
return AndroidRuntime::registerNativeMethods(env, "android/content/res/Configuration", gMethods,
NELEM(gMethods));
}
}; // namespace android

View File

@ -1275,6 +1275,9 @@
android:finishOnCloseSystemDialogs="true"
android:excludeFromRecents="true">
</activity>
<activity android:name="com.android.internal.app.PlatLogoActivity"
android:theme="@style/Theme.NoTitleBar.Fullscreen">
</activity>
<activity android:name="com.android.internal.app.DisableCarModeActivity"
android:theme="@style/Theme.NoDisplay"
android:excludeFromRecents="true">

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

View File

@ -0,0 +1,36 @@
/*
* 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.
*/
#ifndef _ANDROID_CONTENT_RES_CONFIGURATION_H
#define _ANDROID_CONTENT_RES_CONFIGURATION_H
#include <utils/ResourceTypes.h>
#include <android/configuration.h>
#include "jni.h"
struct AConfiguration : android::ResTable_config {
};
namespace android {
extern void android_Configuration_getFromJava(
JNIEnv* env, jobject clazz, struct AConfiguration* out);
} // namespace android
#endif // _ANDROID_CONTENT_RES_CONFIGURATION_H

View File

@ -129,6 +129,8 @@ public:
*/
void setConfiguration(const ResTable_config& config, const char* locale = NULL);
void getConfiguration(ResTable_config* outConfig) const;
typedef Asset::AccessMode AccessMode; // typing shortcut
/*

View File

@ -31,6 +31,8 @@
#include <stdint.h>
#include <sys/types.h>
#include <android/configuration.h>
namespace android {
/** ********************************************************************
@ -822,25 +824,25 @@ struct ResTable_config
};
enum {
ORIENTATION_ANY = 0x0000,
ORIENTATION_PORT = 0x0001,
ORIENTATION_LAND = 0x0002,
ORIENTATION_SQUARE = 0x0003,
ORIENTATION_ANY = ACONFIGURATION_ORIENTATION_ANY,
ORIENTATION_PORT = ACONFIGURATION_ORIENTATION_PORT,
ORIENTATION_LAND = ACONFIGURATION_ORIENTATION_LAND,
ORIENTATION_SQUARE = ACONFIGURATION_ORIENTATION_SQUARE,
};
enum {
TOUCHSCREEN_ANY = 0x0000,
TOUCHSCREEN_NOTOUCH = 0x0001,
TOUCHSCREEN_STYLUS = 0x0002,
TOUCHSCREEN_FINGER = 0x0003,
TOUCHSCREEN_ANY = ACONFIGURATION_TOUCHSCREEN_ANY,
TOUCHSCREEN_NOTOUCH = ACONFIGURATION_TOUCHSCREEN_NOTOUCH,
TOUCHSCREEN_STYLUS = ACONFIGURATION_TOUCHSCREEN_STYLUS,
TOUCHSCREEN_FINGER = ACONFIGURATION_TOUCHSCREEN_FINGER,
};
enum {
DENSITY_DEFAULT = 0,
DENSITY_LOW = 120,
DENSITY_MEDIUM = 160,
DENSITY_HIGH = 240,
DENSITY_NONE = 0xffff
DENSITY_DEFAULT = ACONFIGURATION_DENSITY_DEFAULT,
DENSITY_LOW = ACONFIGURATION_DENSITY_LOW,
DENSITY_MEDIUM = ACONFIGURATION_DENSITY_MEDIUM,
DENSITY_HIGH = ACONFIGURATION_DENSITY_HIGH,
DENSITY_NONE = ACONFIGURATION_DENSITY_NONE
};
union {
@ -853,33 +855,34 @@ struct ResTable_config
};
enum {
KEYBOARD_ANY = 0x0000,
KEYBOARD_NOKEYS = 0x0001,
KEYBOARD_QWERTY = 0x0002,
KEYBOARD_12KEY = 0x0003,
KEYBOARD_ANY = ACONFIGURATION_KEYBOARD_ANY,
KEYBOARD_NOKEYS = ACONFIGURATION_KEYBOARD_NOKEYS,
KEYBOARD_QWERTY = ACONFIGURATION_KEYBOARD_QWERTY,
KEYBOARD_12KEY = ACONFIGURATION_KEYBOARD_12KEY,
};
enum {
NAVIGATION_ANY = 0x0000,
NAVIGATION_NONAV = 0x0001,
NAVIGATION_DPAD = 0x0002,
NAVIGATION_TRACKBALL = 0x0003,
NAVIGATION_WHEEL = 0x0004,
NAVIGATION_ANY = ACONFIGURATION_NAVIGATION_ANY,
NAVIGATION_NONAV = ACONFIGURATION_NAVIGATION_NONAV,
NAVIGATION_DPAD = ACONFIGURATION_NAVIGATION_DPAD,
NAVIGATION_TRACKBALL = ACONFIGURATION_NAVIGATION_TRACKBALL,
NAVIGATION_WHEEL = ACONFIGURATION_NAVIGATION_WHEEL,
};
enum {
MASK_KEYSHIDDEN = 0x0003,
KEYSHIDDEN_ANY = 0x0000,
KEYSHIDDEN_NO = 0x0001,
KEYSHIDDEN_YES = 0x0002,
KEYSHIDDEN_SOFT = 0x0003,
KEYSHIDDEN_ANY = ACONFIGURATION_KEYSHIDDEN_ANY,
KEYSHIDDEN_NO = ACONFIGURATION_KEYSHIDDEN_NO,
KEYSHIDDEN_YES = ACONFIGURATION_KEYSHIDDEN_YES,
KEYSHIDDEN_SOFT = ACONFIGURATION_KEYSHIDDEN_SOFT,
};
enum {
MASK_NAVHIDDEN = 0x000c,
NAVHIDDEN_ANY = 0x0000,
NAVHIDDEN_NO = 0x0004,
NAVHIDDEN_YES = 0x0008,
SHIFT_NAVHIDDEN = 2,
NAVHIDDEN_ANY = ACONFIGURATION_NAVHIDDEN_ANY << SHIFT_NAVHIDDEN,
NAVHIDDEN_NO = ACONFIGURATION_NAVHIDDEN_NO << SHIFT_NAVHIDDEN,
NAVHIDDEN_YES = ACONFIGURATION_NAVHIDDEN_YES << SHIFT_NAVHIDDEN,
};
union {
@ -929,32 +932,34 @@ struct ResTable_config
enum {
// screenLayout bits for screen size class.
MASK_SCREENSIZE = 0x0f,
SCREENSIZE_ANY = 0x00,
SCREENSIZE_SMALL = 0x01,
SCREENSIZE_NORMAL = 0x02,
SCREENSIZE_LARGE = 0x03,
SCREENSIZE_XLARGE = 0x04,
SCREENSIZE_ANY = ACONFIGURATION_SCREENSIZE_ANY,
SCREENSIZE_SMALL = ACONFIGURATION_SCREENSIZE_SMALL,
SCREENSIZE_NORMAL = ACONFIGURATION_SCREENSIZE_NORMAL,
SCREENSIZE_LARGE = ACONFIGURATION_SCREENSIZE_LARGE,
SCREENSIZE_XLARGE = ACONFIGURATION_SCREENSIZE_XLARGE,
// screenLayout bits for wide/long screen variation.
MASK_SCREENLONG = 0x30,
SCREENLONG_ANY = 0x00,
SCREENLONG_NO = 0x10,
SCREENLONG_YES = 0x20,
SHIFT_SCREENLONG = 4,
SCREENLONG_ANY = ACONFIGURATION_SCREENLONG_ANY << SHIFT_SCREENLONG,
SCREENLONG_NO = ACONFIGURATION_SCREENLONG_NO << SHIFT_SCREENLONG,
SCREENLONG_YES = ACONFIGURATION_SCREENLONG_YES << SHIFT_SCREENLONG,
};
enum {
// uiMode bits for the mode type.
MASK_UI_MODE_TYPE = 0x0f,
UI_MODE_TYPE_ANY = 0x00,
UI_MODE_TYPE_NORMAL = 0x01,
UI_MODE_TYPE_DESK = 0x02,
UI_MODE_TYPE_CAR = 0x03,
UI_MODE_TYPE_ANY = ACONFIGURATION_UI_MODE_TYPE_ANY,
UI_MODE_TYPE_NORMAL = ACONFIGURATION_UI_MODE_TYPE_NORMAL,
UI_MODE_TYPE_DESK = ACONFIGURATION_UI_MODE_TYPE_DESK,
UI_MODE_TYPE_CAR = ACONFIGURATION_UI_MODE_TYPE_CAR,
// uiMode bits for the night switch.
MASK_UI_MODE_NIGHT = 0x30,
UI_MODE_NIGHT_ANY = 0x00,
UI_MODE_NIGHT_NO = 0x10,
UI_MODE_NIGHT_YES = 0x20,
SHIFT_UI_MODE_NIGHT = 4,
UI_MODE_NIGHT_ANY = ACONFIGURATION_UI_MODE_NIGHT_ANY << SHIFT_UI_MODE_NIGHT,
UI_MODE_NIGHT_NO = ACONFIGURATION_UI_MODE_NIGHT_NO << SHIFT_UI_MODE_NIGHT,
UI_MODE_NIGHT_YES = ACONFIGURATION_UI_MODE_NIGHT_YES << SHIFT_UI_MODE_NIGHT,
};
union {
@ -1023,19 +1028,19 @@ struct ResTable_config
// match the corresponding ones in android.content.pm.ActivityInfo and
// attrs_manifest.xml.
enum {
CONFIG_MCC = 0x0001,
CONFIG_MNC = 0x0002,
CONFIG_LOCALE = 0x0004,
CONFIG_TOUCHSCREEN = 0x0008,
CONFIG_KEYBOARD = 0x0010,
CONFIG_KEYBOARD_HIDDEN = 0x0020,
CONFIG_NAVIGATION = 0x0040,
CONFIG_ORIENTATION = 0x0080,
CONFIG_DENSITY = 0x0100,
CONFIG_SCREEN_SIZE = 0x0200,
CONFIG_VERSION = 0x0400,
CONFIG_SCREEN_LAYOUT = 0x0800,
CONFIG_UI_MODE = 0x1000
CONFIG_MCC = ACONFIGURATION_MCC,
CONFIG_MNC = ACONFIGURATION_MCC,
CONFIG_LOCALE = ACONFIGURATION_LOCALE,
CONFIG_TOUCHSCREEN = ACONFIGURATION_TOUCHSCREEN,
CONFIG_KEYBOARD = ACONFIGURATION_KEYBOARD,
CONFIG_KEYBOARD_HIDDEN = ACONFIGURATION_KEYBOARD_HIDDEN,
CONFIG_NAVIGATION = ACONFIGURATION_NAVIGATION,
CONFIG_ORIENTATION = ACONFIGURATION_ORIENTATION,
CONFIG_DENSITY = ACONFIGURATION_DENSITY,
CONFIG_SCREEN_SIZE = ACONFIGURATION_SCREEN_SIZE,
CONFIG_VERSION = ACONFIGURATION_VERSION,
CONFIG_SCREEN_LAYOUT = ACONFIGURATION_SCREEN_LAYOUT,
CONFIG_UI_MODE = ACONFIGURATION_UI_MODE
};
// Compare two configuration, returning CONFIG_* flags set for each value

View File

@ -232,6 +232,12 @@ void AssetManager::setConfiguration(const ResTable_config& config, const char* l
}
}
void AssetManager::getConfiguration(ResTable_config* outConfig) const
{
AutoMutex _l(mLock);
*outConfig = *mConfig;
}
/*
* Open an asset.
*

View File

@ -7,6 +7,7 @@ include $(CLEAR_VARS)
#
LOCAL_SRC_FILES:= \
asset_manager.cpp \
configuration.cpp \
input.cpp \
looper.cpp \
native_activity.cpp \

View File

@ -17,7 +17,7 @@
#define LOG_TAG "NAsset"
#include <utils/Log.h>
#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>
#include <utils/AssetManager.h>
#include <utils/AssetDir.h>
#include <utils/Asset.h>

View File

@ -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);
}

55
native/copy-to-ndk.sh Normal file
View File

@ -0,0 +1,55 @@
# Take care of copying current header files over to the correct
# location in the NDK.
copyndkheaders() {
local CURR_PLATFORM=android-9
local ALL_PLATFORMS="$CURR_PLATFORM android-8 android-5 android-4 android-3"
local SRC_HEADERS=$ANDROID_BUILD_TOP/frameworks/base/native/include/android
local NDK_PLATFORMS=$ANDROID_BUILD_TOP/development/ndk/platforms
local DST_HEADERS=$NDK_PLATFORMS/$CURR_PLATFORM
local SRC_LIB_ANDROID=$ANDROID_PRODUCT_OUT/system/lib/libandroid.so
local DST_LIB_ANDROID=$NDK_PLATFORMS/$CURR_PLATFORM/arch-arm/usr/lib/libandroid.so
local didsomething=""
#echo "SRC_HEADERS: $SRC_HEADERS"
for i in $(cd $SRC_HEADERS; ls *.h); do
local src=$SRC_HEADERS/$i
local changed=""
for j in $ALL_PLATFORMS; do
local dst=$NDK_PLATFORMS/$j/arch-arm/usr/include/android/$i
if [ "$changed" == "" -a -e $dst ]; then
#echo "Exists: $dst"
if diff $src $dst >/dev/null; then
echo "$i: has not changed from $j" >/dev/null
changed="false"
else
changed="true"
echo "$i: has changed from $j" >/dev/null
fi
fi
done
if [ "$changed" == "true" -o "$changed" == "" ]; then
echo "Updating: $i"
cp $src $NDK_PLATFORMS/$CURR_PLATFORM/arch-arm/usr/include/android/$i
didsomething="true"
fi
done
if diff $SRC_LIB_ANDROID $DST_LIB_ANDROID >/dev/null; then
echo "libandroid.so: has not changed" >/dev/null
else
echo "Updating: $DST_LIB_ANDROID"
cp $SRC_LIB_ANDROID $DST_LIB_ANDROID
didsomething="true"
fi
if [ "$didsomething" != "" ]; then
echo "Headers changed... rebuilding platforms."
sh $ANDROID_BUILD_TOP/ndk/build/tools/build-platforms.sh
fi
}
copyndkheaders

View File

@ -18,8 +18,6 @@
#ifndef ANDROID_ASSET_MANAGER_H
#define ANDROID_ASSET_MANAGER_H
#include <jni.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -42,14 +40,6 @@ enum {
};
/**
* Given a Dalvik AssetManager object, obtain the corresponding native AAssetManager
* object. Note that the caller is responsible for obtaining and holding a VM reference
* to the jobject to prevent its being garbage collected while the native object is
* in use.
*/
AAssetManager* AAssetManager_fromJava(JNIEnv* env, jobject assetManager);
/**
* Open the named directory within the asset hierarchy. The directory can then
* be inspected with the AAssetDir functions. To open the top-level directory,

View File

@ -0,0 +1,40 @@
/*
* 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.
*/
#ifndef ANDROID_ASSET_MANAGER_JNI_H
#define ANDROID_ASSET_MANAGER_JNI_H
#include <android/asset_manager.h>
#include <jni.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Given a Dalvik AssetManager object, obtain the corresponding native AAssetManager
* object. Note that the caller is responsible for obtaining and holding a VM reference
* to the jobject to prevent its being garbage collected while the native object is
* in use.
*/
AAssetManager* AAssetManager_fromJava(JNIEnv* env, jobject assetManager);
#ifdef __cplusplus
};
#endif
#endif // ANDROID_ASSET_MANAGER_JNI_H

View File

@ -0,0 +1,319 @@
/*
* 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.
*/
#ifndef ANDROID_CONFIGURATION_H
#define ANDROID_CONFIGURATION_H
#include <android/asset_manager.h>
#ifdef __cplusplus
extern "C" {
#endif
struct AConfiguration;
typedef struct AConfiguration AConfiguration;
enum {
ACONFIGURATION_ORIENTATION_ANY = 0x0000,
ACONFIGURATION_ORIENTATION_PORT = 0x0001,
ACONFIGURATION_ORIENTATION_LAND = 0x0002,
ACONFIGURATION_ORIENTATION_SQUARE = 0x0003,
ACONFIGURATION_TOUCHSCREEN_ANY = 0x0000,
ACONFIGURATION_TOUCHSCREEN_NOTOUCH = 0x0001,
ACONFIGURATION_TOUCHSCREEN_STYLUS = 0x0002,
ACONFIGURATION_TOUCHSCREEN_FINGER = 0x0003,
ACONFIGURATION_DENSITY_DEFAULT = 0,
ACONFIGURATION_DENSITY_LOW = 120,
ACONFIGURATION_DENSITY_MEDIUM = 160,
ACONFIGURATION_DENSITY_HIGH = 240,
ACONFIGURATION_DENSITY_NONE = 0xffff,
ACONFIGURATION_KEYBOARD_ANY = 0x0000,
ACONFIGURATION_KEYBOARD_NOKEYS = 0x0001,
ACONFIGURATION_KEYBOARD_QWERTY = 0x0002,
ACONFIGURATION_KEYBOARD_12KEY = 0x0003,
ACONFIGURATION_NAVIGATION_ANY = 0x0000,
ACONFIGURATION_NAVIGATION_NONAV = 0x0001,
ACONFIGURATION_NAVIGATION_DPAD = 0x0002,
ACONFIGURATION_NAVIGATION_TRACKBALL = 0x0003,
ACONFIGURATION_NAVIGATION_WHEEL = 0x0004,
ACONFIGURATION_KEYSHIDDEN_ANY = 0x0000,
ACONFIGURATION_KEYSHIDDEN_NO = 0x0001,
ACONFIGURATION_KEYSHIDDEN_YES = 0x0002,
ACONFIGURATION_KEYSHIDDEN_SOFT = 0x0003,
ACONFIGURATION_NAVHIDDEN_ANY = 0x0000,
ACONFIGURATION_NAVHIDDEN_NO = 0x0001,
ACONFIGURATION_NAVHIDDEN_YES = 0x0002,
ACONFIGURATION_SCREENSIZE_ANY = 0x00,
ACONFIGURATION_SCREENSIZE_SMALL = 0x01,
ACONFIGURATION_SCREENSIZE_NORMAL = 0x02,
ACONFIGURATION_SCREENSIZE_LARGE = 0x03,
ACONFIGURATION_SCREENSIZE_XLARGE = 0x04,
ACONFIGURATION_SCREENLONG_ANY = 0x00,
ACONFIGURATION_SCREENLONG_NO = 0x1,
ACONFIGURATION_SCREENLONG_YES = 0x2,
ACONFIGURATION_UI_MODE_TYPE_ANY = 0x00,
ACONFIGURATION_UI_MODE_TYPE_NORMAL = 0x01,
ACONFIGURATION_UI_MODE_TYPE_DESK = 0x02,
ACONFIGURATION_UI_MODE_TYPE_CAR = 0x03,
ACONFIGURATION_UI_MODE_NIGHT_ANY = 0x00,
ACONFIGURATION_UI_MODE_NIGHT_NO = 0x10,
ACONFIGURATION_UI_MODE_NIGHT_YES = 0x20,
ACONFIGURATION_MCC = 0x0001,
ACONFIGURATION_MNC = 0x0002,
ACONFIGURATION_LOCALE = 0x0004,
ACONFIGURATION_TOUCHSCREEN = 0x0008,
ACONFIGURATION_KEYBOARD = 0x0010,
ACONFIGURATION_KEYBOARD_HIDDEN = 0x0020,
ACONFIGURATION_NAVIGATION = 0x0040,
ACONFIGURATION_ORIENTATION = 0x0080,
ACONFIGURATION_DENSITY = 0x0100,
ACONFIGURATION_SCREEN_SIZE = 0x0200,
ACONFIGURATION_VERSION = 0x0400,
ACONFIGURATION_SCREEN_LAYOUT = 0x0800,
ACONFIGURATION_UI_MODE = 0x1000,
};
/**
* Create a new AConfiguration, initialized with no values set.
*/
AConfiguration* AConfiguration_new();
/**
* Free an AConfiguration that was previously created with
* AConfiguration_new().
*/
void AConfiguration_delete(AConfiguration* config);
/**
* Create and return a new AConfiguration based on the current configuration in
* use in the given AssetManager.
*/
void AConfiguration_fromAssetManager(AConfiguration* out, AAssetManager* am);
/**
* Copy the contents of 'src' to 'dest'.
*/
void AConfiguration_copy(AConfiguration* dest, AConfiguration* src);
/**
* Return the current MCC set in the configuration. 0 if not set.
*/
int32_t AConfiguration_getMcc(AConfiguration* config);
/**
* Set the current MCC in the configuration. 0 to clear.
*/
void AConfiguration_setMcc(AConfiguration* config, int32_t mcc);
/**
* Return the current MNC set in the configuration. 0 if not set.
*/
int32_t AConfiguration_getMnc(AConfiguration* config);
/**
* Set the current MNC in the configuration. 0 to clear.
*/
void AConfiguration_setMnc(AConfiguration* config, int32_t mnc);
/**
* Return the current language code set in the configuration. The output will
* be filled with an array of two characters. They are not 0-terminated. If
* a language is not set, they will be 0.
*/
void AConfiguration_getLanguage(AConfiguration* config, char* outLanguage);
/**
* Set the current language code in the configuration, from the first two
* characters in the string.
*/
void AConfiguration_setLanguage(AConfiguration* config, const char* language);
/**
* Return the current country code set in the configuration. The output will
* be filled with an array of two characters. They are not 0-terminated. If
* a country is not set, they will be 0.
*/
void AConfiguration_getCountry(AConfiguration* config, char* outCountry);
/**
* Set the current country code in the configuration, from the first two
* characters in the string.
*/
void AConfiguration_setCountry(AConfiguration* config, const char* country);
/**
* Return the current ACONFIGURATION_ORIENTATION_* set in the configuration.
*/
int32_t AConfiguration_getOrientation(AConfiguration* config);
/**
* Set the current orientation in the configuration.
*/
void AConfiguration_setOrientation(AConfiguration* config, int32_t orientation);
/**
* Return the current ACONFIGURATION_TOUCHSCREEN_* set in the configuration.
*/
int32_t AConfiguration_getTouchscreen(AConfiguration* config);
/**
* Set the current touchscreen in the configuration.
*/
void AConfiguration_setTouchscreen(AConfiguration* config, int32_t touchscreen);
/**
* Return the current ACONFIGURATION_DENSITY_* set in the configuration.
*/
int32_t AConfiguration_getDensity(AConfiguration* config);
/**
* Set the current density in the configuration.
*/
void AConfiguration_setDensity(AConfiguration* config, int32_t density);
/**
* Return the current ACONFIGURATION_KEYBOARD_* set in the configuration.
*/
int32_t AConfiguration_getKeyboard(AConfiguration* config);
/**
* Set the current keyboard in the configuration.
*/
void AConfiguration_setKeyboard(AConfiguration* config, int32_t keyboard);
/**
* Return the current ACONFIGURATION_NAVIGATION_* set in the configuration.
*/
int32_t AConfiguration_getNavigation(AConfiguration* config);
/**
* Set the current navigation in the configuration.
*/
void AConfiguration_setNavigation(AConfiguration* config, int32_t navigation);
/**
* Return the current ACONFIGURATION_KEYSHIDDEN_* set in the configuration.
*/
int32_t AConfiguration_getKeysHidden(AConfiguration* config);
/**
* Set the current keys hidden in the configuration.
*/
void AConfiguration_setKeysHidden(AConfiguration* config, int32_t keysHidden);
/**
* Return the current ACONFIGURATION_NAVHIDDEN_* set in the configuration.
*/
int32_t AConfiguration_getNavHidden(AConfiguration* config);
/**
* Set the current nav hidden in the configuration.
*/
void AConfiguration_setNavHidden(AConfiguration* config, int32_t navHidden);
/**
* Return the current SDK (API) version set in the configuration.
*/
int32_t AConfiguration_getSdkVersion(AConfiguration* config);
/**
* Set the current SDK version in the configuration.
*/
void AConfiguration_setSdkVersion(AConfiguration* config, int32_t sdkVersion);
/**
* Return the current ACONFIGURATION_SCREENSIZE_* set in the configuration.
*/
int32_t AConfiguration_getScreenSize(AConfiguration* config);
/**
* Set the current screen size in the configuration.
*/
void AConfiguration_setScreenSize(AConfiguration* config, int32_t screenSize);
/**
* Return the current ACONFIGURATION_SCREENLONG_* set in the configuration.
*/
int32_t AConfiguration_getScreenLong(AConfiguration* config);
/**
* Set the current screen long in the configuration.
*/
void AConfiguration_setScreenLong(AConfiguration* config, int32_t screenLong);
/**
* Return the current ACONFIGURATION_UI_MODE_TYPE_* set in the configuration.
*/
int32_t AConfiguration_getUiModeType(AConfiguration* config);
/**
* Set the current UI mode type in the configuration.
*/
void AConfiguration_setUiModeType(AConfiguration* config, int32_t uiModeType);
/**
* Return the current ACONFIGURATION_UI_MODE_NIGHT_* set in the configuration.
*/
int32_t AConfiguration_getUiModeNight(AConfiguration* config);
/**
* Set the current UI mode night in the configuration.
*/
void AConfiguration_setUiModeNight(AConfiguration* config, int32_t uiModeNight);
/**
* Perform a diff between two configurations. Returns a bit mask of
* ACONFIGURATION_* constants, each bit set meaning that configuration element
* is different between them.
*/
int32_t AConfiguration_diff(AConfiguration* config1, AConfiguration* config2);
/**
* Determine whether 'base' is a valid configuration for use within the
* environment 'requested'. Returns 0 if there are any values in 'base'
* that conflict with 'requested'. Returns 1 if it does not conflict.
*/
int32_t AConfiguration_match(AConfiguration* base, AConfiguration* requested);
/**
* Determine whether the configuration in 'test' is better than the existing
* configuration in 'base'. If 'requested' is non-NULL, this decision is based
* on the overall configuration given there. If it is NULL, this decision is
* simply based on which configuration is more specific. Returns non-0 if
* 'test' is better than 'base'.
*
* This assumes you have already filtered the configurations with
* AConfiguration_match().
*/
int32_t AConfiguration_isBetterThan(AConfiguration* base, AConfiguration* test,
AConfiguration* requested);
#ifdef __cplusplus
};
#endif
#endif // ANDROID_CONFIGURATION_H

View File

@ -196,6 +196,12 @@ typedef struct ANativeActivityCallbacks {
*/
void (*onContentRectChanged)(ANativeActivity* activity, const ARect* rect);
/**
* The current device AConfiguration has changed. The new configuration can
* be retrieved from assetManager.
*/
void (*onConfigurationChanged)(ANativeActivity* activity);
/**
* The system is running low on memory. Use this callback to release
* resources you do not need, to help the system avoid killing more
@ -208,7 +214,9 @@ typedef struct ANativeActivityCallbacks {
* This is the function that must be in the native code to instantiate the
* application's native activity. It is called with the activity instance (see
* above); if the code is being instantiated from a previously saved instance,
* the savedState will be non-NULL and point to the saved data.
* the savedState will be non-NULL and point to the saved data. You must make
* any copy of this data you need -- it will be released after you return from
* this function.
*/
typedef void ANativeActivity_createFunc(ANativeActivity* activity,
void* savedState, size_t savedStateSize);

View File

@ -36,12 +36,23 @@ struct ANativeWindow;
typedef struct ANativeWindow ANativeWindow;
typedef struct ANativeWindow_Buffer {
// The number of pixels that are show horizontally.
int32_t width;
// The number of pixels that are shown vertically.
int32_t height;
// The number of *pixels* that a line in the buffer takes in
// memory. This may be >= width.
int32_t stride;
// The format of the buffer. One of WINDOW_FORMAT_*
int32_t format;
// The actual bits.
void* bits;
// Do not touch.
uint32_t reserved[6];
} ANativeWindow_Buffer;