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

Commit 5dc01a91 authored by Franck Lenormand's avatar Franck Lenormand Committed by android-build-merger
Browse files

Merge "Prevent javacrash when TELEPHONY_SERVICE is not found"

am: 8367ebbe

* commit '8367ebbe':
  Prevent javacrash when TELEPHONY_SERVICE is not found
parents 0a5cbbd0 8367ebbe
Loading
Loading
Loading
Loading
+20 −7
Original line number Diff line number Diff line
@@ -87,6 +87,10 @@ class HeadsetPhoneState {
    HeadsetPhoneState(Context context, HeadsetStateMachine stateMachine) {
        mStateMachine = stateMachine;
        mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        if (mTelephonyManager == null) {
            Log.e(TAG, "getSystemService(Context.TELEPHONY_SERVICE) failed, "
                  + "cannot register for SubscriptionInfo changes");
        }
        mContext = context;

        // Register for SubscriptionInfo list changes which is guaranteed
@@ -123,7 +127,10 @@ class HeadsetPhoneState {

            if (SubscriptionManager.isValidSubscriptionId(subId)) {
                mPhoneStateListener = getPhoneStateListener(subId);

                if (mTelephonyManager == null) {
                    Log.e(TAG, "mTelephonyManager is null, "
                         + "cannot start listening for phone state changes");
                } else {
                    mTelephonyManager.listen(mPhoneStateListener,
                                             PhoneStateListener.LISTEN_SERVICE_STATE |
                                             PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
@@ -131,14 +138,20 @@ class HeadsetPhoneState {
                }
            }
        }
    }

    private void stopListenForPhoneState() {
        if (mListening) {

            if (mTelephonyManager == null) {
                Log.e(TAG, "mTelephonyManager is null, "
                     + "cannot send request to stop listening for phone state changes");
            } else {
                mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
                mListening = false;
            }
        }
    }

    int getService() {
        return mService;