Merge change Iaad9c8d1 into eclair-mr2

* changes:
  Restore 7.xml.
diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp
index f1c1cb9..094b02d 100644
--- a/core/jni/android_util_Process.cpp
+++ b/core/jni/android_util_Process.cpp
@@ -285,6 +285,7 @@
 
     if (rc) {
         signalExceptionForGroupError(env, clazz, errno);
+        return;
     }
 
     if (setpriority(PRIO_PROCESS, pid, pri) < 0) {
diff --git a/include/media/stagefright/OMXPluginBase.h b/include/media/stagefright/OMXPluginBase.h
index 9643c5f..61cc50a 100644
--- a/include/media/stagefright/OMXPluginBase.h
+++ b/include/media/stagefright/OMXPluginBase.h
@@ -36,6 +36,9 @@
             OMX_PTR appData,
             OMX_COMPONENTTYPE **component) = 0;
 
+    virtual OMX_ERRORTYPE destroyComponentInstance(
+            OMX_COMPONENTTYPE *component) = 0;
+
     virtual OMX_ERRORTYPE enumerateComponents(
             OMX_STRING name,
             size_t size,
diff --git a/media/libstagefright/include/OMXNodeInstance.h b/media/libstagefright/include/OMXNodeInstance.h
index 09a8816..19d3940 100644
--- a/media/libstagefright/include/OMXNodeInstance.h
+++ b/media/libstagefright/include/OMXNodeInstance.h
@@ -26,6 +26,7 @@
 namespace android {
 
 class IOMXObserver;
+struct OMXMaster;
 
 struct OMXNodeInstance {
     OMXNodeInstance(
@@ -37,7 +38,7 @@
     sp<IOMXObserver> observer();
     OMX::node_id nodeID();
 
-    status_t freeNode();
+    status_t freeNode(OMXMaster *master);
 
     status_t sendCommand(OMX_COMMANDTYPE cmd, OMX_S32 param);
     status_t getParameter(OMX_INDEXTYPE index, void *params, size_t size);
@@ -72,7 +73,7 @@
             const char *parameterName, OMX_INDEXTYPE *index);
 
     void onMessage(const omx_message &msg);
-    void onObserverDied();
+    void onObserverDied(OMXMaster *master);
     void onGetHandleFailed();
 
     static OMX_CALLBACKTYPE kCallbacks;
diff --git a/media/libstagefright/omx/OMX.cpp b/media/libstagefright/omx/OMX.cpp
index 9f93c31..61be8f7 100644
--- a/media/libstagefright/omx/OMX.cpp
+++ b/media/libstagefright/omx/OMX.cpp
@@ -205,7 +205,7 @@
         invalidateNodeID_l(instance->nodeID());
     }
 
-    instance->onObserverDied();
+    instance->onObserverDied(mMaster);
 }
 
 status_t OMX::listNodes(List<String8> *list) {
@@ -262,7 +262,7 @@
     mLiveNodes.removeItemsAt(index);
     instance->observer()->asBinder()->unlinkToDeath(this);
 
-    return instance->freeNode();
+    return instance->freeNode(mMaster);
 }
 
 status_t OMX::sendCommand(
diff --git a/media/libstagefright/omx/OMXMaster.cpp b/media/libstagefright/omx/OMXMaster.cpp
index 838a9f7..12302f3 100644
--- a/media/libstagefright/omx/OMXMaster.cpp
+++ b/media/libstagefright/omx/OMXMaster.cpp
@@ -60,7 +60,9 @@
         (CreateOMXPluginFunc)dlsym(
                 mVendorLibHandle, "_ZN7android15createOMXPluginEv");
 
-    addPlugin((*createOMXPlugin)());
+    if (createOMXPlugin) {
+        addPlugin((*createOMXPlugin)());
+    }
 }
 
 void OMXMaster::addPlugin(OMXPluginBase *plugin) {
@@ -118,7 +120,32 @@
     }
 
     OMXPluginBase *plugin = mPluginByComponentName.valueAt(index);
-    return plugin->makeComponentInstance(name, callbacks, appData, component);
+    OMX_ERRORTYPE err =
+        plugin->makeComponentInstance(name, callbacks, appData, component);
+
+    if (err != OMX_ErrorNone) {
+        return err;
+    }
+
+    mPluginByInstance.add(*component, plugin);
+
+    return err;
+}
+
+OMX_ERRORTYPE OMXMaster::destroyComponentInstance(
+        OMX_COMPONENTTYPE *component) {
+    Mutex::Autolock autoLock(mLock);
+
+    ssize_t index = mPluginByInstance.indexOfKey(component);
+
+    if (index < 0) {
+        return OMX_ErrorBadParameter;
+    }
+
+    OMXPluginBase *plugin = mPluginByInstance.valueAt(index);
+    mPluginByInstance.removeItemsAt(index);
+
+    return plugin->destroyComponentInstance(component);
 }
 
 OMX_ERRORTYPE OMXMaster::enumerateComponents(
diff --git a/media/libstagefright/omx/OMXMaster.h b/media/libstagefright/omx/OMXMaster.h
index 63cd664..e944c4a 100644
--- a/media/libstagefright/omx/OMXMaster.h
+++ b/media/libstagefright/omx/OMXMaster.h
@@ -37,6 +37,9 @@
             OMX_PTR appData,
             OMX_COMPONENTTYPE **component);
 
