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

Commit 93018a4d authored by Roshan Pius's avatar Roshan Pius
Browse files

Handle exceptions when accessing Content providers.

BUG: 21638129
Change-Id: I88f7dcf67e395f49136a1f434fbd9c75e15cddad
parent 7e9cb0d0
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -177,15 +177,19 @@ public class PhoneNumberUtils
            phoneColumn = ContactsContract.CommonDataKinds.Phone.NUMBER;
        }

        final Cursor c = context.getContentResolver().query(uri, new String[] {
            phoneColumn
        }, null, null, null);
        if (c != null) {
        Cursor c = null;
        try {
            c = context.getContentResolver().query(uri, new String[] { phoneColumn },
                    null, null, null);
            if (c != null) {
                if (c.moveToFirst()) {
                    number = c.getString(c.getColumnIndex(phoneColumn));
                }
            }
        } catch (RuntimeException e) {
            Rlog.e(LOG_TAG, "Error getting phone number.", e);
        } finally {
            if (c != null) {
                c.close();
            }
        }
+12 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.telephony;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
@@ -282,10 +283,17 @@ public class CallerInfo {
     * number. The returned CallerInfo is null if no number is supplied.
     */
    public static CallerInfo getCallerInfo(Context context, Uri contactRef) {

        return getCallerInfo(context, contactRef,
                CallerInfoAsyncQuery.getCurrentProfileContentResolver(context)
                        .query(contactRef, null, null, null, null));
        CallerInfo info = null;
        ContentResolver cr = CallerInfoAsyncQuery.getCurrentProfileContentResolver(context);
        if (cr != null) {
            try {
                info = getCallerInfo(context, contactRef,
                        cr.query(contactRef, null, null, null, null));
            } catch (RuntimeException re) {
                Rlog.e(TAG, "Error getting caller info.", re);
            }
        }
        return info;
    }

    /**