Merge "Issue 3315999: catch ToneGenerator exceptions." into honeycomb
diff --git a/api/11.xml b/api/11.xml
index 6c06a0a..eb2c15c 100644
--- a/api/11.xml
+++ b/api/11.xml
@@ -252338,21 +252338,6 @@
  deprecated="not deprecated"
  visibility="public"
 >
-<parameter name="viewId" type="int">
-</parameter>
-<parameter name="intent" type="android.content.Intent">
-</parameter>
-</method>
-<method name="setRemoteAdapter"
- return="void"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
 <parameter name="appWidgetId" type="int">
 </parameter>
 <parameter name="viewId" type="int">
diff --git a/api/current.xml b/api/current.xml
index 73581f1..d100031 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -252483,21 +252483,6 @@
  deprecated="not deprecated"
  visibility="public"
 >
-<parameter name="viewId" type="int">
-</parameter>
-<parameter name="intent" type="android.content.Intent">
-</parameter>
-</method>
-<method name="setRemoteAdapter"
- return="void"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
 <parameter name="appWidgetId" type="int">
 </parameter>
 <parameter name="viewId" type="int">
diff --git a/core/java/android/accounts/AccountManagerService.java b/core/java/android/accounts/AccountManagerService.java
index e6eaf71..2c99f14 100644
--- a/core/java/android/accounts/AccountManagerService.java
+++ b/core/java/android/accounts/AccountManagerService.java
@@ -722,6 +722,9 @@
                 final String[] argsAccountId = {String.valueOf(accountId)};
                 db.update(TABLE_ACCOUNTS, values, ACCOUNTS_ID + "=?", argsAccountId);
                 db.delete(TABLE_AUTHTOKENS, AUTHTOKENS_ACCOUNTS_ID + "=?", argsAccountId);
+                synchronized (mCacheLock) {
+                    mAuthTokenCache.remove(account);
+                }
                 db.setTransactionSuccessful();
             }
         } finally {
@@ -1812,6 +1815,11 @@
                 try {
                     db.execSQL("DELETE from " + TABLE_AUTHTOKENS);
                     db.execSQL("UPDATE " + TABLE_ACCOUNTS + " SET " + ACCOUNTS_PASSWORD + " = ''");
+
+                    synchronized (mCacheLock) {
+                        mAuthTokenCache = new HashMap<Account, HashMap<String, String>>();
+                    }
+
                     db.setTransactionSuccessful();
                 } finally {
                     db.endTransaction();
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index c336ccb..482ce56 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -1277,18 +1277,6 @@
     /**
      * Equivalent to calling {@link android.widget.AbsListView#setRemoteViewsAdapter(Intent)}.
      *
-     * @param viewId The id of the view whose text should change
-     * @param intent The intent of the service which will be
-     *            providing data to the RemoteViewsAdapter
-     */
-    public void setRemoteAdapter(int viewId, Intent intent) {
-        // Do nothing.  This method will be removed after all widgets have been updated to the
-        // new API.
-    }
-
-    /**
-     * Equivalent to calling {@link android.widget.AbsListView#setRemoteViewsAdapter(Intent)}.
-     *
      * @param appWidgetId The id of the app widget which contains the specified view
      * @param viewId The id of the view whose text should change
      * @param intent The intent of the service which will be
diff --git a/core/java/android/widget/Toast.java b/core/java/android/widget/Toast.java
index 29ca49a..a8f9f62 100644
--- a/core/java/android/widget/Toast.java
+++ b/core/java/android/widget/Toast.java
@@ -33,6 +33,8 @@
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityManager;
 
+import java.lang.ref.WeakReference;
+
 /**
  * A toast is a view containing a quick little message for the user.  The toast class
  * helps you create and show those.
@@ -67,7 +69,6 @@
      */
     public static final int LENGTH_LONG = 1;
 
-    final Handler mHandler = new Handler();    
     final Context mContext;
     final TN mTN;
     int mDuration;
@@ -87,7 +88,7 @@
      */
     public Toast(Context context) {
         mContext = context;
-        mTN = new TN();
+        mTN = new TN(this);
         mY = context.getResources().getDimensionPixelSize(
                 com.android.internal.R.dimen.toast_y_offset);
     }
@@ -101,13 +102,10 @@
         }
 
         INotificationManager service = getService();
-
         String pkg = mContext.getPackageName();
 
-        TN tn = mTN;
-
         try {
-            service.enqueueToast(pkg, tn, mDuration);
+            service.enqueueToast(pkg, mTN, mDuration);
         } catch (RemoteException e) {
             // Empty
         }
@@ -313,7 +311,9 @@
         return sService;
     }
 
