Skip to content

Tutorials 

EdgeMobileClient Android Wrapper

EdgeMobileClient

EdgeMobileClient is a wrapper library for interacting with the mimik edge service on an Android device. This guide provides instructions for integrating mimik edgeEngine functionality into your Android project.
User authentication may be performed using CustomTab web authentication, or in app using various interfaces.

A mimik edge license and client ID is required for use, and may be acquired through the mimik Developer Console, or from mimik support.

Gradle Usage

EdgeMobileClient is available as a gradle library.

Add the following repository to your project-level build.gradle.

allprojects {
    repositories {
        maven {
            url "https://s3-us-west-2.amazonaws.com/mimik-android-repo"
        }
    }
}

For legacy apps, declare the authorization callback registered with mimik developer portal in your module build.gradle.

android {
    defaultConfig {
        // appAuthRedirectScheme may be empty if your app does not require customtab web authorization
        manifestPlaceholders = ["appAuthRedirectScheme": "com.mimik.exampleplayground"]
    }
}

For new apps, declare a blank callback.

android {
    defaultConfig {
        // appAuthRedirectScheme may be empty if your app does not require customtab web authorization
        manifestPlaceholders = ["appAuthRedirectScheme": ""]
    }
}

Then add the dependency to your module build.gradle.

dependencies {
    implementation 'com.mimik.edgesdk-android-client:edgemobileclient-core:0.0.20'
}
(Optional) Application Manifest

If your app will be using CustomTab web authentication, add the EdgeMobileClient intent handler to the application-level AndroidManifest.xml to receive callbacks from mimik identity services

<manifest>
    <application>
        <activity android:name="com.mimik.edgemobileclient.appauth.HandleAuthorizationActivity">
            <intent-filter>
                <action android:name="com.mimik.edgeappauth.appauth.HANDLE_AUTHORIZATION_RESPONSE_EDGE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>
Wrapper Features
  • Check for platform installation
  • Platform startup and shutdown
  • Platform authorization using mimik identity services
  • Microservice deployment and undeployment
  • List of deployed microservices
  • Platform instance information
  • Setting platform log levels
EdgeMobileClient Initialization

Initialize the EdgeMobileClient instance.

final String EDGE_LICENSE = "{edge license provided by mimik support}";

// EdgeConfig uses port 8083 by default
EdgeMobileClient edgeMobileClient = new EdgeMobileClient(getApplicationContext(), new EdgeConfig(BuildConfig.EDGE_LICENSE));

Using a custom port 6699:

EdgeMobileClient edgeMobileClient = new EdgeMobileClient(getApplicationContext(), new EdgeConfig(6699, BuildConfig.EDGE_LICENSE));

Setting a custom log level

EdgeConfig config = new EdgeConfig(BuildConfig.EDGE_LICENSE);
// Valid log values are "trace", "debug", "info", "warn", "err", "critical", "off"
config.setLogLevel("err");
EdgeMobileClient edgeMobileClient = new EdgeMobileClient(getApplicationContext(), config);
Platform Startup

Check if the mimik edge service is installed, and start it if available.

if (edgeMobileClient.startEdge()) {
    // edge service was started and bound successfully
}
Platform Shutdown

Unbind from the mimik edge service. This will not end the process if other applications are still using it.

edgeMobileClient.stopEdge();
Platform Authorization Without User Interaction

For limited edge functionality, user authorization may not be necessary. This can be achieved using developer token login.

First, acquire a developer token from the mimik Developer Console using the Get ID Token button in the your Project Dashboard.

Then use EdgeMobileClient.loginWithDeveloperToken():

String DEVELOPER_TOKEN = "{developer token acquired from developer portal}";
final String APPAUTH_CLIENT_ID = "{client id provided by developer portal}";
final String APPAUTH_ENDPOINT = "{mimik identity service endpoint acquired from developer portal}";

