diff options
26 files changed, 391 insertions, 968 deletions
diff --git a/cmds/stagefright/Android.mk b/cmds/stagefright/Android.mk index 80d0d2b..33696f4 100644 --- a/cmds/stagefright/Android.mk +++ b/cmds/stagefright/Android.mk @@ -1,5 +1,3 @@ -ifeq ($(BUILD_WITH_FULL_STAGEFRIGHT),true) - LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) @@ -72,5 +70,3 @@ LOCAL_MODULE_TAGS := debug LOCAL_MODULE:= audioloop include $(BUILD_EXECUTABLE) - -endif diff --git a/core/java/android/appwidget/AppWidgetHost.java b/core/java/android/appwidget/AppWidgetHost.java index 88adabd..b2fc13f 100644 --- a/core/java/android/appwidget/AppWidgetHost.java +++ b/core/java/android/appwidget/AppWidgetHost.java @@ -237,7 +237,7 @@ public class AppWidgetHost { v = mViews.get(appWidgetId); } if (v != null) { - v.updateAppWidget(null, AppWidgetHostView.UPDATE_FLAGS_RESET); + v.resetAppWidget(appWidget); } } @@ -247,7 +247,7 @@ public class AppWidgetHost { v = mViews.get(appWidgetId); } if (v != null) { - v.updateAppWidget(views, 0); + v.updateAppWidget(views); } } } diff --git a/core/java/android/appwidget/AppWidgetHostView.java b/core/java/android/appwidget/AppWidgetHostView.java index 5375193..b33b097 100644 --- a/core/java/android/appwidget/AppWidgetHostView.java +++ b/core/java/android/appwidget/AppWidgetHostView.java @@ -46,8 +46,6 @@ public class AppWidgetHostView extends FrameLayout { static final boolean LOGD = false; static final boolean CROSSFADE = false; - static final int UPDATE_FLAGS_RESET = 0x00000001; - static final int VIEW_MODE_NOINIT = 0; static final int VIEW_MODE_CONTENT = 1; static final int VIEW_MODE_ERROR = 2; @@ -102,7 +100,7 @@ public class AppWidgetHostView extends FrameLayout { mAppWidgetId = appWidgetId; mInfo = info; } - + public int getAppWidgetId() { return mAppWidgetId; } @@ -148,21 +146,22 @@ public class AppWidgetHostView extends FrameLayout { } /** + * Update the AppWidgetProviderInfo for this view, and reset it to the + * initial layout. + */ + void resetAppWidget(AppWidgetProviderInfo info) { + mInfo = info; + mViewMode = VIEW_MODE_NOINIT; + updateAppWidget(null); + } + + /** * Process a set of {@link RemoteViews} coming in as an update from the * AppWidget provider. Will animate into these new views as needed */ public void updateAppWidget(RemoteViews remoteViews) { - updateAppWidget(remoteViews, 0); - } + if (LOGD) Log.d(TAG, "updateAppWidget called mOld=" + mOld); - void updateAppWidget(RemoteViews remoteViews, int flags) { - if (LOGD) Log.d(TAG, "updateAppWidget called mOld=" + mOld + " flags=0x" - + Integer.toHexString(flags)); - - if ((flags & UPDATE_FLAGS_RESET) != 0) { - mViewMode = VIEW_MODE_NOINIT; - } - boolean recycled = false; View content = null; Exception exception = null; diff --git a/core/java/android/hardware/Usb.java b/core/java/android/hardware/Usb.java new file mode 100644 index 0000000..e9c2cf7 --- /dev/null +++ b/core/java/android/hardware/Usb.java @@ -0,0 +1,78 @@ +/* + * 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 android.hardware; + +/** + * Class for accessing USB state information. + * @hide + */ +public class Usb { + /** + * Broadcast Action: A broadcast for USB connected events. + * + * The extras bundle will name/value pairs with the name of the function + * and a value of either {@link #USB_FUNCTION_ENABLED} or {@link #USB_FUNCTION_DISABLED}. + * Possible USB function names include {@link #USB_FUNCTION_MASS_STORAGE}, + * {@link #USB_FUNCTION_ADB}, {@link #USB_FUNCTION_RNDIS} and {@link #USB_FUNCTION_MTP}. + */ + public static final String ACTION_USB_CONNECTED = + "android.hardware.action.USB_CONNECTED"; + + /** + * Broadcast Action: A broadcast for USB disconnected events. + */ + public static final String ACTION_USB_DISCONNECTED = + "android.hardware.action.USB_DISCONNECTED"; + + + /** + * Name of the USB mass storage USB function. + * Used in extras for the {@link #ACTION_USB_CONNECTED} broadcast + */ + public static final String USB_FUNCTION_MASS_STORAGE = "mass_storage"; + + /** + * Name of the adb USB function. + * Used in extras for the {@link #ACTION_USB_CONNECTED} broadcast + */ + public static final String USB_FUNCTION_ADB = "adb"; + + /** + * Name of the RNDIS ethernet USB function. + * Used in extras for the {@link #ACTION_USB_CONNECTED} broadcast + */ + public static final String USB_FUNCTION_RNDIS = "rndis"; + + /** + * Name of the MTP USB function. + * Used in extras for the {@link #ACTION_USB_CONNECTED} broadcast + */ + public static final String USB_FUNCTION_MTP = "mtp"; + + /** + * Value indicating that a USB function is enabled. + * Used in extras for the {@link #ACTION_USB_CONNECTED} broadcast + */ + public static final String USB_FUNCTION_ENABLED = "enabled"; + + /** + * Value indicating that a USB function is disabled. + * Used in extras for the {@link #ACTION_USB_CONNECTED} broadcast + */ + public static final String USB_FUNCTION_DISABLED = "disabled"; +} diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index aff9453..b1f81df 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -80,6 +80,9 @@ <protected-broadcast android:name="android.bluetooth.device.action.PAIRING_REQUEST" /> <protected-broadcast android:name="android.bluetooth.device.action.PAIRING_CANCEL" /> + <protected-broadcast android:name="android.hardware.action.USB_CONNECTED" /> + <protected-broadcast android:name="android.hardware.action.USB_DISCONNECTED" /> + <!-- ====================================== --> <!-- Permissions for things that cost money --> <!-- ====================================== --> @@ -436,6 +439,14 @@ android:label="@string/permlab_flashlight" android:description="@string/permdesc_flashlight" /> + <!-- Allows an application to access USB devices + @hide --> + <permission android:name="android.permission.ACCESS_USB" + android:permissionGroup="android.permission-group.HARDWARE_CONTROLS" + android:protectionLevel="signatureOrSystem" + android:label="@string/permlab_accessUsb" + android:description="@string/permdesc_accessUsb" /> + <!-- Allows access to hardware peripherals. Intended only for hardware testing --> <permission android:name="android.permission.HARDWARE_TEST" android:permissionGroup="android.permission-group.HARDWARE_CONTROLS" diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 3c1fdbc..44317bc 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -939,6 +939,11 @@ the flashlight.</string> <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. --> + <string name="permlab_accessUsb">access USB devices</string> + <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. --> + <string name="permdesc_accessUsb">Allows the application to access USB devices.</string> + + <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. --> <string name="permlab_hardware_test">test hardware</string> <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. --> <string name="permdesc_hardware_test">Allows the application to control diff --git a/include/media/MediaPlayerInterface.h b/include/media/MediaPlayerInterface.h index 9e606d9..3662983 100644 --- a/include/media/MediaPlayerInterface.h +++ b/include/media/MediaPlayerInterface.h @@ -39,7 +39,6 @@ template<typename T> class SortedVector; enum player_type { PV_PLAYER = 1, SONIVOX_PLAYER = 2, - VORBIS_PLAYER = 3, STAGEFRIGHT_PLAYER = 4, // Test players are available only in the 'test' and 'eng' builds. // The shared library with the test player is passed passed as an diff --git a/media/jni/Android.mk b/media/jni/Android.mk index 198e865..6eec215 100644 --- a/media/jni/Android.mk +++ b/media/jni/Android.mk @@ -24,6 +24,7 @@ LOCAL_SHARED_LIBRARIES := \ libui \ libcutils \ libsurfaceflinger_client \ + libstagefright \ libcamera_client ifneq ($(BUILD_WITHOUT_PV),true) @@ -34,15 +35,6 @@ else LOCAL_CFLAGS += -DNO_OPENCORE endif -ifeq ($(BUILD_WITH_FULL_STAGEFRIGHT),true) - -LOCAL_CFLAGS += -DBUILD_WITH_FULL_STAGEFRIGHT=1 - -LOCAL_SHARED_LIBRARIES += \ - libstagefright - -endif - LOCAL_STATIC_LIBRARIES := LOCAL_C_INCLUDES += \ diff --git a/media/jni/android_media_MediaScanner.cpp b/media/jni/android_media_MediaScanner.cpp index 2ab2445..273f1af 100644 --- a/media/jni/android_media_MediaScanner.cpp +++ b/media/jni/android_media_MediaScanner.cpp @@ -31,13 +31,7 @@ #include "JNIHelp.h" #include "android_runtime/AndroidRuntime.h" -#ifndef NO_OPENCORE -#include "pvmediascanner.h" -#endif - -#if BUILD_WITH_FULL_STAGEFRIGHT #include <media/stagefright/StagefrightMediaScanner.h> -#endif // ---------------------------------------------------------------------------- @@ -286,25 +280,10 @@ android_media_MediaScanner_native_init(JNIEnv *env) } } -static MediaScanner *createMediaScanner() { -#if BUILD_WITH_FULL_STAGEFRIGHT - char value[PROPERTY_VALUE_MAX]; - if (property_get("media.stagefright.enable-scan", value, NULL) - && (!strcmp(value, "1") || !strcasecmp(value, "true"))) { - return new StagefrightMediaScanner; - } -#endif -#ifndef NO_OPENCORE - return new PVMediaScanner(); -#endif - - return NULL; -} - static void android_media_MediaScanner_native_setup(JNIEnv *env, jobject thiz) { - MediaScanner *mp = createMediaScanner(); + MediaScanner *mp = new StagefrightMediaScanner; if (mp == NULL) { jniThrowException(env, "java/lang/RuntimeException", "Out of memory"); diff --git a/media/libmediaplayerservice/Android.mk b/media/libmediaplayerservice/Android.mk index 3b678cb..8f010c9 100644 --- a/media/libmediaplayerservice/Android.mk +++ b/media/libmediaplayerservice/Android.mk @@ -11,21 +11,11 @@ LOCAL_SRC_FILES:= \ MediaPlayerService.cpp \ MetadataRetrieverClient.cpp \ TestPlayerStub.cpp \ - VorbisPlayer.cpp \ - VorbisMetadataRetriever.cpp \ - MidiMetadataRetriever.cpp \ - MidiFile.cpp - -ifeq ($(BUILD_WITH_FULL_STAGEFRIGHT),true) - -LOCAL_SRC_FILES += \ - StagefrightPlayer.cpp \ + MidiMetadataRetriever.cpp \ + MidiFile.cpp \ + StagefrightPlayer.cpp \ StagefrightRecorder.cpp -LOCAL_CFLAGS += -DBUILD_WITH_FULL_STAGEFRIGHT=1 - -endif - ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true) LOCAL_LDLIBS += -ldl -lpthread endif diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp index d45c17b..82d5c14 100644 --- a/media/libmediaplayerservice/MediaPlayerService.cpp +++ b/media/libmediaplayerservice/MediaPlayerService.cpp @@ -56,7 +56,6 @@ #include "MetadataRetrieverClient.h" #include "MidiFile.h" -#include "VorbisPlayer.h" #include <media/PVPlayer.h> #include "TestPlayerStub.h" #include "StagefrightPlayer.h" @@ -197,8 +196,6 @@ extmap FILE_EXTS [] = { {".rtttl", SONIVOX_PLAYER}, {".rtx", SONIVOX_PLAYER}, {".ota", SONIVOX_PLAYER}, - {".ogg", VORBIS_PLAYER}, - {".oga", VORBIS_PLAYER}, #ifndef NO_OPENCORE {".wma", PV_PLAYER}, {".wmv", PV_PLAYER}, @@ -666,37 +663,9 @@ void MediaPlayerService::Client::disconnect() } static player_type getDefaultPlayerType() { -#if BUILD_WITH_FULL_STAGEFRIGHT - char value[PROPERTY_VALUE_MAX]; - if (property_get("media.stagefright.enable-player", value, NULL) - && (!strcmp(value, "1") || !strcasecmp(value, "true"))) { - return STAGEFRIGHT_PLAYER; - } -#endif - - return PV_PLAYER; -} - -// By default we use the VORBIS_PLAYER for vorbis playback (duh!), -// but if the magic property is set we will use our new experimental -// stagefright code instead. -static player_type OverrideStagefrightForVorbis(player_type player) { - if (player != VORBIS_PLAYER) { - return player; - } - -#if BUILD_WITH_FULL_STAGEFRIGHT - char value[PROPERTY_VALUE_MAX]; - if (property_get("media.stagefright.enable-vorbis", value, NULL) - && (!strcmp(value, "1") || !strcmp(value, "true"))) { - return STAGEFRIGHT_PLAYER; - } -#endif - - return VORBIS_PLAYER; + return STAGEFRIGHT_PLAYER; } - player_type getPlayerType(int fd, int64_t offset, int64_t length) { char buf[20]; @@ -708,7 +677,7 @@ player_type getPlayerType(int fd, int64_t offset, int64_t length) // Ogg vorbis? if (ident == 0x5367674f) // 'OggS' - return OverrideStagefrightForVorbis(VORBIS_PLAYER); + return STAGEFRIGHT_PLAYER; #ifndef NO_OPENCORE if (ident == 0x75b22630) { @@ -744,13 +713,6 @@ player_type getPlayerType(const char* url) return TEST_PLAYER; } - bool useStagefrightForHTTP = false; - char value[PROPERTY_VALUE_MAX]; - if (property_get("media.stagefright.enable-http", value, NULL) - && (!strcmp(value, "1") || !strcasecmp(value, "true"))) { - useStagefrightForHTTP = true; - } - // use MidiFile for MIDI extensions int lenURL = strlen(url); for (int i = 0; i < NELEM(FILE_EXTS); ++i) { @@ -758,22 +720,11 @@ player_type getPlayerType(const char* url) int start = lenURL - len; if (start > 0) { if (!strncasecmp(url + start, FILE_EXTS[i].extension, len)) { - if (FILE_EXTS[i].playertype == VORBIS_PLAYER - && !strncasecmp(url, "http://", 7) - && useStagefrightForHTTP) { - return STAGEFRIGHT_PLAYER; - } - return OverrideStagefrightForVorbis(FILE_EXTS[i].playertype); + return FILE_EXTS[i].playertype; } } } - if (!strncasecmp(url, "http://", 7)) { - if (!useStagefrightForHTTP) { - return PV_PLAYER; - } - } - if (!strncasecmp(url, "rtsp://", 7)) { char value[PROPERTY_VALUE_MAX]; if (!property_get("media.stagefright.enable-rtsp", value, NULL) @@ -802,16 +753,10 @@ static sp<MediaPlayerBase> createPlayer(player_type playerType, void* cookie, LOGV(" create MidiFile"); p = new MidiFile(); break; - case VORBIS_PLAYER: - LOGV(" create VorbisPlayer"); - p = new VorbisPlayer(); - break; -#if BUILD_WITH_FULL_STAGEFRIGHT case STAGEFRIGHT_PLAYER: LOGV(" create StagefrightPlayer"); p = new StagefrightPlayer; break; -#endif case TEST_PLAYER: LOGV("Create Test Player stub"); p = new TestPlayerStub(); diff --git a/media/libmediaplayerservice/MediaRecorderClient.cpp b/media/libmediaplayerservice/MediaRecorderClient.cpp index c507669..084f039 100644 --- a/media/libmediaplayerservice/MediaRecorderClient.cpp +++ b/media/libmediaplayerservice/MediaRecorderClient.cpp @@ -294,13 +294,11 @@ MediaRecorderClient::MediaRecorderClient(const sp<MediaPlayerService>& service, LOGV("Client constructor"); mPid = pid; -#if BUILD_WITH_FULL_STAGEFRIGHT char value[PROPERTY_VALUE_MAX]; if (property_get("media.stagefright.enable-record", value, NULL) && (!strcmp(value, "1") || !strcasecmp(value, "true"))) { mRecorder = new StagefrightRecorder; } else -#endif #ifndef NO_OPENCORE { mRecorder = new PVMediaRecorder(); diff --git a/media/libmediaplayerservice/MetadataRetrieverClient.cpp b/media/libmediaplayerservice/MetadataRetrieverClient.cpp index 550b84d..ca229fa 100644 --- a/media/libmediaplayerservice/MetadataRetrieverClient.cpp +++ b/media/libmediaplayerservice/MetadataRetrieverClient.cpp @@ -37,7 +37,6 @@ #include <media/MediaPlayerInterface.h> #include <media/PVMetadataRetriever.h> #include <private/media/VideoFrame.h> -#include "VorbisMetadataRetriever.h" #include "MidiMetadataRetriever.h" #include "MetadataRetrieverClient.h" #include "StagefrightMetadataRetriever.h" @@ -103,30 +102,17 @@ static sp<MediaMetadataRetrieverBase> createRetriever(player_type playerType) { sp<MediaMetadataRetrieverBase> p; switch (playerType) { -#if BUILD_WITH_FULL_STAGEFRIGHT case STAGEFRIGHT_PLAYER: { - char value[PROPERTY_VALUE_MAX]; - if (property_get("media.stagefright.enable-meta", value, NULL) - && (!strcmp(value, "1") || !strcasecmp(value, "true"))) { - LOGV("create StagefrightMetadataRetriever"); - p = new StagefrightMetadataRetriever; - break; - } - - // fall through + p = new StagefrightMetadataRetriever; + break; } -#endif #ifndef NO_OPENCORE case PV_PLAYER: LOGV("create pv metadata retriever"); p = new PVMetadataRetriever(); break; #endif - case VORBIS_PLAYER: - LOGV("create vorbis metadata retriever"); - p = new VorbisMetadataRetriever(); - break; case SONIVOX_PLAYER: LOGV("create midi metadata retriever"); p = new MidiMetadataRetriever(); diff --git a/media/libmediaplayerservice/VorbisMetadataRetriever.cpp b/media/libmediaplayerservice/VorbisMetadataRetriever.cpp deleted file mode 100644 index eac74fc..0000000 --- a/media/libmediaplayerservice/VorbisMetadataRetriever.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* -** -** Copyright 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_NDEBUG 0 -#define LOG_TAG "VorbisMetadataRetriever" -#include <utils/Log.h> - -#include "VorbisMetadataRetriever.h" -#include <media/mediametadataretriever.h> -# - -namespace android { - -void VorbisMetadataRetriever::clearMetadataValues() -{ - LOGV("cleearMetadataValues"); - mMetadataValues[0][0] = '\0'; -} - -status_t VorbisMetadataRetriever::setDataSource(const char *url) -{ - LOGV("setDataSource: url(%s)", url? url: "NULL pointer"); - Mutex::Autolock lock(mLock); - clearMetadataValues(); - if (mVorbisPlayer == 0) { - mVorbisPlayer = new VorbisPlayer(); - } - // TODO: support headers in MetadataRetriever interface! - return mVorbisPlayer->setDataSource(url, NULL /* headers */); -} - -status_t VorbisMetadataRetriever::setDataSource(int fd, int64_t offset, int64_t length) -{ - LOGV("setDataSource: fd(%d), offset(%lld), and length(%lld)", fd, offset, length); - Mutex::Autolock lock(mLock); - clearMetadataValues(); - if (mVorbisPlayer == 0) { - mVorbisPlayer = new VorbisPlayer(); - } - return mVorbisPlayer->setDataSource(fd, offset, length); -} - -const char* VorbisMetadataRetriever::extractMetadata(int keyCode) -{ - LOGV("extractMetadata: key(%d)", keyCode); - Mutex::Autolock lock(mLock); - if (mVorbisPlayer == 0 || mVorbisPlayer->initCheck() != NO_ERROR) { - LOGE("no vorbis player is initialized yet"); - return NULL; - } - switch (keyCode) { - case METADATA_KEY_DURATION: - { - if (mMetadataValues[0][0] == '\0') { - int duration = -1; - if (mVorbisPlayer->getDuration(&duration) != NO_ERROR) { - LOGE("failed to get duration"); - return NULL; - } - snprintf(mMetadataValues[0], MAX_METADATA_STRING_LENGTH, "%d", duration); - } - LOGV("duration: %s ms", mMetadataValues[0]); - return mMetadataValues[0]; - } - default: - LOGE("Unsupported key code (%d)", keyCode); - return NULL; - } - return NULL; -} - -}; - diff --git a/media/libmediaplayerservice/VorbisMetadataRetriever.h b/media/libmediaplayerservice/VorbisMetadataRetriever.h deleted file mode 100644 index 1c57fe3..0000000 --- a/media/libmediaplayerservice/VorbisMetadataRetriever.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -** -** Copyright 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. -*/ - -#ifndef ANDROID_VORBISMETADATARETRIEVER_H -#define ANDROID_VORBISMETADATARETRIEVER_H - -#include <utils/threads.h> -#include <utils/Errors.h> -#include <media/MediaMetadataRetrieverInterface.h> - -#include "VorbisPlayer.h" - -namespace android { - -class VorbisMetadataRetriever : public MediaMetadataRetrieverInterface { -public: - VorbisMetadataRetriever() {} - ~VorbisMetadataRetriever() {} - - virtual status_t setDataSource(const char *url); - virtual status_t setDataSource(int fd, int64_t offset, int64_t length); - virtual const char* extractMetadata(int keyCode); - -private: - static const uint32_t MAX_METADATA_STRING_LENGTH = 128; - void clearMetadataValues(); - - Mutex mLock; - sp<VorbisPlayer> mVorbisPlayer; - char mMetadataValues[1][MAX_METADATA_STRING_LENGTH]; -}; - -}; // namespace android - -#endif // ANDROID_VORBISMETADATARETRIEVER_H diff --git a/media/libmediaplayerservice/VorbisPlayer.cpp b/media/libmediaplayerservice/VorbisPlayer.cpp deleted file mode 100644 index 8181999..0000000 --- a/media/libmediaplayerservice/VorbisPlayer.cpp +++ /dev/null @@ -1,529 +0,0 @@ -/* -** Copyright 2007, 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_NDEBUG 0 -#define LOG_TAG "VorbisPlayer" -#include "utils/Log.h" - -#include <stdio.h> -#include <assert.h> -#include <limits.h> -#include <unistd.h> -#include <fcntl.h> -#include <sched.h> -#include <sys/types.h> -#include <sys/stat.h> - - -#include "VorbisPlayer.h" - -#ifdef HAVE_GETTID -static pid_t myTid() { return gettid(); } -#else -static pid_t myTid() { return getpid(); } -#endif - -// ---------------------------------------------------------------------------- - -namespace android { - -// ---------------------------------------------------------------------------- - -// TODO: Determine appropriate return codes -static status_t ERROR_NOT_OPEN = -1; -static status_t ERROR_OPEN_FAILED = -2; -static status_t ERROR_ALLOCATE_FAILED = -4; -static status_t ERROR_NOT_SUPPORTED = -8; -static status_t ERROR_NOT_READY = -16; -static status_t STATE_INIT = 0; -static status_t STATE_ERROR = 1; -static status_t STATE_OPEN = 2; - - -VorbisPlayer::VorbisPlayer() : - mAudioBuffer(NULL), mPlayTime(-1), mDuration(-1), mState(STATE_ERROR), - mStreamType(AudioSystem::MUSIC), mLoop(false), mAndroidLoop(false), - mExit(false), mPaused(false), mRender(false), mRenderTid(-1) -{ - LOGV("constructor\n"); - memset(&mVorbisFile, 0, sizeof mVorbisFile); -} - -void VorbisPlayer::onFirstRef() -{ - LOGV("onFirstRef"); - // create playback thread - Mutex::Autolock l(mMutex); - createThreadEtc(renderThread, this, "vorbis decoder", ANDROID_PRIORITY_AUDIO); - mCondition.wait(mMutex); - if (mRenderTid > 0) { - LOGV("render thread(%d) started", mRenderTid); - mState = STATE_INIT; - } -} - -status_t VorbisPlayer::initCheck() -{ - if (mState != STATE_ERROR) return NO_ERROR; - return ERROR_NOT_READY; -} - -VorbisPlayer::~VorbisPlayer() { - LOGV("VorbisPlayer destructor\n"); - release(); -} - -status_t VorbisPlayer::setDataSource( - const char *uri, const KeyedVector<String8, String8> *headers) { - return setdatasource(uri, -1, 0, 0x7ffffffffffffffLL); // intentionally less than LONG_MAX -} - -status_t VorbisPlayer::setDataSource(int fd, int64_t offset, int64_t length) -{ - return setdatasource(NULL, fd, offset, length); -} - -size_t VorbisPlayer::vp_fread(void *buf, size_t size, size_t nmemb, void *me) { - VorbisPlayer *self = (VorbisPlayer*) me; - - long curpos = vp_ftell(me); - while (nmemb != 0 && (curpos + size * nmemb) > self->mLength) { - nmemb--; - } - return fread(buf, size, nmemb, self->mFile); -} - -int VorbisPlayer::vp_fseek(void *me, ogg_int64_t off, int whence) { - VorbisPlayer *self = (VorbisPlayer*) me; - if (whence == SEEK_SET) - return fseek(self->mFile, off + self->mOffset, whence); - else if (whence == SEEK_CUR) - return fseek(self->mFile, off, whence); - else if (whence == SEEK_END) - return fseek(self->mFile, self->mOffset + self->mLength + off, SEEK_SET); - return -1; -} - -int VorbisPlayer::vp_fclose(void *me) { - LOGV("vp_fclose"); - VorbisPlayer *self = (VorbisPlayer*) me; - int ret = fclose (self->mFile); - self->mFile = NULL; - return ret; -} - -long VorbisPlayer::vp_ftell(void *me) { - VorbisPlayer *self = (VorbisPlayer*) me; - return ftell(self->mFile) - self->mOffset; -} - -status_t VorbisPlayer::setdatasource(const char *path, int fd, int64_t offset, int64_t length) -{ - LOGV("setDataSource url=%s, fd=%d\n", path, fd); - - // file still open? - Mutex::Autolock l(mMutex); - if (mState == STATE_OPEN) { - reset_nosync(); - } - - // open file and set paused state - if (path) { - mFile = fopen(path, "r"); - } else { - mFile = fdopen(dup(fd), "r"); - } - if (mFile == NULL) { - return ERROR_OPEN_FAILED; - } - - struct stat sb; - int ret; - if (path) { - ret = stat(path, &sb); - } else { - ret = fstat(fd, &sb); - } - if (ret != 0) { - mState = STATE_ERROR; - fclose(mFile); - return ERROR_OPEN_FAILED; - } - if (sb.st_size > (length + offset)) { - mLength = length; - } else { - mLength = sb.st_size - offset; - } - - ov_callbacks callbacks = { - (size_t (*)(void *, size_t, size_t, void *)) vp_fread, - (int (*)(void *, ogg_int64_t, int)) vp_fseek, - (int (*)(void *)) vp_fclose, - (long (*)(void *)) vp_ftell - }; - - mOffset = offset; - fseek(mFile, offset, SEEK_SET); - - int result = ov_open_callbacks(this, &mVorbisFile, NULL, 0, callbacks); - if (result < 0) { - LOGE("ov_open() failed: [%d]\n", (int)result); - mState = STATE_ERROR; - fclose(mFile); - return ERROR_OPEN_FAILED; - } - - // look for the android loop tag (for ringtones) - char **ptr = ov_comment(&mVorbisFile,-1)->user_comments; - while(*ptr) { - // does the comment start with ANDROID_LOOP_TAG - if(strncmp(*ptr, ANDROID_LOOP_TAG, strlen(ANDROID_LOOP_TAG)) == 0) { - // read the value of the tag - char *val = *ptr + strlen(ANDROID_LOOP_TAG) + 1; - mAndroidLoop = (strncmp(val, "true", 4) == 0); - } - // we keep parsing even after finding one occurence of ANDROID_LOOP_TAG, - // as we could find another one (the tag might have been appended more than once). - ++ptr; - } - LOGV_IF(mAndroidLoop, "looped sound"); - - mState = STATE_OPEN; - return NO_ERROR; -} - -status_t VorbisPlayer::prepare() -{ - LOGV("prepare\n"); - if (mState != STATE_OPEN ) { - return ERROR_NOT_OPEN; - } - return NO_ERROR; -} - -status_t VorbisPlayer::prepareAsync() { - LOGV("prepareAsync\n"); - // can't hold the lock here because of the callback - // it's safe because we don't change state - if (mState != STATE_OPEN ) { - sendEvent(MEDIA_ERROR); - return NO_ERROR; - } - sendEvent(MEDIA_PREPARED); - return NO_ERROR; -} - -status_t VorbisPlayer::start() -{ - LOGV("start\n"); - Mutex::Autolock l(mMutex); - if (mState != STATE_OPEN) { - return ERROR_NOT_OPEN; - } - - mPaused = false; - mRender = true; - - // wake up render thread - LOGV(" wakeup render thread\n"); - mCondition.signal(); - return NO_ERROR; -} - -status_t VorbisPlayer::stop() -{ - LOGV("stop\n"); - Mutex::Autolock l(mMutex); - if (mState != STATE_OPEN) { - return ERROR_NOT_OPEN; - } - mPaused = true; - mRender = false; - return NO_ERROR; -} - -status_t VorbisPlayer::seekTo(int position) -{ - LOGV("seekTo %d\n", position); - Mutex::Autolock l(mMutex); - if (mState != STATE_OPEN) { - return ERROR_NOT_OPEN; - } - - int result = ov_time_seek(&mVorbisFile, position); - if (result != 0) { - LOGE("ov_time_seek() returned %d\n", result); - return result; - } - sendEvent(MEDIA_SEEK_COMPLETE); - return NO_ERROR; -} - -status_t VorbisPlayer::pause() -{ - LOGV("pause\n"); - Mutex::Autolock l(mMutex); - if (mState != STATE_OPEN) { - return ERROR_NOT_OPEN; - } - mPaused = true; - return NO_ERROR; -} - -bool VorbisPlayer::isPlaying() -{ - LOGV("isPlaying\n"); - if (mState == STATE_OPEN) { - return mRender; - } - return false; -} - -status_t VorbisPlayer::getCurrentPosition(int* position) -{ - LOGV("getCurrentPosition\n"); - Mutex::Autolock l(mMutex); - if (mState != STATE_OPEN) { - LOGE("getCurrentPosition(): file not open"); - return ERROR_NOT_OPEN; - } - *position = ov_time_tell(&mVorbisFile); - if (*position < 0) { - LOGE("getCurrentPosition(): ov_time_tell returned %d", *position); - return *position; - } - return NO_ERROR; -} - -status_t VorbisPlayer::getDuration(int* duration) -{ - LOGV("getDuration\n"); - Mutex::Autolock l(mMutex); - if (mState != STATE_OPEN) { - return ERROR_NOT_OPEN; - } - - int ret = ov_time_total(&mVorbisFile, -1); - if (ret == OV_EINVAL) { - return -1; - } - - *duration = ret; - return NO_ERROR; -} - -status_t VorbisPlayer::release() -{ - LOGV("release\n"); - Mutex::Autolock l(mMutex); - reset_nosync(); - - // TODO: timeout when thread won't exit - // wait for render thread to exit - if (mRenderTid > 0) { - mExit = true; - mCondition.signal(); - mCondition.wait(mMutex); - } - return NO_ERROR; -} - -status_t VorbisPlayer::reset() -{ - LOGV("reset\n"); - Mutex::Autolock l(mMutex); - return reset_nosync(); -} - -// always call with lock held -status_t VorbisPlayer::reset_nosync() -{ - // close file - if (mFile != NULL) { - ov_clear(&mVorbisFile); // this also closes the FILE - if (mFile != NULL) { - LOGV("OOPS! Vorbis didn't close the file"); - fclose(mFile); - mFile = NULL; - } - } - mState = STATE_ERROR; - - mPlayTime = -1; - mDuration = -1; - mLoop = false; - mAndroidLoop = false; - mPaused = false; - mRender = false; - return NO_ERROR; -} - -status_t VorbisPlayer::setLooping(int loop) -{ - LOGV("setLooping\n"); - Mutex::Autolock l(mMutex); - mLoop = (loop != 0); - return NO_ERROR; -} - -status_t VorbisPlayer::createOutputTrack() { - // open audio track - vorbis_info *vi = ov_info(&mVorbisFile, -1); - - LOGV("Create AudioTrack object: rate=%ld, channels=%d\n", - vi->rate, vi->channels); - if (mAudioSink->open(vi->rate, vi->channels, AudioSystem::PCM_16_BIT, DEFAULT_AUDIOSINK_BUFFERCOUNT) != NO_ERROR) { - LOGE("mAudioSink open failed"); - return ERROR_OPEN_FAILED; - } - return NO_ERROR; -} - -int VorbisPlayer::renderThread(void* p) { - return ((VorbisPlayer*)p)->render(); -} - -#define AUDIOBUFFER_SIZE 4096 - -int VorbisPlayer::render() { - int result = -1; - int temp; - int current_section = 0; - bool audioStarted = false; - - LOGV("render\n"); - - // allocate render buffer - mAudioBuffer = new char[AUDIOBUFFER_SIZE]; - if (!mAudioBuffer) { - LOGE("mAudioBuffer allocate failed\n"); - goto threadExit; - } - - // let main thread know we're ready - { - Mutex::Autolock l(mMutex); - mRenderTid = myTid(); - mCondition.signal(); - } - - while (1) { - long numread = 0; - { - Mutex::Autolock l(mMutex); - - // pausing? - if (mPaused) { - if (mAudioSink->ready()) mAudioSink->pause(); - mRender = false; - audioStarted = false; - } - - // nothing to render, wait for client thread to wake us up - if (!mExit && !mRender) { - LOGV("render - signal wait\n"); - mCondition.wait(mMutex); - LOGV("render - signal rx'd\n"); - } - if (mExit) break; - - // We could end up here if start() is called, and before we get a - // chance to run, the app calls stop() or reset(). Re-check render - // flag so we don't try to render in stop or reset state. - if (!mRender) continue; - - // render vorbis data into the input buffer - numread = ov_read(&mVorbisFile, mAudioBuffer, AUDIOBUFFER_SIZE, ¤t_section); - if (numread == 0) { - // end of file, do we need to loop? - // ... - if (mLoop || mAndroidLoop) { - ov_time_seek(&mVorbisFile, 0); - current_section = 0; - numread = ov_read(&mVorbisFile, mAudioBuffer, AUDIOBUFFER_SIZE, ¤t_section); - } else { - mAudioSink->stop(); - audioStarted = false; - mRender = false; - mPaused = true; - int endpos = ov_time_tell(&mVorbisFile); - - LOGV("send MEDIA_PLAYBACK_COMPLETE"); - sendEvent(MEDIA_PLAYBACK_COMPLETE); - - // wait until we're started again - LOGV("playback complete - wait for signal"); - mCondition.wait(mMutex); - LOGV("playback complete - signal rx'd"); - if (mExit) break; - - // if we're still at the end, restart from the beginning - if (mState == STATE_OPEN) { - int curpos = ov_time_tell(&mVorbisFile); - if (curpos == endpos) { - ov_time_seek(&mVorbisFile, 0); - } - current_section = 0; - numread = ov_read(&mVorbisFile, mAudioBuffer, AUDIOBUFFER_SIZE, ¤t_section); - } - } - } - } - - // codec returns negative number on error - if (numread < 0) { - LOGE("Error in Vorbis decoder"); - sendEvent(MEDIA_ERROR); - break; - } - - // create audio output track if necessary - if (!mAudioSink->ready()) { - LOGV("render - create output track\n"); - if (createOutputTrack() != NO_ERROR) - break; - } - - // Write data to the audio hardware - if ((temp = mAudioSink->write(mAudioBuffer, numread)) < 0) { - LOGE("Error in writing:%d",temp); - result = temp; - break; - } - - // start audio output if necessary - if (!audioStarted && !mPaused && !mExit) { - LOGV("render - starting audio\n"); - mAudioSink->start(); - audioStarted = true; - } - } - -threadExit: - mAudioSink.clear(); - if (mAudioBuffer) { - delete [] mAudioBuffer; - mAudioBuffer = NULL; - } - - // tell main thread goodbye - Mutex::Autolock l(mMutex); - mRenderTid = -1; - mCondition.signal(); - return result; -} - -} // end namespace android diff --git a/media/libmediaplayerservice/VorbisPlayer.h b/media/libmediaplayerservice/VorbisPlayer.h deleted file mode 100644 index 4a50835..0000000 --- a/media/libmediaplayerservice/VorbisPlayer.h +++ /dev/null @@ -1,94 +0,0 @@ -/* -** -** Copyright 2008, 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_VORBISPLAYER_H -#define ANDROID_VORBISPLAYER_H - -#include <utils/threads.h> - -#include <media/MediaPlayerInterface.h> -#include <media/AudioTrack.h> - -#include "ivorbiscodec.h" -#include "ivorbisfile.h" - -#define ANDROID_LOOP_TAG "ANDROID_LOOP" - -namespace android { - -class VorbisPlayer : public MediaPlayerInterface { -public: - VorbisPlayer(); - ~VorbisPlayer(); - - virtual void onFirstRef(); - virtual status_t initCheck(); - - virtual status_t setDataSource( - const char *uri, const KeyedVector<String8, String8> *headers); - - virtual status_t setDataSource(int fd, int64_t offset, int64_t length); - virtual status_t setVideoSurface(const sp<ISurface>& surface) { return UNKNOWN_ERROR; } - virtual status_t prepare(); - virtual status_t prepareAsync(); - virtual status_t start(); - virtual status_t stop(); - virtual status_t seekTo(int msec); - virtual status_t pause(); - virtual bool isPlaying(); - virtual status_t getCurrentPosition(int* msec); - virtual status_t getDuration(int* msec); - virtual status_t release(); - virtual status_t reset(); - virtual status_t setLooping(int loop); - virtual player_type playerType() { return VORBIS_PLAYER; } - virtual status_t invoke(const Parcel& request, Parcel *reply) {return INVALID_OPERATION;} - -private: - status_t setdatasource(const char *path, int fd, int64_t offset, int64_t length); - status_t reset_nosync(); - status_t createOutputTrack(); - static int renderThread(void*); - int render(); - - static size_t vp_fread(void *, size_t, size_t, void *); - static int vp_fseek(void *, ogg_int64_t, int); - static int vp_fclose(void *); - static long vp_ftell(void *); - - Mutex mMutex; - Condition mCondition; - FILE* mFile; - int64_t mOffset; - int64_t mLength; - OggVorbis_File mVorbisFile; - char* mAudioBuffer; - int mPlayTime; - int mDuration; - status_t mState; - int mStreamType; - bool mLoop; - bool mAndroidLoop; - volatile bool mExit; - bool mPaused; - volatile bool mRender; - pid_t mRenderTid; -}; - -}; // namespace android - -#endif // ANDROID_VORBISPLAYER_H diff --git a/media/libstagefright/Android.mk b/media/libstagefright/Android.mk index 00a6995..60d0233 100644 --- a/media/libstagefright/Android.mk +++ b/media/libstagefright/Android.mk @@ -3,51 +3,44 @@ include $(CLEAR_VARS) include frameworks/base/media/libstagefright/codecs/common/Config.mk -LOCAL_SRC_FILES:= \ - ESDS.cpp \ - MediaBuffer.cpp \ - MediaBufferGroup.cpp \ - MediaDefs.cpp \ - MediaSource.cpp \ - MetaData.cpp \ - OMXCodec.cpp \ - Utils.cpp \ - OMXClient.cpp - -ifeq ($(BUILD_WITH_FULL_STAGEFRIGHT),true) - -LOCAL_SRC_FILES += \ - AMRExtractor.cpp \ - AMRWriter.cpp \ - AudioPlayer.cpp \ - AudioSource.cpp \ - AwesomePlayer.cpp \ - CameraSource.cpp \ - DataSource.cpp \ - FileSource.cpp \ - HTTPStream.cpp \ - JPEGSource.cpp \ - MP3Extractor.cpp \ - MPEG4Extractor.cpp \ - MPEG4Writer.cpp \ - MediaExtractor.cpp \ - NuCachedSource2.cpp \ - NuHTTPDataSource.cpp \ - OggExtractor.cpp \ - SampleIterator.cpp \ - SampleTable.cpp \ - ShoutcastSource.cpp \ - StagefrightMediaScanner.cpp \ - StagefrightMetadataRetriever.cpp \ - ThrottledSource.cpp \ - TimeSource.cpp \ - TimedEventQueue.cpp \ - WAVExtractor.cpp \ +LOCAL_SRC_FILES:= \ + AMRExtractor.cpp \ + AMRWriter.cpp \ + AudioPlayer.cpp \ + AudioSource.cpp \ + AwesomePlayer.cpp \ + CameraSource.cpp \ + DataSource.cpp \ + ESDS.cpp \ + FileSource.cpp \ + HTTPStream.cpp \ + JPEGSource.cpp \ + MP3Extractor.cpp \ + MPEG4Extractor.cpp \ + MPEG4Writer.cpp \ + MediaBuffer.cpp \ + MediaBufferGroup.cpp \ + MediaDefs.cpp \ + MediaExtractor.cpp \ + MediaSource.cpp \ + MetaData.cpp \ + NuCachedSource2.cpp \ + NuHTTPDataSource.cpp \ + OMXClient.cpp \ + OMXCodec.cpp \ + OggExtractor.cpp \ + SampleIterator.cpp \ + SampleTable.cpp \ + ShoutcastSource.cpp \ + StagefrightMediaScanner.cpp \ + StagefrightMetadataRetriever.cpp \ + ThrottledSource.cpp \ + TimeSource.cpp \ + TimedEventQueue.cpp \ + Utils.cpp \ + WAVExtractor.cpp \ string.cpp -LOCAL_CFLAGS += -DBUILD_WITH_FULL_STAGEFRIGHT -endif - LOCAL_C_INCLUDES:= \ $(JNI_H_INCLUDE) \ $(TOP)/external/opencore/extern_libs_v2/khronos/openmax/include \ @@ -82,20 +75,13 @@ LOCAL_STATIC_LIBRARIES := \ libstagefright_mpeg2ts \ libstagefright_httplive \ libstagefright_rtsp \ + libstagefright_id3 \ LOCAL_SHARED_LIBRARIES += \ libstagefright_amrnb_common \ libstagefright_enc_common \ libstagefright_avc_common \ libstagefright_foundation \ - -ifeq ($(BUILD_WITH_FULL_STAGEFRIGHT),true) - - -LOCAL_STATIC_LIBRARIES += \ - libstagefright_id3 - -LOCAL_SHARED_LIBRARIES += \ libstagefright_color_conversion ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true) @@ -108,8 +94,6 @@ ifneq ($(TARGET_SIMULATOR),true) LOCAL_SHARED_LIBRARIES += libdl endif -endif - ifeq ($(TARGET_OS)-$(TARGET_SIMULATOR),linux-true) LOCAL_LDLIBS += -lpthread endif diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp index 8979c3b..02a073e 100644 --- a/media/libstagefright/OMXCodec.cpp +++ b/media/libstagefright/OMXCodec.cpp @@ -425,7 +425,6 @@ sp<MediaSource> OMXCodec::Create( for (size_t i = 0; i < matchingCodecs.size(); ++i) { componentName = matchingCodecs[i].string(); -#if BUILD_WITH_FULL_STAGEFRIGHT sp<MediaSource> softwareCodec = createEncoder? InstantiateSoftwareEncoder(componentName, source, meta): InstantiateSoftwareCodec(componentName, source); @@ -435,7 +434,6 @@ sp<MediaSource> OMXCodec::Create( return softwareCodec; } -#endif LOGV("Attempting to allocate OMX node '%s'", componentName); diff --git a/media/libstagefright/id3/Android.mk b/media/libstagefright/id3/Android.mk index 93fac1c..23c8e44 100644 --- a/media/libstagefright/id3/Android.mk +++ b/media/libstagefright/id3/Android.mk @@ -1,5 +1,3 @@ -ifeq ($(BUILD_WITH_FULL_STAGEFRIGHT),true) - LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) @@ -28,5 +26,3 @@ LOCAL_MODULE_TAGS := debug LOCAL_MODULE := testid3 include $(BUILD_EXECUTABLE) - -endif diff --git a/media/libstagefright/omx/tests/Android.mk b/media/libstagefright/omx/tests/Android.mk index ee117e5..8bf4336 100644 --- a/media/libstagefright/omx/tests/Android.mk +++ b/media/libstagefright/omx/tests/Android.mk @@ -1,5 +1,3 @@ -ifeq ($(BUILD_WITH_FULL_STAGEFRIGHT),true) - LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) @@ -17,7 +15,3 @@ LOCAL_C_INCLUDES:= \ LOCAL_MODULE:= omx_tests include $(BUILD_EXECUTABLE) - -endif - - diff --git a/media/tests/omxjpegdecoder/Android.mk b/media/tests/omxjpegdecoder/Android.mk index b7c18bc..f97f8eb 100644 --- a/media/tests/omxjpegdecoder/Android.mk +++ b/media/tests/omxjpegdecoder/Android.mk @@ -11,7 +11,6 @@ # 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. -ifeq ($(BUILD_WITH_FULL_STAGEFRIGHT),true) LOCAL_PATH:= $(call my-dir) @@ -54,5 +53,3 @@ LOCAL_MODULE := jpeg_bench LOCAL_MODULE_TAGS := optional include $(BUILD_EXECUTABLE) - -endif diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index b91bf73..7130636 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -96,6 +96,7 @@ class ServerThread extends Thread { BluetoothA2dpService bluetoothA2dp = null; HeadsetObserver headset = null; DockObserver dock = null; + UsbObserver usb = null; UiModeManagerService uiMode = null; RecognitionManagerService recognition = null; ThrottleService throttle = null; @@ -373,8 +374,16 @@ class ServerThread extends Thread { } try { + Slog.i(TAG, "USB Observer"); + // Listen for USB changes + usb = new UsbObserver(context); + } catch (Throwable e) { + Slog.e(TAG, "Failure starting UsbObserver", e); + } + + try { Slog.i(TAG, "UI Mode Manager Service"); - // Listen for dock station changes + // Listen for UI mode changes uiMode = new UiModeManagerService(context); } catch (Throwable e) { Slog.e(TAG, "Failure starting UiModeManagerService", e); @@ -461,6 +470,7 @@ class ServerThread extends Thread { final BatteryService batteryF = battery; final ConnectivityService connectivityF = connectivity; final DockObserver dockF = dock; + final UsbObserver usbF = usb; final ThrottleService throttleF = throttle; final UiModeManagerService uiModeF = uiMode; final AppWidgetService appWidgetF = appWidget; @@ -483,6 +493,7 @@ class ServerThread extends Thread { if (batteryF != null) batteryF.systemReady(); if (connectivityF != null) connectivityF.systemReady(); if (dockF != null) dockF.systemReady(); + if (usbF != null) usbF.systemReady(); if (uiModeF != null) uiModeF.systemReady(); if (recognitionF != null) recognitionF.systemReady(); Watchdog.getInstance().start(); diff --git a/services/java/com/android/server/UsbObserver.java b/services/java/com/android/server/UsbObserver.java new file mode 100644 index 0000000..3993a7f --- /dev/null +++ b/services/java/com/android/server/UsbObserver.java @@ -0,0 +1,197 @@ +/* + * 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.server; + +import android.content.ContentResolver; +import android.content.Context; +import android.content.Intent; +import android.hardware.Usb; +import android.net.Uri; +import android.os.Handler; +import android.os.Message; +import android.os.UEventObserver; +import android.provider.Settings; +import android.util.Log; +import android.util.Slog; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.ArrayList; + +/** + * <p>UsbObserver monitors for changes to USB state. + */ +class UsbObserver extends UEventObserver { + private static final String TAG = UsbObserver.class.getSimpleName(); + private static final boolean LOG = false; + + private static final String USB_CONFIGURATION_MATCH = "DEVPATH=/devices/virtual/switch/usb_configuration"; + private static final String USB_FUNCTIONS_MATCH = "DEVPATH=/devices/virtual/usb_composite/"; + private static final String USB_CONFIGURATION_PATH = "/sys/class/switch/usb_configuration/state"; + private static final String USB_COMPOSITE_CLASS_PATH = "/sys/class/usb_composite"; + + private static final int MSG_UPDATE = 0; + + private int mUsbConfig = 0; + private int mPreviousUsbConfig = 0; + + // lists of enabled and disabled USB functions + private final ArrayList<String> mEnabledFunctions = new ArrayList<String>(); + private final ArrayList<String> mDisabledFunctions = new ArrayList<String>(); + + private boolean mSystemReady; + + private final Context mContext; + + private PowerManagerService mPowerManager; + + public UsbObserver(Context context) { + mContext = context; + init(); // set initial status + + startObserving(USB_CONFIGURATION_MATCH); + startObserving(USB_FUNCTIONS_MATCH); + } + + @Override + public void onUEvent(UEventObserver.UEvent event) { + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Slog.v(TAG, "USB UEVENT: " + event.toString()); + } + + synchronized (this) { + String switchState = event.get("SWITCH_STATE"); + if (switchState != null) { + try { + int newConfig = Integer.parseInt(switchState); + if (newConfig != mUsbConfig) { + mPreviousUsbConfig = mUsbConfig; + mUsbConfig = newConfig; + // trigger an Intent broadcast + if (mSystemReady) { + update(); + } + } + } catch (NumberFormatException e) { + Slog.e(TAG, "Could not parse switch state from event " + event); + } + } else { + String function = event.get("FUNCTION"); + String enabledStr = event.get("ENABLED"); + if (function != null && enabledStr != null) { + // Note: we do not broadcast a change when a function is enabled or disabled. + // We just record the state change for the next broadcast. + boolean enabled = "1".equals(enabledStr); + if (enabled) { + if (!mEnabledFunctions.contains(function)) { + mEnabledFunctions.add(function); + } + mDisabledFunctions.remove(function); + } else { + if (!mDisabledFunctions.contains(function)) { + mDisabledFunctions.add(function); + } + mEnabledFunctions.remove(function); + } + } + } + } + } + private final void init() { + char[] buffer = new char[1024]; + + try { + FileReader file = new FileReader(USB_CONFIGURATION_PATH); + int len = file.read(buffer, 0, 1024); + mPreviousUsbConfig = mUsbConfig = Integer.valueOf((new String(buffer, 0, len)).trim()); + + } catch (FileNotFoundException e) { + Slog.w(TAG, "This kernel does not have USB configuration switch support"); + } catch (Exception e) { + Slog.e(TAG, "" , e); + } + + try { + File[] files = new File(USB_COMPOSITE_CLASS_PATH).listFiles(); + for (int i = 0; i < files.length; i++) { + File file = new File(files[i], "enable"); + FileReader reader = new FileReader(file); + int len = reader.read(buffer, 0, 1024); + int value = Integer.valueOf((new String(buffer, 0, len)).trim()); + String functionName = files[i].getName(); + if (value == 1) { + mEnabledFunctions.add(functionName); + } else { + mDisabledFunctions.add(functionName); + } + } + } catch (FileNotFoundException e) { + Slog.w(TAG, "This kernel does not have USB composite class support"); + } catch (Exception e) { + Slog.e(TAG, "" , e); + } + } + + void systemReady() { + synchronized (this) { + update(); + mSystemReady = true; + } + } + + private final void update() { + mHandler.sendEmptyMessage(MSG_UPDATE); + } + + private final Handler mHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case MSG_UPDATE: + synchronized (this) { + final ContentResolver cr = mContext.getContentResolver(); + + if (Settings.Secure.getInt(cr, + Settings.Secure.DEVICE_PROVISIONED, 0) == 0) { + Slog.i(TAG, "Device not provisioned, skipping USB broadcast"); + return; + } + // Send an Intent containing connected/disconnected state + // and the enabled/disabled state of all USB functions + Intent intent; + if (mUsbConfig != 0) { + intent = new Intent(Usb.ACTION_USB_CONNECTED); + + // include state of all USB functions in our extras + for (int i = 0; i < mEnabledFunctions.size(); i++) { + intent.putExtra(mEnabledFunctions.get(i), Usb.USB_FUNCTION_ENABLED); + } + for (int i = 0; i < mDisabledFunctions.size(); i++) { + intent.putExtra(mDisabledFunctions.get(i), Usb.USB_FUNCTION_DISABLED); + } + } else { + intent = new Intent(Usb.ACTION_USB_DISCONNECTED); + } + + mContext.sendBroadcast(intent, android.Manifest.permission.ACCESS_USB); + } + break; + } + } + }; +} diff --git a/tests/appwidgets/AppWidgetProviderTest/res/layout/test_appwidget2.xml b/tests/appwidgets/AppWidgetProviderTest/res/layout/test_appwidget2.xml new file mode 100644 index 0000000..abc6f59 --- /dev/null +++ b/tests/appwidgets/AppWidgetProviderTest/res/layout/test_appwidget2.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2006 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. +--> + +<TextView xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/oh_hai_text" + android:layout_width="150dp" + android:layout_height="150dp" + android:text="@string/appwidget_view_title" + android:background="#8fff" + android:textColor="#000" + android:textStyle="bold" +/> + diff --git a/tests/appwidgets/AppWidgetProviderTest/src/com/android/tests/appwidgetprovider/TestAppWidgetProvider.java b/tests/appwidgets/AppWidgetProviderTest/src/com/android/tests/appwidgetprovider/TestAppWidgetProvider.java index 418be65..d9c0110 100644 --- a/tests/appwidgets/AppWidgetProviderTest/src/com/android/tests/appwidgetprovider/TestAppWidgetProvider.java +++ b/tests/appwidgets/AppWidgetProviderTest/src/com/android/tests/appwidgetprovider/TestAppWidgetProvider.java @@ -41,6 +41,7 @@ public class TestAppWidgetProvider extends BroadcastReceiver { Log.d(TAG, "DISABLED"); } else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) { + if (true) return; Log.d(TAG, "UPDATE"); Bundle extras = intent.getExtras(); int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS); |