-    private class TN extends ITransientNotification.Stub {
+    private static class TN extends ITransientNotification.Stub {
+        final Handler mHandler = new Handler();    
+
         final Runnable mShow = new Runnable() {
             public void run() {
                 handleShow();
@@ -327,10 +327,12 @@
         };
 
         private final WindowManager.LayoutParams mParams = new WindowManager.LayoutParams();
+        private final WeakReference<Toast> mToast;
         
         WindowManagerImpl mWM;
 
-        TN() {
+        TN(Toast toast) {
+            mToast = new WeakReference<Toast>(toast);
             // XXX This should be changed to use a Dialog, with a Theme.Toast
             // defined that sets up the layout params appropriately.
             final WindowManager.LayoutParams params = mParams;
@@ -362,49 +364,53 @@
         }
 
         public void handleShow() {
-            if (localLOGV) Log.v(TAG, "HANDLE SHOW: " + this + " mView=" + mView
-                    + " mNextView=" + mNextView);
-            if (mView != mNextView) {
-                // remove the old view if necessary
-                handleHide();
-                mView = mNextView;
-                mWM = WindowManagerImpl.getDefault();
-                final int gravity = mGravity;
-                mParams.gravity = gravity;
-                if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
-                    mParams.horizontalWeight = 1.0f;
+            final Toast toast = mToast.get();
+            if (toast != null) {
+                if (localLOGV) Log.v(TAG, "HANDLE SHOW: " + this + " mView=" + toast.mView
+                        + " mNextView=" + toast.mNextView);
+                if (toast.mView != toast.mNextView) {
+                    // remove the old view if necessary
+                    handleHide();
+                    toast.mView = toast.mNextView;
+                    mWM = WindowManagerImpl.getDefault();
+                    final int gravity = toast.mGravity;
+                    mParams.gravity = gravity;
+                    if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
+                        mParams.horizontalWeight = 1.0f;
+                    }
+                    if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
+                        mParams.verticalWeight = 1.0f;
+                    }
+                    mParams.x = toast.mX;
+                    mParams.y = toast.mY;
+                    mParams.verticalMargin = toast.mVerticalMargin;
+                    mParams.horizontalMargin = toast.mHorizontalMargin;
+                    if (toast.mView.getParent() != null) {
+                        if (localLOGV) Log.v(TAG, "REMOVE! " + toast.mView + " in " + this);
+                        mWM.removeView(toast.mView);
+                    }
+                    if (localLOGV) Log.v(TAG, "ADD! " + toast.mView + " in " + this);
+                    mWM.addView(toast.mView, mParams);
+                    toast.trySendAccessibilityEvent();
                 }
-                if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
-                    mParams.verticalWeight = 1.0f;
-                }
-                mParams.x = mX;
-                mParams.y = mY;
-                mParams.verticalMargin = mVerticalMargin;
-                mParams.horizontalMargin = mHorizontalMargin;
-                if (mView.getParent() != null) {
-                    if (localLOGV) Log.v(
-                            TAG, "REMOVE! " + mView + " in " + this);
-                    mWM.removeView(mView);
-                }
-                if (localLOGV) Log.v(TAG, "ADD! " + mView + " in " + this);
-                mWM.addView(mView, mParams);
-                trySendAccessibilityEvent();
             }
         }
 
         public void handleHide() {
-            if (localLOGV) Log.v(TAG, "HANDLE HIDE: " + this + " mView=" + mView);
-            if (mView != null) {
-                // note: checking parent() just to make sure the view has
-                // been added...  i have seen cases where we get here when
-                // the view isn't yet added, so let's try not to crash.
-                if (mView.getParent() != null) {
-                    if (localLOGV) Log.v(
-                            TAG, "REMOVE! " + mView + " in " + this);
-                    mWM.removeView(mView);
+            final Toast toast = mToast.get();
+            if (toast != null) {
+                if (localLOGV) Log.v(TAG, "HANDLE HIDE: " + this + " mView=" + toast.mView);
+                if (toast.mView != null) {
+                    // note: checking parent() just to make sure the view has
+                    // been added...  i have seen cases where we get here when
+                    // the view isn't yet added, so let's try not to crash.
+                    if (toast.mView.getParent() != null) {
+                        if (localLOGV) Log.v(TAG, "REMOVE! " + toast.mView + " in " + this);
+                        mWM.removeView(toast.mView);
+                    }
+    
+                    toast.mView = null;
                 }
-
-                mView = null;
             }
         }
     }
diff --git a/core/java/com/android/internal/app/PlatLogoActivity.java b/core/java/com/android/internal/app/PlatLogoActivity.java
index e1c5564..9fbbb3d 100644
--- a/core/java/com/android/internal/app/PlatLogoActivity.java
+++ b/core/java/com/android/internal/app/PlatLogoActivity.java
@@ -29,11 +29,11 @@
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         
-        mToast = Toast.makeText(this, "Zombie art by Jack Larson", Toast.LENGTH_SHORT);
+        mToast = Toast.makeText(this, "REZZZZZZZ...", Toast.LENGTH_SHORT);
 
         ImageView content = new ImageView(this);
         content.setImageResource(com.android.internal.R.drawable.platlogo);
-        content.setScaleType(ImageView.ScaleType.FIT_CENTER);
+        content.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
         
         setContentView(content);
     }
diff --git a/core/res/res/drawable-nodpi/platlogo.png b/core/res/res/drawable-nodpi/platlogo.png
index e5af356..67e6ac3 100644
--- a/core/res/res/drawable-nodpi/platlogo.png
+++ b/core/res/res/drawable-nodpi/platlogo.png
Binary files differ
diff --git a/libs/hwui/Patch.cpp b/libs/hwui/Patch.cpp
index 999e4ea..11eb953 100644
--- a/libs/hwui/Patch.cpp
+++ b/libs/hwui/Patch.cpp
@@ -167,10 +167,6 @@
         float v2 = fmax(0.0f, stepY - 0.5f) / bitmapHeight;
 
         if (stepY > 0.0f) {
-            if (i == mYCount - 1 && mYDivs[i] == bitmapHeight) {
-                y2 = bottom - top;
-                v2 = 1.0f;
-            }
             generateRow(vertex, y1, y2, v1, v2, stretchX, right - left,
                     bitmapWidth, quadCount);
         }
@@ -222,10 +218,6 @@
         float u2 = fmax(0.0f, stepX - 0.5f) / bitmapWidth;
 
         if (stepX > 0.0f) {
-            if (i == mXCount - 1 && mXDivs[i] == bitmapWidth) {
-                x2 = bitmapWidth;
-                u2 = 1.0f;
-            }
             generateQuad(vertex, x1, y1, x2, y2, u1, v1, u2, v2, quadCount);
         }
 
diff --git a/media/jni/mediaeditor/VideoEditorLogging.h b/media/jni/mediaeditor/VideoEditorLogging.h
index ca8c047..c13f6ff 100755
--- a/media/jni/mediaeditor/VideoEditorLogging.h
+++ b/media/jni/mediaeditor/VideoEditorLogging.h
@@ -21,12 +21,13 @@
 
 #define VIDEOEDIT_LOG_INDENTATION                       (3)
 
+#define VIDEOEDIT_LOG_ERROR                             __android_log_print
+#define VIDEOEDIT_LOG_EXCEPTION                         __android_log_print
+
 #ifdef VIDEOEDIT_LOGGING_ENABLED
 
 #define VIDEOEDIT_LOG_ALLOCATION                        __android_log_print
 #define VIDEOEDIT_LOG_API                               __android_log_print
-#define VIDEOEDIT_LOG_ERROR                             __android_log_print
-#define VIDEOEDIT_LOG_EXCEPTION                         __android_log_print
 #define VIDEOEDIT_LOG_FUNCTION                          __android_log_print
 #define VIDEOEDIT_LOG_RESULT(x,y, ...)                     LOGI(y, __VA_ARGS__ )
 #define VIDEOEDIT_LOG_SETTING                           __android_log_print
@@ -40,8 +41,6 @@
 
 #define VIDEOEDIT_LOG_ALLOCATION                        (void)
 #define VIDEOEDIT_LOG_API                               (void)
-#define VIDEOEDIT_LOG_ERROR                             (void)
-#define VIDEOEDIT_LOG_EXCEPTION                         (void)
 #define VIDEOEDIT_LOG_FUNCTION                          (void)
 #define VIDEOEDIT_LOG_RESULT                            (void)
 #define VIDEOEDIT_LOG_SETTING                           (void)
diff --git a/media/jni/mediaeditor/VideoEditorMain.cpp b/media/jni/mediaeditor/VideoEditorMain.cpp
index e66e4b9..643f698 100755
--- a/media/jni/mediaeditor/VideoEditorMain.cpp
+++ b/media/jni/mediaeditor/VideoEditorMain.cpp
@@ -437,7 +437,7 @@
     VideoEditor_renderPreviewFrameStr frameStr;
     M4OSA_Context tnContext = M4OSA_NULL;
     const char* pMessage = NULL;
-    M4VIFI_ImagePlane *yuvPlane;
+    M4VIFI_ImagePlane *yuvPlane = NULL;
 
     VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO,
         "VIDEO_EDITOR", "surfaceWidth = %d",surfaceWidth);
@@ -1179,7 +1179,7 @@
     }
 
     /** Remove the alpha channel */
