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);
}
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);
}
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());
}
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());
}
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);
}
Aggregations