Search in sources :

Example 16 with CustomPolicies

use of org.flyve.policies.manager.CustomPolicies in project android-mdm-agent by flyve-mdm.

the class MQTTConnectivityReceiver method onReceive.

/**
 * It is called when it receives information about the state of the connectivity of the WIFI, Bluetooth and GPS
 * @param context in which the receiver is running
 * @param intent being received
 */
@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();
    FlyveLog.d("Connectivity receiver: " + action);
    PoliciesData cache = new PoliciesData(context);
    CustomPolicies customPolicies = new CustomPolicies(context);
    if (action == null) {
        return;
    }
    try {
        // TELEPHONY MANAGER class object to register one listner
        TelephonyManager tmgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        // Create Listener
        CustomPhoneStateListener phoneListener = new CustomPhoneStateListener();
        // Register listener for LISTEN_CALL_STATE
        tmgr.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
    } catch (Exception ex) {
        FlyveLog.e(this.getClass().getName() + ", onReceive", ex.getMessage());
    }
    if (action.contains("USB")) {
        FlyveLog.d("USB Device Attached");
        customPolicies.disableAllUsbFileTransferProtocols(true);
    }
    if ("android.net.conn.CONNECTIVITY_CHANGE".equalsIgnoreCase(action)) {
        FlyveLog.i("is Online: %s", Helpers.isOnline(context));
        // Disable / Enable Roaming
        Boolean policy = Helpers.boolFromString(cache.getValue(RoamingPolicy.POLICY_NAME).value);
        if (policy) {
            customPolicies.disableRoaming(policy);
        }
        // Disable / Enable Mobile line
        policy = Helpers.boolFromString(cache.getValue(MobileLinePolicy.POLICY_NAME).value);
        if (policy) {
            customPolicies.disableMobileLine(policy);
        }
    }
    if ("android.intent.action.AIRPLANE_MODE".equalsIgnoreCase(action)) {
        // Disable / Enable Airplane Mode
        Boolean policy = Helpers.boolFromString(cache.getValue(AirplaneModePolicy.POLICY_NAME).value);
        if (policy) {
            customPolicies.disableAirplaneMode(policy);
        }
    }
    // Manage WIFI
    if ("android.net.wifi.STATE_CHANGE".equalsIgnoreCase(action) || "android.net.wifi.WIFI_STATE_CHANGED".equalsIgnoreCase(action)) {
        FlyveLog.i("is Online: %s", Helpers.isOnline(context));
        // Disable / Enable Hostpot
        Boolean policy = Helpers.boolFromString(cache.getValue(HostpotTetheringPolicy.POLICY_NAME).value);
        if (policy) {
            customPolicies.disableWifi(policy);
        }
        // Disable / Enable Wifi
        policy = Helpers.boolFromString(cache.getValue(WifiPolicy.POLICY_NAME).value);
        if (policy) {
            customPolicies.disableHostpotTethering(policy);
        }
    }
    // Manage Bluetooth
    if ("android.bluetooth.adapter.action.STATE_CHANGED".equalsIgnoreCase(action)) {
        Boolean policy = Helpers.boolFromString(cache.getValue(BluetoothPolicy.POLICY_NAME).value);
        if (policy) {
            customPolicies.disableBluetooth(policy);
        }
    }
    // Manage NFC
    if ("android.nfc.extra.ADAPTER_STATE".equalsIgnoreCase(action)) {
        Boolean policy = Helpers.boolFromString(cache.getValue(NFCPolicy.POLICY_NAME).value);
        if (policy) {
            customPolicies.disableNFC(policy);
        }
    }
    // Manage location
    if ("android.location.PROVIDERS_CHANGED".equalsIgnoreCase(action)) {
        /*
             *  Turn off GPS need system app
             *  To install apk on system/app with adb on root device
             *
             *   -------------------------------------------
             *   $adb shell
             *   $su
             *   $mount -o rw,remount /system
             *   -------------------------------------------
             *
             *   If apk is on external sdcard
             *
             *   # for Android 4.3 or newest
             *   # move the apk to /system/priv-app
             *   mv /storage/sdcard1/file.apk /system/priv-app
             *
             *   # older Android devices
             *   # move apk to /system/app
             *   mv /storage/sdcard1/file.apk /system/app
             *
             *   # change file permission to execute
             *   chmod 644 file.apk
             *
             *   # exit and reboot the device to take change
             *   adb reboot
             */
        boolean disable = Helpers.boolFromString(cache.getValue(GPSPolicy.POLICY_NAME).value);
        customPolicies.disableGps(disable);
        FlyveLog.i("Location providers change: " + disable);
    }
}
Also used : PoliciesData(org.flyve.mdm.agent.data.database.PoliciesData) TelephonyManager(android.telephony.TelephonyManager) CustomPolicies(org.flyve.policies.manager.CustomPolicies)

