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

Commit 674a012c authored by Mark Chien's avatar Mark Chien
Browse files

Register callback and receiver after tethering is created

Tethering service is created after boot complete which means most of
the services are ready before tethering. Once tethering register the
callback, callback event may come-in immediately. Make sure all of
tethering related object is created, then register the callback,
receiver, or listener.

Bug: 149965121
Test: atest TetheringTests
      manual on/off tethering

Change-Id: Ifdc427341db7d1313ad4b61207a96ab379d100aa
Merged-In: I3941a186770679e7b476073d774e2310e25e44c6
(cherry picked from commit 285be1ee)
parent f51b6aa5
Loading
Loading
Loading
Loading
+16 −15
Original line number Diff line number Diff line
@@ -307,28 +307,22 @@ public class Tethering {
                userManager, this, mNotificationUpdater);
        mExecutor = new TetheringThreadExecutor(mHandler);
        mActiveDataSubIdListener = new ActiveDataSubIdListener(mExecutor);
        mNetdCallback = new NetdCallback();

        // Load tethering configuration.
        updateConfiguration();
        // NetdCallback should be registered after updateConfiguration() to ensure
        // TetheringConfiguration is created.
        mNetdCallback = new NetdCallback();
    }

    /**
     * Start to register callbacks.
     * Call this function when tethering is ready to handle callback events.
     */
    public void startStateMachineUpdaters() {
        try {
            mNetd.registerUnsolicitedEventListener(mNetdCallback);
        } catch (RemoteException e) {
            mLog.e("Unable to register netd UnsolicitedEventListener");
        }

        startStateMachineUpdaters(mHandler);
        startTrackDefaultNetwork();

        final WifiManager wifiManager = getWifiManager();
        if (wifiManager != null) {
            wifiManager.registerSoftApCallback(mExecutor, new TetheringSoftApCallback());
        }
    }

    private void startStateMachineUpdaters(Handler handler) {
        mCarrierConfigChange.startListening();
        mContext.getSystemService(TelephonyManager.class).listen(mActiveDataSubIdListener,
                PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE);
@@ -341,7 +335,14 @@ public class Tethering {
        filter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
        filter.addAction(UserManager.ACTION_USER_RESTRICTIONS_CHANGED);
        filter.addAction(ACTION_RESTRICT_BACKGROUND_CHANGED);
        mContext.registerReceiver(mStateReceiver, filter, null, handler);
        mContext.registerReceiver(mStateReceiver, filter, null, mHandler);

        final WifiManager wifiManager = getWifiManager();
        if (wifiManager != null) {
            wifiManager.registerSoftApCallback(mExecutor, new TetheringSoftApCallback());
        }

        startTrackDefaultNetwork();
    }

    private class TetheringThreadExecutor implements Executor {
+1 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ public class TetheringService extends Service {
        mContext = mDeps.getContext();
        mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        mTethering = makeTethering(mDeps);
        mTethering.startStateMachineUpdaters();
    }

    /**
+1 −0
Original line number Diff line number Diff line
@@ -484,6 +484,7 @@ public class TetheringTest {
        mServiceContext.registerReceiver(mBroadcastReceiver,
                new IntentFilter(ACTION_TETHER_STATE_CHANGED));
        mTethering = makeTethering();
        mTethering.startStateMachineUpdaters();
        verify(mStatsManager, times(1)).registerNetworkStatsProvider(anyString(), any());
        verify(mNetd).registerUnsolicitedEventListener(any());
        final ArgumentCaptor<PhoneStateListener> phoneListenerCaptor =