+    virtual OMX_ERRORTYPE destroyComponentInstance(
+            OMX_COMPONENTTYPE *component);
+
     virtual OMX_ERRORTYPE enumerateComponents(
             OMX_STRING name,
             size_t size,
@@ -46,6 +49,8 @@
     Mutex mLock;
     List<OMXPluginBase *> mPlugins;
     KeyedVector<String8, OMXPluginBase *> mPluginByComponentName;
+    KeyedVector<OMX_COMPONENTTYPE *, OMXPluginBase *> mPluginByInstance;
+
     void *mVendorLibHandle;
 
     void addVendorPlugin();
diff --git a/media/libstagefright/omx/OMXNodeInstance.cpp b/media/libstagefright/omx/OMXNodeInstance.cpp
index 099139a..288710e 100644
--- a/media/libstagefright/omx/OMXNodeInstance.cpp
+++ b/media/libstagefright/omx/OMXNodeInstance.cpp
@@ -19,6 +19,7 @@
 #include <utils/Log.h>
 
 #include "../include/OMXNodeInstance.h"
+#include "OMXMaster.h"
 
 #include <OMX_Component.h>
 
@@ -106,7 +107,7 @@
     return (err == OMX_ErrorNone) ? OK : UNKNOWN_ERROR;
 }
 
