use of android.hardware.location.NanoAppInstanceInfo in project robolectric by robolectric.
the class ShadowContextHubManagerTest method getNanoAppInstanceInfo_noNanoAppsAdded.
@Test
public void getNanoAppInstanceInfo_noNanoAppsAdded() {
ContextHubManager contextHubManager = context.getSystemService(ContextHubManager.class);
NanoAppInstanceInfo info = contextHubManager.getNanoAppInstanceInfo(0);
assertThat(info).isNull();
}
use of android.hardware.location.NanoAppInstanceInfo 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.NanoAppInstanceInfo in project robolectric by robolectric.
the class ShadowContextHubManagerTest method getNanoAppInstanceInfo_returnsValidInfo.
@Test
public void getNanoAppInstanceInfo_returnsValidInfo() {
ContextHubManager contextHubManager = context.getSystemService(ContextHubManager.class);
ShadowContextHubManager shadowManager = Shadow.extract(contextHubManager);
int[] handles = contextHubManager.getContextHubHandles();
ContextHubInfo hubInfo = contextHubManager.getContextHubInfo(handles[0]);
long nanoAppId = 5;
int nanoAppVersion = 1;
int nanoAppUid = 0;
shadowManager.addNanoApp(hubInfo, nanoAppUid, nanoAppId, nanoAppVersion);
NanoAppInstanceInfo info = contextHubManager.getNanoAppInstanceInfo(nanoAppUid);
assertThat(info).isNotNull();
assertThat(info.getAppId()).isEqualTo(nanoAppId);
assertThat(info.getAppVersion()).isEqualTo(nanoAppVersion);
}
use of android.hardware.location.NanoAppInstanceInfo in project robolectric by robolectric.
the class ShadowContextHubManager method addNanoApp.
/**
* Adds a nanoApp to the list of nanoApps that are supported by the provided contexthubinfo.
*/
public void addNanoApp(ContextHubInfo info, int nanoAppUid, long nanoAppId, int nanoAppVersion) {
contextHubToNanoappUid.put(info, nanoAppUid);
NanoAppInstanceInfo instanceInfo = createInstanceInfo(info, nanoAppUid, nanoAppId, nanoAppVersion);
nanoAppUidToInfo.put(nanoAppUid, instanceInfo);
}
use of android.hardware.location.NanoAppInstanceInfo in project robolectric by robolectric.
the class ShadowContextHubManager method createInstanceInfo.
/**
* Creates and returns a {@link NanoAppInstanceInfo}.
*/
public NanoAppInstanceInfo createInstanceInfo(ContextHubInfo info, int nanoAppUid, long nanoAppId, int nanoAppVersion) {
if (VERSION.SDK_INT >= VERSION_CODES.P) {
return new NanoAppInstanceInfo(nanoAppUid, nanoAppId, nanoAppVersion, info.getId());
} else {
NanoAppInstanceInfo instanceInfo = new NanoAppInstanceInfo();
ReflectorNanoAppInstanceInfo reflectedInfo = reflector(ReflectorNanoAppInstanceInfo.class, instanceInfo);
reflectedInfo.setAppId(nanoAppId);
reflectedInfo.setAppVersion(nanoAppVersion);
return instanceInfo;
}
}
Aggregations