-    for (int i = 0, j = 0; i < frameSize_argb; i++) {
+    for (size_t i = 0, j = 0; i < frameSize_argb; i++) {
         if ((i % 4) == 0) continue;
         pFramingCtx->FramingRgb->pac_data[j] = pTmpData[i];
         j++;
@@ -2729,7 +2729,7 @@
 } M4AM_Buffer;
 
 
-M4OSA_UInt8 logLookUp[256]{
+M4OSA_UInt8 logLookUp[256] = {
 0,120,137,146,154,159,163,167,171,173,176,178,181,182,184,186,188,189,190,192,193,
 194,195,196,198,199,199,200,201,202,203,204,205,205,206,207,207,208,209,209,210,
 211,211,212,212,213,213,214,215,215,216,216,216,217,217,218,218,219,219,220,220,
@@ -2788,7 +2788,7 @@
     err = M4OSA_fileReadOpen (&inputFileHandle, pInputFileURL, M4OSA_kFileRead);
     if (inputFileHandle == M4OSA_NULL) {
         VIDEOEDIT_LOG_ERROR(ANDROID_LOG_INFO, "VIDEO_EDITOR",
-            "M4MA_generateAudioGraphFile: Cannot open input file 0x%x", err);
+            "M4MA_generateAudioGraphFile: Cannot open input file 0x%lx", err);
         return err;
     }
 
@@ -2822,7 +2822,7 @@
         bufferIn.m_bufferSize = samplesCountInBytes*sizeof(M4OSA_UInt16);
     } else {
         VIDEOEDIT_LOG_ERROR(ANDROID_LOG_INFO, "VIDEO_EDITOR",
-            "M4MA_generateAudioGraphFile: Malloc failed for bufferIn.m_dataAddress 0x%x",\
+            "M4MA_generateAudioGraphFile: Malloc failed for bufferIn.m_dataAddress 0x%lx",
             M4ERR_ALLOC);
         return M4ERR_ALLOC;
     }
@@ -2862,7 +2862,7 @@
         if (err != M4NO_ERROR) {
             // if out value of bytes-read is 0, break
             if ( numBytesToRead == 0) {
-                VIDEOEDIT_LOG_ERROR(ANDROID_LOG_INFO, "VIDEO_EDITOR", "numBytesToRead 0x%x",\
+                VIDEOEDIT_LOG_ERROR(ANDROID_LOG_INFO, "VIDEO_EDITOR", "numBytesToRead 0x%lx",
                 numBytesToRead);
                 break; /* stop if file is empty or EOF */
             }
@@ -2914,7 +2914,7 @@
 
     } while (numBytesToRead != 0);
 
-    VIDEOEDIT_LOG_ERROR(ANDROID_LOG_INFO, "VIDEO_EDITOR", "loop 0x%x", volumeValuesCount);
+    VIDEOEDIT_LOG_ERROR(ANDROID_LOG_INFO, "VIDEO_EDITOR", "loop 0x%lx", volumeValuesCount);
 
     /* if some error occured in fwrite */
     if (numBytesToRead != 0) {
diff --git a/media/libstagefright/httplive/LiveSession.cpp b/media/libstagefright/httplive/LiveSession.cpp
index 5979be6..f20a4cb 100644
--- a/media/libstagefright/httplive/LiveSession.cpp
+++ b/media/libstagefright/httplive/LiveSession.cpp
@@ -438,8 +438,7 @@
 
     if (mSeqNumber < firstSeqNumberInPlaylist
             || mSeqNumber > lastSeqNumberInPlaylist) {
-        if (mSeqNumber < firstSeqNumberInPlaylist
-                && mPrevBandwidthIndex != (ssize_t)bandwidthIndex) {
+        if (mPrevBandwidthIndex != (ssize_t)bandwidthIndex) {
             // Go back to the previous bandwidth.
 
             LOGI("new bandwidth does not have the sequence number "
@@ -493,8 +492,14 @@
 
     CHECK(buffer != NULL);
 
-    CHECK_EQ((status_t)OK,
-             decryptBuffer(mSeqNumber - firstSeqNumberInPlaylist, buffer));
+    err = decryptBuffer(mSeqNumber - firstSeqNumberInPlaylist, buffer);
+
+    if (err != OK) {
+        LOGE("decryptBuffer failed w/ error %d", err);
+
+        mDataSource->queueEOS(err);
+        return;
+    }
 
     if (buffer->size() == 0 || buffer->data()[0] != 0x47) {
         // Not a transport stream???
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 0548b4d..df21399 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -61,7 +61,6 @@
 import android.provider.Settings;
 import android.util.EventLog;
 import android.util.Log;
-import android.util.Slog;
 import android.app.backup.IBackupManager;
 import android.bluetooth.BluetoothAdapter;
 import android.content.BroadcastReceiver;
@@ -1671,10 +1670,18 @@
                         nwService.startAccessPoint((WifiConfiguration) message.obj,
                                     mInterfaceName,
                                     SOFTAP_IFACE);
-                    } catch(Exception e) {
-                        Log.e(TAG, "Exception in startAccessPoint()");
-                        sendMessage(obtainMessage(CMD_UNLOAD_DRIVER, WIFI_AP_STATE_FAILED, 0));
-                        break;
+                    } catch (Exception e) {
+                        Log.e(TAG, "Exception in softap start " + e);
+                        try {
+                            nwService.stopAccessPoint();
+                            nwService.startAccessPoint((WifiConfiguration) message.obj,
+                                    mInterfaceName,
+                                    SOFTAP_IFACE);
+                        } catch (Exception ee) {
+                            Log.e(TAG, "Exception during softap restart : " + ee);
+                            sendMessage(obtainMessage(CMD_UNLOAD_DRIVER, WIFI_AP_STATE_FAILED, 0));
+                            break;
+                        }
                     }
                     Log.d(TAG, "Soft AP start successful");
                     setWifiApState(WIFI_AP_STATE_ENABLED);
@@ -2824,13 +2831,16 @@
                                     mInterfaceName,
                                     SOFTAP_IFACE);
                     } catch(Exception e) {
-                        Log.e(TAG, "Exception in nwService during soft AP set");
+                        Log.e(TAG, "Exception in softap set " + e);
                         try {
                             nwService.stopAccessPoint();
+                            nwService.startAccessPoint((WifiConfiguration) message.obj,
+                                    mInterfaceName,
+                                    SOFTAP_IFACE);
                         } catch (Exception ee) {
-                            Slog.e(TAG, "Could not stop AP, :" + ee);
+                            Log.e(TAG, "Could not restart softap after set failed " + ee);
+                            sendMessage(obtainMessage(CMD_UNLOAD_DRIVER, WIFI_AP_STATE_FAILED, 0));
                         }
-                        sendMessage(obtainMessage(CMD_UNLOAD_DRIVER, WIFI_AP_STATE_FAILED, 0));
                     }
                     break;
                 /* Fail client mode operation when soft AP is enabled */