Git Product home page Git Product logo

rms-sdk-ui-for-android's Introduction

UI Library for Microsoft RMS SDK v4 for Android

The UI Library for Microsoft RMS SDK v4 for Android provides Android Activities that implement the UI required for the SDK functionality. This library is optional and a developer may choose to build their own UI when using Microsoft RMS SDK v4.

##Features

This library provides following Android Activities:

  • EmailActivity: Shows an email address input screen, which is required for RMS operations like protection of files. RMS SDK expects to get the email address of the user who wants to protect data or files to redirect to his organization sign-in portal.
  • PolicyPickerActivity: Shows a policy picker screen, where the user can choose RMS template or specify the permissions to create a policy for protection of data or files.
  • UserPolicyViewerActivity: Shows the permissions that the user has on a RMS protected data or file.

Community Help and Support

We leverage Stack Overflow to work with the community on supporting Azure Active Directory and its SDKs, including this one! We highly recommend you ask your questions on Stack Overflow (we're all on there!) Also browser existing issues to see if someone has had your question before.

We recommend you use the "adal" tag so we can see it! Here is the latest Q&A on Stack Overflow for ADAL: http://stackoverflow.com/questions/tagged/adal

Security Reporting

If you find a security issue with our libraries or services please report it to [email protected] with as much detail as possible. Your submission may be eligible for a bounty through the Microsoft Bounty program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. We encourage you to get notifications of when security incidents occur by visiting this page and subscribing to Security Advisory Alerts.

##Contributing

All code is licensed under MICROSOFT SOFTWARE LICENSE TERMS, MICROSOFT RIGHTS MANAGEMENT SERVICE SDK UI LIBRARIES. We enthusiastically welcome contributions and feedback. You can clone the repo and start contributing now.

How to use this library

Prerequisites

You must have downloaded and/or installed following software

  • Git
  • Android SDK
  • AVD image or device running (API level 15) or higher
  • Eclipse ADT (You may use any IDE, however this guidance assumes use of Eclipse ADT)

###Download

To get the source code of this library via git just type

git clone https://github.com/AzureAD/rms-sdk-ui-for-android.git
cd ./rms-sdk-ui-for-android/src

Setup workspace for msipcsampleapp

Application under ./rms-sdk-ui-for-android/samples/msipcsampleapp demonstrates a sample RMS complaint application that uses RMS SDK v4, this UI library and ADAL. This sample application uses a submodule of ADAL repository. You need to perform following additional steps to get ADAL code via submodule.

cd ./rms-sdk-ui-for-android/external/azure-activedirectory-library-for-android
git submodule init
git submodule update

After that import following projects

  • (com.microsoft.adal) ./rms-sdk-ui-for-android/external/azure-activedirectory-library-for-android/adal
  • (com.microsoft.rightsmanagement) ./rms-sdk-ui-for-android/external/rmssdk/sdk/com/microsoft/rightsmanagement
  • (msipcsampleapp) ./rms-sdk-ui-for-android/samples/msipcsampleapp
  • (uilib) ./rms-sdk-ui-for-android

Note You may be required to add following two libraries to ADAL(com.microsoft.adal) project: android-support-v4.jar and gson.jar. Please select the project and go to Properties->Java Build Path->Libraries->Add External JARs.. and add the required .jar files.

Setting up development environment

To develop your own RMS complaint Android application using RMS SDK V4 please follow these steps.

  1. Download Microsoft RMS SDK v4 for Android from here and setup up your development environment following this guidance. After this step your workspace should at least have two projects (your application project and com.microsoft.rightsmanagement(RMS SDK v4) library project).
  2. Import UI library project (uilib) under ./rms-sdk-ui-for-android/ directory.
  3. Setup ADAL project by following instructions here and import it.
  4. Add library reference of RMS SDK v4 library project to uilib project and your application project.
  5. Add library reference of uilib project to your application project.
  6. Add library reference of ADAL project to your application project.
  7. Add following Activities to your application's AndroidManifest.xml
<activity android:name="com.microsoft.rightsmanagement.ui.EmailActivity"
            android:exported="false"
            android:theme="@style/Overlay"
            android:windowSoftInputMode="stateHidden" />
        
<activity android:name="com.microsoft.rightsmanagement.ui.PolicyPickerActivity"
            android:exported="false"
            android:theme="@style/Overlay"
            android:windowSoftInputMode="stateHidden" />
        
<activity android:name="com.microsoft.rightsmanagement.ui.UserPolicyViewerActivity"
            android:exported="false"
            android:theme="@style/Overlay"
            android:windowSoftInputMode="stateHidden" />

Note For more information about the RMS SDK v4 please visit developer guidance, code examples and API reference.

Using Activities

Each activity provides two static methods

  • show - to take input and start the activity
  • onActivityResult - to process results returned to application's main activity and invoke CompletionCallback.

Following snippets are from PolicyPickerActivity.java

public class PolicyPickerActivity extends FragmentActivity
{
    /**
     * Show UI.
     * 
     * @param requestCode the request code
     * @param parentActivity the activity
     * @param templateDescriptorList the template descriptor list
     * @param originalTemplateDescriptor the original template descriptor
     * @param pickerCompletionCallback the picker completion callback
     * @throws InvalidParameterException the invalid parameter exception
     */
    public static void show(int requestCode,
                            Activity parentActivity,
                            List<TemplateDescriptor> templateDescriptorList,
                            TemplateDescriptor originalTemplateDescriptor,
                            CompletionCallback<PolicyPickerActivityResult> pickerCompletionCallback)
            throws InvalidParameterException
    { 
              ...
    }

    /**
     * Processes the result of PolicyPickerActivity started via startActivityForResult from the parent
     * activity, and invokes the callback supplied to show(). This method must be called from parent Activity's
     * onActivityResult.
     * 
     * @param resultCode the result code parameter as supplied to parent Activity's onActivityResult
     * @param data the data parameter as supplied to parent Activity's onActivityResult
     */
    public static void onActivityResult(int resultCode, Intent data)
    {
    } 
}

Notice show method uses CompletionCallback as one of its parameters

/**
 * The Interface CompletionCallback.
 * Provides callback methods for MSIPC UI Activity completion events.

 * @param <T> the generic type
 */

public interface CompletionCallback<T>
{
	/**
	 * This method is called upon completion of async operation
	 * @param item the created item
	 */
    void onSuccess(T item);
    
    /**
     * This method is called on cancellation.
     */
    void onCancel();
}

For other Activities, please find the following classes: src/com/microsoft/rightsmanagement/ui/EmailActivity.java src/com/microsoft/rightsmanagement/ui/PolicyPickerActivityResult.java

Sample Usage

Sample application included in the repository demonstrates the usage of this library. It is located at samples\MsipcSampleApp. Following are some snippets from the sample application ordered to achieve a following scenario.

Sample Scenario: Publish a file using a RMS template and show UserPolicy.

Step 1 : Receive email input from user by using EmailActivity

CompletionCallback<String> emailActivityCompletionCallback = new CompletionCallback<String>()
        {
            @Override
            public void onCancel()
            {
             
            }

            @Override
            public void onSuccess(String item)
            {
             
                continueMsipcPolicyCreationWithEmailId(item, originalUserPolicy, 
                showUserPolicyViewerOnPolicyCreation, onPolicyCreationCallback);
            }
        };
try
{
    EmailActivity.show(EMAIL_INPUT_REQUEST, getActivity(), emailActivityCompletionCallback);
}
catch (InvalidParameterException e)
{
}

Step 2 : Use user email and get Templates using MSIPC SDK v4

CreationCallback<List<TemplateDescriptor>> getTemplatesCreationCallback = new CreationCallback<List<TemplateDescriptor>>()
        {
            @Override
            public Context getContext()
            {
            }

            @Override
            public void onCancel()
            {
            }

            @Override
            public void onFailure(ProtectionException e)
            {
            }

            @Override
            public void onSuccess(List<TemplateDescriptor> templateDescriptors)
            {
                TemplateDescriptor originalTemplateDescriptor = null;
                if (originalUserPolicy != null && 
                    originalUserPolicy.getType() == UserPolicyType.TemplateBased)
                {
                    originalTemplateDescriptor = originalUserPolicy.getTemplateDescriptor();
                }
                continueMsipcPolicyCreationByPickingAPolicy(templateDescriptors, 
                 originalTemplateDescriptor, showUserPolicyViewerOnPolicyCreation, onPolicyCreationCallback);
            }
        };
        try
        {
             mIAsyncControl = TemplateDescriptor.getTemplates(emailId, mRmsAuthCallback, 
               getTemplatesCreationCallback);
        }
        catch (com.microsoft.rightsmanagement.exceptions.InvalidParameterException e)
        {
         
        } 

Step 3: Use PolicyPickerActivity to show these templates Use list of templates obtained above to call PolicyPickerActivity.Show method to display templates. Notice you can also pass in previously chosen template (originalTemplateDescriptor) for highlighting it.

private void continueMsipcPolicyCreationByPickingAPolicy(List<TemplateDescriptor> templateDescriptors, 
                                                         TemplateDescriptor originalTemplateDescriptor, 
                                                         final boolean showUserPolicyViewerOnPolicyCreation, 
                                                         final Runnable onPolicyCreationCallback)
{
        
CompletionCallback<PolicyPickerActivityResult> policyPickerActivityCompletionCallback = new CompletionCallback<PolicyPickerActivityResult>()
        {
            @Override
            public void onCancel()
            {
                
            }

            @Override
            public void onSuccess(PolicyPickerActivityResult policyPickerResult)
            {
                switch (policyPickerResult.mResultType)
                {
                    case Template:
                        if (policyPickerResult.mTemplateDescriptor == null)
                        {
                            
                        }
                        else
                        {
                            
                        }
                        break;
                   …
                }
            }
        };
        try
        {
            PolicyPickerActivity.show(POLICY_PICK_REQUEST, getActivity(), templateDescriptors,
                    originalTemplateDescriptor, policyPickerActivityCompletionCallback);
        }
        catch (InvalidParameterException e)
        {
        }
}

Step 4: Create UserPolicy from TemplateDescriptor chosen in step 3 using MSIPC SDK v4 API

mIAsyncControl = UserPolicy.create((TemplateDescriptor)selectedDescriptor, mEmailId, 
                                    mRmsAuthCallback,UserPolicyCreationFlags.NONE, null, 
                                    userPolicyCreationCallback);

Step 5: Show chosen policy to user. Notice that you can allow editing of chosen user policy (assuming user has rights to do so).

CompletionCallback<Integer> userPolicyViewerActivityCompletionCallback = new CompletionCallback<Integer>()
        {
            @Override
            public void onCancel()
            {
            }

            @Override
            public void onSuccess(Integer result)
            {
                switch (result)
                {
                    case UserPolicyViewerActivityResult.EDIT_POLICY:
                        startMsipcPolicyCreation(true);
                        break;
                }
            }
        };
        try
        {
            UserPolicy userPolicy = mUserPolicy;
            if (userPolicy != null)
            {
                UserPolicyViewerActivity.show(POLICY_VIEW_REQUEST, getActivity(), userPolicy, 
                   sSupportedRights, 
                   mUserPolicy.isIssuedToOwner() ? UserPolicyViewerActivityRequestOption.EDIT_ALLOWED
                                : UserPolicyViewerActivityRequestOption.NONE,
                   userPolicyViewerActivityCompletionCallback);
            }
        }
        catch (InvalidParameterException e)
        {
        }

Step 6: Add following code to your application MainActivity to handle results from all UI Lib activities

   /**
     * Recieve results from child activity.
     * 
     * @param requestCode the request code
     * @param resultCode the result code
     * @param data the data
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        // handle ADAL results
        if (App.getInstance().getAuthenticationContext() != null)
        {
            App.getInstance().getAuthenticationContext().onActivityResult(requestCode, resultCode, data);
        }
        // handle MSIPC Results
        MsipcTaskFragment.handleMsipcUIActivityResult(requestCode, resultCode, data);
    }
    // Request codes for MSIPC UI Activities
    public static final int EMAIL_INPUT_REQUEST = 0x1;
    public static final int POLICY_VIEW_REQUEST = 0x3;
    public static final int POLICY_PICK_REQUEST = 0x2;
    /**
     * Handle msipc ui activity result.
     * 
     * @param requestCode the request code
     * @param resultCode the result code
     * @param data the data
     */
    public static void handleMsipcUIActivityResult(int requestCode, int resultCode, Intent data)
    {
        // handle MSIPC Results
        switch (requestCode)
        {
            case POLICY_PICK_REQUEST:
                PolicyPickerActivity.onActivityResult(resultCode, data);
                break;
            case POLICY_VIEW_REQUEST:
                UserPolicyViewerActivity.onActivityResult(resultCode, data);
                break;
            case EMAIL_INPUT_REQUEST:
                EmailActivity.onActivityResult(resultCode, data);
                break;
            default:
                // handle invalid request error
        }
    }

We Value and Adhere to the Microsoft Open Source Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

rms-sdk-ui-for-android's People

Contributors

brandwe avatar herveyw-msft avatar kunchawla avatar pomortaz avatar prachiuk avatar raeitan avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rms-sdk-ui-for-android's Issues

NullPointerException after changing device lock

If I use this lib on a device without any device lock (password or pin) it works fine. If I activate device lock after installing and using the app once I get a NullPointerException. If I delete the app's content and try again it works. After I disable device lock the same.

  • Nexus 5, Android 5.1.0
  • Nexus 9, Android 5.0.1

Logcat:

    E/AndroidRuntime(26826): java.lang.RuntimeException: An error occured while executing doInBackground()
    E/AndroidRuntime(26826):    at android.os.AsyncTask$3.done(AsyncTask.java:300)
    E/AndroidRuntime(26826):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
    E/AndroidRuntime(26826):    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
    E/AndroidRuntime(26826):    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    E/AndroidRuntime(26826):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    E/AndroidRuntime(26826):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    E/AndroidRuntime(26826):    at java.lang.Thread.run(Thread.java:818)
    E/AndroidRuntime(26826): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'long com.microsoft.rightsmanagement.utils.SemiSecureClock.getCurrentTimeInMillis()' on a null object reference
    E/AndroidRuntime(26826):    at com.microsoft.rightsmanagement.identity.IdentityStore.getServiceDiscoveryDetails(IdentityStore.java:76)
    E/AndroidRuntime(26826):    at com.microsoft.rightsmanagement.flows.PrivateFlowUtils.getServiceDiscoveryDetails(PrivateFlowUtils.java:57)
    E/AndroidRuntime(26826):    at com.microsoft.rightsmanagement.flows.GetTemplatesFlow.getTemplateArray(GetTemplatesFlow.java:104)
    E/AndroidRuntime(26826):    at com.microsoft.rightsmanagement.flows.GetTemplatesFlow.doInBackground(GetTemplatesFlow.java:73)
    E/AndroidRuntime(26826):    at com.microsoft.rightsmanagement.flows.GetTemplatesFlow.doInBackground(GetTemplatesFlow.java:28)
    E/AndroidRuntime(26826):    at android.os.AsyncTask$2.call(AsyncTask.java:288)
    E/AndroidRuntime(26826):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    E/AndroidRuntime(26826):    ... 3 more

I tried to dig this through and it seems be actually caused by a bad padding exception.

The crash seems to happen in OfflineKeyManagerV2.retreiveOfflineKeyInternal(Context)

    this.mOfflineKey = (SecretKey)wrapCipher.unwrap(wrappedOfflineKeyBlob, "AES", 3);

I'm afraid that the AndroidKeyStore is messing something up.

Android Studio and Maven support

I would much appreciate it if you add all libraries to maven not just ADAL. That would make usage much easier especially with Android Studio, which the new default IDE for Android.

So I only have to add something like

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.microsoft.aad:adal:1.1.1' // <-- This already works
    compile 'com.microsoft.rightsmanagement:rightsmanagement:x.x.x' // <-- That would be new
    compile 'com.microsoft.rightsmanagement:uilib:x.x.x' // <-- That would be new
}

to my build.gradle.

Thank you very much

[Action Needed] This repo is inactive

This GitHub repository has been identified as a candidate for archival

This repository has had no activity in more than [x amount of time]. Long periods of inactivity present security and code hygiene risks. Archiving will not prevent users from viewing or forking the code. A banner will appear on the repository alerting users that the repository is archived.

Please see https://aka.ms/sunsetting-faq to learn more about this process.

Action

✍️

❗**If this repository is still actively maintained, please simply close this issue. Closing an issue on a repository is considered activity and the repository will not be archived.🔒

If you take no action, this repository is still inactive 30 days from today it will be automatically archived..

Need more help? 🖐️

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.