Search in sources :

Example 6 with ContextHubManager

use of android.hardware.location.ContextHubManager 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);
}
Also used : ContextHubManager(android.hardware.location.ContextHubManager) ContextHubInfo(android.hardware.location.ContextHubInfo) NanoAppInstanceInfo(android.hardware.location.NanoAppInstanceInfo) Test(org.junit.Test)

Example 7 with ContextHubManager

use of android.hardware.location.ContextHubManager 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 8 with ContextHubManager

use of android.hardware.location.ContextHubManager in project robolectric by robolectric.

the class ShadowContextHubManagerTest method createClient_returnsValidClient.

@Test
@Config(minSdk = Build.VERSION_CODES.P)
public void createClient_returnsValidClient() {
    ContextHubManager contextHubManager = (ContextHubManager) context.getSystemService(Context.CONTEXTHUB_SERVICE);
    ContextHubClient contextHubClient = contextHubManager.createClient(null, null);
    assertThat(contextHubClient).isNotNull();
}
Also used : ContextHubManager(android.hardware.location.ContextHubManager) ContextHubClient(android.hardware.location.ContextHubClient) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 9 with ContextHubManager

use of android.hardware.location.ContextHubManager 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

ContextHubManager (android.hardware.location.ContextHubManager)9 Test (org.junit.Test)9 ContextHubInfo (android.hardware.location.ContextHubInfo)4 Config (org.robolectric.annotation.Config)4 ContextHubTransaction (android.hardware.location.ContextHubTransaction)2 NanoAppInstanceInfo (android.hardware.location.NanoAppInstanceInfo)2 NanoAppState (android.hardware.location.NanoAppState)2 List (java.util.List)2 ContextHubClient (android.hardware.location.ContextHubClient)1