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

Commit 4ee1ab41 authored by Jeff Nainaparampil's avatar Jeff Nainaparampil Committed by Android (Google) Code Review
Browse files

Merge "[People Service] Prevent system_server crashes due to Content Provider...

Merge "[People Service] Prevent system_server crashes due to Content Provider issues in People Service" into main
parents 0f0032d1 9488a3e5
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -96,6 +96,8 @@ class CallLogQueryHelper {
        } catch (SecurityException ex) {
            Slog.e(TAG, "Query call log failed: " + ex);
            return false;
        } catch (Exception e) {
            Slog.e(TAG, "Exception when querying call log.", e);
        }
        return hasResults;
    }
+6 −2
Original line number Diff line number Diff line
@@ -151,9 +151,11 @@ class ContactsQueryHelper {
                found = true;
            }
        } catch (SQLiteException exception) {
            Slog.w("SQLite exception when querying contacts.", exception);
            Slog.w(TAG, "SQLite exception when querying contacts.", exception);
        } catch (IllegalArgumentException exception) {
            Slog.w("Illegal Argument exception when querying contacts.", exception);
            Slog.w(TAG, "Illegal Argument exception when querying contacts.", exception);
        } catch (Exception exception) {
            Slog.e(TAG, "Exception when querying contacts.", exception);
        }
        if (found && lookupKey != null && hasPhoneNumber) {
            return queryPhoneNumber(lookupKey);
@@ -181,6 +183,8 @@ class ContactsQueryHelper {
                    mPhoneNumber = cursor.getString(phoneNumIdx);
                }
            }
        } catch (Exception exception) {
            Slog.e(TAG, "Exception when querying contact phone number.", exception);
        }
        return true;
    }
+4 −0
Original line number Diff line number Diff line
@@ -100,6 +100,8 @@ class MmsQueryHelper {
                    }
                }
            }
        } catch (Exception e) {
            Slog.e(TAG, "Exception when querying MMS table.", e);
        } finally {
            Binder.defaultBlockingForCurrentThread();
        }
@@ -133,6 +135,8 @@ class MmsQueryHelper {
                    address = cursor.getString(addrIndex);
                }
            }
        } catch (Exception e) {
            Slog.e(TAG, "Exception when querying MMS address table.", e);
        }
        if (!Mms.isPhoneNumber(address)) {
            return null;
+2 −0
Original line number Diff line number Diff line
@@ -98,6 +98,8 @@ class SmsQueryHelper {
                    }
                }
            }
        } catch (Exception e) {
            Slog.e(TAG, "Exception when querying SMS table.", e);
        } finally {
            Binder.defaultBlockingForCurrentThread();
        }
+19 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.when;

import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.provider.CallLog.Calls;
import android.test.mock.MockContentProvider;
@@ -58,6 +59,7 @@ public final class CallLogQueryHelperTest {
    private MatrixCursor mCursor;
    private EventConsumer mEventConsumer;
    private CallLogQueryHelper mHelper;
    private CallLogContentProvider mCallLogContentProvider;

    @Before
    public void setUp() {
@@ -66,7 +68,8 @@ public final class CallLogQueryHelperTest {
        mCursor = new MatrixCursor(CALL_LOG_COLUMNS);

        MockContentResolver contentResolver = new MockContentResolver();
        contentResolver.addProvider(CALL_LOG_AUTHORITY, new CallLogContentProvider());
        mCallLogContentProvider = new CallLogContentProvider();
        contentResolver.addProvider(CALL_LOG_AUTHORITY, mCallLogContentProvider);
        when(mContext.getContentResolver()).thenReturn(contentResolver);

        mEventConsumer = new EventConsumer();
@@ -79,6 +82,12 @@ public final class CallLogQueryHelperTest {
        assertFalse(mEventConsumer.mEventMap.containsKey(NORMALIZED_PHONE_NUMBER));
    }

    @Test
    public void testQueryWithSQLiteException() {
        mCallLogContentProvider.setThrowSQLiteException(true);
        assertFalse(mHelper.querySince(50L));
    }

    @Test
    public void testQueryIncomingCall() {
        mCursor.addRow(new Object[] {
@@ -159,11 +168,20 @@ public final class CallLogQueryHelperTest {
    }

    private class CallLogContentProvider extends MockContentProvider {
        private boolean mThrowSQLiteException = false;

        @Override
        public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
                String sortOrder) {
            if (mThrowSQLiteException) {
                throw new SQLiteException();
            }

            return mCursor;
        }

        public void setThrowSQLiteException(boolean throwException) {
            this.mThrowSQLiteException = throwException;
        }
    }
}
Loading