├── settings.gradle ├── knoxActivator ├── gradle.properties ├── libs │ ├── knoxsdk.jar │ └── supportlib.jar ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── akexorcist │ │ │ │ └── knoxactivator │ │ │ │ ├── event │ │ │ │ ├── AdminDeactivatedEvent.java │ │ │ │ ├── LicenseActivatedEvent.java │ │ │ │ └── LicenseActivationFailedEvent.java │ │ │ │ ├── receiver │ │ │ │ ├── KnoxDeviceAdminReceiver.java │ │ │ │ └── KnoxLicenseReceiver.java │ │ │ │ ├── ActivationCallback.java │ │ │ │ └── KnoxActivationManager.java │ │ ├── res │ │ │ └── xml │ │ │ │ └── enterprise_device_admin.xml │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── akexorcist │ │ │ └── knoxactivator │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── akexorcist │ │ └── knoxactivator │ │ └── ApplicationTest.java └── build.gradle ├── app ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable-hdpi │ │ │ │ └── ic_launcher_activation.png │ │ │ ├── drawable-mdpi │ │ │ │ └── ic_launcher_activation.png │ │ │ ├── drawable-xhdpi │ │ │ │ └── ic_launcher_activation.png │ │ │ ├── drawable-xxhdpi │ │ │ │ └── ic_launcher_activation.png │ │ │ ├── drawable-xxxhdpi │ │ │ │ └── ic_launcher_activation.png │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── styles.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── strings.xml │ │ │ └── layout │ │ │ │ ├── activity_activation.xml │ │ │ │ └── activity_do_something.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── akexorcist │ │ │ │ └── knoxactivator │ │ │ │ └── sample │ │ │ │ ├── LicenseKey.java │ │ │ │ ├── DoSomethingActivity.java │ │ │ │ ├── manager │ │ │ │ ├── ToastManager.java │ │ │ │ ├── SharedPreferenceManager.java │ │ │ │ └── DialogManager.java │ │ │ │ └── ActivationActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── akexorcist │ │ │ └── knoxsampleapp │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── akexorcist │ │ └── knoxsampleapp │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── .gitignore ├── gradle.properties ├── maven_push.gradle ├── README.md └── LICENSE /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':knoxActivator' 2 | -------------------------------------------------------------------------------- /knoxActivator/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=KnoxActivator 2 | POM_ARTIFACT_ID=knoxactivator 3 | POM_PACKAGING=aar 4 | -------------------------------------------------------------------------------- /knoxActivator/libs/knoxsdk.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akexorcist/KnoxActivator/HEAD/knoxActivator/libs/knoxsdk.jar -------------------------------------------------------------------------------- /knoxActivator/libs/supportlib.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akexorcist/KnoxActivator/HEAD/knoxActivator/libs/supportlib.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher_activation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akexorcist/KnoxActivator/HEAD/app/src/main/res/drawable-hdpi/ic_launcher_activation.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher_activation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akexorcist/KnoxActivator/HEAD/app/src/main/res/drawable-mdpi/ic_launcher_activation.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher_activation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akexorcist/KnoxActivator/HEAD/app/src/main/res/drawable-xhdpi/ic_launcher_activation.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher_activation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akexorcist/KnoxActivator/HEAD/app/src/main/res/drawable-xxhdpi/ic_launcher_activation.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_launcher_activation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akexorcist/KnoxActivator/HEAD/app/src/main/res/drawable-xxxhdpi/ic_launcher_activation.png -------------------------------------------------------------------------------- /knoxActivator/src/main/java/com/akexorcist/knoxactivator/event/AdminDeactivatedEvent.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator.event; 2 | 3 | /** 4 | * Created by Akexorcist on 4/21/2016 AD. 5 | */ 6 | public class AdminDeactivatedEvent { } 7 | -------------------------------------------------------------------------------- /knoxActivator/src/main/java/com/akexorcist/knoxactivator/event/LicenseActivatedEvent.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator.event; 2 | 3 | /** 4 | * Created by Akexorcist on 4/21/2016 AD. 5 | */ 6 | public class LicenseActivatedEvent { } 7 | -------------------------------------------------------------------------------- /knoxActivator/src/main/res/xml/enterprise_device_admin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /knoxActivator/src/main/java/com/akexorcist/knoxactivator/receiver/KnoxDeviceAdminReceiver.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator.receiver; 2 | 3 | import android.app.admin.DeviceAdminReceiver; 4 | 5 | public class KnoxDeviceAdminReceiver extends DeviceAdminReceiver { 6 | } 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #515151 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/akexorcist/knoxsampleapp/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxsampleapp; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/java/com/akexorcist/knoxactivator/sample/LicenseKey.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator.sample; 2 | 3 | public class LicenseKey { 4 | // TODO Put your SKL key here (Samsung Knox License Key) 5 | public static final String KNOX_LICENSE_KEY = "YOUR_KNOX_LICENSE_KEY"; 6 | 7 | // TODO Put your ELM key here (Backward-compatible key) 8 | public static final String BACKWARD_LICENSE_KEY = "YOUR_BACKWARD_LICENSE_KEY"; 9 | } 10 | -------------------------------------------------------------------------------- /knoxActivator/src/test/java/com/akexorcist/knoxactivator/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/com/akexorcist/knoxsampleapp/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxsampleapp; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 8dp 3 | 4dp 4 | 16dp 5 | 16sp 6 | 12sp 7 | 20sp 8 | 30sp 9 | 10 | -------------------------------------------------------------------------------- /knoxActivator/src/main/java/com/akexorcist/knoxactivator/event/LicenseActivationFailedEvent.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator.event; 2 | 3 | /** 4 | * Created by Akexorcist on 4/21/2016 AD. 5 | */ 6 | public class LicenseActivationFailedEvent { 7 | int errorType; 8 | 9 | public LicenseActivationFailedEvent(int errorType) { 10 | this.errorType = errorType; 11 | } 12 | 13 | public int getErrorType() { 14 | return errorType; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/akexorcist/knoxactivator/sample/DoSomethingActivity.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | public class DoSomethingActivity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_do_something); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /knoxActivator/src/androidTest/java/com/akexorcist/knoxactivator/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /knoxActivator/src/main/java/com/akexorcist/knoxactivator/ActivationCallback.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator; 2 | 3 | /** 4 | * Created by Akexorcist on 4/20/2016 AD. 5 | */ 6 | public interface ActivationCallback { 7 | void onDeviceAdminActivated(); 8 | 9 | void onDeviceAdminActivationCancelled(); 10 | 11 | void onKnoxLicenseActivated(); 12 | 13 | void onBackwardLicenseActivated(); 14 | 15 | void onLicenseActivateFailed(int errorCode, String errorMessage); 16 | } 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | 39 | # Keystore files 40 | *.jks 41 | *.aar 42 | -------------------------------------------------------------------------------- /knoxActivator/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 27 5 | buildToolsVersion "27.0.3" 6 | 7 | defaultConfig { 8 | minSdkVersion 21 9 | targetSdkVersion 27 10 | versionCode 20001 11 | versionName "2.0.1" 12 | } 13 | sourceSets { 14 | main { 15 | manifest.srcFile 'src/main/AndroidManifest.xml' 16 | java.srcDirs = ['src/main/java'] 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | testImplementation 'junit:junit:4.12' 23 | compileOnly files('libs/knoxsdk.jar') 24 | runtimeOnly files('libs/supportlib.jar') 25 | } 26 | 27 | apply from: '../maven_push.gradle' 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/akexorcist/knoxactivator/sample/manager/ToastManager.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator.sample.manager; 2 | 3 | import android.content.Context; 4 | import android.widget.Toast; 5 | 6 | import com.akexorcist.knoxactivator.sample.R; 7 | 8 | 9 | /** 10 | * Created by Akexorcist on 4/22/2016 AD. 11 | */ 12 | public class ToastManager { 13 | public static void showLicenseActivationSuccess(Context context) { 14 | showToast(context, R.string.license_activation_success); 15 | } 16 | 17 | public static void showDeviceAdminActivationSuccess(Context context) { 18 | showToast(context, R.string.device_admin_activation_success); 19 | } 20 | 21 | public static void showToast(Context context, int message) { 22 | Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Applications/ADT/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | -dontwarn com.samsung.** 20 | -keep class com.samsung.** { *; } 21 | -keep interface com.samsung.** { *; } 22 | -keep enum com.samsung.** { *; } 23 | -keepclassmembers class com.samsung.** { *; } 24 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | buildToolsVersion "27.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.akexorcist.knoxactivator.sample" 9 | minSdkVersion 21 10 | targetSdkVersion 27 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled true 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(include: ['*.jar'], dir: 'libs') 24 | testImplementation 'junit:junit:4.12' 25 | implementation('com.android.support:appcompat-v7:27.1.1') { 26 | transitive = true 27 | } 28 | implementation 'com.afollestad.material-dialogs:core:0.9.6.0' 29 | implementation 'com.akexorcist:knoxactivator:2.0.1' 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_activation.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_do_something.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 10 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | VERSION_NAME=2.0.1 16 | VERSION_CODE=020001 17 | GROUP=com.akexorcist 18 | POM_DESCRIPTION=Knox Standard SDK activation wrapper 19 | POM_URL=https://github.com/akexorcist/Android-KnoxActivator 20 | POM_SCM_URL=https://github.com/akexorcist/Android-KnoxActivator 21 | POM_SCM_CONNECTION=scm:git@github.com:akexorcist/Android-KnoxActivator.git 22 | POM_SCM_DEV_CONNECTION=scm:git@github.com:akexorcist/Android-KnoxActivator.git 23 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 24 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 25 | POM_LICENCE_DIST=repo 26 | POM_DEVELOPER_ID=Akexorcist 27 | POM_DEVELOPER_NAME=Somkiat Khitwongwattana 28 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | KNOX Activation Example 3 | Auto license and device admin activation will start immediately 4 | Let\'s do something with Samsung KNOX Standard SDK 5 | Setup Problem 6 | Device Administration is required to enable. Please enable it to use this app. 7 | License Activation Problem 8 | Something wrong while license activation.\n Code : %s (%d) 9 | Device Problem 10 | This device does not support by KNOX Standard SDK. 11 | Cancel 12 | Retry 13 | OK 14 | Device admin activation success 15 | KNOX license activation success 16 | License Activating 17 | Loading… 18 | App may not work properly when disable Device Administration 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/akexorcist/knoxactivator/sample/manager/SharedPreferenceManager.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator.sample.manager; 2 | 3 | import android.content.Context; 4 | 5 | /** 6 | * Created by Akexorcist on 6/9/16 AD. 7 | */ 8 | public class SharedPreferenceManager { 9 | private static final String PREFERENCE_STATE = "preference_state"; 10 | private static final String KEY_KNOX_LICENSE_ACTIVATED = "key_knox_license_activated"; 11 | private static final String KEY_BACKWARD_LICENSE_ACTIVATED = "key_backward_license_activated"; 12 | 13 | public static void setKnoxLicenseActivated(Context context) { 14 | context.getSharedPreferences(PREFERENCE_STATE, Context.MODE_PRIVATE) 15 | .edit() 16 | .putBoolean(KEY_KNOX_LICENSE_ACTIVATED, true) 17 | .apply(); 18 | } 19 | 20 | public static boolean isKnoxLicenseActivated(Context context) { 21 | return context.getSharedPreferences(PREFERENCE_STATE, Context.MODE_PRIVATE) 22 | .getBoolean(KEY_KNOX_LICENSE_ACTIVATED, false); 23 | } 24 | 25 | public static void setBackwardLicenseActivated(Context context) { 26 | context.getSharedPreferences(PREFERENCE_STATE, Context.MODE_PRIVATE) 27 | .edit() 28 | .putBoolean(KEY_BACKWARD_LICENSE_ACTIVATED, true) 29 | .apply(); 30 | } 31 | 32 | public static boolean isBackwardLicenseActivated(Context context) { 33 | return context.getSharedPreferences(PREFERENCE_STATE, Context.MODE_PRIVATE) 34 | .getBoolean(KEY_BACKWARD_LICENSE_ACTIVATED, false); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /maven_push.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven' 2 | apply plugin: 'signing' 3 | 4 | def sonatypeRepositoryUrl 5 | if (isReleaseBuild()) { 6 | println 'RELEASE BUILD' 7 | sonatypeRepositoryUrl = hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL 8 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 9 | } else { 10 | println 'DEBUG BUILD' 11 | sonatypeRepositoryUrl = hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL 12 | : "https://oss.sonatype.org/content/repositories/snapshots/" 13 | } 14 | 15 | def getRepositoryUsername() { 16 | return hasProperty('nexusUsername') ? nexusUsername : "" 17 | } 18 | 19 | def getRepositoryPassword() { 20 | return hasProperty('nexusPassword') ? nexusPassword : "" 21 | } 22 | 23 | afterEvaluate { project -> 24 | uploadArchives { 25 | repositories { 26 | mavenDeployer { 27 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 28 | 29 | pom.artifactId = POM_ARTIFACT_ID 30 | 31 | repository(url: sonatypeRepositoryUrl) { 32 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 33 | } 34 | 35 | pom.project { 36 | name POM_NAME 37 | packaging POM_PACKAGING 38 | description POM_DESCRIPTION 39 | url POM_URL 40 | 41 | scm { 42 | url POM_SCM_URL 43 | connection POM_SCM_CONNECTION 44 | developerConnection POM_SCM_DEV_CONNECTION 45 | } 46 | 47 | licenses { 48 | license { 49 | name POM_LICENCE_NAME 50 | url POM_LICENCE_URL 51 | distribution POM_LICENCE_DIST 52 | } 53 | } 54 | 55 | developers { 56 | developer { 57 | id POM_DEVELOPER_ID 58 | name POM_DEVELOPER_NAME 59 | } 60 | } 61 | } 62 | } 63 | } 64 | } 65 | 66 | signing { 67 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 68 | sign configurations.archives 69 | } 70 | 71 | task androidJavadocs(type: Javadoc) { 72 | source = android.sourceSets.main.java.sourceFiles 73 | } 74 | 75 | task androidJavadocsJar(type: Jar) { 76 | classifier = 'javadoc' 77 | //basename = artifact_id 78 | from androidJavadocs.destinationDir 79 | } 80 | 81 | task androidSourcesJar(type: Jar) { 82 | classifier = 'sources' 83 | //basename = artifact_id 84 | from android.sourceSets.main.java.sourceFiles 85 | } 86 | 87 | artifacts { 88 | //archives packageReleaseJar 89 | archives androidSourcesJar 90 | archives androidJavadocsJar 91 | } 92 | } -------------------------------------------------------------------------------- /knoxActivator/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 8 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /knoxActivator/src/main/java/com/akexorcist/knoxactivator/receiver/KnoxLicenseReceiver.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator.receiver; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.util.Log; 8 | 9 | import com.akexorcist.knoxactivator.BuildConfig; 10 | import com.samsung.android.knox.license.EnterpriseLicenseManager; 11 | 12 | public abstract class KnoxLicenseReceiver extends BroadcastReceiver { 13 | private static final String TAG = KnoxLicenseReceiver.class.getSimpleName(); 14 | public static final int ERROR_DEFAULT = -1; 15 | public static final String ACTION_ELM_LICENSE_STATUS = "edm.intent.action.license.status"; 16 | public static final String ACTION_KLM_LICENSE_STATUS = "edm.intent.action.knox_license.status"; 17 | public static final String EXTRA_KLM_ERROR_CODE = "edm.intent.extra.knox_license.errorcode"; 18 | public static final String EXTRA_ELM_ERROR_CODE = "edm.intent.extra.license.errorcode"; 19 | 20 | @Override 21 | public void onReceive(Context context, Intent intent) { 22 | if (intent != null) { 23 | debugLicenseStatus(intent); 24 | String action = intent.getAction(); 25 | if (EnterpriseLicenseManager.ACTION_LICENSE_STATUS.equalsIgnoreCase(action)) { 26 | checkKnoxResultCode(context, intent); 27 | return; 28 | } else if (ACTION_KLM_LICENSE_STATUS.equalsIgnoreCase(action)) { 29 | checkKlmResultCode(context, intent); 30 | return; 31 | } else if (ACTION_ELM_LICENSE_STATUS.equalsIgnoreCase(action)) { 32 | checkElmResultCode(context, intent); 33 | return; 34 | } 35 | } 36 | onLicenseActivationFailed(context, EnterpriseLicenseManager.ERROR_UNKNOWN); 37 | } 38 | 39 | private void checkKnoxResultCode(Context context, Intent intent) { 40 | int errorCode = intent.getIntExtra(EnterpriseLicenseManager.EXTRA_LICENSE_ERROR_CODE, ERROR_DEFAULT); 41 | if (errorCode == EnterpriseLicenseManager.ERROR_NONE) { 42 | onKnoxLicenseActivated(context); 43 | } else { 44 | onLicenseActivationFailed(context, errorCode); 45 | } 46 | } 47 | 48 | private void checkKlmResultCode(Context context, Intent intent) { 49 | int errorCode = intent.getIntExtra(EXTRA_KLM_ERROR_CODE, ERROR_DEFAULT); 50 | if (errorCode == EnterpriseLicenseManager.ERROR_NONE) { 51 | onKnoxLicenseActivated(context); 52 | } else { 53 | onLicenseActivationFailed(context, errorCode); 54 | } 55 | } 56 | 57 | private void checkElmResultCode(Context context, Intent intent) { 58 | int errorCode = intent.getIntExtra(EXTRA_ELM_ERROR_CODE, ERROR_DEFAULT); 59 | if (errorCode == EnterpriseLicenseManager.ERROR_NONE) { 60 | onBackwardLicenseActivated(context); 61 | } else { 62 | onLicenseActivationFailed(context, errorCode); 63 | } 64 | } 65 | 66 | private void debugLicenseStatus(Intent intent) { 67 | if (BuildConfig.DEBUG) { 68 | Log.d(TAG, String.format("Action : %s", intent.getAction())); 69 | Bundle bundle = intent.getExtras(); 70 | if (bundle != null) { 71 | for (String key : bundle.keySet()) { 72 | Object value = bundle.get(key); 73 | Log.d(TAG, String.format("%s %s (%s)", key, 74 | value != null ? value.toString() : "null", 75 | value != null ? value.getClass().getName() : "")); 76 | } 77 | } 78 | } 79 | } 80 | 81 | public abstract void onKnoxLicenseActivated(Context context); 82 | 83 | public abstract void onBackwardLicenseActivated(Context context); 84 | 85 | public abstract void onLicenseActivationFailed(Context context, int errorCode); 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/java/com/akexorcist/knoxactivator/sample/manager/DialogManager.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator.sample.manager; 2 | 3 | import android.app.Dialog; 4 | import android.content.Context; 5 | import android.support.annotation.NonNull; 6 | 7 | import com.afollestad.materialdialogs.DialogAction; 8 | import com.afollestad.materialdialogs.MaterialDialog; 9 | import com.akexorcist.knoxactivator.sample.R; 10 | 11 | /** 12 | * Created by Akexorcist on 4/22/2016 AD. 13 | */ 14 | public class DialogManager { 15 | public static Dialog showLicenseActivationLoading(Context context) { 16 | return new MaterialDialog.Builder(context) 17 | .title(R.string.license_activation_loading_title) 18 | .content(R.string.license_activation_loading_content) 19 | .progress(true, 0) 20 | .cancelable(false) 21 | .show(); 22 | } 23 | 24 | public static void showDialog(Context context, String title, String content, String positive, String negative, final OnDialogClickListener listener) { 25 | new MaterialDialog.Builder(context) 26 | .title(title) 27 | .content(content) 28 | .positiveText(positive) 29 | .negativeText(negative) 30 | .onPositive(new MaterialDialog.SingleButtonCallback() { 31 | @Override 32 | public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { 33 | if (listener != null) { 34 | listener.onPositiveClick(); 35 | } 36 | } 37 | }) 38 | .onNegative(new MaterialDialog.SingleButtonCallback() { 39 | @Override 40 | public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { 41 | if (listener != null) { 42 | listener.onNegativeClick(); 43 | } 44 | } 45 | }) 46 | .show(); 47 | } 48 | 49 | public static void showDeviceUnsupportedProblem(Context context, final OnDialogClickListener listener) { 50 | new MaterialDialog.Builder(context) 51 | .title(R.string.device_unsupported_title) 52 | .content(R.string.device_unsupported_content) 53 | .neutralText(R.string.ok) 54 | .onNeutral(new MaterialDialog.SingleButtonCallback() { 55 | @Override 56 | public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { 57 | if (listener != null) { 58 | listener.onNeutralClick(); 59 | } 60 | } 61 | }) 62 | .show(); 63 | } 64 | 65 | public static void showDeviceAdminActivationProblem(Context context, OnDialogClickListener listener) { 66 | showDialog(context, 67 | context.getString(R.string.device_admin_cancelled_title), 68 | context.getString(R.string.device_admin_cancelled_content), 69 | context.getString(R.string.retry), 70 | context.getString(R.string.cancel), 71 | listener); 72 | } 73 | 74 | public static void showLicenseActivationProblem(Context context, int errorType, String errorMessage, OnDialogClickListener listener) { 75 | showDialog(context, 76 | context.getString(R.string.license_failed_title), 77 | context.getString(R.string.license_failed_content, errorMessage, errorType), 78 | context.getString(R.string.retry), 79 | context.getString(R.string.cancel), 80 | listener); 81 | } 82 | 83 | public interface OnDialogClickListener { 84 | void onPositiveClick(); 85 | 86 | void onNegativeClick(); 87 | 88 | void onNeutralClick(); 89 | } 90 | 91 | public static class OnDialogClickAdapter implements OnDialogClickListener { 92 | @Override 93 | public void onPositiveClick() { /*....*/ } 94 | 95 | @Override 96 | public void onNegativeClick() { /*....*/ } 97 | 98 | @Override 99 | public void onNeutralClick() { /*....*/ } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /app/src/main/java/com/akexorcist/knoxactivator/sample/ActivationActivity.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator.sample; 2 | 3 | import android.app.Dialog; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.v7.app.AppCompatActivity; 7 | 8 | import com.akexorcist.knoxactivator.ActivationCallback; 9 | import com.akexorcist.knoxactivator.KnoxActivationManager; 10 | import com.akexorcist.knoxactivator.sample.manager.DialogManager; 11 | import com.akexorcist.knoxactivator.sample.manager.SharedPreferenceManager; 12 | import com.akexorcist.knoxactivator.sample.manager.ToastManager; 13 | 14 | public class ActivationActivity extends AppCompatActivity { 15 | private Dialog dialogLoading; 16 | 17 | @Override 18 | public void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_activation); 21 | checkKnoxSdkSupported(); 22 | KnoxActivationManager.getInstance().register(this, activationCallback); 23 | } 24 | 25 | @Override 26 | public void onDestroy() { 27 | super.onDestroy(); 28 | // Unregister activator manager callback 29 | KnoxActivationManager.getInstance().unregister(this); 30 | } 31 | 32 | @Override 33 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 34 | super.onActivityResult(requestCode, resultCode, data); 35 | // Handle activity result from Knox automatically 36 | KnoxActivationManager.getInstance().onActivityResult(requestCode, resultCode, data); 37 | } 38 | 39 | private ActivationCallback activationCallback = new ActivationCallback() { 40 | @Override 41 | public void onDeviceAdminActivated() { 42 | setDeviceAdminActivated(); 43 | } 44 | 45 | @Override 46 | public void onDeviceAdminActivationCancelled() { 47 | showDeviceAdminActivationProblem(); 48 | } 49 | 50 | @Override 51 | public void onKnoxLicenseActivated() { 52 | saveKnoxLicenseActivationStateToSharedPreference(); 53 | if (KnoxActivationManager.getInstance().isLegacySdk()) { 54 | activateBackwardLicense(); 55 | } else { 56 | setLicenseActivationSuccess(); 57 | } 58 | } 59 | 60 | @Override 61 | public void onBackwardLicenseActivated() { 62 | saveBackwardLicenseActivationStateToSharedPreference(); 63 | setLicenseActivationSuccess(); 64 | } 65 | 66 | @Override 67 | public void onLicenseActivateFailed(int errorType, String errorMessage) { 68 | hideLoadingDialog(); 69 | showLicenseActivationProblem(errorType, errorMessage); 70 | } 71 | }; 72 | 73 | private void checkKnoxSdkSupported() { 74 | if (KnoxActivationManager.getInstance().isKnoxSdkSupported()) { 75 | activateDeviceAdmin(); 76 | } else { 77 | showDeviceUnsupportedProblem(); 78 | } 79 | } 80 | 81 | private void activateDeviceAdmin() { 82 | if (KnoxActivationManager.getInstance().isDeviceAdminActivated(this)) { 83 | setDeviceAdminActivated(); 84 | } else { 85 | KnoxActivationManager.getInstance().activateDeviceAdmin(this, null); 86 | } 87 | } 88 | 89 | private void activateKnoxLicense() { 90 | showLoadingDialog(); 91 | if (SharedPreferenceManager.isKnoxLicenseActivated(this)) { 92 | activationCallback.onKnoxLicenseActivated(); 93 | } else { 94 | KnoxActivationManager.getInstance().activateKnoxLicense(this, LicenseKey.KNOX_LICENSE_KEY); 95 | } 96 | } 97 | 98 | private void activateBackwardLicense() { 99 | if (SharedPreferenceManager.isBackwardLicenseActivated(this)) { 100 | activationCallback.onBackwardLicenseActivated(); 101 | } else { 102 | KnoxActivationManager.getInstance().activateBackwardLicense(this, LicenseKey.BACKWARD_LICENSE_KEY); 103 | } 104 | } 105 | 106 | private void setDeviceAdminActivated() { 107 | showDeviceAdminActivationSuccess(); 108 | activateKnoxLicense(); 109 | } 110 | 111 | private void setLicenseActivationSuccess() { 112 | hideLoadingDialog(); 113 | showLicenseActivationSuccess(); 114 | goToDoSomethingActivity(); 115 | } 116 | 117 | private void saveKnoxLicenseActivationStateToSharedPreference() { 118 | SharedPreferenceManager.setKnoxLicenseActivated(this); 119 | } 120 | 121 | private void saveBackwardLicenseActivationStateToSharedPreference() { 122 | SharedPreferenceManager.setBackwardLicenseActivated(this); 123 | } 124 | 125 | private void goToDoSomethingActivity() { 126 | startActivity(new Intent(this, DoSomethingActivity.class)); 127 | finish(); 128 | } 129 | 130 | private void showLicenseActivationSuccess() { 131 | ToastManager.showLicenseActivationSuccess(this); 132 | } 133 | 134 | private void showDeviceAdminActivationSuccess() { 135 | ToastManager.showDeviceAdminActivationSuccess(this); 136 | } 137 | 138 | private void showDeviceUnsupportedProblem() { 139 | DialogManager.showDeviceUnsupportedProblem(this, new DialogManager.OnDialogClickAdapter() { 140 | @Override 141 | public void onNeutralClick() { 142 | finish(); 143 | } 144 | }); 145 | } 146 | 147 | private void showDeviceAdminActivationProblem() { 148 | DialogManager.showDeviceAdminActivationProblem(this, new DialogManager.OnDialogClickAdapter() { 149 | @Override 150 | public void onPositiveClick() { 151 | activateDeviceAdmin(); 152 | } 153 | 154 | @Override 155 | public void onNegativeClick() { 156 | finish(); 157 | } 158 | }); 159 | } 160 | 161 | private void showLicenseActivationProblem(int errorType, String errorMessage) { 162 | DialogManager.showLicenseActivationProblem(this, errorType, errorMessage, new DialogManager.OnDialogClickAdapter() { 163 | @Override 164 | public void onPositiveClick() { 165 | activateKnoxLicense(); 166 | } 167 | 168 | @Override 169 | public void onNegativeClick() { 170 | finish(); 171 | } 172 | }); 173 | } 174 | 175 | private void showLoadingDialog() { 176 | dialogLoading = DialogManager.showLicenseActivationLoading(this); 177 | } 178 | 179 | private void hideLoadingDialog() { 180 | if (dialogLoading != null) { 181 | dialogLoading.dismiss(); 182 | dialogLoading = null; 183 | } 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android-KnoxActivator 2 | Samsung's Knox Standard activation helper library for Android. 3 | 4 | [What's Samsung Knox SDK?](https://seap.samsung.com/license-keys/create/knox-android) 5 | 6 | What's new in v2.0.1 7 | =============================== 8 | Update to Knox SDK v25 with backward-compatible library 9 | 10 | 11 | Download 12 | =============================== 13 | 14 | Maven 15 | ``` 16 | 17 | com.akexorcist 18 | knoxactivator 19 | 2.0.1 20 | 21 | ``` 22 | 23 | Gradle 24 | ```groovy 25 | implementation 'com.akexorcist:knoxactivator:2.0.1' 26 | ``` 27 | 28 | Public Method 29 | =============================== 30 | ```java 31 | // Setup 32 | void register(Context context, ActivationCallback callback) 33 | void unregister(Context context) 34 | void onActivityResult(int requestCode, final int resultCode, Intent data) 35 | 36 | // Activate / Deactivate 37 | void activateDeviceAdmin(Activity activity, String description) 38 | boolean deactivateDeviceAdmin(Context context) 39 | void activateKnoxLicense(Context context, String licenseKey) 40 | void deactivateKnoxLicense(Context context, String licenseKey) 41 | void activateBackwardLicense(Context context, String licenseKey) 42 | 43 | // Status Checking 44 | boolean isDeviceAdminActivated(Context context) 45 | boolean isKnoxSdkSupported() 46 | boolean isMdmApiSupported(int requiredVersion) 47 | boolean isLegacySdk() 48 | ``` 49 | 50 | Usage 51 | =============================== 52 | 53 | ### Setup 54 | Required methods in Activity class for Knox Standard activation 55 | ```java 56 | public class YourActivity extends AppCompatActivity { 57 | 58 | // ... 59 | 60 | @Override 61 | public void onCreate(Bundle savedInstanceState) { 62 | // ... 63 | KnoxActivationManager.getInstance().register(this, activationCallback); 64 | } 65 | 66 | @Override 67 | public void onDestroy() { 68 | // ... 69 | KnoxActivationManager.getInstance().unregister(this); 70 | } 71 | 72 | @Override 73 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 74 | // ... 75 | KnoxActivationManager.getInstance().onActivityResult(requestCode, resultCode, data); 76 | } 77 | } 78 | ``` 79 | 80 | ### Activate & Deactivate method 81 | ```java 82 | // Device Administration 83 | String deviceAdminRequestDescription = "Enable Device Administration is required"; 84 | KnoxActivationManager.getInstance().activateDeviceAdmin(getActivity(), deviceAdminRequestDescription); 85 | KnoxActivationManager.getInstance().deactivateDeviceAdmin(getContext()); 86 | 87 | // Knox SDK 88 | String knoxLicenseKey = "YOUR_KNOX_LICENSE_KEY"; 89 | KnoxActivationManager.getInstance().activateKnoxLicense(getContext(), knoxLicenseKey); 90 | 91 | // Backward-compatible for SDK v2.7 or lower 92 | String backwardLicenseKey = "YOUR_BACKWARD_LICENSE_KEY"; 93 | KnoxActivationManager.getInstance().activateBackwardLicense(getContext(), backwardLicenseKey); 94 | ``` 95 | How to get the license key? 96 | https://seap.samsung.com/license-keys/create/knox-android 97 | 98 | If your app ... 99 | 100 | Only work with Knox SDK v2.8 or higher 101 | - Use only Knox License Key 102 | 103 | All Knox SDK version supporting 104 | - Use Knox license key and Backward-compatible license key 105 | 106 | *Note - Knox SDK version depends on the device.* 107 | 108 | ### Status checking method 109 | Utility methods 110 | ```java 111 | KnoxActivationManager manager = KnoxActivationManager.getInstance(); 112 | 113 | // Is Device Administration activated? 114 | boolean isDeviceAdminActivated = manager.isDeviceAdminActivated(getContext()); 115 | 116 | // Is Knox SDK Supported? 117 | boolean isKnoxSdkSupported = manager.isKnoxSdkSupported(); 118 | 119 | // Is current MDM API version supported? 120 | int sdkVersion = EnterpriseDeviceManager.KNOX_VERSION_CODES.KNOX_2_7; 121 | boolean isMdmApiSupported = manager.isMdmApiSupported(sdkVersion); 122 | 123 | // Is device run on legacy SDK version (deviceVersion <= v2.7) 124 | boolean isLegacySdk = manager.isLegacySdk() 125 | ``` 126 | 127 | ### ActivationCallback 128 | Callback when activate/deactivate method called 129 | ```java 130 | ActivationCallback activationCallback = new ActivationCallback() { 131 | @Override 132 | public void onDeviceAdminActivated() { 133 | // ... 134 | } 135 | 136 | @Override 137 | public void onDeviceAdminActivationCancelled() { 138 | // ... 139 | } 140 | 141 | @Override 142 | public void onKnoxLicenseActivated() { 143 | // ... 144 | } 145 | 146 | @Override 147 | public void onBackwardLicenseActivated() { 148 | // ... 149 | } 150 | 151 | @Override 152 | public void onLicenseActivateFailed(int errorType, String errorMessage) { 153 | // ... 154 | } 155 | }; 156 | ``` 157 | 158 | Migrate from v1 to v2 159 | =========================== 160 | • Change `register()` to `register(Context context)` 161 | 162 | • Move register method from `onStart()` to `onCreate(Bundle savedInstanceState)` 163 | 164 | • Change `unregister()` to `unregister(Context context)` 165 | 166 | • Move unregister method from `onStop()` to `onDestroy()` 167 | 168 | • Change `activeDeviceAdmin(Activity activity)` to `activateDeviceAdmin(Activity activity, String description)`. The description message will display on Device Administration request screen. 169 | 170 | • For SDK v2.8 or higher only : Change `activateLicense(Context context, String licenseKey)` to `activateKnoxLicense(Context context, String licenseKey)` with Knox SDK license key 171 | 172 | • For all SDK version support : You need to activate the both Knox license and backward-compatible license. Activate the Knox license with `activateKnoxLicense(Context context, String licenseKey)` by Knox SDK license key, then active the backward-compatible license key with `activateBackwardLicense(Context context, String licenseKey)` by backward-compatible license kry. 173 | 174 | • No Knox policy required in XML resource anymore. You have to declare as Knox SDK permission with `` in your AndroidManifest.xml. [More detail](https://seap.samsung.com/license-keys/manifest-knox-permissions) 175 | 176 | 177 | ProGuard 178 | =========================== 179 | ``` 180 | # Samsung Knox SDK 181 | -dontwarn com.samsung.** 182 | -keep class com.samsung.** { *; } 183 | -keep interface com.samsung.** { *; } 184 | -keep enum com.samsung.** { *; } 185 | -keepclassmembers class com.samsung.** { *; } 186 | ``` 187 | 188 | Licence 189 | =========================== 190 | Copyright 2018 Akexorcist 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at: 193 | 194 | http://www.apache.org/licenses/LICENSE-2.0 195 | 196 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 197 | -------------------------------------------------------------------------------- /knoxActivator/src/main/java/com/akexorcist/knoxactivator/KnoxActivationManager.java: -------------------------------------------------------------------------------- 1 | package com.akexorcist.knoxactivator; 2 | 3 | import android.app.Activity; 4 | import android.app.admin.DevicePolicyManager; 5 | import android.content.ComponentName; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.content.IntentFilter; 9 | 10 | import com.akexorcist.knoxactivator.receiver.KnoxDeviceAdminReceiver; 11 | import com.akexorcist.knoxactivator.receiver.KnoxLicenseReceiver; 12 | import com.samsung.android.knox.EnterpriseDeviceManager; 13 | import com.samsung.android.knox.license.EnterpriseLicenseManager; 14 | import com.samsung.android.knox.license.KnoxEnterpriseLicenseManager; 15 | 16 | /** 17 | * Created by Akexorcist on 4/20/2016 AD. 18 | */ 19 | 20 | @SuppressWarnings("unused") 21 | public class KnoxActivationManager { 22 | @SuppressWarnings("WeakerAccess") 23 | public static final int REQUEST_CODE_KNOX = 4545; 24 | 25 | private static KnoxActivationManager knoxActivationManager; 26 | 27 | public static KnoxActivationManager getInstance() { 28 | if (knoxActivationManager == null) { 29 | knoxActivationManager = new KnoxActivationManager(); 30 | } 31 | return knoxActivationManager; 32 | } 33 | 34 | private ActivationCallback activationCallback; 35 | 36 | public void register(Context context, ActivationCallback callback) { 37 | this.activationCallback = callback; 38 | IntentFilter intentFilter = new IntentFilter(); 39 | intentFilter.addAction(EnterpriseLicenseManager.ACTION_LICENSE_STATUS); 40 | intentFilter.addAction(KnoxLicenseReceiver.ACTION_ELM_LICENSE_STATUS); 41 | intentFilter.addAction(KnoxLicenseReceiver.ACTION_KLM_LICENSE_STATUS); 42 | context.registerReceiver(knoxLicenseReceiver, intentFilter); 43 | } 44 | 45 | public void unregister(Context context) { 46 | activationCallback = null; 47 | context.unregisterReceiver(knoxLicenseReceiver); 48 | } 49 | 50 | @SuppressWarnings("unused") 51 | public void onActivityResult(int requestCode, final int resultCode, Intent data) { 52 | if (requestCode == REQUEST_CODE_KNOX) { 53 | if (activationCallback != null) { 54 | if (resultCode == Activity.RESULT_OK) { 55 | activationCallback.onDeviceAdminActivated(); 56 | } else if (resultCode == Activity.RESULT_CANCELED) { 57 | activationCallback.onDeviceAdminActivationCancelled(); 58 | } 59 | } 60 | } 61 | } 62 | 63 | public void activateDeviceAdmin(Activity activity, String description) { 64 | ComponentName componentName = new ComponentName(activity, KnoxDeviceAdminReceiver.class); 65 | Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); 66 | intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName); 67 | if (description != null) { 68 | intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, description); 69 | } 70 | activity.startActivityForResult(intent, REQUEST_CODE_KNOX); 71 | } 72 | 73 | @SuppressWarnings("UnusedReturnValue") 74 | public boolean deactivateDeviceAdmin(Context context) { 75 | DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); 76 | if (devicePolicyManager != null) { 77 | ComponentName componentName = new ComponentName(context, KnoxDeviceAdminReceiver.class); 78 | devicePolicyManager.removeActiveAdmin(componentName); 79 | return true; 80 | } 81 | return false; 82 | } 83 | 84 | public void activateKnoxLicense(Context context, String licenseKey) { 85 | KnoxEnterpriseLicenseManager knoxEnterpriseLicenseManager = KnoxEnterpriseLicenseManager.getInstance(context); 86 | knoxEnterpriseLicenseManager.activateLicense(licenseKey); 87 | } 88 | 89 | public void deactivateKnoxLicense(Context context, String licenseKey) { 90 | KnoxEnterpriseLicenseManager knoxEnterpriseLicenseManager = KnoxEnterpriseLicenseManager.getInstance(context); 91 | knoxEnterpriseLicenseManager.deActivateLicense(licenseKey); 92 | } 93 | 94 | public void activateBackwardLicense(Context context, String licenseKey) { 95 | EnterpriseLicenseManager enterpriseLicenseManager = EnterpriseLicenseManager.getInstance(context); 96 | enterpriseLicenseManager.activateLicense(licenseKey); 97 | } 98 | 99 | public boolean isDeviceAdminActivated(Context context) { 100 | DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); 101 | ComponentName componentName = new ComponentName(context, KnoxDeviceAdminReceiver.class); 102 | return devicePolicyManager != null && devicePolicyManager.isAdminActive(componentName); 103 | } 104 | 105 | public boolean isKnoxSdkSupported() { 106 | try { 107 | EnterpriseDeviceManager.getAPILevel(); 108 | return true; 109 | } catch (RuntimeException e) { 110 | e.printStackTrace(); 111 | } 112 | return false; 113 | } 114 | 115 | public boolean isMdmApiSupported(int requiredVersion) { 116 | try { 117 | return EnterpriseDeviceManager.getAPILevel() < requiredVersion; 118 | } catch (RuntimeException e) { 119 | e.printStackTrace(); 120 | } 121 | return false; 122 | } 123 | 124 | public boolean isLegacySdk() { 125 | try { 126 | return EnterpriseDeviceManager.getAPILevel() < EnterpriseDeviceManager.KNOX_VERSION_CODES.KNOX_2_8; 127 | } catch (RuntimeException e) { 128 | e.printStackTrace(); 129 | } 130 | return false; 131 | } 132 | 133 | private KnoxLicenseReceiver knoxLicenseReceiver = new KnoxLicenseReceiver() { 134 | @Override 135 | public void onKnoxLicenseActivated(Context context) { 136 | if (activationCallback != null) { 137 | activationCallback.onKnoxLicenseActivated(); 138 | } 139 | } 140 | 141 | @Override 142 | public void onBackwardLicenseActivated(Context context) { 143 | if (activationCallback != null) { 144 | activationCallback.onBackwardLicenseActivated(); 145 | } 146 | } 147 | 148 | @Override 149 | public void onLicenseActivationFailed(Context context, int errorCode) { 150 | if (activationCallback != null) { 151 | activationCallback.onLicenseActivateFailed(errorCode, getErrorMessage(errorCode)); 152 | } 153 | } 154 | }; 155 | 156 | private String getErrorMessage(int errorCode) { 157 | switch (errorCode) { 158 | case EnterpriseLicenseManager.ERROR_INTERNAL: 159 | return "ERROR_INTERNAL"; 160 | case EnterpriseLicenseManager.ERROR_INTERNAL_SERVER: 161 | return "ERROR_INTERNAL_SERVER"; 162 | case EnterpriseLicenseManager.ERROR_INVALID_LICENSE: 163 | return "ERROR_INVALID_LICENSE"; 164 | case EnterpriseLicenseManager.ERROR_INVALID_PACKAGE_NAME: 165 | return "ERROR_INVALID_PACKAGE_NAME"; 166 | case EnterpriseLicenseManager.ERROR_LICENSE_TERMINATED: 167 | return "ERROR_LICENSE_TERMINATED"; 168 | case EnterpriseLicenseManager.ERROR_NETWORK_DISCONNECTED: 169 | return "ERROR_NETWORK_DISCONNECTED"; 170 | case EnterpriseLicenseManager.ERROR_NETWORK_GENERAL: 171 | return "ERROR_NETWORK_GENERAL"; 172 | case EnterpriseLicenseManager.ERROR_NOT_CURRENT_DATE: 173 | return "ERROR_NOT_CURRENT_DATE"; 174 | case EnterpriseLicenseManager.ERROR_NULL_PARAMS: 175 | return "ERROR_NULL_PARAMS"; 176 | case EnterpriseLicenseManager.ERROR_SIGNATURE_MISMATCH: 177 | return "ERROR_SIGNATURE_MISMATCH"; 178 | case EnterpriseLicenseManager.ERROR_USER_DISAGREES_LICENSE_AGREEMENT: 179 | return "ERROR_USER_DISAGREES_LICENSE_AGREEMENT"; 180 | case EnterpriseLicenseManager.ERROR_VERSION_CODE_MISMATCH: 181 | return "ERROR_VERSION_CODE_MISMATCH"; 182 | case EnterpriseLicenseManager.ERROR_UNKNOWN: 183 | default: 184 | return "ERROR_UNKNOWN"; 185 | } 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------