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

Commit 201a3198 authored by James Mattis's avatar James Mattis
Browse files

Support for hotspot client visibility.

Adding support for visibility into clients that connect to an active hotspot.

Bug: 137309578
Test: atest FrameworksNetTests:com.android.server.connectivity.TetheringTest
atest FrameworksWifiApiTests:android.net.wifi.WifiManagerTest
atest FrameworksWifiApiTests:android.net.wifi.WifiClientTest
Tested manually on Pixel 3.

Change-Id: I1caeb10bc50202873e760a76b346bccd941e2574
Merged-In: I1caeb10bc50202873e760a76b346bccd941e2574
parent f9cb43d6
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -4657,6 +4657,13 @@ package android.net.wifi {
    field @Deprecated public byte id;
    field @Deprecated public byte id;
  }
  }
  public final class WifiClient implements android.os.Parcelable {
    method public int describeContents();
    method @NonNull public android.net.MacAddress getMacAddress();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.WifiClient> CREATOR;
  }
  @Deprecated public class WifiConfiguration implements android.os.Parcelable {
  @Deprecated public class WifiConfiguration implements android.os.Parcelable {
    method @Deprecated public boolean hasNoInternetAccess();
    method @Deprecated public boolean hasNoInternetAccess();
    method @Deprecated public boolean isEphemeral();
    method @Deprecated public boolean isEphemeral();
+13 −8
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.systemui.Dependency.MAIN_HANDLER_NAME;
import android.app.ActivityManager;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager;
import android.net.wifi.WifiClient;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.Handler;
import android.os.UserManager;
import android.os.UserManager;
@@ -29,12 +30,14 @@ import android.util.Log;
import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;


import javax.inject.Inject;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.inject.Singleton;


/**
/**
 * Controller used to retrieve information related to a hotspot.
 */
 */
@Singleton
@Singleton
public class HotspotControllerImpl implements HotspotController, WifiManager.SoftApCallback {
public class HotspotControllerImpl implements HotspotController, WifiManager.SoftApCallback {
@@ -49,10 +52,11 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof
    private final Context mContext;
    private final Context mContext;


    private int mHotspotState;
    private int mHotspotState;
    private int mNumConnectedDevices;
    private volatile int mNumConnectedDevices;
    private boolean mWaitingForTerminalState;
    private boolean mWaitingForTerminalState;


    /**
    /**
     * Controller used to retrieve information related to a hotspot.
     */
     */
    @Inject
    @Inject
    public HotspotControllerImpl(Context context, @Named(MAIN_HANDLER_NAME) Handler mainHandler) {
    public HotspotControllerImpl(Context context, @Named(MAIN_HANDLER_NAME) Handler mainHandler) {
@@ -96,7 +100,6 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof
    /**
    /**
     * Adds {@code callback} to the controller. The controller will update the callback on state
     * Adds {@code callback} to the controller. The controller will update the callback on state
     * changes. It will immediately trigger the callback added to notify current state.
     * changes. It will immediately trigger the callback added to notify current state.
     * @param callback
     */
     */
    @Override
    @Override
    public void addCallback(Callback callback) {
    public void addCallback(Callback callback) {
@@ -108,11 +111,13 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof
                if (mCallbacks.size() == 1) {
                if (mCallbacks.size() == 1) {
                    mWifiManager.registerSoftApCallback(this, mMainHandler);
                    mWifiManager.registerSoftApCallback(this, mMainHandler);
                } else {
                } else {
                    // mWifiManager#registerSoftApCallback triggers a call to onNumClientsChanged
                    // mWifiManager#registerSoftApCallback triggers a call to
                    // on the Main Handler. In order to always update the callback on added, we
                    // onConnectedClientsChanged on the Main Handler. In order to always update
                    // make this call when adding callbacks after the first.
                    // the callback on added, we make this call when adding callbacks after the
                    // first.
                    mMainHandler.post(() ->
                    mMainHandler.post(() ->
                            callback.onHotspotChanged(isHotspotEnabled(), mNumConnectedDevices));
                            callback.onHotspotChanged(isHotspotEnabled(),
                                    mNumConnectedDevices));
                }
                }
            }
            }
        }
        }
@@ -217,8 +222,8 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof
    }
    }


    @Override
    @Override
    public void onNumClientsChanged(int numConnectedDevices) {
    public void onConnectedClientsChanged(List<WifiClient> clients) {
        mNumConnectedDevices = numConnectedDevices;
        mNumConnectedDevices = clients.size();
        fireHotspotChangedCallback();
        fireHotspotChangedCallback();
    }
    }
}
}
+4 −1
Original line number Original line Diff line number Diff line
@@ -42,6 +42,8 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.invocation.InvocationOnMock;


import java.util.ArrayList;

@SmallTest
@SmallTest
@RunWith(AndroidTestingRunner.class)
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@TestableLooper.RunWithLooper
@@ -67,7 +69,8 @@ public class HotspotControllerImplTest extends SysuiTestCase {
        mContext.addMockSystemService(WifiManager.class, mWifiManager);
        mContext.addMockSystemService(WifiManager.class, mWifiManager);


        doAnswer((InvocationOnMock invocation) -> {
        doAnswer((InvocationOnMock invocation) -> {
            ((WifiManager.SoftApCallback) invocation.getArgument(0)).onNumClientsChanged(1);
            ((WifiManager.SoftApCallback) invocation.getArgument(0))
                    .onConnectedClientsChanged(new ArrayList<>());
            return null;
            return null;
        }).when(mWifiManager).registerSoftApCallback(any(WifiManager.SoftApCallback.class),
        }).when(mWifiManager).registerSoftApCallback(any(WifiManager.SoftApCallback.class),
                any(Handler.class));
                any(Handler.class));
+5 −3
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package android.net.wifi;
package android.net.wifi;


import android.net.wifi.WifiClient;

/**
/**
 * Interface for Soft AP callback.
 * Interface for Soft AP callback.
 *
 *
@@ -36,9 +38,9 @@ oneway interface ISoftApCallback
    void onStateChanged(int state, int failureReason);
    void onStateChanged(int state, int failureReason);


    /**
    /**
     * Service to manager callback providing number of connected clients.
     * Service to manager callback providing connected client's information.
     *
     *
     * @param numClients number of connected clients
     * @param clients the currently connected clients
     */
     */
    void onNumClientsChanged(int numClients);
    void onConnectedClientsChanged(in List<WifiClient> clients);
}
}
+19 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.net.wifi;

@JavaOnlyStableParcelable parcelable WifiClient;
 No newline at end of file
Loading