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

Commit 126fb611 authored by Hemant Gupta's avatar Hemant Gupta
Browse files

PBAP: Fix crash in com.android.bluetooth

This patch will add the changes to catch the
CursorWindowAllocationException at all the places where cursor
is used for quering operations. Without this patch, crash was
observed in com.android.bluetooth in stress test of BT On/off
multiple times.

FATAL EXCEPTION: main
android.database.CursorWindowAllocationException:
Cursor window could not be created from binder.
com.android.bluetooth.pbap.BluetoothPbapVcardManager.
getCallHistorySize(BluetoothPbapVcardManager.java)

Change-Id: I6a4fadb949969dca453cff0fe84a25d849063573
parent 77d89942
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ public class BluetoothPbapUtils {
        boolean isSet = (c != null && c.getCount() > 0);
        if (c != null) {
            c.close();
            c = null;
        }
        return isSet;
    }
@@ -147,6 +148,7 @@ public class BluetoothPbapUtils {
        }
        if (c != null) {
            c.close();
            c = null;
        }
        return ownerName;
    }
+28 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ package com.android.bluetooth.pbap;

import android.content.ContentResolver;
import android.content.Context;
import android.database.CursorWindowAllocationException;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CallLog;
@@ -168,9 +169,12 @@ public class BluetoothPbapVcardManager {
            if (contactCursor != null) {
                size = contactCursor.getCount() + 1; // always has the 0.vcf
            }
        } catch (CursorWindowAllocationException e) {
            Log.e(TAG, "CursorWindowAllocationException while getting Contacts size");
        } finally {
            if (contactCursor != null) {
                contactCursor.close();
                contactCursor = null;
            }
        }
        return size;
@@ -187,9 +191,12 @@ public class BluetoothPbapVcardManager {
            if (callCursor != null) {
                size = callCursor.getCount();
            }
        } catch (CursorWindowAllocationException e) {
            Log.e(TAG, "CursorWindowAllocationException while getting CallHistory size");
        } finally {
            if (callCursor != null) {
                callCursor.close();
                callCursor = null;
            }
        }
        return size;
@@ -227,9 +234,12 @@ public class BluetoothPbapVcardManager {
                    list.add(name);
                }
            }
        } catch (CursorWindowAllocationException e) {
            Log.e(TAG, "CursorWindowAllocationException while loading CallHistory");
        } finally {
            if (callCursor != null) {
                callCursor.close();
                callCursor = null;
            }
        }
        return list;
@@ -271,9 +281,12 @@ public class BluetoothPbapVcardManager {
                    nameList.add(name + "," + id);
                }
            }
        } catch (CursorWindowAllocationException e) {
            Log.e(TAG, "CursorWindowAllocationException while getting Phonebook name list");
        } finally {
            if (contactCursor != null) {
                contactCursor.close();
                contactCursor = null;
            }
        }
        return nameList;
@@ -308,9 +321,12 @@ public class BluetoothPbapVcardManager {
                    nameList.add(name + "," + id);
                }
            }
        } catch (CursorWindowAllocationException e) {
            Log.e(TAG, "CursorWindowAllocationException while getting contact names");
        } finally {
            if (contactCursor != null) {
                contactCursor.close();
                contactCursor = null;
            }
        }
        return nameList;
@@ -349,9 +365,12 @@ public class BluetoothPbapVcardManager {
                }
                if (V) Log.v(TAG, "Call log query endPointId = " + endPointId);
            }
        } catch (CursorWindowAllocationException e) {
            Log.e(TAG, "CursorWindowAllocationException while composing calllog vcards");
        } finally {
            if (callsCursor != null) {
                callsCursor.close();
                callsCursor = null;
            }
        }

@@ -403,9 +422,12 @@ public class BluetoothPbapVcardManager {
                }
                if (V) Log.v(TAG, "Query endPointId = " + endPointId);
            }
        } catch (CursorWindowAllocationException e) {
            Log.e(TAG, "CursorWindowAllocationException while composing phonebook vcards");
        } finally {
            if (contactCursor != null) {
                contactCursor.close();
                contactCursor = null;
            }
        }

@@ -441,9 +463,12 @@ public class BluetoothPbapVcardManager {
                    contactId = contactCursor.getLong(CONTACTS_ID_COLUMN_INDEX);
                    if (V) Log.v(TAG, "Query startPointId = " + contactId);
                }
            } catch (CursorWindowAllocationException e) {
                Log.e(TAG, "CursorWindowAllocationException while composing phonebook one vcard order by index");
            } finally {
                if (contactCursor != null) {
                    contactCursor.close();
                    contactCursor = null;
                }
            }
        } else if (orderByWhat == BluetoothPbapObexServer.ORDER_BY_ALPHABETICAL) {
@@ -455,9 +480,12 @@ public class BluetoothPbapVcardManager {
                    contactId = contactCursor.getLong(CONTACTS_ID_COLUMN_INDEX);
                    if (V) Log.v(TAG, "Query startPointId = " + contactId);
                }
            } catch (CursorWindowAllocationException e) {
                Log.e(TAG, "CursorWindowAllocationException while composing phonebook one vcard order by alphabetical");
            } finally {
                if (contactCursor != null) {
                    contactCursor.close();
                    contactCursor = null;
                }
            }
        } else {