-status_t OMXNodeInstance::freeNode() {
+status_t OMXNodeInstance::freeNode(OMXMaster *master) {
     // Transition the node from its current state all the way down
     // to "Loaded".
     // This ensures that all active buffers are properly freed even
@@ -157,8 +158,9 @@
             break;
     }
 
-    OMX_ERRORTYPE err =
-        (*static_cast<OMX_COMPONENTTYPE *>(mHandle)->ComponentDeInit)(mHandle);
+    OMX_ERRORTYPE err = master->destroyComponentInstance(
+            static_cast<OMX_COMPONENTTYPE *>(mHandle));
+
     mHandle = NULL;
 
     if (err != OMX_ErrorNone) {
@@ -384,11 +386,11 @@
     mObserver->onMessage(msg);
 }
 
-void OMXNodeInstance::onObserverDied() {
+void OMXNodeInstance::onObserverDied(OMXMaster *master) {
     LOGE("!!! Observer died. Quickly, do something, ... anything...");
 
     // Try to force shutdown of the node and hope for the best.
-    freeNode();
+    freeNode(master);
 }
 
 void OMXNodeInstance::onGetHandleFailed() {
diff --git a/media/libstagefright/omx/OMXPVCodecsPlugin.cpp b/media/libstagefright/omx/OMXPVCodecsPlugin.cpp
index 3957901..2bd8094 100644
--- a/media/libstagefright/omx/OMXPVCodecsPlugin.cpp
+++ b/media/libstagefright/omx/OMXPVCodecsPlugin.cpp
@@ -35,20 +35,16 @@
         const OMX_CALLBACKTYPE *callbacks,
         OMX_PTR appData,
         OMX_COMPONENTTYPE **component) {
-    OMX_ERRORTYPE err = OMX_MasterGetHandle(
+    return OMX_MasterGetHandle(
             reinterpret_cast<OMX_HANDLETYPE *>(component),
             const_cast<char *>(name),
             appData,
             const_cast<OMX_CALLBACKTYPE *>(callbacks));
+}
 
-    if (err != OMX_ErrorNone) {
-        return err;
-    }
-
-    // PV is not even filling this in...
-    (*component)->ComponentDeInit = &OMX_MasterFreeHandle;
-
-    return OMX_ErrorNone;
+OMX_ERRORTYPE OMXPVCodecsPlugin::destroyComponentInstance(
+        OMX_COMPONENTTYPE *component) {
+    return OMX_MasterFreeHandle(component);
 }
 
 OMX_ERRORTYPE OMXPVCodecsPlugin::enumerateComponents(
diff --git a/media/libstagefright/omx/OMXPVCodecsPlugin.h b/media/libstagefright/omx/OMXPVCodecsPlugin.h
index 55ca87a..f32eede 100644
--- a/media/libstagefright/omx/OMXPVCodecsPlugin.h
+++ b/media/libstagefright/omx/OMXPVCodecsPlugin.h
@@ -32,6 +32,9 @@
             OMX_PTR appData,
             OMX_COMPONENTTYPE **component);
 
+    virtual OMX_ERRORTYPE destroyComponentInstance(
+            OMX_COMPONENTTYPE *component);
+
     virtual OMX_ERRORTYPE enumerateComponents(
             OMX_STRING name,
             size_t size,
diff --git a/media/libstagefright/omx/OMXSoftwareCodecsPlugin.cpp b/media/libstagefright/omx/OMXSoftwareCodecsPlugin.cpp
index 22f58cc..45610df 100644
--- a/media/libstagefright/omx/OMXSoftwareCodecsPlugin.cpp
+++ b/media/libstagefright/omx/OMXSoftwareCodecsPlugin.cpp
@@ -63,6 +63,11 @@
     return OMX_ErrorInvalidComponentName;
 }
 
+OMX_ERRORTYPE OMXSoftwareCodecsPlugin::destroyComponentInstance(
+        OMX_COMPONENTTYPE *component) {
+    return (*component->ComponentDeInit)(component);
+}
+
 OMX_ERRORTYPE OMXSoftwareCodecsPlugin::enumerateComponents(
         OMX_STRING name,
         size_t size,
diff --git a/media/libstagefright/omx/OMXSoftwareCodecsPlugin.h b/media/libstagefright/omx/OMXSoftwareCodecsPlugin.h
index dcb5b19..5beeb26 100644
--- a/media/libstagefright/omx/OMXSoftwareCodecsPlugin.h
+++ b/media/libstagefright/omx/OMXSoftwareCodecsPlugin.h
@@ -31,6 +31,9 @@
             OMX_PTR appData,
             OMX_COMPONENTTYPE **component);
 
+    virtual OMX_ERRORTYPE destroyComponentInstance(
+            OMX_COMPONENTTYPE *component);
+
     virtual OMX_ERRORTYPE enumerateComponents(
             OMX_STRING name,
             size_t size,
diff --git a/services/java/com/android/server/am/UsageStatsService.java b/services/java/com/android/server/am/UsageStatsService.java
index 373b44e..f99ca96 100644
--- a/services/java/com/android/server/am/UsageStatsService.java
+++ b/services/java/com/android/server/am/UsageStatsService.java
@@ -380,11 +380,15 @@
             // Get the most recent file
             mFileLeaf = getCurrentDateStr(FILE_PREFIX);
             // Copy current file to back up
-            File backupFile =  new File(mFile.getPath() + ".bak");
-            if (!mFile.renameTo(backupFile)) {
-                Log.w(TAG, "Failed to persist new stats");
-                return;
+            File backupFile = null;
+            if (mFile != null && mFile.exists()) {
+                backupFile = new File(mFile.getPath() + ".bak");
+                if (!mFile.renameTo(backupFile)) {
+                    Log.w(TAG, "Failed to persist new stats");
+                    return;
+                }
             }
+
             try {
                 // Write mStats to file
                 writeStatsFLOCK();
@@ -468,16 +472,10 @@
             
             final boolean samePackage = pkgName.equals(mLastResumedPkg);
             if (mIsResumed) {
-                if (samePackage) {
-                    Log.w(TAG, "Something wrong here, didn't expect "
-                            + pkgName + " to be resumed");
-                    return;
-                }
-                
                 if (mLastResumedPkg != null) {
                     // We last resumed some other package...  just pause it now
                     // to recover.
-                    Log.w(TAG, "Unexpected resume of " + pkgName
+                    Log.i(TAG, "Unexpected resume of " + pkgName
                             + " while already resumed in " + mLastResumedPkg);
                     PkgUsageStatsExtended pus = mStats.get(mLastResumedPkg);
                     if (pus != null) {
@@ -516,7 +514,7 @@
                 return;
             }
             if (!mIsResumed) {
-                Log.w(TAG, "Something wrong here, didn't expect "
+                Log.i(TAG, "Something wrong here, didn't expect "
                         + pkgName + " to be paused");
                 return;
             }
@@ -527,7 +525,7 @@
             PkgUsageStatsExtended pus = mStats.get(pkgName);
             if (pus == null) {
                 // Weird some error here
-                Log.w(TAG, "No package stats for pkg:"+pkgName);
+                Log.i(TAG, "No package stats for pkg:"+pkgName);
                 return;
             }
             pus.updatePause();