Example 17 with CustomPolicies

use of org.flyve.policies.manager.CustomPolicies in project android-mdm-agent by flyve-mdm.

the class AirplaneModePolicy method process.

@Override
protected boolean process() {
    try {
        boolean disable = Boolean.parseBoolean(this.policyValue.toString());
        CustomPolicies customPolicies = new CustomPolicies(context);
        customPolicies.disableAirplaneMode(disable);
        return true;
    } catch (Exception ex) {
        FlyveLog.e(this.getClass().getName() + ", process", ex.getMessage());
        return false;
    }
}
Also used : CustomPolicies(org.flyve.policies.manager.CustomPolicies)

Example 18 with CustomPolicies

use of org.flyve.policies.manager.CustomPolicies in project android-mdm-agent by flyve-mdm.

the class GPSPolicy method process.

@Override
protected boolean process() {
    try {
        boolean disable = Boolean.parseBoolean(this.policyValue.toString());
        CustomPolicies customPolicies = new CustomPolicies(context);
        customPolicies.disableGps(disable);
        return true;
    } catch (Exception ex) {
        FlyveLog.e(this.getClass().getName() + ", process", ex.getMessage());
        return false;
    }
}
Also used : CustomPolicies(org.flyve.policies.manager.CustomPolicies)

Example 19 with CustomPolicies

use of org.flyve.policies.manager.CustomPolicies in project android-mdm-agent by flyve-mdm.

the class MobileLinePolicy method process.

@Override
protected boolean process() {
    try {
        boolean disable = Boolean.parseBoolean(this.policyValue.toString());
        CustomPolicies customPolicies = new CustomPolicies(context);
        customPolicies.disableMobileLine(disable);
        return true;
    } catch (Exception ex) {
        FlyveLog.e(this.getClass().getName() + ", process", ex.getMessage());
        return false;
    }
}
Also used : CustomPolicies(org.flyve.policies.manager.CustomPolicies)

Example 20 with CustomPolicies

use of org.flyve.policies.manager.CustomPolicies in project android-mdm-agent by flyve-mdm.

the class StreamAccessibilityPolicy method process.

@Override
protected boolean process() {
    if (Build.VERSION.SDK_INT <= 26) {
        return false;
    }
    try {
        boolean disable = Boolean.parseBoolean(this.policyValue.toString());
        CustomPolicies customPolicies = new CustomPolicies(context);
        customPolicies.disableSounds(AudioManager.STREAM_ACCESSIBILITY, disable);
        return true;
    } catch (Exception ex) {
        FlyveLog.e(this.getClass().getName() + ", process", ex.getMessage());
        return false;
    }
}
Also used : CustomPolicies(org.flyve.policies.manager.CustomPolicies)

Aggregations

CustomPolicies (org.flyve.policies.manager.CustomPolicies)22 PoliciesData (org.flyve.mdm.agent.data.database.PoliciesData)3 Context (android.content.Context)1 TelephonyManager (android.telephony.TelephonyManager)1 View (android.view.View)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1 EditText (android.widget.EditText)1 Switch (android.widget.Switch)1 FlyveAdminReceiver (org.flyve.mdm.agent.receivers.FlyveAdminReceiver)1 StorageFolder (org.flyve.mdm.agent.utils.StorageFolder)1 AndroidPolicies (org.flyve.policies.manager.AndroidPolicies)1