use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/**
* MatchingEngine APIs require special user approved permissions to READ_PHONE_STATE and
* one of the following:
* ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION.
*
* The example RequestPermissions utility creates a UI dialog, if needed.
*
* You can do this anywhere, MainApplication.onActivityResumed(), or a subset of permissions
* onResume() on each Activity.
*
* Permissions must exist prior to API usage to avoid SecurityExceptions.
*/
mRpUtil = new RequestPermissions();
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
mLocationRequest = new LocationRequest();
// Restore app's matching engine location preference, defaulting to false:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
PreferenceManager.setDefaultValues(this, R.xml.location_preferences, false);
boolean matchingEngineLocationAllowed = prefs.getBoolean(getResources().getString(R.string.preference_matching_engine_location_verification), false);
// ! [matchingengine_allow_location_usage_gdpr]
MatchingEngine.setMatchingEngineLocationAllowed(matchingEngineLocationAllowed);
// ! [matchingengine_allow_location_usage_gdpr]
// Watch allowed preference:
prefs.registerOnSharedPreferenceChangeListener(this);
// Client side FusedLocation updates.
mDoLocationUpdates = true;
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
automationCloudlet1.setLatitude(50.110922);
automationCloudlet1.setLongitude(8.682127);
automationCloudlet2.setLatitude(53.5511);
automationCloudlet2.setLongitude(9.9937);
// ! [basic_location_handler_example]
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
if (locationResult == null) {
return;
}
String clientLocText = "";
mLastLocationResult = locationResult;
// Post into edgeEvents updater:
me.getEdgeEventsConnectionFuture().thenApply(connection -> {
if (connection != null) {
connection.postLocationUpdate(locationResult.getLastLocation());
}
return null;
});
for (Location location : locationResult.getLocations()) {
// Update UI with client location data
clientLocText += "[" + location.toString() + "]";
}
TextView tv = findViewById(R.id.client_location_content);
tv.setText(clientLocText);
}
};
// ! [basic_location_handler_example]
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
doEnhancedLocationVerification();
}
});
Toolbar myToolbar = findViewById(R.id.toolbar);
setSupportActionBar(myToolbar);
// Open dialog for MobiledgeX MatchingEngine if this is the first time the app is created:
String firstTimeUsePrefKey = getResources().getString(R.string.preference_first_time_use);
boolean firstTimeUse = prefs.getBoolean(firstTimeUsePrefKey, true);
if (firstTimeUse) {
Intent intent = new Intent(this, FirstTimeUseActivity.class);
startActivity(intent);
}
netTest = new NetTest();
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class MatchingEngineUnitTest method testGetQosPositionKpi.
@Test
public void testGetQosPositionKpi() {
Context ctx = getInstrumentation().getTargetContext();
MatchingEngine me = new MatchingEngine(ctx);
me.setMatchingEngineLocationAllowed(true);
me.setAllowSwitchIfNoSubscriberInfo(true);
registerClient(me, ctx);
LocOuterClass.Loc loc = LocOuterClass.Loc.newBuilder().setLongitude(latitude).setLatitude(longitude).build();
List<AppClient.QosPosition> qosPositions = generateQosPositionList(loc, 45, 200, 1);
try {
AppClient.QosPositionRequest request = me.createDefaultQosPositionRequest(qosPositions, lteCategory, bandSelection).build();
ChannelIterator<AppClient.QosPositionKpiReply> responseIterator = me.getQosPositionKpi(request, GRPC_TIMEOUT_MS);
assertTrue("No QosPositionKpi reply", responseIterator.hasNext());
while (responseIterator.hasNext()) {
AppClient.QosPositionKpiReply reply = responseIterator.next();
AppClient.ReplyStatus status = reply.getStatus();
assertEquals("QosPositionKpi reply status is " + status, AppClient.ReplyStatus.RS_SUCCESS, status);
}
} catch (DmeDnsException dde) {
assertTrue("ExecutionException getting app inst list. " + dde.getMessage(), false);
} catch (ExecutionException ee) {
assertTrue("ExecutionException getting app inst list. " + ee.getMessage(), false);
} catch (InterruptedException ie) {
assertTrue("InterruptedException getting app inst list. " + ie.getMessage(), false);
}
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class MatchingEngineUnitTest method testVerifyLocation.
@Test
public void testVerifyLocation() {
Context ctx = getInstrumentation().getTargetContext();
MatchingEngine me = new MatchingEngine(ctx);
me.setMatchingEngineLocationAllowed(true);
me.setAllowSwitchIfNoSubscriberInfo(true);
registerClient(me, ctx);
Location location = new Location("MobiledgeX_Loc_Sim");
location.setLatitude(latitude);
location.setLongitude(longitude);
try {
AppClient.VerifyLocationRequest request = me.createDefaultVerifyLocationRequest(ctx, location).build();
AppClient.VerifyLocationReply reply = me.verifyLocation(request, GRPC_TIMEOUT_MS);
assertTrue("Unable to get VerifyLocation", reply != null);
assertEquals("VerifyLocation Tower status is " + reply.getTowerStatus(), AppClient.VerifyLocationReply.TowerStatus.CONNECTED_TO_SPECIFIED_TOWER, reply.getTowerStatus());
assertEquals("VerifyLocation GPS Location status is " + reply.getGpsLocationStatus(), AppClient.VerifyLocationReply.GPSLocationStatus.LOC_VERIFIED, reply.getGpsLocationStatus());
} catch (DmeDnsException dde) {
assertTrue("DmeDnsException verifying location. " + dde.getMessage(), false);
} catch (ExecutionException ee) {
assertTrue("ExecutionException verifying location. " + ee.getMessage(), false);
} catch (InterruptedException ie) {
assertTrue("InterruptedException verifying location. " + ie.getMessage(), false);
} catch (IOException ioe) {
assertTrue("IOException verifying location. " + ioe.getMessage(), false);
}
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class EngineCallTest method verifyMockedLocationTest_NorthPole.
/**
* Mocked Location test. Note that responsibility of verifying location is in the MatchingEngine
* on the server side, not client side.
*/
@Test
public void verifyMockedLocationTest_NorthPole() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
enableMockLocation(context, true);
Location mockLoc = MockUtils.createLocation("verifyMockedLocationTest_NorthPole", 90d, 1d);
MatchingEngine me = new MatchingEngine(context);
me.setUseWifiOnly(useWifiOnly);
me.setMatchingEngineLocationAllowed(true);
me.setAllowSwitchIfNoSubscriberInfo(true);
AppClient.VerifyLocationReply verifyLocationReply = null;
try {
Location location = getTestLocation(47.6062, 122.3321);
String carrierName = me.retrieveNetworkCarrierName(context);
registerClient(me);
AppClient.VerifyLocationRequest verifyLocationRequest = me.createDefaultVerifyLocationRequest(context, location).setCarrierName(carrierName).build();
if (useHostOverride) {
verifyLocationReply = me.verifyLocation(verifyLocationRequest, hostOverride, portOverride, GRPC_TIMEOUT_MS);
} else {
verifyLocationReply = me.verifyLocation(verifyLocationRequest, GRPC_TIMEOUT_MS);
}
assert (verifyLocationReply != null);
} catch (DmeDnsException dde) {
Log.e(TAG, Log.getStackTraceString(dde));
assertFalse("verifyMockedLocationTest_NorthPole: DmeDnsException", true);
} catch (IOException ioe) {
Log.e(TAG, Log.getStackTraceString(ioe));
assertFalse("verifyMockedLocationTest_NorthPole: IOException!", true);
} catch (ExecutionException ee) {
Log.e(TAG, Log.getStackTraceString(ee));
assertFalse("verifyMockedLocationTest_NorthPole: ExecutionException!", true);
} catch (InterruptedException ie) {
Log.e(TAG, Log.getStackTraceString(ie));
assertFalse("verifyMockedLocationTest_NorthPole: InterruptedException!", true);
}
// Temporary.
assertEquals(0, verifyLocationReply.getVer());
assertEquals(AppClient.VerifyLocationReply.TowerStatus.TOWER_UNKNOWN, verifyLocationReply.getTowerStatus());
// Based on test data.
assertEquals(AppClient.VerifyLocationReply.GPSLocationStatus.LOC_ROAMING_COUNTRY_MATCH, verifyLocationReply.getGpsLocationStatus());
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class EngineCallTest method testRegisterAndFindCloudlet_001.
@Test
public void testRegisterAndFindCloudlet_001() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
MatchingEngine me = new MatchingEngine(context);
me.setUseWifiOnly(useWifiOnly);
me.setMatchingEngineLocationAllowed(true);
me.setAllowSwitchIfNoSubscriberInfo(true);
AppConnectionManager appConnectionManager = me.getAppConnectionManager();
AppClient.RegisterClientReply registerClientReply = null;
String carrierName = "TDG";
String organizationName = "MobiledgeX";
String appName = "HttpEcho";
String appVersion = "20191204";
Socket socket = null;
try {
Location location = getTestLocation(47.6062, 122.3321);
Future<AppClient.FindCloudletReply> findCloudletReplyFuture = me.registerAndFindCloudlet(context, hostOverride, portOverride, organizationName, appName, appVersion, location, "", 0, null, null, // FIXME: These parameters should be overloaded or optional.
null);
// Just wait:
AppClient.FindCloudletReply findCloudletReply = findCloudletReplyFuture.get();
HashMap<Integer, AppPort> appTcpPortMap = appConnectionManager.getTCPMap(findCloudletReply);
AppPort appPort = appTcpPortMap.get(3001);
// There should be at least one for a connection to be made.
assertTrue(appPort != null);
Future<Socket> socketFuture = me.getAppConnectionManager().getTcpSocket(findCloudletReply, appPort, appPort.getPublicPort(), (int) GRPC_TIMEOUT_MS);
socket = socketFuture.get();
assertTrue("FindCloudletReply failed!", findCloudletReply != null);
} catch (ExecutionException ee) {
Log.i(TAG, Log.getStackTraceString(ee));
assertFalse("testRegisterAndFindCloudlet_001: ExecutionException! " + ee.getLocalizedMessage(), true);
} catch (StatusRuntimeException sre) {
Log.i(TAG, Log.getStackTraceString(sre));
assertFalse("testRegisterAndFindCloudlet_001: StatusRuntimeException!", true);
} catch (InterruptedException ie) {
Log.i(TAG, Log.getStackTraceString(ie));
assertFalse("testRegisterAndFindCloudlet_001: InterruptedException!", true);
} finally {
try {
if (socket != null) {
socket.close();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
enableMockLocation(context, false);
}
}
Aggregations