DeveloperTokenLoginConfig config = new DeveloperTokenLoginConfig();
config.setClientId(APPAUTH_CLIENT_ID);
config.setAuthorizationRootUri(APPAUTH_ENDPOINT);
config.setAdditionalScopes(new ArrayList<>());
config.setDeveloperToken(DEVELOPER_TOKEN);
edgeMobileClient.loginWithDeveloperToken(getApplicationContext(), config, new EdgeResponseHandler() {
    @Override
    public void onError(EdgeRequestError edgeRequestError) {
        // There was an error with edge authorization
        Log.d("EdgeResponseHandler", "onError: " + edgeRequestError.getErrorMessage());
    }

    @Override
    public void onResponse(EdgeRequestResponse edgeRequestResponse) {
    // edge service was successfully authorized
    Log.d("MainActivity", "onResponse: " + ((AuthResponse)edgeRequestResponse).getAccessToken();
    }
});

Additional scopes may be required based on supplementary backend functionality and discussions with mimik support.

Platform Authorization With In-App Authentication

Authorization of the mimik edge service using mimik identity services. Authentication using various methods is implemented in-app, instead of in a CustomTab web view.

The following is an example of email passcode verification.

First, request a verification code using an email address:

final String APPAUTH_CLIENT_ID = "{client id provided by developer portal}";
final String APPAUTH_ENDPOINT = "{mimik identity service endpoint acquired from developer portal}";

EmailAuthConfig config = new EmailAuthConfig();
config.setClientId(APPAUTH_CLIENT_ID);
config.setAuthorizationRootUri(APPAUTH_ENDPOINT);
config.setEmail("example@mimik.com");
config.setAdditionalScopes(new ArrayList<>());
edgeMobileClient.requestEmailVerification(
    this,
    config,
    new EdgeResponseHandler() {
        @Override
        public void onError(EdgeRequestError edgeRequestError) {
            // There was an error requesting an email verification code
            Log.d("EdgeResponseHandler", "onError: " + edgeRequestError.getErrorMessage());
        }

        @Override
        public void onResponse(EdgeRequestResponse edgeRequestResponse) {
            // Store the response as an EmailVerificationConfig for later use with a verification code
            mEmailVerificationConfig = new EmailVerificationConfig((CodeAuthResponse)response);
        }
    });

Once the user has received the verification email and entered the binding code:

mEmailVerificationConfig.setBindingCode("{binding code acquired from email}");
mEmailVerificationConfig.setPassword("{password entered by user}");
edgeMobileClient.authorizeWithEmail(
    this,
    mEmailVerificationConfig,
    new EdgeResponseHandler() {
        @Override
        public void onError(EdgeRequestError edgeRequestError) {
            // There was an error with authentication
            Log.d("EdgeResponseHandler", "onError: " + edgeRequestError.getErrorMessage());
        }

        @Override
        public void onResponse(EdgeRequestResponse edgeRequestResponse) {
            // edge service was successfully authorized
            Log.d("EdgeResponseHandler", "onResponse: " + (CombinedAuthResponse)edgeRequestResponse).getMimikTokens().getAccessToken();
        }
    });

If the user has previously created an account, a simple login is used:

EmailLoginConfig config = new EmailLoginConfig();
config.setEmail("example@mimik.com");
config.setPassword("somepassword");
config.setBackendScopes(new ArrayList<>());
edgeMobileClient.loginWithEmail(
    getApplicationContext(),
    config,
    new EdgeResponseHandler() {
        @Override
        public void onError(EdgeRequestError edgeRequestError) {
            // There was an error with authentication
            Log.d("EdgeResponseHandler", "onError: " + edgeRequestError.getErrorMessage());
        }

        @Override
        public void onResponse(EdgeRequestResponse edgeRequestResponse) {
            // edge service was successfully authorized
            Log.d("EdgeResponseHandler", "onResponse: " + (CombinedAuthResponse)edgeRequestResponse).getMimikTokens().getAccessToken();
        }
    });
Platform Authorization With SMS Authentication

The following is an example of Phone SMS passcode verification.

First, request a verification code using an email address:


final String APPAUTH_CLIENT_ID = "{client id provided by developer portal}";
final String APPAUTH_ENDPOINT = "{mimik identity service endpoint acquired from developer portal}";
final String TEST_PHONE_NUMBER = "{some test number}";

PhoneAuthConfig config = new PhoneAuthConfig();
config.setPhoneNumber(TEST_PHONE_NUMBER);
config.setClientId(APPAUTH_CLIENT_ID);
config.setAuthorizationRootUri(APPAUTH_ENDPOINT);
config.setAdditionalScopes(new ArrayList<>());
edgeMobileClient.requestPhoneNumberVerification(
    this,
    config,
    new EdgeResponseHandler() {
        @Override
        public void onError(EdgeRequestError edgeRequestError) {
            // There was an error requesting an SMS verification code
            Log.d("EdgeResponseHandler", "onError: " + edgeRequestError.getErrorMessage());
        }

        @Override
        public void onResponse(EdgeRequestResponse edgeRequestResponse) {
            // Cast edgeRequestResponse to CodeAuthResponse then store 
            // the response as a PhoneVerificationConfig for later use
            // once the SMS has arrived
            mPhoneVerificationConfig = new PhoneVerificationConfig((CodeAuthResponse)response);
        }
    });

Once the user has received the verification message and entered the binding code:

mPhoneVerificationConfig.setBindingCode("{binding code acquired from SMS message}");
edgeMobileClient.authorizeWithPhoneNumber(
    this,
    mPhoneVerificationConfig,
    new EdgeResponseHandler() {
        @Override
        public void onError(EdgeRequestError edgeRequestError) {
            // There was an error with authentication
            Log.d("EdgeResponseHandler", "onError: " + edgeRequestError.getErrorMessage());
        }

        @Override
        public void onResponse(EdgeRequestResponse edgeRequestResponse) {
            // edge service was successfully authorized
            Log.d("EdgeResponseHandler", "onResponse: " + (CombinedAuthResponse)edgeRequestResponse).getMimikTokens().getAccessToken();
        }
    });
Platform Authorization With CustomTab Web Authentication

Authorization of the mimik edge service using mimik identity services. A CustomTab is used to access the web portal, and callbacks are received as intents.

Send an authorization request.

final String APPAUTH_CLIENT_ID = "{client id provided by developer portal}";
final String REDIRECT_URI = "{redirect uri registered with developer portal}";
final String APPAUTH_ENDPOINT = "{mimik identity service endpoint acquired from developer portal}";
final String MIMIK_LOGIN_ACTION = "some.intent.authorization.action";
final int REQUEST_CODE = 1234;

AuthConfig config = new AuthConfig();
config.setAuthorizationRootUri(Uri.parse(APPAUTH_ENDPOINT));
config.setClientId(APPAUTH_CLIENT_ID);
config.setRedirectUri(Uri.parse(REDIRECT_URI));
List<String> additionalScopes = new ArrayList<>();
additionalScopes.add("read:me");
config.setAdditionalScopes(additionalScopes);
Intent postAuthorizationIntent = new Intent(getContext(), this.getClass());
postAuthorizationIntent.setAction(MIMIK_LOGIN_ACTION);
postAuthorizationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), REQUEST_CODE, postAuthorizationIntent, 0);
edgeMobileClient.authorize(getApplicationContext(), config, pendingIntent);

