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

Commit 9b331a18 authored by Sal Savage's avatar Sal Savage Committed by Gerrit Code Review
Browse files

Merge changes If1c07a42,I4ee9fdb4 into main

* changes:
  Update conditions using log tag enforcement variables with other logic
  Update per-instance tag patterns to use the message and not tag
parents 0d2fba74 bbadeb9c
Loading
Loading
Loading
Loading
+25 −43
Original line number Diff line number Diff line
@@ -47,9 +47,8 @@ import java.util.concurrent.atomic.AtomicInteger;
 * In both cases the {@link ObexServerSockets} object have terminated, and a new must be created.
 */
public class ObexServerSockets {
    private final String mTag;
    private static final String STAG = "ObexServerSockets";
    private static final boolean D = true; // TODO: set to false!
    private static final String TAG = "ObexServerSockets";
    private static final boolean D = true; // TODO: set this to false!

    private final IObexConnectionHandler mConHandler;
    /* The wrapped sockets */
@@ -66,7 +65,6 @@ public class ObexServerSockets {
        mConHandler = conHandler;
        mRfcommSocket = rfcommSocket;
        mL2capSocket = l2capSocket;
        mTag = "ObexServerSockets" + sInstanceCounter.getAndIncrement();
    }

    /**
@@ -113,7 +111,7 @@ public class ObexServerSockets {
    private static ObexServerSockets create(IObexConnectionHandler validator, int rfcommChannel,
            int l2capPsm, boolean isSecure) {
        if (D) {
            Log.d(STAG, "create(rfcomm = " + rfcommChannel + ", l2capPsm = " + l2capPsm + ")");
            Log.d(TAG, "create(rfcomm = " + rfcommChannel + ", l2capPsm = " + l2capPsm + ")");
        }
        BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
        if (bt == null) {
@@ -142,10 +140,10 @@ public class ObexServerSockets {
                    }
                }
            } catch (IOException e) {
                Log.e(STAG, "Error create ServerSockets ", e);
                Log.e(TAG, "Error create ServerSockets ", e);
                initSocketOK = false;
            } catch (SecurityException e) {
                Log.e(STAG, "Error create ServerSockets ", e);
                Log.e(TAG, "Error create ServerSockets ", e);
                initSocketOK = false;
                break;
            }
@@ -154,16 +152,16 @@ public class ObexServerSockets {
                int state = bt.getState();
                if ((state != BluetoothAdapter.STATE_TURNING_ON) && (state
                        != BluetoothAdapter.STATE_ON)) {
                    Log.w(STAG, "initServerSockets failed as BT is (being) turned off");
                    Log.w(TAG, "initServerSockets failed as BT is (being) turned off");
                    break;
                }
                try {
                    if (D) {
                        Log.v(STAG, "waiting 300 ms...");
                        Log.v(TAG, "waiting 300 ms...");
                    }
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    Log.e(STAG, "create() was interrupted");
                    Log.e(TAG, "create() was interrupted");
                }
            } else {
                break;
@@ -172,13 +170,13 @@ public class ObexServerSockets {

        if (initSocketOK) {
            if (D) {
                Log.d(STAG, "Succeed to create listening sockets ");
                Log.d(TAG, "Succeed to create listening sockets ");
            }
            ObexServerSockets sockets = new ObexServerSockets(validator, rfcommSocket, l2capSocket);
            sockets.startAccept();
            return sockets;
        } else {
            Log.e(STAG, "Error to create listening socket after " + CREATE_RETRY_TIME + " try");
            Log.e(TAG, "Error to create listening socket after " + CREATE_RETRY_TIME + " try");
            return null;
        }
    }
@@ -207,9 +205,7 @@ public class ObexServerSockets {
     * the {@link IObexConnectionValidator#onConnect()}, at which point both threads will exit.
     */
    private void startAccept() {
        if (D) {
            Log.d(mTag, "startAccept()");
        }
        Log.d(TAG, "startAccept()");

        mRfcommThread = new SocketAcceptThread(mRfcommSocket);
        mRfcommThread.start();
@@ -225,9 +221,7 @@ public class ObexServerSockets {
     * @return true if the connection is accepted, false otherwise.
     */
    private synchronized boolean onConnect(BluetoothDevice device, BluetoothSocket conSocket) {
        if (D) {
            Log.d(mTag, "onConnect() socket: " + conSocket);
        }
        Log.d(TAG, "onConnect() socket: " + conSocket);
        return mConHandler.onConnect(device, conSocket);
    }

@@ -238,7 +232,7 @@ public class ObexServerSockets {
        shutdown(false);
        BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();
        if ((mAdapter != null) && (mAdapter.getState() == BluetoothAdapter.STATE_ON)) {
            Log.d(mTag, "onAcceptFailed() calling shutdown...");
            Log.d(TAG, "onAcceptFailed() calling shutdown...");
            mConHandler.onAcceptFailed();
        }
    }
@@ -249,9 +243,7 @@ public class ObexServerSockets {
     * has ended execution
     */
    public synchronized void shutdown(boolean block) {
        if (D) {
            Log.d(mTag, "shutdown(block = " + block + ")");
        }
        Log.d(TAG, "shutdown(block = " + block + ")");
        if (mRfcommThread != null) {
            mRfcommThread.shutdown();
        }
@@ -270,7 +262,7 @@ public class ObexServerSockets {
                        mL2capThread = null;
                    }
                } catch (InterruptedException e) {
                    Log.i(mTag, "shutdown() interrupted, continue waiting...", e);
                    Log.i(TAG, "shutdown() interrupted, continue waiting...", e);
                }
            }
        } else {
@@ -314,28 +306,24 @@ public class ObexServerSockets {
                    BluetoothDevice device;

                    try {
                        if (D) {
                            Log.d(mTag, "Accepting socket connection...");
                        }
                        Log.d(TAG, "Accepting socket connection...");

                        connSocket = mServerSocket.accept();
                        if (D) {
                            Log.d(mTag, "Accepted socket connection from: " + mServerSocket);
                        }
                        Log.d(TAG, "Accepted socket connection from: " + mServerSocket);

                        if (connSocket == null) {
                            // TODO: Do we need a max error count, to avoid spinning?
                            Log.w(mTag, "connSocket is null - reattempt accept");
                            Log.w(TAG, "connSocket is null - reattempt accept");
                            continue;
                        }
                        device = connSocket.getRemoteDevice();

                        if (device == null) {
                            Log.i(mTag, "getRemoteDevice() = null - reattempt accept");
                            Log.i(TAG, "getRemoteDevice() = null - reattempt accept");
                            try {
                                connSocket.close();
                            } catch (IOException e) {
                                Log.w(mTag, "Error closing the socket. ignoring...", e);
                                Log.w(TAG, "Error closing the socket. ignoring...", e);
                            }
                            continue;
                        }
@@ -348,7 +336,7 @@ public class ObexServerSockets {
                            /* Close connection if we already have a connection with another device
                             * by responding to the OBEX connect request.
                             */
                            Log.i(mTag, "RemoteDevice is invalid - creating ObexRejectServer.");
                            Log.i(TAG, "RemoteDevice is invalid - creating ObexRejectServer.");
                            BluetoothObexTransport obexTrans =
                                    new BluetoothObexTransport(connSocket);
                            // Create and detach a selfdestructing ServerSession to respond to any
@@ -364,16 +352,14 @@ public class ObexServerSockets {
                        if (mStopped) {
                            // Expected exception because of shutdown.
                        } else {
                            Log.w(mTag, "Accept exception for " + mServerSocket, ex);
                            Log.w(TAG, "Accept exception for " + mServerSocket, ex);
                            ObexServerSockets.this.onAcceptFailed();
                        }
                        mStopped = true;
                    }
                } // End while()
            } finally {
                if (D) {
                    Log.d(mTag, "AcceptThread ended for: " + mServerSocket);
                }
                Log.d(TAG, "AcceptThread ended for: " + mServerSocket);
            }
        }

@@ -391,18 +377,14 @@ public class ObexServerSockets {
                try {
                    mServerSocket.close();
                } catch (IOException e) {
                    if (D) {
                        Log.d(mTag, "Exception while thread shutdown:", e);
                    }
                    Log.w(TAG, "Exception while thread shutdown:", e);
                }
            }
            // If called from another thread, interrupt the thread
            if (!Thread.currentThread().equals(this)) {
                // TODO: Will this interrupt the thread if it is blocked in synchronized?
                // Else: change to use InterruptableLock
                if (D) {
                    Log.d(mTag, "shutdown called from another thread - interrupt().");
                }
                Log.d(TAG, "shutdown called from another thread - interrupt().");
                interrupt();
            }
        }
+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);
    }
}
+39 −51

File changed.

Preview size limit exceeded, changes collapsed.

+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);
                    }
                }
            }
        }
    }
Loading