Search in sources :

Example 1 with NanoAppInstanceInfo

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

Example 2 with NanoAppInstanceInfo

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;
}
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 3 with NanoAppInstanceInfo

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

Example 4 with NanoAppInstanceInfo

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);
}
Also used : NanoAppInstanceInfo(android.hardware.location.NanoAppInstanceInfo)

Example 5 with NanoAppInstanceInfo

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;
    }
}
Also used : NanoAppInstanceInfo(android.hardware.location.NanoAppInstanceInfo)

Aggregations

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