Android App Wrappers

This guide serves as a main documentation that you will need to learn how to use and integrate edgeSDK app wrappers into your Android project.


Main Packages

Note: For edgeSDK integration, user needs to install mimik edge service from Google Play Store; the developer can choose to prompt a redirection to Google Play Store if edgeSDK is not detected upon starting the application.

Hint: There is an edgeSDK detection function under edgeSDK-android-app-ops wrapper.


Installation

  1. Add the mimik Android maven repository to the project gradle.properties file
    
                              allprojects {
                                repositories {
                                  maven {
                                    url "https://s3-us-west-2.amazonaws.com/mimik-android-repo"
                                  }
                                }
                              }
                          

  2. Then add the libraries to the module gradle.properties file
    
                                dependencies {
                                  implementation 'com.mimik.edgesdk-android-client:edgeappops:0.1.13'
                                  implementation 'com.mimik.edgesdk-android-client:edgeappauth:0.1.8'
                                }
                            

  3. Finally, add the mimik authorization handler activity to the application object in AndroidManifest.xml
    
                                <activity android:name="com.mimik.edgeappauth.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>
                            

edgeSDK-android-app-ops wrapper


Usage


Wrapper Initialization

                                      /*
                                      Creates an EdgeAppOps object. The Context parameter is the application context, while the 
                                      EdgeConfig parameter contains the port which the edge service should attach to.
                                      */
                                      EdgeConfig edgeConfig = new EdgeConfig(9999);
                                      EdgeAppOps opsWrapper = new EdgeAppOps(getApplicationContext(), edgeConfig);
                                    

Check edgeSDK Availability

                                        /*
                                        Returns true if the Android OS package manager detects the edge service (com.mimik.edgeservice) is enabled.
                                        */
                                        boolean edgeInstalled = opsWrapper.isPackageInstalled();
                                      

Start edgeSDK

                                        /*
                                        Initializes and starts the edge service. Returns true if the service has been successfully started, or false otherwise.                                        
                                        */
                                        boolean edgeStarted = opsWrapper.startEdge();
                                      

Stop edgeSDK

                                        /*
                                        Attempts to stop the edge service if it has been started. The opsWrapper instance must be the same as the instance 
                                        used to start edge, or this function will do nothing.                                        
                                        */
                                        opsWrapper.stopEdge();
                                      

Get edge service Info

                                              Intent postInfoIntent = new Intent(getApplicationContext(), SomeActivity.class);
                                              postInfoIntent.setAction(SOME_ACTION);
                                              PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), SOME_REQUEST_CODE, postInfoIntent, 0);
                                              opsWrapper.getInfo(pendingCompletionIntent);

                                              /*
                                              Request information about the edge service that is running on the device. 
                                              The PendingIntent parameter defines an intent for the wrapper to send once the information is ready.
                                              Request status will be provided as an extra string in the intent, which can be parsed using the following:
                                              */

                                              protected void onNewIntent(Intent intent) {
                                                if (intent.getAction() != null && intent.getAction().equals(SOME_ACTION)) { // Detect if intent is the one that was passed in getInfo()
                                                  EdgeRequestStatus<EdgeInfoResponse> status = EdgeRequestStatus.fromIntent(intent, EdgeInfoResponse.class);
                                                  if (status.response != null) {
                                                    Log.d(TAG, status.response.toJson()); // Success case
                                                  } else {
                                                    Log.d(TAG, status.error.getErrorMessage()); // Failure case
                                                  }
                                                }
                                              }

                                              /*
                                              The response object contains the following members:
                                              */

                                              EdgeInfoResponse response = status.response;
                                              String accountId = response.getAccountId(); // The currently associated account's accountId
                                              String name = response.getName(); // The name of the device determined by the edge service
                                              String nodeId = response.getNodeId(); // The nodeId of the edge service instance
                                              String version = response.getVersion(); // The version of the edge service                                              
                                            

Report Device Location

                                        /*
                                        Reports a location for the edge service to log. This location will be used for proximity functionality with other edge service nodes.
                                        The String parameter accessToken is a valid accessToken for the account associated with the edge service.
                                        The Location parameter is a standard Android Location object (android.location.Location).
                                        The PendingIntent parameter defines an intent for the wrapper to send once the information is ready.                                       
                                        */
                                        opsWrapper.reportLocation(accessToken, location, pendingCompletionIntent);
                                      

Deploy microservice

                                        /*
                                        Deploys a microservice to the mimik container manager. Deploying a microservice makes it accessible at the endpoint specified in the configuration.                                       
                                        */
                                        MicroserviceDeploymentStatus status = opsWrapper.deployEdgeMicroservice(accessToken, microserviceConfig);
                                      

