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

Commit 4bb02709 authored by Mark Chien's avatar Mark Chien Committed by android-build-merger
Browse files

Merge changes from topic "tether_migrate"

am: e8401aff

Change-Id: I03e43b7a112f91637941e5193bd21b3e714f5dac
parents 6b828d29 e8401aff
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -17,7 +17,7 @@
package android.net;
package android.net;


/**
/**
 * Configuration details for a tethering.
 * Configuration details for tethering.
 * @hide
 * @hide
 */
 */
parcelable TetheringConfigurationParcel {
parcelable TetheringConfigurationParcel {
+8 −2
Original line number Original line Diff line number Diff line
@@ -168,11 +168,12 @@ public class TetheringManager {
     * #getTetherableIfaces() to ensure corresponding interface is available for
     * #getTetherableIfaces() to ensure corresponding interface is available for
     * tethering before calling #tether().
     * tethering before calling #tether().
     *
     *
     * TODO: Deprecate this API. The only usages should be in PanService and Wifi P2P which
     * @deprecated The only usages should be in PanService and Wifi P2P which
     * need direct access.
     * need direct access.
     *
     *
     * {@hide}
     * {@hide}
     */
     */
    @Deprecated
    public int tether(@NonNull String iface) {
    public int tether(@NonNull String iface) {
        try {
        try {
            mConnector.tether(iface);
            mConnector.tether(iface);
@@ -185,8 +186,10 @@ public class TetheringManager {
    /**
    /**
     * Stop tethering the named interface.
     * Stop tethering the named interface.
     *
     *
     * @deprecated
     * {@hide}
     * {@hide}
     */
     */
    @Deprecated
    public int untether(@NonNull String iface) {
    public int untether(@NonNull String iface) {
        try {
        try {
            mConnector.untether(iface);
            mConnector.untether(iface);
@@ -202,9 +205,10 @@ public class TetheringManager {
     * encapsulate proper entitlement logic. If the API is used and an entitlement check is needed,
     * encapsulate proper entitlement logic. If the API is used and an entitlement check is needed,
     * downstream USB tethering will be enabled but will not have any upstream.
     * downstream USB tethering will be enabled but will not have any upstream.
     *
     *
     * @Deprecated
     * @deprecated
     * {@hide}
     * {@hide}
     */
     */
    @Deprecated
    public int setUsbTethering(boolean enable) {
    public int setUsbTethering(boolean enable) {
        try {
        try {
            mConnector.setUsbTethering(enable);
            mConnector.setUsbTethering(enable);
@@ -386,8 +390,10 @@ public class TetheringManager {
    /**
    /**
     * Get the set of tethered dhcp ranges.
     * Get the set of tethered dhcp ranges.
     *
     *
     * @deprecated This API just return the default value which is not used in DhcpServer.
     * {@hide}
     * {@hide}
     */
     */
    @Deprecated
    public @NonNull String[] getTetheredDhcpRanges() {
    public @NonNull String[] getTetheredDhcpRanges() {
        if (!mCallback.awaitCallbackCreation()) {
        if (!mCallback.awaitCallbackCreation()) {
            throw new NullPointerException("callback was not ready yet");
            throw new NullPointerException("callback was not ready yet");
+30 −19
Original line number Original line Diff line number Diff line
@@ -93,8 +93,6 @@ import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ResultReceiver;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import android.os.UserManagerInternal;
import android.os.UserManagerInternal.UserRestrictionsListener;
import android.telephony.PhoneStateListener;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.text.TextUtils;
@@ -111,7 +109,6 @@ import com.android.internal.util.MessageUtils;
import com.android.internal.util.Protocol;
import com.android.internal.util.Protocol;
import com.android.internal.util.State;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.internal.util.StateMachine;
import com.android.server.LocalServices;


import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.PrintWriter;
@@ -188,6 +185,7 @@ public class Tethering {
    private final PhoneStateListener mPhoneStateListener;
    private final PhoneStateListener mPhoneStateListener;
    private final INetd mNetd;
    private final INetd mNetd;
    private final NetdCallback mNetdCallback;
    private final NetdCallback mNetdCallback;
    private final UserRestrictionActionListener mTetheringRestriction;
    private int mActiveDataSubId = INVALID_SUBSCRIPTION_ID;
    private int mActiveDataSubId = INVALID_SUBSCRIPTION_ID;
    // All the usage of mTetherInternalCallback should run in the same thread.
    // All the usage of mTetherInternalCallback should run in the same thread.
    private ITetherInternalCallback mTetherInternalCallback = null;
    private ITetherInternalCallback mTetherInternalCallback = null;
@@ -280,6 +278,10 @@ public class Tethering {
            mLog.e("Unable to register netd UnsolicitedEventListener");
            mLog.e("Unable to register netd UnsolicitedEventListener");
        }
        }


        final UserManager userManager = (UserManager) mContext.getSystemService(
                    Context.USER_SERVICE);
        mTetheringRestriction = new UserRestrictionActionListener(userManager, this);

        // Load tethering configuration.
        // Load tethering configuration.
        updateConfiguration();
        updateConfiguration();


@@ -298,6 +300,7 @@ public class Tethering {
        filter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
        filter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
        filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
        filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
        filter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
        filter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
        filter.addAction(UserManager.ACTION_USER_RESTRICTIONS_CHANGED);
        mContext.registerReceiver(mStateReceiver, filter, null, handler);
        mContext.registerReceiver(mStateReceiver, filter, null, handler);


        filter = new IntentFilter();
        filter = new IntentFilter();
@@ -306,11 +309,6 @@ public class Tethering {
        filter.addDataScheme("file");
        filter.addDataScheme("file");
        mContext.registerReceiver(mStateReceiver, filter, null, handler);
        mContext.registerReceiver(mStateReceiver, filter, null, handler);


        final UserManagerInternal umi = LocalServices.getService(UserManagerInternal.class);
        // This check is useful only for some unit tests; example: ConnectivityServiceTest.
        if (umi != null) {
            umi.addUserRestrictionsListener(new TetheringUserRestrictionListener(this));
        }
    }
    }


    private WifiManager getWifiManager() {
    private WifiManager getWifiManager() {
@@ -717,8 +715,8 @@ public class Tethering {
        }
        }


        if (mTetheredNotificationBuilder == null) {
        if (mTetheredNotificationBuilder == null) {
            mTetheredNotificationBuilder =
            mTetheredNotificationBuilder = new Notification.Builder(mContext,
                    new Notification.Builder(mContext, SystemNotificationChannels.NETWORK_STATUS);
                    SystemNotificationChannels.NETWORK_STATUS);
            mTetheredNotificationBuilder.setWhen(0)
            mTetheredNotificationBuilder.setWhen(0)
                    .setOngoing(true)
                    .setOngoing(true)
                    .setColor(mContext.getColor(
                    .setColor(mContext.getColor(
@@ -764,6 +762,9 @@ public class Tethering {
            } else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
            } else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
                mLog.log("OBSERVED configuration changed");
                mLog.log("OBSERVED configuration changed");
                updateConfiguration();
                updateConfiguration();
            } else if (action.equals(UserManager.ACTION_USER_RESTRICTIONS_CHANGED)) {
                mLog.log("OBSERVED user restrictions changed");
                handleUserRestrictionAction();
            }
            }
        }
        }


@@ -870,25 +871,35 @@ public class Tethering {
                }
                }
            }
            }
        }
        }

        private void handleUserRestrictionAction() {
            mTetheringRestriction.onUserRestrictionsChanged();
        }
    }
    }


    @VisibleForTesting
    @VisibleForTesting
    protected static class TetheringUserRestrictionListener implements UserRestrictionsListener {
    protected static class UserRestrictionActionListener {
        private final UserManager mUserManager;
        private final Tethering mWrapper;
        private final Tethering mWrapper;
        public boolean mDisallowTethering;


        public TetheringUserRestrictionListener(Tethering wrapper) {
        public UserRestrictionActionListener(UserManager um, Tethering wrapper) {
            mUserManager = um;
            mWrapper = wrapper;
            mWrapper = wrapper;
            mDisallowTethering = false;
        }
        }


        public void onUserRestrictionsChanged(int userId,
        public void onUserRestrictionsChanged() {
                                              Bundle newRestrictions,
            // getUserRestrictions gets restriction for this process' user, which is the primary
                                              Bundle prevRestrictions) {
            // user. This is fine because DISALLOW_CONFIG_TETHERING can only be set on the primary
            // user. See UserManager.DISALLOW_CONFIG_TETHERING.
            final Bundle restrictions = mUserManager.getUserRestrictions();
            final boolean newlyDisallowed =
            final boolean newlyDisallowed =
                    newRestrictions.getBoolean(UserManager.DISALLOW_CONFIG_TETHERING);
                    restrictions.getBoolean(UserManager.DISALLOW_CONFIG_TETHERING);
            final boolean previouslyDisallowed =
            final boolean prevDisallowed = mDisallowTethering;
                    prevRestrictions.getBoolean(UserManager.DISALLOW_CONFIG_TETHERING);
            mDisallowTethering = newlyDisallowed;
            final boolean tetheringDisallowedChanged = (newlyDisallowed != previouslyDisallowed);


            final boolean tetheringDisallowedChanged = (newlyDisallowed != prevDisallowed);
            if (!tetheringDisallowedChanged) {
            if (!tetheringDisallowedChanged) {
                return;
                return;
            }
            }
+20 −18
Original line number Original line Diff line number Diff line
@@ -166,6 +166,7 @@ public class TetheringTest {
    @Mock private RouterAdvertisementDaemon mRouterAdvertisementDaemon;
    @Mock private RouterAdvertisementDaemon mRouterAdvertisementDaemon;
    @Mock private IDhcpServer mDhcpServer;
    @Mock private IDhcpServer mDhcpServer;
    @Mock private INetd mNetd;
    @Mock private INetd mNetd;
    @Mock private UserManager mUserManager;


    private final MockIpServerDependencies mIpServerDependencies =
    private final MockIpServerDependencies mIpServerDependencies =
            spy(new MockIpServerDependencies());
            spy(new MockIpServerDependencies());
@@ -214,6 +215,7 @@ public class TetheringTest {
            if (Context.WIFI_SERVICE.equals(name)) return mWifiManager;
            if (Context.WIFI_SERVICE.equals(name)) return mWifiManager;
            if (Context.USB_SERVICE.equals(name)) return mUsbManager;
            if (Context.USB_SERVICE.equals(name)) return mUsbManager;
            if (Context.TELEPHONY_SERVICE.equals(name)) return mTelephonyManager;
            if (Context.TELEPHONY_SERVICE.equals(name)) return mTelephonyManager;
            if (Context.USER_SERVICE.equals(name)) return mUserManager;
            return super.getSystemService(name);
            return super.getSystemService(name);
        }
        }


@@ -954,26 +956,26 @@ public class TetheringTest {
        verifyNoMoreInteractions(mNMService);
        verifyNoMoreInteractions(mNMService);
    }
    }


    private void userRestrictionsListenerBehaviour(
    private void runUserRestrictionsChange(
            boolean currentDisallow, boolean nextDisallow, String[] activeTetheringIfacesList,
            boolean currentDisallow, boolean nextDisallow, String[] activeTetheringIfacesList,
            int expectedInteractionsWithShowNotification) throws  Exception {
            int expectedInteractionsWithShowNotification) throws  Exception {
        final int userId = 0;
        final Bundle currRestrictions = new Bundle();
        final Bundle newRestrictions = new Bundle();
        final Bundle newRestrictions = new Bundle();
        Tethering tethering = mock(Tethering.class);
        Tethering.TetheringUserRestrictionListener turl =
                new Tethering.TetheringUserRestrictionListener(tethering);

        currRestrictions.putBoolean(UserManager.DISALLOW_CONFIG_TETHERING, currentDisallow);
        newRestrictions.putBoolean(UserManager.DISALLOW_CONFIG_TETHERING, nextDisallow);
        newRestrictions.putBoolean(UserManager.DISALLOW_CONFIG_TETHERING, nextDisallow);
        when(tethering.getTetheredIfaces()).thenReturn(activeTetheringIfacesList);
        final Tethering mockTethering = mock(Tethering.class);
        when(mockTethering.getTetheredIfaces()).thenReturn(activeTetheringIfacesList);
        when(mUserManager.getUserRestrictions()).thenReturn(newRestrictions);

        final Tethering.UserRestrictionActionListener ural =
                new Tethering.UserRestrictionActionListener(mUserManager, mockTethering);
        ural.mDisallowTethering = currentDisallow;


        turl.onUserRestrictionsChanged(userId, newRestrictions, currRestrictions);
        ural.onUserRestrictionsChanged();


        verify(tethering, times(expectedInteractionsWithShowNotification))
        verify(mockTethering, times(expectedInteractionsWithShowNotification))
                .showTetheredNotification(anyInt(), eq(false));
                .showTetheredNotification(anyInt(), eq(false));


        verify(tethering, times(expectedInteractionsWithShowNotification)).untetherAll();
        verify(mockTethering, times(expectedInteractionsWithShowNotification))
                .untetherAll();
    }
    }


    @Test
    @Test
@@ -983,7 +985,7 @@ public class TetheringTest {
        final boolean nextDisallow = true;
        final boolean nextDisallow = true;
        final int expectedInteractionsWithShowNotification = 0;
        final int expectedInteractionsWithShowNotification = 0;


        userRestrictionsListenerBehaviour(currDisallow, nextDisallow, emptyActiveIfacesList,
        runUserRestrictionsChange(currDisallow, nextDisallow, emptyActiveIfacesList,
                expectedInteractionsWithShowNotification);
                expectedInteractionsWithShowNotification);
    }
    }


@@ -994,7 +996,7 @@ public class TetheringTest {
        final boolean nextDisallow = true;
        final boolean nextDisallow = true;
        final int expectedInteractionsWithShowNotification = 1;
        final int expectedInteractionsWithShowNotification = 1;


        userRestrictionsListenerBehaviour(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
        runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
                expectedInteractionsWithShowNotification);
                expectedInteractionsWithShowNotification);
    }
    }


@@ -1005,7 +1007,7 @@ public class TetheringTest {
        final boolean nextDisallow = false;
        final boolean nextDisallow = false;
        final int expectedInteractionsWithShowNotification = 0;
        final int expectedInteractionsWithShowNotification = 0;


        userRestrictionsListenerBehaviour(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
        runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
                expectedInteractionsWithShowNotification);
                expectedInteractionsWithShowNotification);
    }
    }


@@ -1016,7 +1018,7 @@ public class TetheringTest {
        final boolean nextDisallow = false;
        final boolean nextDisallow = false;
        final int expectedInteractionsWithShowNotification = 0;
        final int expectedInteractionsWithShowNotification = 0;


        userRestrictionsListenerBehaviour(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
        runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
                expectedInteractionsWithShowNotification);
                expectedInteractionsWithShowNotification);
    }
    }


@@ -1027,13 +1029,13 @@ public class TetheringTest {
        boolean currDisallow = true;
        boolean currDisallow = true;
        boolean nextDisallow = true;
        boolean nextDisallow = true;


        userRestrictionsListenerBehaviour(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
        runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
                expectedInteractionsWithShowNotification);
                expectedInteractionsWithShowNotification);


        currDisallow = false;
        currDisallow = false;
        nextDisallow = false;
        nextDisallow = false;


        userRestrictionsListenerBehaviour(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
        runUserRestrictionsChange(currDisallow, nextDisallow, nonEmptyActiveIfacesList,
                expectedInteractionsWithShowNotification);
                expectedInteractionsWithShowNotification);
    }
    }


+8 −8

File changed.

Contains only whitespace changes.