Then handle the callback intent in your activity.

static final String MIMIK_LOGIN_ACTION = "some.intent.authorization.action";

@Override
public void onNewIntent(Intent intent) {
    if (MIMIK_LOGIN_ACTION.equals(intent.getAction())) {
        EdgeRequestStatus<AuthResponse> authRequestStatus
                = EdgeRequestStatus.fromIntent(intent, AuthResponse.class);
        if (authRequestStatus.error != null) {
            // There was an error with authentication
        } else {
            // Authentication was performed successfully
            String accessToken = authRequestStatus.response.getAccessToken();
        }
    }
}
Platform Unauthorization Without CustomTab Web Authentication

Use the clearEdgeData() function.

edgeMobileClient.clearEdgeData();
Platform Unauthorization With CustomTab Web Authentication

Unauthorization of the mimik edge service using mimik identity services. A CustomTab is used to access the web portal, and callbacks are received as intents.

Send an unauthorization request.

final String APPAUTH_ENDPOINT = "https://mid.mimik360.com/";
final String APPAUTH_CLIENT_ID = "{client id provided by developer portal}";
final String REDIRECT_URI = "{redirect uri registered with developer portal}";
final String MIMIK_UNAUTHORIZATION_ACTION = "some.intent.unauthorization.action";
final int REQUEST_CODE = 1234;