Remove microservice

                                        /*
                                        Remove a microservice from the mimik container manager. Removing a microservice makes it inaccessible and clears any configuration.
                                        The removed microservice is determined by the name field of the configuration object.                                       
                                        */
                                        MicroserviceDeploymentStatus status = opsWrapper.removeEdgeMicroservice(accessToken, microserviceConfig);
                                      

microservice Configuration

                                                      MicroserviceDeploymentConfig config = new MicroserviceDeploymentConfig();
                                                      config.setName("example"); // Name of the microservice
                                                      config.setFilename("example.tar"); // Filename of the microservice image
                                                      config.setResourceStream(getResources().openRawResource(R.raw.example)); // ResourceStream of the microservice image file
                                                      config.setApiRootUri(Uri.parse("/example")); // Endpoint at which the microservice will be accessible
                                                      Map<String, String> env = new HashMap<>();
                                                      env.put("test_variable", "Hello world!");
                                                      config.setEnvVariables(env); // Map of environment variables made available to the microservice
                                                    

edgeSDK-android-app-auth wrapper


Usage


edge service Authorization

                                                            AuthConfig authConfig = new AuthConfig();
                                                            authConfig.setClientId(CLIENT_ID); // ClientId provided by mimik developer portal
                                                            authConfig.setRedirectUri(REDIRECT_URI); // RedirectUri specified by the developer when registering with the mimik developer portal
                                                            List<String> additionalScopes = new ArrayList<String>();
                                                            additionalScopes.add(SCOPE_GPS);
                                                            authConfig.setAdditionalScopes(additionalScopes); // Additional scopes which provide permission to used certain functionality
                                                            authConfig.setAuthorizationRootUri(BuildConfig.MID_URI); // Root url of the mimik login server
                                                            
                                                            Intent postInfoIntent = new Intent(getApplicationContext(), SomeActivity.class);
                                                            postInfoIntent.setAction(AUTHORIZATION_ACTION);
                                                            PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), SOME_REQUEST_CODE, postInfoIntent, 0);
                                                            EdgeAppAuth.authorize(getApplicationContext(), authConfig, pendingCompletionIntent);

                                                            /*
                                                            Acquire information from the running edge service, request an access token from the mimik login server, and associate the edge service with the account. 
                                                            AuthConfig is a configuration object specifying the mimik login server that will be used. First, a query will be sent to the edge service to acquire 
                                                            information on the instance. This information, will be passed to the login server, along with prompting the user to log in within a CustomTab. 
                                                            If the user logs in and allows access, the edge service will be associated with the user’s account. The access token, along with relevant OpenID
                                                            information, will be returned as an extra field added to the intent defined in the PendingIntent, which can be parsed using the following:
                                                            */

                                                            protected void onNewIntent(Intent intent) {
                                                              if (intent.getAction() != null && intent.getAction().equals(AUTHORIZATION_ACTION)) { // Detect if intent is the one that was passed in authorize()
                                                                EdgeRequestStatus<AuthResponse> status = EdgeRequestStatus.fromIntent(intent, AuthResponse.class);
                                                                if (status.response != null) {
                                                                  Log.d(TAG, status.response.getAccessToken()); // Success case
                                                                } else {
                                                                  Log.d(TAG, status.error.getErrorMessage()); // Failure case
                                                                }
                                                              }
                                                            }
                                                          

edge service Unauthorization

                                                              AuthConfig authConfig = new AuthConfig();
                                                              authConfig.setClientId(CLIENT_ID);
                                                              authConfig.setRedirectUri(REDIRECT_URI);
                                                              authConfig.setAuthorizationRootUri(MID_URI);
                                                              
                                                              Intent postInfoIntent = new Intent(getApplicationContext(), SomeActivity.class);
                                                              postInfoIntent.setAction(UNAUTHORIZATION_ACTION);
                                                              PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), SOME_REQUEST_CODE, postInfoIntent, 0);
                                                              EdgeAppAuth.unauthorize(getApplicationContext, authConfig, pendingCompletionIntent);

                                                              /*
                                                              Acquire information from the running edge service, request an access token from the mimik login server, and unassociate 
                                                              the edge service with the account. This process follows the same procedure as authorization, except it disassociates the
                                                              edge service with the user account.
                                                              */

                                                              protected void onNewIntent(Intent intent) {
                                                                if (intent.getAction() != null && intent.getAction().equals(UNAUTHORIZATION_ACTION)) { // Detect if intent is the one that was passed in authorize()
                                                                  EdgeRequestStatus<AuthResponse> status = EdgeRequestStatus.fromIntent(intent, AuthResponse.class);
                                                                  if (status.response != null) {
                                                                    Log.d(TAG, status.response.getAccessToken()); // Success case
                                                                  } else {
                                                                    Log.d(TAG, status.error.getErrorMessage()); // Failure case
                                                                  }
                                                                }
                                                              }