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

Commit bbadeb9c authored by Sal Savage's avatar Sal Savage
Browse files

Update conditions using log tag enforcement variables with other logic

This pattern is hard to script for while still preserving the intended
logic of the code. Update the few instances that do this so they can be
properly migrated to the new logging scheme.

Tag: #refactor
Flag: EXEMPT, logical no-op
Bug: 315046089
Test: atest AtPhonebookTest.java
Test: atest BluetoothMapContentTest.java
Test: atest BluetoothMapContentObserverTest.java
Test: atest BluetoothMapObexServerTest.java
Test: atest BmessageTest.java
Test: atest SapMessageTest.java
Change-Id: If1c07a42caf12419fc46fc3fb16fd08ca1e52c69
parent cc500fa5
Loading
Loading
Loading
Loading
+26 −28
Original line number Diff line number Diff line
@@ -169,24 +169,24 @@ public class AtPhonebook {
    }

    public void handleCscsCommand(String atString, int type, BluetoothDevice device) {
        log("handleCscsCommand - atString = " + atString);
        Log.d(TAG, "handleCscsCommand - atString = " + atString);
        // Select Character Set
        int atCommandResult = HeadsetHalConstants.AT_RESPONSE_ERROR;
        int atCommandErrorCode = -1;
        String atCommandResponse = null;
        switch (type) {
            case TYPE_READ: // Read
                log("handleCscsCommand - Read Command");
                Log.d(TAG, "handleCscsCommand - Read Command");
                atCommandResponse = "+CSCS: \"" + mCharacterSet + "\"";
                atCommandResult = HeadsetHalConstants.AT_RESPONSE_OK;
                break;
            case TYPE_TEST: // Test
                log("handleCscsCommand - Test Command");
                Log.d(TAG, "handleCscsCommand - Test Command");
                atCommandResponse = ("+CSCS: (\"UTF-8\",\"IRA\",\"GSM\")");
                atCommandResult = HeadsetHalConstants.AT_RESPONSE_OK;
                break;
            case TYPE_SET: // Set
                log("handleCscsCommand - Set Command");
                Log.d(TAG, "handleCscsCommand - Set Command");
                String[] args = atString.split("=");
                if (args.length < 2 || args[1] == null) {
                    mNativeInterface.atResponseCode(device, atCommandResult, atCommandErrorCode);
@@ -204,7 +204,7 @@ public class AtPhonebook {
                break;
            case TYPE_UNKNOWN:
            default:
                log("handleCscsCommand - Invalid chars");
                Log.d(TAG, "handleCscsCommand - Invalid chars");
                atCommandErrorCode = BluetoothCmeError.TEXT_HAS_INVALID_CHARS;
        }
        if (atCommandResponse != null) {
@@ -215,13 +215,13 @@ public class AtPhonebook {

    public void handleCpbsCommand(String atString, int type, BluetoothDevice device) {
        // Select PhoneBook memory Storage
        log("handleCpbsCommand - atString = " + atString);
        Log.d(TAG, "handleCpbsCommand - atString = " + atString);
        int atCommandResult = HeadsetHalConstants.AT_RESPONSE_ERROR;
        int atCommandErrorCode = -1;
        String atCommandResponse = null;
        switch (type) {
            case TYPE_READ: // Read
                log("handleCpbsCommand - read command");
                Log.d(TAG, "handleCpbsCommand - read command");
                // Return current size and max size
                if ("SM".equals(mCurrentPhonebook)) {
                    atCommandResponse = "+CPBS: \"SM\",0," + getMaxPhoneBookSize(0);
@@ -242,12 +242,12 @@ public class AtPhonebook {
                atCommandResult = HeadsetHalConstants.AT_RESPONSE_OK;
                break;
            case TYPE_TEST: // Test
                log("handleCpbsCommand - test command");
                Log.d(TAG, "handleCpbsCommand - test command");
                atCommandResponse = ("+CPBS: (\"ME\",\"SM\",\"DC\",\"RC\",\"MC\")");
                atCommandResult = HeadsetHalConstants.AT_RESPONSE_OK;
                break;
            case TYPE_SET: // Set
                log("handleCpbsCommand - set command");
                Log.d(TAG, "handleCpbsCommand - set command");
                String[] args = atString.split("=");
                // Select phonebook memory
                if (args.length < 2 || args[1] == null) {
@@ -263,7 +263,7 @@ public class AtPhonebook {
                }
                if (getPhonebookResult(pb, false) == null && !"SM".equals(pb)) {
                    if (DBG) {
                        log("Dont know phonebook: '" + pb + "'");
                        Log.d(TAG, "Dont know phonebook: '" + pb + "'");
                    }
                    atCommandErrorCode = BluetoothCmeError.OPERATION_NOT_ALLOWED;
                    break;
@@ -273,7 +273,7 @@ public class AtPhonebook {
                break;
            case TYPE_UNKNOWN:
            default:
                log("handleCpbsCommand - invalid chars");
                Log.d(TAG, "handleCpbsCommand - invalid chars");
                atCommandErrorCode = BluetoothCmeError.TEXT_HAS_INVALID_CHARS;
        }
        if (atCommandResponse != null) {
@@ -283,7 +283,7 @@ public class AtPhonebook {
    }

    void handleCpbrCommand(String atString, int type, BluetoothDevice remoteDevice) {
        log("handleCpbrCommand - atString = " + atString);
        Log.d(TAG, "handleCpbrCommand - atString = " + atString);
        int atCommandResult = HeadsetHalConstants.AT_RESPONSE_ERROR;
        int atCommandErrorCode = -1;
        String atCommandResponse = null;
@@ -294,7 +294,7 @@ public class AtPhonebook {
                 * Parrot CK3300. So instead send just the range of currently
                 * valid index's.
                 */
                log("handleCpbrCommand - test command");
                Log.d(TAG, "handleCpbrCommand - test command");
                int size;
                if ("SM".equals(mCurrentPhonebook)) {
                    size = 0;
@@ -307,7 +307,7 @@ public class AtPhonebook {
                        break;
                    }
                    size = pbr.cursor.getCount();
                    log("handleCpbrCommand - size = " + size);
                    Log.d(TAG, "handleCpbrCommand - size = " + size);
                    pbr.cursor.close();
                    pbr.cursor = null;
                }
@@ -325,7 +325,7 @@ public class AtPhonebook {
            case TYPE_SET: // Set & read
                // Phone Book Read Request
                // AT+CPBR=<index1>[,<index2>]
                log("handleCpbrCommand - set/read command");
                Log.d(TAG, "handleCpbrCommand - set/read command");
                if (mCpbrIndex1 != -1) {
                   /* handling a CPBR at the moment, reject this CPBR command */
                    atCommandErrorCode = BluetoothCmeError.OPERATION_NOT_ALLOWED;
@@ -355,7 +355,7 @@ public class AtPhonebook {
                        index2 = Integer.parseInt(indices[1]);
                    }
                } catch (Exception e) {
                    log("handleCpbrCommand - exception - invalid chars: " + e.toString());
                    Log.d(TAG, "handleCpbrCommand - exception - invalid chars: " + e.toString());
                    atCommandErrorCode = BluetoothCmeError.TEXT_HAS_INVALID_CHARS;
                    mNativeInterface.atResponseCode(remoteDevice, atCommandResult,
                            atCommandErrorCode);
@@ -386,7 +386,7 @@ public class AtPhonebook {
                break;
            case TYPE_UNKNOWN:
            default:
                log("handleCpbrCommand - invalid chars");
                Log.d(TAG, "handleCpbrCommand - invalid chars");
                atCommandErrorCode = BluetoothCmeError.TEXT_HAS_INVALID_CHARS;
                mNativeInterface.atResponseCode(remoteDevice, atCommandResult, atCommandErrorCode);
        }
@@ -505,7 +505,7 @@ public class AtPhonebook {

    // process CPBR command after permission check
    /*package*/ int processCpbrCommand(BluetoothDevice device) {
        log("processCpbrCommand");
        Log.d(TAG, "processCpbrCommand");
        int atCommandResult = HeadsetHalConstants.AT_RESPONSE_ERROR;
        int atCommandErrorCode = -1;
        String atCommandResponse = null;
@@ -546,7 +546,7 @@ public class AtPhonebook {
        atCommandResult = HeadsetHalConstants.AT_RESPONSE_OK;
        int errorDetected = -1; // no error
        pbr.cursor.moveToPosition(mCpbrIndex1 - 1);
        log("mCpbrIndex1 = " + mCpbrIndex1 + " and mCpbrIndex2 = " + mCpbrIndex2);
        Log.d(TAG, "mCpbrIndex1 = " + mCpbrIndex1 + " and mCpbrIndex2 = " + mCpbrIndex2);
        for (int index = mCpbrIndex1; index <= mCpbrIndex2; index++) {
            String number = pbr.cursor.getString(pbr.numberColumn);
            String name = null;
@@ -573,14 +573,16 @@ public class AtPhonebook {
                    }
                    c.close();
                }
                if (DBG && name == null) {
                    log("Caller ID lookup failed for " + number);
                if (name == null) {
                    if (DBG) {
                        Log.d(TAG, "Caller ID lookup failed for " + number);
                    }
                }

            } else if (pbr.nameColumn != -1) {
                name = pbr.cursor.getString(pbr.nameColumn);
            } else {
                log("processCpbrCommand: empty name and number");
                Log.d(TAG, "processCpbrCommand: empty name and number");
            }
            if (name == null) {
                name = "";
@@ -652,11 +654,11 @@ public class AtPhonebook {
     */
    @VisibleForTesting
    int checkAccessPermission(BluetoothDevice remoteDevice) {
        log("checkAccessPermission");
        Log.d(TAG, "checkAccessPermission");
        int permission = remoteDevice.getPhonebookAccessPermission();

        if (permission == BluetoothDevice.ACCESS_UNKNOWN) {
            log("checkAccessPermission - ACTION_CONNECTION_ACCESS_REQUEST");
            Log.d(TAG, "checkAccessPermission - ACTION_CONNECTION_ACCESS_REQUEST");
            Intent intent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_REQUEST);
            intent.setPackage(mPairingPackage);
            intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
@@ -690,8 +692,4 @@ public class AtPhonebook {
                return "O";
        }
    }

    private static void log(String msg) {
        Log.d(TAG, msg);
    }
}
+7 −5
Original line number Diff line number Diff line
@@ -3940,12 +3940,14 @@ public class BluetoothMapContent {
    public byte[] getEmailMessage(long id, BluetoothMapAppParams appParams,
            BluetoothMapFolderElement currentFolder) throws UnsupportedEncodingException {
        // Log print out of application parameters set
        if (D && appParams != null) {
            Log.d(TAG,
                    "TYPE_MESSAGE (GET): Attachment = " + appParams.getAttachment() + ", Charset = "
        if (D) {
            if (appParams != null) {
                Log.d(TAG, "TYPE_MESSAGE (GET): Attachment = " + appParams.getAttachment()
                        + ", Charset = "
                        + appParams.getCharset() + ", FractionRequest = "
                        + appParams.getFractionRequest());
            }
        }

        // Throw exception if requester NATIVE charset for Email
        // Exception is caught by MapObexServer sendGetMessageResp
+13 −5
Original line number Diff line number Diff line
@@ -3334,9 +3334,11 @@ public class BluetoothMapContentObserver {

        uri = Uri.parse(Mms.CONTENT_URI + "/" + handle + "/addr");
        uri = mResolver.insert(uri, values);
        if (uri != null && V) {
        if (uri != null) {
            if (V) {
                Log.v(TAG, " NEW URI " + uri.toString());
            }
        }

        values.clear();
        values.put(Mms.Addr.CONTACT_ID, "null");
@@ -3346,10 +3348,12 @@ public class BluetoothMapContentObserver {
            values.put(Mms.Addr.ADDRESS, address);
            uri = Uri.parse(Mms.CONTENT_URI + "/" + handle + "/addr");
            uri = mResolver.insert(uri, values);
            if (uri != null && V) {
            if (uri != null) {
                if (V) {
                    Log.v(TAG, " NEW URI " + uri.toString());
                }
            }
        }
        return handle;
    }

@@ -3628,7 +3632,11 @@ public class BluetoothMapContentObserver {
                /* Delete from DB */
                Uri msgUri = ContentUris.withAppendedId(Sms.CONTENT_URI, handle);
                int nRows = mResolver.delete(msgUri, null, null);
                if (V && nRows > 0) Log.v(TAG, "Deleted message with Uri = " + msgUri);
                if (nRows > 0) {
                    if (V) {
                        Log.v(TAG, "Deleted message with Uri = " + msgUri);
                    }
                }
            }
        }
    }
+61 −64
Original line number Diff line number Diff line
@@ -608,11 +608,7 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
                    BluetoothProtoEnums.BLUETOOTH_MAP_OBEX_SERVER,
                    BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                    9);
            if (D) {
                Log.e(TAG, "Exception occured while handling request", e);
            } else {
                Log.e(TAG, "Exception occured while handling request");
            }
            Log.e(TAG, "Exception occurred while handling request", e);
            if (mIsAborted) {
                return ResponseCodes.OBEX_HTTP_OK;
            } else {
@@ -878,7 +874,7 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
                    BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                    20);
            if (D) {
                Log.e(TAG, "Exception occured: ", e);
                Log.e(TAG, "Exception occurred: ", e);
            }
            if (mIsAborted) {
                if (D) {
@@ -1111,11 +1107,7 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
                    BluetoothProtoEnums.BLUETOOTH_MAP_OBEX_SERVER,
                    BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                    32);
            if (D) {
            Log.e(TAG, "request headers error", e);
            } else {
                Log.e(TAG, "request headers error");
            }
            return ResponseCodes.OBEX_HTTP_BAD_REQUEST;
        }

@@ -1204,22 +1196,24 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
            }

            if (type.equals(TYPE_GET_FOLDER_LISTING)) {
                if (V && appParams != null) {
                    Log.d(TAG,
                            "TYPE_GET_FOLDER_LISTING: MaxListCount = " + appParams.getMaxListCount()
                                    + ", ListStartOffset = " + appParams.getStartOffset());
                if (V) {
                    if (appParams != null) {
                        Log.d(TAG, "TYPE_GET_FOLDER_LISTING: MaxListCount = "
                                + appParams.getMaxListCount() + ", ListStartOffset = "
                                + appParams.getStartOffset());
                    }
                }
                // Block until all packets have been send.
                return sendFolderListingRsp(op, appParams);
            } else if (type.equals(TYPE_GET_MESSAGE_LISTING)) {
                name = (String) request.getHeader(HeaderSet.NAME);
                if (V && appParams != null) {
                if (V) {
                    if (appParams != null) {
                        Log.d(TAG, "TYPE_GET_MESSAGE_LISTING: folder name is: " + name
                                + ", MaxListCount = " + appParams.getMaxListCount()
                                + ", ListStartOffset = " + appParams.getStartOffset());
                    Log.d(TAG,
                            "SubjectLength = " + appParams.getSubjectLength() + ", ParameterMask = "
                                    + appParams.getParameterMask());
                        Log.d(TAG, "SubjectLength = " + appParams.getSubjectLength()
                                + ", ParameterMask = " + appParams.getParameterMask());
                        Log.d(TAG, "FilterMessageType = " + appParams.getFilterMessageType());
                        Log.d(TAG, "FilterPeriodBegin = " + appParams.getFilterPeriodBeginString()
                                + ", FilterPeriodEnd = " + appParams.getFilterPeriodEndString()
@@ -1235,6 +1229,7 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
                        Log.d(TAG, "FilterConvoId = " + ((tmpLongLong == null) ? ""
                                : Long.toHexString(tmpLongLong.getLeastSignificantBits())));
                    }
                }
                if (!isUserUnlocked()) {
                    Log.e(TAG, "Storage locked, " + type + " failed");
                    ContentProfileErrorReportUtils.report(
@@ -1250,16 +1245,19 @@ public class BluetoothMapObexServer extends ServerRequestHandler {

            } else if (type.equals(TYPE_GET_CONVO_LISTING)) {
                name = (String) request.getHeader(HeaderSet.NAME);
                if (V && appParams != null) {
                if (V) {
                    if (appParams != null) {
                        Log.d(TAG, "TYPE_GET_CONVO_LISTING: name is" + name + ", MaxListCount = "
                                + appParams.getMaxListCount() + ", ListStartOffset = "
                                + appParams.getStartOffset());
                    Log.d(TAG,
                            "FilterLastActivityBegin = " + appParams.getFilterLastActivityBegin());
                    Log.d(TAG, "FilterLastActivityEnd = " + appParams.getFilterLastActivityEnd());
                        Log.d(TAG, "FilterLastActivityBegin = "
                                + appParams.getFilterLastActivityBegin());
                        Log.d(TAG, "FilterLastActivityEnd = "
                                + appParams.getFilterLastActivityEnd());
                        Log.d(TAG, "FilterReadStatus = " + appParams.getFilterReadStatus());
                        Log.d(TAG, "FilterRecipient = " + appParams.getFilterRecipient());
                    }
                }
                if (!isUserUnlocked()) {
                    Log.e(TAG, "Storage locked, " + type + " failed");
                    ContentProfileErrorReportUtils.report(
@@ -1273,18 +1271,23 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
                // Block until all packets have been send.
                return sendConvoListingRsp(op, appParams);
            } else if (type.equals(TYPE_GET_MAS_INSTANCE_INFORMATION)) {
                if (V && appParams != null) {
                    Log.d(TAG,
                            "TYPE_MESSAGE (GET): MASInstandeId = " + appParams.getMasInstanceId());
                if (V) {
                    if (appParams != null) {
                        Log.d(TAG, "TYPE_MESSAGE (GET): MASInstandeId = "
                                + appParams.getMasInstanceId());
                    }
                }
                // Block until all packets have been send.
                return sendMASInstanceInformationRsp(op, appParams);
            } else if (type.equals(TYPE_MESSAGE)) {
                name = (String) request.getHeader(HeaderSet.NAME);
                if (V && appParams != null) {
                if (V) {
                    if (appParams != null) {
                        Log.d(TAG, "TYPE_MESSAGE (GET): name is" + name + ", Attachment = "
                            + appParams.getAttachment() + ", Charset = " + appParams.getCharset()
                            + ", FractionRequest = " + appParams.getFractionRequest());
                                + appParams.getAttachment() + ", Charset = "
                                + appParams.getCharset() + ", FractionRequest = "
                                + appParams.getFractionRequest());
                    }
                }
                if (!isUserUnlocked()) {
                    Log.e(TAG, "Storage locked, " + type + " failed");
@@ -1330,11 +1333,7 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
                    BluetoothProtoEnums.BLUETOOTH_MAP_OBEX_SERVER,
                    BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                    39);
            if (D) {
                Log.e(TAG, "Exception occured while handling request", e);
            } else {
                Log.e(TAG, "Exception occured while handling request");
            }
            Log.e(TAG, "Exception occurred while handling request", e);
            if (mIsAborted) {
                if (D) {
                    Log.d(TAG, "onGet Operation Aborted");
@@ -2180,8 +2179,10 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
                        BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                        69);
                // We were probably aborted or disconnected
                if (D && e.getMessage().equals("Abort Received")) {
                    Log.w(TAG, "getMessage() Aborted...", e);
                if (e.getMessage().equals("Abort Received")) {
                    if (D) {
                        Log.d(TAG, "getMessage() Aborted...", e);
                    }
                }
            } finally {
                if (outStream != null) {
@@ -2274,11 +2275,7 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
                    BluetoothProtoEnums.BLUETOOTH_MAP_OBEX_SERVER,
                    BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                    73);
            if (D) {
                Log.e(TAG, "Exception occured while handling request", e);
            } else {
                Log.e(TAG, "Exception occured while handling request");
            }
            Log.e(TAG, "Exception occurred while handling request", e);
            if (mIsAborted) {
                return ResponseCodes.OBEX_HTTP_OK;
            } else {
+4 −2
Original line number Diff line number Diff line
@@ -293,9 +293,11 @@ class BmessageParser {
         * 2020-06-01: we could now expect MMS to be more than text, e.g., image-only, so charset
         * not always UTF-8, downgrading log message from ERROR to DEBUG.
         */
        if (DBG && !"UTF-8".equals(mBmsg.mBbodyCharset)) {
        if (!"UTF-8".equals(mBmsg.mBbodyCharset)) {
            if (DBG) {
                Log.d(TAG, "The charset was not set to charset UTF-8: " + mBmsg.mBbodyCharset);
            }
        }

        /*
         * <bmessage-body-content>::={ "BEGIN:MSG"<CRLF> 'message'<CRLF>
Loading