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

Commit 4b8afb3a authored by Hyundo Moon's avatar Hyundo Moon
Browse files

Metrics: Log error metrics for MAP

Note: This CL also includes automated java format fixups
which are triggered by presubmit hook.

Bug: 317002318
Bug: 294797589
Test: m -j;
Change-Id: I6199b97225739e07ffb43d6d2c4f13d1e36fb5a2
parent cae7c96d
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@

package com.android.bluetooth.map;

import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProtoEnums;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.Context;
@@ -28,6 +30,8 @@ import android.os.RemoteException;
import android.text.format.DateUtils;
import android.util.Log;

import com.android.bluetooth.BluetoothStatsLog;
import com.android.bluetooth.content_profiles.ContentProfileErrorReportUtils;
import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
import com.android.bluetooth.mapapi.BluetoothMapContract;

@@ -36,6 +40,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;

// Next tag value for ContentProfileErrorReportUtils.report(): 1
public class BluetoothMapAccountLoader {
    private static final String TAG = "BluetoothMapAccountLoader";
    private static final boolean D = BluetoothMapService.DEBUG;
@@ -174,10 +179,20 @@ public class BluetoothMapAccountLoader {
                c = mProviderClient.query(uri, BluetoothMapContract.BT_IM_ACCOUNT_PROJECTION, null,
                        null, BluetoothMapContract.AccountColumns._ID + " DESC");
            } else {
                c = mProviderClient.query(uri, BluetoothMapContract.BT_ACCOUNT_PROJECTION, null,
                        null, BluetoothMapContract.AccountColumns._ID + " DESC");
                c =
                        mProviderClient.query(
                                uri,
                                BluetoothMapContract.BT_ACCOUNT_PROJECTION,
                                null,
                                null,
                                BluetoothMapContract.AccountColumns._ID + " DESC");
            }
        } catch (RemoteException e) {
            ContentProfileErrorReportUtils.report(
                    BluetoothProfile.MAP,
                    BluetoothProtoEnums.BLUETOOTH_MAP_ACCOUNT_LOADER,
                    BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                    0);
            if (D) {
                Log.d(TAG, "Could not establish ContentProviderClient for " + app.getPackageName()
                        + " - returning empty account list");
+160 −107
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
*/
package com.android.bluetooth.map;

import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProtoEnums;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
@@ -25,6 +27,8 @@ import android.database.ContentObserver;
import android.net.Uri;
import android.util.Log;

import com.android.bluetooth.BluetoothStatsLog;
import com.android.bluetooth.content_profiles.ContentProfileErrorReportUtils;
import com.android.bluetooth.mapapi.BluetoothMapContract;

import java.util.ArrayList;
@@ -32,12 +36,8 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;

/**
 * Class to construct content observers for for email applications on the system.
 *
 *
 */

/** Class to construct content observers for email applications on the system. */
// Next tag value for ContentProfileErrorReportUtils.report(): 6
public class BluetoothMapAppObserver {

    private static final String TAG = "BluetoothMapAppObserver";
@@ -168,22 +168,27 @@ public class BluetoothMapAppObserver {

        } else {
            Log.e(TAG, "Received change notification on package not registered for notifications!");

            ContentProfileErrorReportUtils.report(
                    BluetoothProfile.MAP,
                    BluetoothProtoEnums.BLUETOOTH_MAP_APP_OBSERVER,
                    BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__LOG_ERROR,
                    0);
        }
    }

    /**
     * Adds a new content observer to the list of content observers.
     * The key for the observer is the uri as string
     * Adds a new content observer to the list of content observers. The key for the observer is the
     * uri as string
     *
     * @param app app item for the package that supports MAP email
     */

    public void registerObserver(BluetoothMapAccountItem app) {
        Uri uri = BluetoothMapContract.buildAccountUri(app.getProviderAuthority());
        if (V) {
            Log.d(TAG, "registerObserver for URI " + uri.toString() + "\n");
        }
        ContentObserver observer = new ContentObserver(null) {
        ContentObserver observer =
                new ContentObserver(null) {
                    @Override
                    public void onChange(boolean selfChange) {
                        onChange(selfChange, null);
@@ -192,16 +197,26 @@ public class BluetoothMapAppObserver {
                    @Override
                    public void onChange(boolean selfChange, Uri uri) {
                        if (V) {
                    Log.d(TAG,
                            "onChange on thread: " + Thread.currentThread().getId() + " Uri: " + uri
                                    + " selfchange: " + selfChange);
                            Log.d(
                                    TAG,
                                    "onChange on thread: "
                                            + Thread.currentThread().getId()
                                            + " Uri: "
                                            + uri
                                            + " selfchange: "
                                            + selfChange);
                        }
                        if (uri != null) {
                            handleAccountChanges(uri.getHost());
                        } else {
                            Log.e(TAG, "Unable to handle change as the URI is NULL!");
                            ContentProfileErrorReportUtils.report(
                                    BluetoothProfile.MAP,
                                    BluetoothProtoEnums.BLUETOOTH_MAP_APP_OBSERVER,
                                    BluetoothStatsLog
                                            .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__LOG_ERROR,
                                    1);
                        }

                    }
                };
        mObserverMap.put(uri.toString(), observer);
@@ -245,7 +260,8 @@ public class BluetoothMapAppObserver {
        intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
        intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        intentFilter.addDataScheme("package");
        mReceiver = new BroadcastReceiver() {
        mReceiver =
                new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        if (D) {
@@ -264,31 +280,43 @@ public class BluetoothMapAppObserver {
                            ResolveInfo resolveInfo = null;
                            Intent[] searchIntents = new Intent[2];
                            // Array <Intent> searchIntents = new Array <Intent>();
                    searchIntents[0] = new Intent(BluetoothMapContract.PROVIDER_INTERFACE_EMAIL);
                    searchIntents[1] = new Intent(BluetoothMapContract.PROVIDER_INTERFACE_IM);
                    // Find all installed packages and filter out those that support Bluetooth Map.
                            searchIntents[0] =
                                    new Intent(BluetoothMapContract.PROVIDER_INTERFACE_EMAIL);
                            searchIntents[1] =
                                    new Intent(BluetoothMapContract.PROVIDER_INTERFACE_IM);
                            // Find all installed packages and filter out those that support
                            // Bluetooth Map.

                            mPackageManager = mContext.getPackageManager();

                            for (Intent searchIntent : searchIntents) {
                                List<ResolveInfo> resInfos =
                                mPackageManager.queryIntentContentProviders(searchIntent, 0);
                                        mPackageManager.queryIntentContentProviders(
                                                searchIntent, 0);
                                if (resInfos != null) {
                                    if (D) {
                                Log.d(TAG,
                                        "Found " + resInfos.size() + " application(s) with intent "
                                        Log.d(
                                                TAG,
                                                "Found "
                                                        + resInfos.size()
                                                        + " application(s) with intent "
                                                        + searchIntent.getAction());
                                    }
                                    for (ResolveInfo rInfo : resInfos) {
                                        if (rInfo != null) {
                                            // Find out if package contain Bluetooth MAP support
                                    if (packageName.equals(rInfo.providerInfo.packageName)) {
                                            if (packageName.equals(
                                                    rInfo.providerInfo.packageName)) {
                                                resolveInfo = rInfo;
                                        if (Objects.equals(searchIntent.getAction(),
                                                BluetoothMapContract.PROVIDER_INTERFACE_EMAIL)) {
                                                if (Objects.equals(
                                                        searchIntent.getAction(),
                                                        BluetoothMapContract
                                                                .PROVIDER_INTERFACE_EMAIL)) {
                                                    msgType = BluetoothMapUtils.TYPE.EMAIL;
                                        } else if (Objects.equals(searchIntent.getAction(),
                                                BluetoothMapContract.PROVIDER_INTERFACE_IM)) {
                                                } else if (Objects.equals(
                                                        searchIntent.getAction(),
                                                        BluetoothMapContract
                                                                .PROVIDER_INTERFACE_IM)) {
                                                    msgType = BluetoothMapUtils.TYPE.IM;
                                                }
                                                break;
@@ -300,8 +328,12 @@ public class BluetoothMapAppObserver {
                            // if application found with Bluetooth MAP support add to list
                            if (resolveInfo != null) {
                                if (D) {
                            Log.d(TAG, "Found " + resolveInfo.providerInfo.packageName
                                    + " application of type " + msgType);
                                    Log.d(
                                            TAG,
                                            "Found "
                                                    + resolveInfo.providerInfo.packageName
                                                    + " application of type "
                                                    + msgType);
                                }
                                BluetoothMapAccountItem app =
                                        mLoader.createAppItem(resolveInfo, false, msgType);
@@ -334,6 +366,11 @@ public class BluetoothMapAppObserver {
                mContext.registerReceiver(mReceiver, intentFilter);
                mRegisteredReceiver = true;
            } catch (Exception e) {
                ContentProfileErrorReportUtils.report(
                        BluetoothProfile.MAP,
                        BluetoothProtoEnums.BLUETOOTH_MAP_APP_OBSERVER,
                        BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                        2);
                Log.e(TAG, "Unable to register MapAppObserver receiver", e);
            }
        }
@@ -348,14 +385,19 @@ public class BluetoothMapAppObserver {
                mRegisteredReceiver = false;
                mContext.unregisterReceiver(mReceiver);
            } catch (Exception e) {
                ContentProfileErrorReportUtils.report(
                        BluetoothProfile.MAP,
                        BluetoothProtoEnums.BLUETOOTH_MAP_APP_OBSERVER,
                        BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                        3);
                Log.e(TAG, "Unable to unregister mapAppObserver receiver", e);
            }
        }
    }

    /**
     * Method to get a list of the accounts (across all apps) that are set to be shared
     * through MAP.
     * Method to get a list of the accounts (across all apps) that are set to be shared through MAP.
     *
     * @return Arraylist<BluetoothMapAccountItem> containing all enabled accounts
     */
    public ArrayList<BluetoothMapAccountItem> getEnabledAccountItems() {
@@ -374,9 +416,20 @@ public class BluetoothMapAppObserver {
                    }
                } else {
                    Log.w(TAG, "getEnabledAccountItems() - No AccountList enabled\n");
                    ContentProfileErrorReportUtils.report(
                            BluetoothProfile.MAP,
                            BluetoothProtoEnums.BLUETOOTH_MAP_APP_OBSERVER,
                            BluetoothStatsLog
                                    .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__LOG_WARN,
                            4);
                }
            } else {
                Log.w(TAG, "getEnabledAccountItems() - No Account in App enabled\n");
                ContentProfileErrorReportUtils.report(
                        BluetoothProfile.MAP,
                        BluetoothProtoEnums.BLUETOOTH_MAP_APP_OBSERVER,
                        BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__LOG_WARN,
                        5);
            }
        }
        return list;
+296 −22

File changed.

Preview size limit exceeded, changes collapsed.

+91 −1
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
*/
package com.android.bluetooth.map;

import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProtoEnums;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
@@ -36,9 +38,11 @@ import android.text.util.Rfc822Tokenizer;
import android.util.Log;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.BluetoothStatsLog;
import com.android.bluetooth.DeviceWorkArounds;
import com.android.bluetooth.SignedLongLong;
import com.android.bluetooth.Utils;
import com.android.bluetooth.content_profiles.ContentProfileErrorReportUtils;
import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
import com.android.bluetooth.map.BluetoothMapbMessageMime.MimePart;
import com.android.bluetooth.mapapi.BluetoothMapContract;
@@ -59,6 +63,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

// Next tag value for ContentProfileErrorReportUtils.report(): 15
public class BluetoothMapContent {

    private static final String TAG = "BluetoothMapContent";
@@ -456,6 +461,11 @@ public class BluetoothMapContent {
                c.close();
            }
        } catch (IOException e) {
            ContentProfileErrorReportUtils.report(
                    BluetoothProfile.MAP,
                    BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                    BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                    0);
            Log.w(TAG, e);
        }
    }
@@ -1722,6 +1732,11 @@ public class BluetoothMapContent {
            where = BluetoothMapContract.MessageColumns.FOLDER_ID + " = " + folderId;
        } else {
            Log.e(TAG, "setWhereFilterFolderTypeEmail: not valid!");
            ContentProfileErrorReportUtils.report(
                    BluetoothProfile.MAP,
                    BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                    BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__LOG_ERROR,
                    1);
            throw new IllegalArgumentException("Invalid folder ID");
        }
        return where;
@@ -1733,6 +1748,11 @@ public class BluetoothMapContent {
            where = BluetoothMapContract.MessageColumns.FOLDER_ID + " = " + folderId;
        } else {
            Log.e(TAG, "setWhereFilterFolderTypeIm: not valid!");
            ContentProfileErrorReportUtils.report(
                    BluetoothProfile.MAP,
                    BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                    BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__LOG_ERROR,
                    2);
            throw new IllegalArgumentException("Invalid folder ID");
        }
        return where;
@@ -3195,6 +3215,12 @@ public class BluetoothMapContent {
                    // TODO: Not sure this is how to convert to UTF-8
                    summary = new String(summary.getBytes(cs), "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    ContentProfileErrorReportUtils.report(
                            BluetoothProfile.MAP,
                            BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                            BluetoothStatsLog
                                    .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                            3);
                    Log.e(TAG, "populateSmsMmsConvoElement: " + e);
                }
            }
@@ -3381,6 +3407,11 @@ public class BluetoothMapContent {
                }
                foundContact = true;
            } catch (NumberFormatException ex) {
                ContentProfileErrorReportUtils.report(
                        BluetoothProfile.MAP,
                        BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                        BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                        4);
                // skip this id
                continue;
            }
@@ -3674,9 +3705,9 @@ public class BluetoothMapContent {
        }
    }


    /**
     * Read out a mime data part and return the data in a byte array.
     *
     * @param contentPartUri TODO
     * @param partid the content provider id of the Mime Part.
     */
@@ -3697,6 +3728,11 @@ public class BluetoothMapContent {
            }
            retVal = os.toByteArray();
        } catch (IOException e) {
            ContentProfileErrorReportUtils.report(
                    BluetoothProfile.MAP,
                    BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                    BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                    5);
            // do nothing for now
            Log.w(TAG, "Error reading part data", e);
        } finally {
@@ -3777,6 +3813,12 @@ public class BluetoothMapContent {
                            text = sb.toString();
                            part.mContentType = "text";
                        } catch (UnsupportedEncodingException e) {
                            ContentProfileErrorReportUtils.report(
                                    BluetoothProfile.MAP,
                                    BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                                    BluetoothStatsLog
                                            .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                                    6);
                            Log.d(TAG, "extractMmsParts", e);
                        }
                    }
@@ -3794,10 +3836,22 @@ public class BluetoothMapContent {
                            }
                        }
                    } catch (NumberFormatException e) {
                        ContentProfileErrorReportUtils.report(
                                BluetoothProfile.MAP,
                                BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                                BluetoothStatsLog
                                        .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                                7);
                        Log.d(TAG, "extractMmsParts", e);
                        part.mData = null;
                        part.mCharsetName = null;
                    } catch (UnsupportedEncodingException e) {
                        ContentProfileErrorReportUtils.report(
                                BluetoothProfile.MAP,
                                BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                                BluetoothStatsLog
                                        .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                                8);
                        Log.d(TAG, "extractMmsParts", e);
                        part.mData = null;
                        part.mCharsetName = null;
@@ -3925,6 +3979,12 @@ public class BluetoothMapContent {
                            // TODO: request message from server
                            Log.w(TAG, "getEmailMessage - receptionState not COMPLETE -  Not "
                                    + "Implemented!");
                            ContentProfileErrorReportUtils.report(
                                    BluetoothProfile.MAP,
                                    BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                                    BluetoothStatsLog
                                            .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__LOG_WARN,
                                    9);
                        }
                    }
                    // Set read status:
@@ -4015,10 +4075,28 @@ public class BluetoothMapContent {
                    // Set email message body:
                    message.setEmailBody(email.toString());
                } catch (FileNotFoundException e) {
                    ContentProfileErrorReportUtils.report(
                            BluetoothProfile.MAP,
                            BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                            BluetoothStatsLog
                                    .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                            10);
                    Log.w(TAG, e);
                } catch (NullPointerException e) {
                    ContentProfileErrorReportUtils.report(
                            BluetoothProfile.MAP,
                            BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                            BluetoothStatsLog
                                    .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                            11);
                    Log.w(TAG, e);
                } catch (IOException e) {
                    ContentProfileErrorReportUtils.report(
                            BluetoothProfile.MAP,
                            BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                            BluetoothStatsLog
                                    .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                            12);
                    Log.w(TAG, e);
                } finally {
                    try {
@@ -4026,6 +4104,12 @@ public class BluetoothMapContent {
                            is.close();
                        }
                    } catch (IOException e) {
                        ContentProfileErrorReportUtils.report(
                                BluetoothProfile.MAP,
                                BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                                BluetoothStatsLog
                                        .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                                13);
                        Log.w(TAG, e);
                    }
                    try {
@@ -4033,6 +4117,12 @@ public class BluetoothMapContent {
                            fd.close();
                        }
                    } catch (IOException e) {
                        ContentProfileErrorReportUtils.report(
                                BluetoothProfile.MAP,
                                BluetoothProtoEnums.BLUETOOTH_MAP_CONTENT,
                                BluetoothStatsLog
                                        .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                                14);
                        Log.w(TAG, e);
                    }
                }
+293 −50

File changed.

Preview size limit exceeded, changes collapsed.

Loading