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

Commit 422eb73f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[WifiManger] add API to get suggestion"

parents c53d2809 f6b731a8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -29830,6 +29830,7 @@ package android.net.wifi {
    method public android.net.wifi.WifiInfo getConnectionInfo();
    method public android.net.DhcpInfo getDhcpInfo();
    method public int getMaxNumberOfNetworkSuggestionsPerApp();
    method @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) @NonNull public java.util.List<android.net.wifi.WifiNetworkSuggestion> getNetworkSuggestions();
    method @Deprecated @RequiresPermission(anyOf={"android.permission.NETWORK_SETTINGS", "android.permission.NETWORK_SETUP_WIZARD"}) public java.util.List<android.net.wifi.hotspot2.PasspointConfiguration> getPasspointConfigurations();
    method public java.util.List<android.net.wifi.ScanResult> getScanResults();
    method public int getWifiState();
+2 −0
Original line number Diff line number Diff line
@@ -205,6 +205,8 @@ interface IWifiManager

    int removeNetworkSuggestions(in List<WifiNetworkSuggestion> networkSuggestions, in String packageName);

    List<WifiNetworkSuggestion> getNetworkSuggestions(in String packageName);

    String[] getFactoryMacAddresses();

    void setDeviceMobilityState(int state);
+15 −0
Original line number Diff line number Diff line
@@ -1721,6 +1721,21 @@ public class WifiManager {
        }
    }

    /**
     * Get all network suggestions provided by the calling app.
     * See {@link #addNetworkSuggestions(List)}
     * See {@link #removeNetworkSuggestions(List)}
     * @return a list of {@link WifiNetworkSuggestion}
     */
    @RequiresPermission(ACCESS_WIFI_STATE)
    public @NonNull List<WifiNetworkSuggestion> getNetworkSuggestions() {
        try {
            return mService.getNetworkSuggestions(mContext.getOpPackageName());
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }

    /**
     * Returns the max number of network suggestions that are allowed per app on the device.
     * @see #addNetworkSuggestions(List)
+5 −0
Original line number Diff line number Diff line
@@ -439,6 +439,11 @@ public class BaseWifiService extends IWifiManager.Stub {
        throw new UnsupportedOperationException();
    }

    @Override
    public List<WifiNetworkSuggestion> getNetworkSuggestions(String packageName) {
        throw new UnsupportedOperationException();
    }

    @Override
    public String[] getFactoryMacAddresses() {
        throw new UnsupportedOperationException();
+10 −3
Original line number Diff line number Diff line
@@ -1313,20 +1313,27 @@ i * Verify that a call to cancel WPS immediately returns a failure.
    }

    /**
     * Verify calls to {@link WifiManager#addNetworkSuggestions(List)} and
     * Verify calls to {@link WifiManager#addNetworkSuggestions(List)},
     * {@link WifiManager#getNetworkSuggestions()} and
     * {@link WifiManager#removeNetworkSuggestions(List)}.
     */
    @Test
    public void addRemoveNetworkSuggestions() throws Exception {
    public void addGetRemoveNetworkSuggestions() throws Exception {
        List<WifiNetworkSuggestion> testList = new ArrayList<>();
        when(mWifiService.addNetworkSuggestions(any(List.class), anyString()))
                .thenReturn(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS);
        when(mWifiService.removeNetworkSuggestions(any(List.class), anyString()))
                .thenReturn(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS);
        when(mWifiService.getNetworkSuggestions(anyString()))
                .thenReturn(testList);

        assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
                mWifiManager.addNetworkSuggestions(new ArrayList<>()));
                mWifiManager.addNetworkSuggestions(testList));
        verify(mWifiService).addNetworkSuggestions(anyList(), eq(TEST_PACKAGE_NAME));

        assertEquals(testList, mWifiManager.getNetworkSuggestions());
        verify(mWifiService).getNetworkSuggestions(eq(TEST_PACKAGE_NAME));

        assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
                mWifiManager.removeNetworkSuggestions(new ArrayList<>()));
        verify(mWifiService).removeNetworkSuggestions(anyList(), eq(TEST_PACKAGE_NAME));