OSDN Git Service

Fix bug #17459965 Take photo for Profile twice leads to "A resource was acquired...
authorFabrice Di Meglio <fdimeglio@google.com>
Wed, 10 Sep 2014 23:35:36 +0000 (16:35 -0700)
committerFabrice Di Meglio <fdimeglio@google.com>
Thu, 11 Sep 2014 00:20:17 +0000 (17:20 -0700)
- close the stream properly in all cases

Change-Id: I3a593be534ea444a2e2659458918cce221891456

src/com/android/settings/users/EditUserPhotoController.java

index 538f332..82e550e 100644 (file)
@@ -35,6 +35,7 @@ import android.os.AsyncTask;
 import android.provider.MediaStore;
 import android.provider.ContactsContract.DisplayPhoto;
 import android.support.v4.content.FileProvider;
+import android.util.Log;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.AdapterView;
@@ -48,11 +49,14 @@ import com.android.settings.drawable.CircleFramedDrawable;
 
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
 public class EditUserPhotoController {
+    private static final String TAG = "EditUserPhotoController";
+
     private static final int POPUP_LIST_ITEM_ID_CHOOSE_PHOTO = 1;
     private static final int POPUP_LIST_ITEM_ID_TAKE_PHOTO = 2;
 
@@ -239,12 +243,22 @@ public class EditUserPhotoController {
             @Override
             protected Bitmap doInBackground(Void... params) {
                 if (cropped) {
+                    InputStream imageStream = null;
                     try {
-                        InputStream imageStream = mContext.getContentResolver()
+                        imageStream = mContext.getContentResolver()
                                 .openInputStream(data);
                         return BitmapFactory.decodeStream(imageStream);
                     } catch (FileNotFoundException fe) {
+                        Log.w(TAG, "Cannot find image file", fe);
                         return null;
+                    } finally {
+                        if (imageStream != null) {
+                            try {
+                                imageStream.close();
+                            } catch (IOException ioe) {
+                                Log.w(TAG, "Cannot close image stream", ioe);
+                            }
+                        }
                     }
                 } else {
                     // Scale and crop to a square aspect ratio