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

Commit c71a8fde authored by Hemant Gupta's avatar Hemant Gupta
Browse files

PBAP: Improvisation in start time of BluetoothPbapService

This change is an improvisation to reduce time to start PBAP
Service by moving task of getting local phone details from
start() method running in main Bluetooth context to PbapHandler
Thread. Getting phone details from telephony service was adding
around 20ms in starting PBAP Profile and thus increasing time
for Bluetooth startup.

Test: Calculate timetaken to turn on BT and observed reduction of
20 ms.

Bug: 118604915
Change-Id: I76c9e4846e2eb6048125ea6e942860c55705d113
parent 4dfb3d1d
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
@@ -127,6 +127,7 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
    static final int CONTACTS_LOADED = 5;
    static final int CHECK_SECONDARY_VERSION_COUNTER = 6;
    static final int ROLLOVER_COUNTERS = 7;
    static final int GET_LOCAL_TELEPHONY_DETAILS = 8;

    static final int USER_CONFIRM_TIMEOUT_VALUE = 30000;
    static final int RELEASE_WAKE_LOCK_DELAY = 10000;
@@ -408,6 +409,8 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
                        mPbapStateMachineMap.remove(remoteDevice);
                    }
                    break;
                case GET_LOCAL_TELEPHONY_DETAILS:
                    getLocalTelephonyDetails();
                default:
                    break;
            }
@@ -507,16 +510,10 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
            Log.e(TAG, "Illegal state exception, content observer is already registered");
        }

        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (tm != null) {
            sLocalPhoneNum = tm.getLine1Number();
            sLocalPhoneName = tm.getLine1AlphaTag();
            if (TextUtils.isEmpty(sLocalPhoneName)) {
                sLocalPhoneName = this.getString(R.string.localPhoneName);
            }
        }

        setBluetoothPbapService(this);

        mSessionStatusHandler.sendMessage(
                mSessionStatusHandler.obtainMessage(GET_LOCAL_TELEPHONY_DETAILS));
        mSessionStatusHandler.sendMessage(mSessionStatusHandler.obtainMessage(LOAD_CONTACTS));
        mSessionStatusHandler.sendMessage(mSessionStatusHandler.obtainMessage(START_LISTENER));
        return true;
@@ -775,4 +772,18 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
            mThreadUpdateSecVersionCounter.start();
        }
    }

    private void getLocalTelephonyDetails() {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (tm != null) {
            sLocalPhoneNum = tm.getLine1Number();
            sLocalPhoneName = tm.getLine1AlphaTag();
            if (TextUtils.isEmpty(sLocalPhoneName)) {
                sLocalPhoneName = this.getString(R.string.localPhoneName);
            }
        }
        if (VERBOSE)
            Log.v(TAG, "Local Phone Details- Number:" + sLocalPhoneNum
                    + ", Name:" + sLocalPhoneName);
    }
}