Search in sources :

Example 1 with RecommendationResult

use of android.net.RecommendationResult in project platform_frameworks_base by android.

the class NetworkScoreServiceTest method testRequestRecommendationAsync_requestTimesOut.

@Test
public void testRequestRecommendationAsync_requestTimesOut() throws Exception {
    injectProvider();
    Settings.Global.putLong(mContentResolver, Settings.Global.NETWORK_RECOMMENDATION_REQUEST_TIMEOUT_MS, 1L);
    mNetworkScoreService.refreshRecommendationRequestTimeoutMs();
    mNetworkScoreService.requestRecommendationAsync(mRecommendationRequest, mRemoteCallback);
    boolean callbackRan = mOnResultListener.countDownLatch.await(3, TimeUnit.SECONDS);
    assertTrue(callbackRan);
    verify(mRecommendationProvider).requestRecommendation(eq(mRecommendationRequest), isA(IRemoteCallback.Stub.class), anyInt());
    assertTrue(mOnResultListener.receivedBundle.containsKey(EXTRA_RECOMMENDATION_RESULT));
    RecommendationResult result = mOnResultListener.receivedBundle.getParcelable(EXTRA_RECOMMENDATION_RESULT);
    assertTrue(result.hasRecommendation());
    assertEquals(mRecommendationRequest.getDefaultWifiConfig().SSID, result.getWifiConfiguration().SSID);
}
Also used : RecommendationResult(android.net.RecommendationResult) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 2 with RecommendationResult

use of android.net.RecommendationResult in project platform_frameworks_base by android.

the class NetworkScoreService method sendDefaultRecommendationResponse.

private static void sendDefaultRecommendationResponse(RecommendationRequest request, OneTimeCallback remoteCallback) {
    if (DBG) {
        Log.d(TAG, "Returning the default network recommendation.");
    }
    final RecommendationResult result;
    if (request != null && request.getDefaultWifiConfig() != null) {
        result = RecommendationResult.createConnectRecommendation(request.getDefaultWifiConfig());
    } else {
        result = RecommendationResult.createDoNotConnectRecommendation();
    }
    final Bundle data = new Bundle();
    data.putParcelable(EXTRA_RECOMMENDATION_RESULT, result);
    remoteCallback.sendResult(data);
}
Also used : Bundle(android.os.Bundle) RecommendationResult(android.net.RecommendationResult)

Example 3 with RecommendationResult

use of android.net.RecommendationResult in project platform_frameworks_base by android.

the class NetworkScoreServiceTest method testRequestRecommendation_providerThrowsRemoteException.

@Test
public void testRequestRecommendation_providerThrowsRemoteException() throws Exception {
    injectProvider();
    when(mContext.getMainLooper()).thenReturn(Looper.getMainLooper());
    doThrow(new RemoteException()).when(mRecommendationProvider).requestRecommendation(eq(mRecommendationRequest), isA(IRemoteCallback.class), anyInt());
    final RecommendationResult result = mNetworkScoreService.requestRecommendation(mRecommendationRequest);
    assertNotNull(result);
    assertEquals(mRecommendationRequest.getDefaultWifiConfig(), result.getWifiConfiguration());
}
Also used : IRemoteCallback(android.os.IRemoteCallback) RecommendationResult(android.net.RecommendationResult) RemoteException(android.os.RemoteException) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 4 with RecommendationResult

use of android.net.RecommendationResult in project platform_frameworks_base by android.

the class NetworkScoreServiceTest method testRequestRecommendation_providerNotConnected.

@Test
public void testRequestRecommendation_providerNotConnected() throws Exception {
    when(mContext.getMainLooper()).thenReturn(Looper.getMainLooper());
    final RecommendationResult result = mNetworkScoreService.requestRecommendation(mRecommendationRequest);
    assertNotNull(result);
    assertEquals(mRecommendationRequest.getDefaultWifiConfig(), result.getWifiConfiguration());
}
Also used : RecommendationResult(android.net.RecommendationResult) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 5 with RecommendationResult

use of android.net.RecommendationResult in project platform_frameworks_base by android.

the class NetworkScoreServiceTest method testRequestRecommendation_resultReturned.

@Test
public void testRequestRecommendation_resultReturned() throws Exception {
    injectProvider();
    when(mContext.getMainLooper()).thenReturn(Looper.getMainLooper());
    final WifiConfiguration wifiConfiguration = new WifiConfiguration();
    wifiConfiguration.SSID = "testRequestRecommendation_resultReturned_SSID";
    wifiConfiguration.BSSID = "testRequestRecommendation_resultReturned_BSSID";
    final RecommendationResult providerResult = RecommendationResult.createConnectRecommendation(wifiConfiguration);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(EXTRA_RECOMMENDATION_RESULT, providerResult);
    doAnswer(invocation -> {
        bundle.putInt(EXTRA_SEQUENCE, invocation.getArgument(2));
        invocation.<IRemoteCallback>getArgument(1).sendResult(bundle);
        return null;
    }).when(mRecommendationProvider).requestRecommendation(eq(mRecommendationRequest), isA(IRemoteCallback.class), anyInt());
    final RecommendationResult result = mNetworkScoreService.requestRecommendation(mRecommendationRequest);
    assertNotNull(result);
    assertEquals(providerResult.getWifiConfiguration().SSID, result.getWifiConfiguration().SSID);
    assertEquals(providerResult.getWifiConfiguration().BSSID, result.getWifiConfiguration().BSSID);
}
Also used : IRemoteCallback(android.os.IRemoteCallback) WifiConfiguration(android.net.wifi.WifiConfiguration) Bundle(android.os.Bundle) RecommendationResult(android.net.RecommendationResult) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Aggregations

RecommendationResult (android.net.RecommendationResult)5 MediumTest (android.support.test.filters.MediumTest)4 Test (org.junit.Test)4 Bundle (android.os.Bundle)2 IRemoteCallback (android.os.IRemoteCallback)2 WifiConfiguration (android.net.wifi.WifiConfiguration)1 RemoteException (android.os.RemoteException)1