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

Commit 98b14ec2 authored by Roshan Pius's avatar Roshan Pius
Browse files

WifiManager: Implement network suggestion API

Bug: 115504887
Test: ./frameworks/base/wifi/tests/runtests.sh
Change-Id: Iddbd4884f2af7ef4a8c2b32daa8268540ba8dce6
parent 6a554a54
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.net.wifi.ScanResult;
import android.net.wifi.WifiActivityEnergyInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiNetworkSuggestion;

import android.os.Messenger;
import android.os.ResultReceiver;
@@ -188,5 +189,9 @@ interface IWifiManager
    void registerNetworkRequestMatchCallback(in IBinder binder, in INetworkRequestMatchCallback callback, int callbackIdentifier);

    void unregisterNetworkRequestMatchCallback(int callbackIdentifier);

    boolean addNetworkSuggestions(in List<WifiNetworkSuggestion> networkSuggestions, in String packageName);

    boolean removeNetworkSuggestions(in List<WifiNetworkSuggestion> networkSuggestions, in String packageName);
}
+11 −4
Original line number Diff line number Diff line
@@ -1482,8 +1482,11 @@ public class WifiManager {
     */
    @RequiresPermission(android.Manifest.permission.CHANGE_WIFI_STATE)
    public boolean addNetworkSuggestions(@NonNull List<WifiNetworkSuggestion> networkSuggestions) {
        // TODO(b/115504887): Implementation
        return false;
        try {
            return mService.addNetworkSuggestions(networkSuggestions, mContext.getOpPackageName());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }


@@ -1502,8 +1505,12 @@ public class WifiManager {
    @RequiresPermission(android.Manifest.permission.CHANGE_WIFI_STATE)
    public boolean removeNetworkSuggestions(
            @NonNull List<WifiNetworkSuggestion> networkSuggestions) {
        // TODO(b/115504887): Implementation
        return false;
        try {
            return mService.removeNetworkSuggestions(
                    networkSuggestions, mContext.getOpPackageName());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
+19 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2018, 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;

parcelable WifiNetworkSuggestion;
+13 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.net.wifi.ScanResult;
import android.net.wifi.WifiActivityEnergyInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiNetworkSuggestion;
import android.net.wifi.hotspot2.IProvisioningCallback;
import android.net.wifi.hotspot2.OsuProvider;
import android.net.wifi.hotspot2.PasspointConfiguration;
@@ -427,4 +428,16 @@ public abstract class AbstractWifiService extends IWifiManager.Stub {
    public void unregisterNetworkRequestMatchCallback(int callbackIdentifier) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean addNetworkSuggestions(
            List<WifiNetworkSuggestion> networkSuggestions, String callingPackageName) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean removeNetworkSuggestions(
            List<WifiNetworkSuggestion> networkSuggestions, String callingPackageName) {
        throw new UnsupportedOperationException();
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -1286,4 +1286,20 @@ i * Verify that a call to cancel WPS immediately returns a failure.

        verify(mWifiService).getMatchingOsuProviders(any(ScanResult.class));
    }

    /**
     * Verify calls to {@link WifiManager#addNetworkSuggestions(List)} and
     * {@link WifiManager#removeNetworkSuggestions(List)}.
     */
    @Test
    public void addRemoveNetworkSuggestions() throws Exception {
        when(mWifiService.addNetworkSuggestions(any(List.class), anyString())).thenReturn(true);
        when(mWifiService.removeNetworkSuggestions(any(List.class), anyString())).thenReturn(true);

        assertTrue(mWifiManager.addNetworkSuggestions(new ArrayList<>()));
        verify(mWifiService).addNetworkSuggestions(anyList(), eq(TEST_PACKAGE_NAME));

        assertTrue(mWifiManager.removeNetworkSuggestions(new ArrayList<>()));
        verify(mWifiService).removeNetworkSuggestions(anyList(), eq(TEST_PACKAGE_NAME));
    }
}