package com.akexorcist.knoxkioskapp;

import android.app.enterprise.ApplicationPolicy;
import android.app.enterprise.EnterpriseDeviceManager;
import android.app.enterprise.kioskmode.KioskMode;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

/**
 * Created by Akexorcist on 5/11/16 AD.
 */
public class KIOSKReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null) {
            String action = intent.getAction();
            if (action.equals(KioskMode.ACTION_ENABLE_KIOSK_MODE_RESULT)) {
                // KIOSK enabled
                addApplicationShortcut(context);
            } else if (action.equals(KioskMode.ACTION_DISABLE_KIOSK_MODE_RESULT)) {
                // KIOSK disabled
                removeApplicationShortcut(context);
            } else if (action.equals(KioskMode.ACTION_UNEXPECTED_KIOSK_BEHAVIOR)) {
                // KIOSK unexpected error
            }
        }
    }

    @SuppressWarnings("WrongConstant")


    void addApplicationShortcut(Context context) {
        EnterpriseDeviceManager edm = (EnterpriseDeviceManager) context.getSystemService(EnterpriseDeviceManager.ENTERPRISE_POLICY_SERVICE);
        ApplicationPolicy appPolicy = edm.getApplicationPolicy();
        appPolicy.addHomeShortcut(context.getPackageName(), null);
    }


    @SuppressWarnings("WrongConstant")


    void removeApplicationShortcut(Context context) {
        EnterpriseDeviceManager edm = (EnterpriseDeviceManager)
                context.getSystemService(EnterpriseDeviceManager.ENTERPRISE_POLICY_SERVICE);
        ApplicationPolicy appPolicy = edm.getApplicationPolicy();
        appPolicy.deleteHomeShortcut(context.getPackageName(), null);
    }


}


@@ -1063,34 +1063,32 @@
 WrongConstant%22)%0A
-%0A%0A
     void addAppl
@@ -1403,17 +1403,16 @@
 %0A    %7D%0A%0A
-%0A
     @Sup
@@ -1442,18 +1442,16 @@
 stant%22)%0A
-%0A%0A
     void
@@ -1559,32 +1559,16 @@
 Manager)
-%0A               
  context
@@ -1777,15 +1777,13 @@
 l);%0A
+
     %7D%0A
-%0A%0A
 %7D%0A%0A

Refactor code