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

Commit b50307ec authored by Hyundo Moon's avatar Hyundo Moon Committed by Gerrit Code Review
Browse files

Merge "OppService: Extract stop behaviors with a method" into main

parents 1de13d04 eaed715e
Loading
Loading
Loading
Loading
+54 −51
Original line number Diff line number Diff line
@@ -379,57 +379,7 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
                public void handleMessage(Message msg) {
                    switch (msg.what) {
                        case STOP_LISTENER:
                            stopListeners();
                            mListenStarted = false;
                            // Stop Active INBOUND Transfer
                            if (mServerTransfer != null) {
                                mServerTransfer.onBatchCanceled();
                                mServerTransfer = null;
                            }
                            // Stop Active OUTBOUND Transfer
                            if (mTransfer != null) {
                                mTransfer.onBatchCanceled();
                                mTransfer = null;
                            }
                            unregisterReceivers();
                            synchronized (BluetoothOppService.this) {
                                if (mUpdateThread != null) {
                                    mUpdateThread.interrupt();
                                }
                            }
                            while (mUpdateThread != null && mUpdateThreadRunning) {
                                try {
                                    Thread.sleep(50);
                                } catch (Exception e) {
                                    ContentProfileErrorReportUtils.report(
                                            BluetoothProfile.OPP,
                                            BluetoothProtoEnums.BLUETOOTH_OPP_SERVICE,
                                            BluetoothStatsLog
                                                    .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                                            4);
                                    Log.e(TAG, "Thread sleep", e);
                                }
                            }
                            synchronized (BluetoothOppService.this) {
                                if (mUpdateThread != null) {
                                    try {
                                        mUpdateThread.join();
                                    } catch (InterruptedException e) {
                                        ContentProfileErrorReportUtils.report(
                                                BluetoothProfile.OPP,
                                                BluetoothProtoEnums.BLUETOOTH_OPP_SERVICE,
                                                BluetoothStatsLog
                                                        .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                                                5);
                                        Log.e(TAG, "Interrupted", e);
                                    }
                                    mUpdateThread = null;
                                }
                            }

                            if (mNotifier != null) {
                                mNotifier.cancelNotifications();
                            }
                            stopInternal();
                            break;
                        case START_LISTENER:
                            if (mAdapterService.isEnabled()) {
@@ -634,6 +584,59 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti
        }
    }

    private void stopInternal() {
        stopListeners();
        mListenStarted = false;
        // Stop Active INBOUND Transfer
        if (mServerTransfer != null) {
            mServerTransfer.onBatchCanceled();
            mServerTransfer = null;
        }
        // Stop Active OUTBOUND Transfer
        if (mTransfer != null) {
            mTransfer.onBatchCanceled();
            mTransfer = null;
        }
        unregisterReceivers();
        synchronized (BluetoothOppService.this) {
            if (mUpdateThread != null) {
                mUpdateThread.interrupt();
            }
        }
        while (mUpdateThread != null && mUpdateThreadRunning) {
            try {
                Thread.sleep(50);
            } catch (Exception e) {
                ContentProfileErrorReportUtils.report(
                        BluetoothProfile.OPP,
                        BluetoothProtoEnums.BLUETOOTH_OPP_SERVICE,
                        BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                        4);
                Log.e(TAG, "Thread sleep", e);
            }
        }
        synchronized (BluetoothOppService.this) {
            if (mUpdateThread != null) {
                try {
                    mUpdateThread.join();
                } catch (InterruptedException e) {
                    ContentProfileErrorReportUtils.report(
                            BluetoothProfile.OPP,
                            BluetoothProtoEnums.BLUETOOTH_OPP_SERVICE,
                            BluetoothStatsLog
                                    .BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
                            5);
                    Log.e(TAG, "Interrupted", e);
                }
                mUpdateThread = null;
            }
        }

        if (mNotifier != null) {
            mNotifier.cancelNotifications();
        }
    }

    /* suppose we auto accept an incoming OPUSH connection */
    private void createServerSession(ObexTransport transport) {
        mServerSession = new BluetoothOppObexServerSession(this, transport, this);