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

Commit 955c650a authored by James Mattis's avatar James Mattis Committed by android-build-merger
Browse files

Merge "Support for hotspot client visibility." am: 81200971

am: 6f1bf857

Change-Id: Ie0b8b3f4ab168f132f4f6cc01df525c69c8cde41
parents 8e8c40b5 6f1bf857
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -4657,6 +4657,13 @@ package android.net.wifi {
    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 {
    method @Deprecated public boolean hasNoInternetAccess();
    method @Deprecated public boolean isEphemeral();
+13 −8
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.systemui.Dependency.MAIN_HANDLER_NAME;
import android.app.ActivityManager;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.wifi.WifiClient;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.UserManager;
@@ -29,12 +30,14 @@ import android.util.Log;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

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

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

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

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

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

import java.util.ArrayList;

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

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

package android.net.wifi;

import android.net.wifi.WifiClient;

/**
 * Interface for Soft AP callback.
 *
@@ -36,9 +38,9 @@ oneway interface ISoftApCallback
    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 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