AuthConfig config = new AuthConfig();
config.setAuthorizationRootUri(Uri.parse(APPAUTH_ENDPOINT));
config.setClientId(APPAUTH_CLIENT_ID);
config.setRedirectUri(Uri.parse(REDIRECT_URI));
Intent postAuthorizationIntent = new Intent(this, this.getClass());
postAuthorizationIntent.setAction(MIMIK_UNAUTHORIZATION_ACTION);
postAuthorizationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), REQUEST_CODE, postAuthorizationIntent, 0);
edgeMobileClient.authorize(getApplicationContext(), config, pendingIntent);

Then handle the callback intent in your activity.

static final String MIMIK_UNAUTHORIZATION_ACTION= "some.intent.unauthorization.action";

@Override
public void onNewIntent(Intent intent) {
    if (MIMIK_UNAUTHORIZATION_ACTION.equals(intent.getAction())) {
        EdgeRequestStatus<AuthResponse> authRequestStatus
                = EdgeRequestStatus.fromIntent(intent, AuthResponse.class);
        if (authRequestStatus.error != null) {
            // There was an error with unauthorization
        } else {
            // Unauthorization was performed successfully
            String accessToken = authRequestStatus.response.getAccessToken();
        }
    }
}
Deploying Microservices

Microservice deployment requires an access token from the authorization step

The following example uses an InputStream from a raw resource.

MicroserviceDeploymentConfig config = new MicroserviceDeploymentConfig();
config.setName("example-v1");
config.setFilename("example-v1.tar");
config.setResourceStream(getApplicationContext().getResources().openRawResource(R.raw.example_v1));
config.setApiRootUri(Uri.parse("/example/v1"));
Map<String, String> env = new HashMap<>();
env.put("MCM.WEBSOCKET_SUPPORT", "true");
env.put("uMDS", "http://127.0.0.1:8083/mds/v1");
config.setEnvVariables(env);

MicroserviceDeploymentStatus status = edgeMobileClient.deployEdgeMicroservice(accessToken, config);
if (status.error != null) {
    // There was an error deploying the microservice
} else {
    // The microservice was deployed successfully
}
Removing Microservices

Microservice removal requires an access token from the authorization step

MicroserviceDeploymentConfig config = new MicroserviceDeploymentConfig();
config.setName("example-v1");

MicroserviceDeploymentStatus status = edgeMobileClient.removeEdgeMicroservice(accessToken, config);
if (status.error != null) {
    // There was an error removing the microservice
} else {
    // The microservice was removed successfully
}
Listing Deployed Microservices

Listing deployed microservices requires an access token from the authorization step.

// List of microservice images uploaded to edge
List<MicroserviceImage> imageList = edgeMobileClient.getDeployedImages(accessToken);

// List of containerized microservice images running on edge
List<MicroserviceContainer> imageList = edgeMobileClient.getDeployedContainers(accessToken);
Platform Instance Information

Running information from the mimik edge platform. Information is received through an intent.

Send an information request.

final String ACTION_EDGEINFO = "some.intent.info.action";
final int REQUEST_CODE = 12345;

Intent postInfoIntent = new Intent(this, this.getClass());
postInfoIntent.setAction(ACTION_EDGEINFO);
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), /*Arbitrary*/ REQUEST_CODE, postInfoIntent, 0);
mEdgeAppOps.getInfo(pendingIntent);

Then handle the callback intent in your activity.

final String ACTION_EDGEINFO = "some.intent.info.action";

@Override
public void onNewIntent(Intent intent) {
    if (ACTION_EDGEINFO.equals(intent.getAction())) {
        EdgeRequestStatus<EdgeInfoResponse> status = EdgeRequestStatus.fromIntent(intent, EdgeInfoResponse.class);
        if (status.error != null) {
            // There was an error getting the platform information
        } else {
            String nodeId = status.response.getNodeId();
        }
    }
}
Need more help?
Feel free to contact us on Stack Overflow or send us a question via our support page if you have any questions.

Your feedback is important to us ~