Search in sources :

Example 1 with ContextHubTransaction

use of android.hardware.location.ContextHubTransaction 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;
}
Also used : ArrayList(java.util.ArrayList) NanoAppState(android.hardware.location.NanoAppState) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ContextHubTransaction(android.hardware.location.ContextHubTransaction) NanoAppInstanceInfo(android.hardware.location.NanoAppInstanceInfo) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 2 with ContextHubTransaction

use of android.hardware.location.ContextHubTransaction 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();
}
Also used : ContextHubManager(android.hardware.location.ContextHubManager) ContextHubInfo(android.hardware.location.ContextHubInfo) List(java.util.List) ContextHubTransaction(android.hardware.location.ContextHubTransaction) NanoAppState(android.hardware.location.NanoAppState) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 3 with ContextHubTransaction

use of android.hardware.location.ContextHubTransaction 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();
}
Also used : ContextHubManager(android.hardware.location.ContextHubManager) ContextHubInfo(android.hardware.location.ContextHubInfo) List(java.util.List) ContextHubTransaction(android.hardware.location.ContextHubTransaction) NanoAppState(android.hardware.location.NanoAppState) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

ContextHubTransaction (android.hardware.location.ContextHubTransaction)3 NanoAppState (android.hardware.location.NanoAppState)3 List (java.util.List)3 ContextHubInfo (android.hardware.location.ContextHubInfo)2 ContextHubManager (android.hardware.location.ContextHubManager)2 Test (org.junit.Test)2 Config (org.robolectric.annotation.Config)2 NanoAppInstanceInfo (android.hardware.location.NanoAppInstanceInfo)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 HiddenApi (org.robolectric.annotation.HiddenApi)1 Implementation (org.robolectric.annotation.Implementation)1