Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0798c0fe authored by Hemant Gupta's avatar Hemant Gupta Committed by Linux Build Service Account
Browse files

Bluetooth: Fix resource leak in OPP (3/3)

- This patch handles closing of input stream if no device is selected
  by user when trying to send file via BT. Without this patch, input
  stream was never closed resulting in leak with each iteration and
  system crash after 1024 iterations.

- This change will remove hashmap share entry if user selected share
  via BT and press back or press cancel. Otherwise, hashmap will reach
  its limit for successive share via BT and cause BT app to crash.
  Change-Id: I6e145950975c3fe4cc5d1936c692e351779f242d

CRs-Fixed: 662147, 678607
Change-Id: I92aa0d8e81977fde0446f565f1de95e2d91e1e9c
parent 13a7f3e3
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -50,11 +50,17 @@ import com.android.internal.app.AlertController;
public class BluetoothOppBtEnableActivity extends AlertActivity implements
        DialogInterface.OnClickListener {

    private boolean mBtEnabled;

    private BluetoothOppManager mOppManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set up the "dialog"
        mOppManager = BluetoothOppManager.getInstance(this);
        mBtEnabled = false;
        final AlertController.AlertParams p = mAlertParams;
        p.mIconAttrId = android.R.attr.alertDialogIcon;
        p.mTitle = getString(R.string.bt_enable_title);
@@ -78,9 +84,9 @@ public class BluetoothOppBtEnableActivity extends AlertActivity implements
    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
                BluetoothOppManager mOppManager = BluetoothOppManager.getInstance(this);
                mOppManager.enableBluetooth(); // this is an asyn call
                mOppManager.mSendingFlag = true;
                mBtEnabled = true;

                Toast.makeText(this, getString(R.string.enabling_progress_content),
                        Toast.LENGTH_SHORT).show();
@@ -97,4 +103,13 @@ public class BluetoothOppBtEnableActivity extends AlertActivity implements
                break;
        }
    }

    @Override
    public void onPause() {
        super.onPause();

        if (!mBtEnabled) {
            mOppManager.cleanUpSendingFileInfo();
        }
    }
}
+21 −0
Original line number Diff line number Diff line
@@ -278,6 +278,27 @@ public class BluetoothOppManager {
        }
    }

    public void cleanUpSendingFileInfo() {
        synchronized (BluetoothOppManager.this) {
            Uri uri;
            if (V) Log.v(TAG, "cleanUpSendingFileInfo: mMultipleFlag = " +
                mMultipleFlag);
            if (!mMultipleFlag) {
                uri = Uri.parse(mUriOfSendingFile);
                if (V) Log.v(TAG, "cleanUpSendingFileInfo: " +
                    "closeSendFileInfo for uri = " + uri);
                BluetoothOppUtility.closeSendFileInfo(uri);
            } else {
                for (int i = 0, count = mUrisOfSendingFiles.size(); i < count; i++) {
                    uri = mUrisOfSendingFiles.get(i);
                    if (V) Log.v(TAG, "cleanUpSendingFileInfo: " +
                        "closeSendFileInfo for uri = " + uri);
                    BluetoothOppUtility.closeSendFileInfo(uri);
                }
            }
        }
    }

    /**
     * Get the current status of Bluetooth hardware.
     * @return true if Bluetooth enabled, false otherwise.
+4 −0
Original line number Diff line number Diff line
@@ -89,6 +89,10 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
                    }
                }
            }
        } else if (action.equals(BluetoothDevicePicker.ACTION_DEVICE_NOT_SELECTED)) {
            if (V) Log.v(TAG, "ACTION_DEVICE_NOT_SELECTED");
            BluetoothOppManager mOppManager = BluetoothOppManager.getInstance(context);
            mOppManager.cleanUpSendingFileInfo();
        } else if (action.equals(BluetoothDevicePicker.ACTION_DEVICE_SELECTED)) {
            BluetoothOppManager mOppManager = BluetoothOppManager.getInstance(context);