use of android.hardware.location.NanoAppState in project robolectric by robolectric.
the class ShadowContextHubManager method queryNanoApps.
@Implementation(minSdk = VERSION_CODES.P)
@HiddenApi
protected Object queryNanoApps(ContextHubInfo hubInfo) {
@SuppressWarnings("unchecked") ContextHubTransaction<List<NanoAppState>> transaction = ReflectionHelpers.callConstructor(ContextHubTransaction.class, ClassParameter.from(int.class, ContextHubTransaction.TYPE_QUERY_NANOAPPS));
Collection<Integer> uids = contextHubToNanoappUid.get(hubInfo);
List<NanoAppState> nanoAppStates = new ArrayList<>();
for (Integer uid : uids) {
NanoAppInstanceInfo info = nanoAppUidToInfo.get(uid);
if (info != null) {
nanoAppStates.add(new NanoAppState(info.getAppId(), info.getAppVersion(), true));
}
}
@SuppressWarnings("unchecked") ContextHubTransaction.Response<List<NanoAppState>> response = ReflectionHelpers.newInstance(ContextHubTransaction.Response.class);
ReflectorContextHubTransactionResponse reflectedResponse = reflector(ReflectorContextHubTransactionResponse.class, response);
reflectedResponse.setResult(ContextHubTransaction.RESULT_SUCCESS);
reflectedResponse.setContents(nanoAppStates);
reflector(ReflectorContextHubTransaction.class, transaction).setResponse(response);
return transaction;
}
use of android.hardware.location.NanoAppState in project robolectric by robolectric.
the class ShadowContextHubManagerTest method queryNanoApps_returnsValidNanoApps.
@Test
@Config(minSdk = Build.VERSION_CODES.P)
public void queryNanoApps_returnsValidNanoApps() throws Exception {
ContextHubManager contextHubManager = context.getSystemService(ContextHubManager.class);
ShadowContextHubManager shadowManager = Shadow.extract(contextHubManager);
List<ContextHubInfo> contextHubInfoList = contextHubManager.getContextHubs();
long nanoAppId = 5;
int nanoAppVersion = 1;
shadowManager.addNanoApp(contextHubInfoList.get(0), 0, /* nanoAppUid */
nanoAppId, nanoAppVersion);
ContextHubTransaction<List<NanoAppState>> transaction = contextHubManager.queryNanoApps(contextHubInfoList.get(0));
assertThat(transaction.getType()).isEqualTo(ContextHubTransaction.TYPE_QUERY_NANOAPPS);
ContextHubTransaction.Response<List<NanoAppState>> response = transaction.waitForResponse(1, SECONDS);
assertThat(response.getResult()).isEqualTo(ContextHubTransaction.RESULT_SUCCESS);
List<NanoAppState> states = response.getContents();
assertThat(states).isNotNull();
assertThat(states).hasSize(1);
NanoAppState state = states.get(0);
assertThat(state.getNanoAppId()).isEqualTo(nanoAppId);
assertThat(state.getNanoAppVersion()).isEqualTo(nanoAppVersion);
assertThat(state.isEnabled()).isTrue();
}
use of android.hardware.location.NanoAppState in project robolectric by robolectric.
the class ShadowContextHubManagerTest method queryNanoApps_noNanoAppsAdded.
@Test
@Config(minSdk = Build.VERSION_CODES.P)
public void queryNanoApps_noNanoAppsAdded() throws Exception {
ContextHubManager contextHubManager = context.getSystemService(ContextHubManager.class);
List<ContextHubInfo> contextHubInfoList = contextHubManager.getContextHubs();
ContextHubTransaction<List<NanoAppState>> transaction = contextHubManager.queryNanoApps(contextHubInfoList.get(0));
assertThat(transaction.getType()).isEqualTo(ContextHubTransaction.TYPE_QUERY_NANOAPPS);
ContextHubTransaction.Response<List<NanoAppState>> response = transaction.waitForResponse(1, SECONDS);
assertThat(response.getResult()).isEqualTo(ContextHubTransaction.RESULT_SUCCESS);
List<NanoAppState> states = response.getContents();
assertThat(states).isNotNull();
assertThat(states).isEmpty();
}
Aggregations