Search in sources :

Example 6 with PoliciesData

use of org.flyve.mdm.agent.data.database.PoliciesData in project android-mdm-agent by flyve-mdm.

the class FragmentTestPolicies method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_test_policies, container, false);
    cache = new PoliciesData(FragmentTestPolicies.this.getContext());
    mdm = new AndroidPolicies(FragmentTestPolicies.this.getContext(), FlyveAdminReceiver.class);
    customPolicies = new CustomPolicies(FragmentTestPolicies.this.getContext());
    Switch swGPS = v.findViewById(R.id.swGPS);
    swGPS.setChecked(Boolean.parseBoolean(cache.getValue(GPSPolicy.POLICY_NAME).value));
    swGPS.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                customPolicies.disableGps(isChecked);
            }
        }
    });
    Switch swAirplane = v.findViewById(R.id.swAirplane);
    swAirplane.setChecked(Boolean.parseBoolean(cache.getValue(AirplaneModePolicy.POLICY_NAME).value));
    swAirplane.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            customPolicies.disableAirplaneMode(isChecked);
        }
    });
    Switch swBluetooth = v.findViewById(R.id.swBluetooth);
    swBluetooth.setChecked(Boolean.parseBoolean(cache.getValue(BluetoothPolicy.POLICY_NAME).value));
    swBluetooth.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                customPolicies.disableBluetooth(isChecked);
            }
        }
    });
    Switch swWifi = v.findViewById(R.id.swWifi);
    swWifi.setChecked(Boolean.parseBoolean(cache.getValue(WifiPolicy.POLICY_NAME).value));
    swWifi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                customPolicies.disableWifi(isChecked);
            }
        }
    });
    Switch swNFC = v.findViewById(R.id.swNFC);
    swNFC.setChecked(Boolean.parseBoolean(cache.getValue(NFCPolicy.POLICY_NAME).value));
    swNFC.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                customPolicies.disableNFC(isChecked);
            }
        }
    });
    Switch swHostpot = v.findViewById(R.id.swHostpot);
    swHostpot.setChecked(Boolean.parseBoolean(cache.getValue(HostpotTetheringPolicy.POLICY_NAME).value));
    swHostpot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                customPolicies.disableHostpotTethering(isChecked);
            }
        }
    });
    Switch swMobileLine = v.findViewById(R.id.swMobileLine);
    swMobileLine.setChecked(Boolean.parseBoolean(cache.getValue(MobileLinePolicy.POLICY_NAME).value));
    swMobileLine.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                customPolicies.disableMobileLine(isChecked);
            }
        }
    });
    Button btnLock = v.findViewById(R.id.btnLock);
    btnLock.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mdm.lockScreen(LockActivity.class, getContext());
        }
    });
    Switch swDisableCamera = v.findViewById(R.id.swDisableCamera);
    swDisableCamera.setChecked(Boolean.parseBoolean(cache.getValue(CameraPolicy.POLICY_NAME).value));
    swDisableCamera.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mdm.disableCamera(isChecked);
        }
    });
    Switch swStorageEncryptionDevice = v.findViewById(R.id.swStorageEncryptionDevice);
    swStorageEncryptionDevice.setChecked(Boolean.parseBoolean(cache.getValue(StorageEncryptionPolicy.POLICY_NAME).value));
    swStorageEncryptionDevice.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mdm.storageEncryptionDevice(isChecked);
        }
    });
    Button btnReboot = v.findViewById(R.id.btnReboot);
    btnReboot.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mdm.reboot();
        }
    });
    Button btnClearMQTT = v.findViewById(R.id.btnCleatMQTT);
    btnClearMQTT.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                Helpers.deleteMQTTCache(FragmentTestPolicies.this.getContext());
            } catch (Exception ex) {
                FlyveLog.e(this.getClass().getName() + ", onCreateView", ex.getMessage());
            }
        }
    });
    final EditText edtPasswordLength = v.findViewById(R.id.edtPasswordLength);
    final EditText edtPasswordMinimumLetters = v.findViewById(R.id.edtPasswordMinimumLetters);
    final EditText edtPasswordMinimumLowerCase = v.findViewById(R.id.edtPasswordMinimumLowerCase);
    final EditText edtPasswordMinimumUpperCase = v.findViewById(R.id.edtPasswordMinimumUpperCase);
    final EditText edtPasswordMinimumNonLetter = v.findViewById(R.id.edtPasswordMinimumNonLetter);
    final EditText edtPasswordMinimumNumeric = v.findViewById(R.id.edtPasswordMinimumNumeric);
    final EditText edtPasswordMinimumSymbols = v.findViewById(R.id.edtPasswordMinimumSymbols);
    final EditText edtMaximumFailedPasswordsForWipe = v.findViewById(R.id.edtMaximumFailedPasswordsForWipe);
    final EditText edtMaximumTimeToLock = v.findViewById(R.id.edtMaximumTimeToLock);
    Button btnPassword = v.findViewById(R.id.btnPassword);
    btnPassword.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            int minimumLength = Integer.parseInt(edtPasswordLength.getText().toString());
            int minimumLetters = Integer.parseInt(edtPasswordMinimumLetters.getText().toString());
            int minimumUpperCase = Integer.parseInt(edtPasswordMinimumUpperCase.getText().toString());
            int minimumLowerCase = Integer.parseInt(edtPasswordMinimumLowerCase.getText().toString());
            int minimumNonLetter = Integer.parseInt(edtPasswordMinimumNonLetter.getText().toString());
            int minimumNumeric = Integer.parseInt(edtPasswordMinimumNumeric.getText().toString());
            int minimumSymbols = Integer.parseInt(edtPasswordMinimumSymbols.getText().toString());
            int maximumFailedPasswordsForWipe = Integer.parseInt(edtMaximumFailedPasswordsForWipe.getText().toString());
            int maximumTimeToLock = Integer.parseInt(edtMaximumTimeToLock.getText().toString());
            mdm.setPasswordLength(minimumLength);
            mdm.setPasswordMinimumLetters(minimumLetters);
            mdm.setPasswordMinimumUpperCase(minimumUpperCase);
            mdm.setPasswordMinimumLowerCase(minimumLowerCase);
            mdm.setPasswordMinimumNonLetter(minimumNonLetter);
            mdm.setPasswordMinimumNumeric(minimumNumeric);
            mdm.setPasswordMinimumSymbols(minimumSymbols);
            mdm.setMaximumFailedPasswordsForWipe(maximumFailedPasswordsForWipe);
            mdm.setMaximumTimeToLock(maximumTimeToLock);
        }
    });
    Button btnPasswordEnable = v.findViewById(R.id.btnPasswordEnable);
    btnPasswordEnable.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mdm.enablePassword(true, "", MainActivity.class);
        }
    });
    Button btnDownloadFile = v.findViewById(R.id.btnDownloadFile);
    btnDownloadFile.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new Thread(new Runnable() {

                public void run() {
                    // 
                    String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/CHANGELOG.md";
                    FlyveLog.d(path);
                    ConnectionHTTP.getSyncFile("https://raw.githubusercontent.com/flyve-mdm/android-mdm-agent/develop/CHANGELOG.md", path, "", new ConnectionHTTP.ProgressCallback() {

                        @Override
                        public void progress(int value) {
                        }
                    });
                }
            }).start();
        }
    });
    Button btnDownloadAPK = v.findViewById(R.id.btnDownloadAPK);
    btnDownloadAPK.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String path = new StorageFolder(getContext()).getDocumentsDir() + "/flyve-apk.apk";
            FlyveLog.d(path);
            ConnectionHTTP.getSyncFile("https://f-droid.org/repo/org.flyve.inventory.agent_37960.apk", path, "", new ConnectionHTTP.ProgressCallback() {

                @Override
                public void progress(int value) {
                }
            });
        }
    });
    Button btnEnablePassword = v.findViewById(R.id.btnEnablePassword);
    btnEnablePassword.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Helpers.sendToNotificationBar(getContext(), 1009, "MDM Agent", "Please create a new password", true, MainActivity.class, "TestPolicies");
        }
    });
    Button btnInstallSilently = v.findViewById(R.id.btnInstallSilently);
    btnInstallSilently.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String path = new StorageFolder(FragmentTestPolicies.this.getContext()).getDownloadDir() + "/test.apk";
            Helpers.installApkSilently(path);
        }
    });
    return v;
}
Also used : EditText(android.widget.EditText) FlyveAdminReceiver(org.flyve.mdm.agent.receivers.FlyveAdminReceiver) CustomPolicies(org.flyve.policies.manager.CustomPolicies) View(android.view.View) PoliciesData(org.flyve.mdm.agent.data.database.PoliciesData) Switch(android.widget.Switch) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) AndroidPolicies(org.flyve.policies.manager.AndroidPolicies) CompoundButton(android.widget.CompoundButton) StorageFolder(org.flyve.mdm.agent.utils.StorageFolder)

Example 7 with PoliciesData

use of org.flyve.mdm.agent.data.database.PoliciesData in project android-mdm-agent by flyve-mdm.

the class PoliciesAsyncTask method doInBackground.

protected Boolean doInBackground(Object... object) {
    final Context context = (Context) object[0];
    final Integer action = (Integer) object[1];
    final String topic = (String) object[2];
    final String message = (String) object[3];
    mHandler.post(new Runnable() {

        public void run() {
            switch(action) {
                case LOCK:
                    {
                        if (!MDMAgent.isSecureVersion()) {
                            try {
                                JSONObject jsonObj = new JSONObject(message);
                                if (jsonObj.has("lock")) {
                                    String lock = jsonObj.getString("lock");
                                    AndroidPolicies androidPolicies = new AndroidPolicies(context, FlyveAdminReceiver.class);
                                    if (lock.equalsIgnoreCase("now")) {
                                        // lock screen
                                        androidPolicies.lockScreen(LockActivity.class, context);
                                        // lock device
                                        androidPolicies.lockDevice();
                                    } else {
                                        // unlock screen
                                        if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M && Settings.canDrawOverlays(context)) {
                                            try {
                                                MDMAgent mainActivity = ((MDMAgent) context);
                                                mainActivity.getLockActivity().unlockScreen();
                                            } catch (Exception e) {
                                            }
                                        }
                                        // unlock device
                                        androidPolicies.unlockDevice();
                                        Helpers.sendBroadcast("unlock", "org.flyvemdm.finishlock", context);
                                    }
                                }
                            } catch (Exception ex) {
                                FlyveLog.e(this.getClass().getName() + ", LOCK ", ex.getMessage());
                            }
                        }
                    }
                case PING:
                    {
                        String data = "{\"input\":{\"_pong\":\"!\"}}";
                        Routes routes = new Routes(context);
                        MqttData cache = new MqttData(context);
                        String url = routes.pluginFlyvemdmAgent(cache.getAgentId());
                        pluginHttpResponse(context, url, data);
                    }
                    break;
                case WIPE:
                    {
                        if (!MDMAgent.isSecureVersion()) {
                            try {
                                JSONObject jsonObj = new JSONObject(message);
                                if (jsonObj.has("wipe") && "NOW".equalsIgnoreCase(jsonObj.getString("wipe"))) {
                                    sendStatusbyHttp(context, false);
                                    new AndroidPolicies(context, FlyveAdminReceiver.class).wipe();
                                }
                            } catch (Exception ex) {
                                FlyveLog.e(this.getClass().getName() + ", WIPE ", ex.getMessage());
                            }
                        }
                    }
                    break;
                case UNENROLL:
                    {
                        // set offline
                        sendStatusbyHttp(context, false);
                        // Remove all the information
                        new ApplicationData(context).deleteAll();
                        new FileData(context).deleteAll();
                        new MqttData(context).deleteAll();
                        new PoliciesData(context).deleteAll();
                    }
                    break;
                case GEOLOCATE:
                    {
                        FastLocationProvider fastLocationProvider = new FastLocationProvider();
                        Routes routes = new Routes(context);
                        final String url = routes.pluginFlyvemdmGeolocation();
                        boolean isAvailable = fastLocationProvider.getLocation(context, new FastLocationProvider.LocationResult() {

                            @Override
                            public void gotLocation(Location location) {
                                if (location == null) {
                                    FlyveLog.e(this.getClass().getName() + ", sendGPS", "without location yet...");
                                    try {
                                        JSONObject jsonPayload = new JSONObject();
                                        jsonPayload.put("_datetime", Helpers.getUnixTime(context));
                                        jsonPayload.put("_agents_id", new MqttData(context).getAgentId());
                                        jsonPayload.put("computers_id", new MqttData(context).getComputersId());
                                        jsonPayload.put("_gps", "off");
                                        JSONObject jsonInput = new JSONObject();
                                        jsonInput.put("input", jsonPayload);
                                        String payload = jsonInput.toString();
                                        pluginHttpResponse(context, url, payload);
                                    } catch (Exception ex) {
                                        Helpers.storeLog("fcm", "Error on GPS location", ex.getMessage());
                                    }
                                } else {
                                    try {
                                        String latitude = String.valueOf(location.getLatitude());
                                        String longitude = String.valueOf(location.getLongitude());
                                        // "{"input":{"_agents_id":":id","_datetime":":string","latitude":":float","longitude":":float"}}"
                                        JSONObject jsonGPS = new JSONObject();
                                        jsonGPS.put("latitude", latitude);
                                        jsonGPS.put("longitude", longitude);
                                        jsonGPS.put("_datetime", Helpers.getUnixTime(context));
                                        jsonGPS.put("_agents_id", new MqttData(context).getAgentId());
                                        jsonGPS.put("computers_id", new MqttData(context).getComputersId());
                                        JSONObject jsonInput = new JSONObject();
                                        jsonInput.put("input", jsonGPS);
                                        String payload = jsonInput.toString();
                                        pluginHttpResponse(context, url, payload);
                                    } catch (Exception ex) {
                                        FlyveLog.e(this.getClass().getName() + ", sendGPS", ex.getMessage());
                                        Helpers.storeLog("fcm", "Error on GPS location", ex.getMessage());
                                    }
                                }
                            }
                        });
                        if (!isAvailable) {
                            try {
                                JSONObject jsonPayload = new JSONObject();
                                jsonPayload.put("_datetime", Helpers.getUnixTime(context));
                                jsonPayload.put("_agents_id", new MqttData(context).getAgentId());
                                jsonPayload.put("_gps", "off");
                                jsonPayload.put("computers_id", new MqttData(context).getComputersId());
                                JSONObject jsonInput = new JSONObject();
                                jsonInput.put("input", jsonPayload);
                                String payload = jsonInput.toString();
                                pluginHttpResponse(context, url, payload);
                            } catch (Exception ex) {
                                Helpers.storeLog("fcm", "Error on GPS location", ex.getMessage());
                            }
                        }
                    }
                    break;
                case INVENTORY:
                    {
                        Inventory inventory = new Inventory();
                        inventory.getXMLInventory(context, new InventoryTask.OnTaskCompleted() {

                            @Override
                            public void onTaskSuccess(String s) {
                                Routes routes = new Routes(context);
                                MqttData cache = new MqttData(context);
                                String url = routes.pluginFlyvemdmAgent(cache.getAgentId());
                                try {
                                    JSONObject jsonPayload = new JSONObject();
                                    jsonPayload.put("_inventory", Helpers.base64encode(s));
                                    JSONObject jsonInput = new JSONObject();
                                    jsonInput.put("input", jsonPayload);
                                    String payload = jsonInput.toString();
                                    pluginHttpResponse(context, url, payload);
                                    Helpers.storeLog("fcm", "Inventory", "Inventory Send");
                                } catch (Exception ex) {
                                    Helpers.storeLog("fcm", "Error on json createInventory", ex.getMessage());
                                }
                            }

                            @Override
                            public void onTaskError(Throwable throwable) {
                                Helpers.storeLog("fcm", "Error on createInventory", throwable.getMessage());
                            }
                        });
                    }
                case POLICIES:
                    {
                        // Policy/passwordEnabled
                        callPolicy(context, PasswordEnablePolicy.class, PasswordEnablePolicy.POLICY_NAME, priority, topic, message);
                        // Policy/passwordQuality
                        callPolicy(context, PasswordQualityPolicy.class, PasswordQualityPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/passwordMinLength
                        callPolicy(context, PasswordMinLengthPolicy.class, PasswordMinLengthPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/passwordMinLowerCase
                        callPolicy(context, PasswordMinLowerCasePolicy.class, PasswordMinLowerCasePolicy.POLICY_NAME, priority, topic, message);
                        // Policy/passwordMinUpperCase
                        callPolicy(context, PasswordMinUpperCasePolicy.class, PasswordMinUpperCasePolicy.POLICY_NAME, priority, topic, message);
                        // Policy/passwordMinNonLetter
                        callPolicy(context, PasswordMinNonLetterPolicy.class, PasswordMinNonLetterPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/passwordMinLetters
                        callPolicy(context, PasswordMinLetterPolicy.class, PasswordMinLetterPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/passwordMinNumeric
                        callPolicy(context, PasswordMinNumericPolicy.class, PasswordMinNumericPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/passwordMinSymbols
                        callPolicy(context, PasswordMinSymbolsPolicy.class, PasswordMinSymbolsPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/MaximumFailedPasswordsForWipe
                        callPolicy(context, MaximumFailedPasswordForWipePolicy.class, MaximumFailedPasswordForWipePolicy.POLICY_NAME, priority, topic, message);
                        // Policy/MaximumTimeToLock
                        callPolicy(context, MaximumTimeToLockPolicy.class, MaximumTimeToLockPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/storageEncryption
                        callPolicy(context, StorageEncryptionPolicy.class, StorageEncryptionPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableCamera
                        callPolicy(context, CameraPolicy.class, CameraPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableBluetooth
                        callPolicy(context, BluetoothPolicy.class, BluetoothPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableHostpotTethering
                        callPolicy(context, HostpotTetheringPolicy.class, HostpotTetheringPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableRoaming
                        callPolicy(context, RoamingPolicy.class, RoamingPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableWifi
                        callPolicy(context, WifiPolicy.class, WifiPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableSpeakerphone
                        callPolicy(context, SpeakerphonePolicy.class, SpeakerphonePolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableCreateVpnProfiles
                        callPolicy(context, VPNPolicy.class, VPNPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableStreamMusic
                        callPolicy(context, StreamMusicPolicy.class, StreamMusicPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableStreamRing
                        callPolicy(context, StreamRingPolicy.class, StreamRingPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableStreamAlarm
                        callPolicy(context, StreamAlarmPolicy.class, StreamAlarmPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableStreamNotification
                        callPolicy(context, StreamNotificationPolicy.class, StreamNotificationPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableStreamAccessibility
                        callPolicy(context, StreamAccessibilityPolicy.class, StreamAccessibilityPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableStreamVoiceCall
                        callPolicy(context, StreamVoiceCallPolicy.class, StreamVoiceCallPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableStreamDTMF
                        callPolicy(context, StreamVoiceCallPolicy.class, StreamVoiceCallPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableScreenCapture
                        // ROOT REQUIRED
                        callPolicy(context, ScreenCapturePolicy.class, ScreenCapturePolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableAirplaneMode
                        // ROOT REQUIRED
                        callPolicy(context, AirplaneModePolicy.class, AirplaneModePolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableGPS
                        // ROOT REQUIRED
                        callPolicy(context, GPSPolicy.class, GPSPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableMobileLine
                        // ROOT
                        callPolicy(context, MobileLinePolicy.class, MobileLinePolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableNfc
                        // ROOT
                        callPolicy(context, NFCPolicy.class, NFCPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableStatusBar
                        // ROOT
                        callPolicy(context, StatusBarPolicy.class, StatusBarPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableUsbMtp
                        // ROOT
                        callPolicy(context, UsbMtpPolicy.class, UsbMtpPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableUsbPtp
                        // ROOT
                        callPolicy(context, UsbPtpPolicy.class, UsbPtpPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/disableUsbAdb
                        // ROOT
                        callPolicy(context, UsbAdbPolicy.class, UsbAdbPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/deployApp
                        // ROOT
                        callPolicy(context, DeployAppPolicy.class, DeployAppPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/removeApp
                        // ROOT
                        callPolicy(context, RemoveAppPolicy.class, RemoveAppPolicy.POLICY_NAME, priority, topic, message);
                        // Policy/deployFile
                        // ROOT
                        callPolicy(context, DeployFilePolicy.class, DeployFilePolicy.POLICY_NAME, priority, topic, message);
                        // Policy/removeFile
                        // ROOT
                        callPolicy(context, RemoveFilePolicy.class, RemoveFilePolicy.POLICY_NAME, priority, topic, message);
                    }
                    break;
                default:
            }
        }
    });
    return true;
}
Also used : Context(android.content.Context) MqttData(org.flyve.mdm.agent.data.database.MqttData) MDMAgent(org.flyve.mdm.agent.ui.MDMAgent) FlyveAdminReceiver(org.flyve.mdm.agent.receivers.FlyveAdminReceiver) ApplicationData(org.flyve.mdm.agent.data.database.ApplicationData) Routes(org.flyve.mdm.agent.core.Routes) PoliciesData(org.flyve.mdm.agent.data.database.PoliciesData) InventoryTask(org.flyve.inventory.InventoryTask) JSONObject(org.json.JSONObject) FastLocationProvider(org.flyve.mdm.agent.utils.FastLocationProvider) AndroidPolicies(org.flyve.policies.manager.AndroidPolicies) FileData(org.flyve.mdm.agent.data.database.FileData) Inventory(org.flyve.mdm.agent.utils.Inventory) Location(android.location.Location)

Example 8 with PoliciesData

use of org.flyve.mdm.agent.data.database.PoliciesData 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 9 with PoliciesData

use of org.flyve.mdm.agent.data.database.PoliciesData in project android-mdm-agent by flyve-mdm.

the class ApplicationsAdapter method getView.

/**
 * Get a View that displays the data at the specified position
 * @param position of the item within the adapter's data set of the item whose View we want
 * @param convertView the old View to reuse, if possible
 * @param parent the parent that this View will eventually be attached to
 * @return View a View corresponding to the data at the specified position
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View vi = inflater.inflate(R.layout.list_item_application, null);
    final Application app;
    try {
        app = data[position];
    } catch (Exception ex) {
        FlyveLog.e(this.getClass().getName() + ", getView", ex.getMessage());
        return vi;
    }
    TextView txtStatus = vi.findViewById(R.id.txtStatus);
    ImageButton img_trash = vi.findViewById(R.id.btnUninstall);
    String status = "";
    if (Helpers.isPackageInstalled(parent.getContext(), app.appPackage)) {
        try {
            PackageManager pm = parent.getContext().getPackageManager();
            PackageInfo packageInfo = pm.getPackageInfo(app.appPackage, 0);
            if (Integer.parseInt(app.appVersionCode) > packageInfo.versionCode) {
                status = parent.getResources().getString(R.string.app_ready_to_update);
                img_trash.setVisibility(View.GONE);
            } else {
                status = parent.getResources().getString(R.string.app_installed);
                // for this app if we have removeApp policies
                Policies policies = new PoliciesData(this.context).getByTaskId(app.taskId);
                if (policies.policyName.equalsIgnoreCase("removeApp")) {
                    status = parent.getResources().getString(R.string.app_need_to_be_uninstall);
                    img_trash.setVisibility(View.VISIBLE);
                    // on click  start activity to uninstall app
                    img_trash.setOnClickListener(new ImageButton.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent();
                            String mPackage = app.appPackage;
                            if (Build.VERSION.SDK_INT < 14) {
                                intent.setAction(Intent.ACTION_DELETE);
                                // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.setDataAndType(Uri.parse("package:" + mPackage), "application/vnd.android.package-archive");
                            } else if (Build.VERSION.SDK_INT < 16) {
                                intent.setAction(Intent.ACTION_UNINSTALL_PACKAGE);
                                intent.setData(Uri.parse("package:" + mPackage));
                                // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
                                intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
                                intent.putExtra(Intent.EXTRA_ALLOW_REPLACE, true);
                            } else if (Build.VERSION.SDK_INT < 24) {
                                intent.setAction(Intent.ACTION_UNINSTALL_PACKAGE);
                                intent.setData(Uri.parse("package:" + mPackage));
                                // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
                                intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
                            } else {
                                // Android N
                                intent.setAction(Intent.ACTION_UNINSTALL_PACKAGE);
                                intent.setData(Uri.parse("package:" + mPackage));
                                // grant READ permission for this content Uri
                                // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
                                intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
                            }
                            try {
                                v.getContext().startActivity(intent);
                            } catch (ActivityNotFoundException e) {
                                FlyveLog.e(this.getClass().getName() + ", un	installApk", e.getMessage());
                            }
                        }
                    });
                } else {
                    img_trash.setVisibility(View.GONE);
                }
            }
        } catch (Exception ex) {
            FlyveLog.e(this.getClass().getName() + ", getView", ex.getMessage());
        }
    } else {
        status = parent.getResources().getString(R.string.app_not_installed);
        Policies policies = new PoliciesData(this.context).getByTaskId(app.taskId);
        if (policies.policyName.equalsIgnoreCase("deployApp")) {
            status = parent.getResources().getString(R.string.app_pending_to_install);
        }
        img_trash.setVisibility(View.GONE);
    }
    txtStatus.setText(status);
    TextView txtAppName = vi.findViewById(R.id.txtAppName);
    txtAppName.setText(app.appName);
    TextView txtPackageName = vi.findViewById(R.id.txtPackageName);
    txtPackageName.setText(app.appPackage);
    TextView txtVersionCode = vi.findViewById(R.id.txtVersionCode);
    txtVersionCode.setText(parent.getContext().getString(R.string.version_code, app.appVersionCode));
    TextView txtVersionName = vi.findViewById(R.id.txtVersionName);
    txtVersionName.setText(parent.getContext().getString(R.string.version_name, app.appVersionName));
    ImageView imgApp = vi.findViewById(R.id.imgApp);
    imgApp.setImageDrawable(Helpers.getApplicationImage(parent.getContext(), app.appPackage));
    return vi;
}
Also used : Policies(org.flyve.mdm.agent.data.database.entity.Policies) FragmentPolicies(org.flyve.mdm.agent.ui.FragmentPolicies) PackageInfo(android.content.pm.PackageInfo) Intent(android.content.Intent) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ActivityNotFoundException(android.content.ActivityNotFoundException) PoliciesData(org.flyve.mdm.agent.data.database.PoliciesData) ImageButton(android.widget.ImageButton) PackageManager(android.content.pm.PackageManager) ActivityNotFoundException(android.content.ActivityNotFoundException) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Application(org.flyve.mdm.agent.data.database.entity.Application)

Aggregations

PoliciesData (org.flyve.mdm.agent.data.database.PoliciesData)9 View (android.view.View)3 CustomPolicies (org.flyve.policies.manager.CustomPolicies)3 JSONObject (org.json.JSONObject)3 Context (android.content.Context)2 Button (android.widget.Button)2 HashMap (java.util.HashMap)2 Policies (org.flyve.mdm.agent.data.database.entity.Policies)2 PoliciesAsyncTask (org.flyve.mdm.agent.policies.PoliciesAsyncTask)2 FlyveAdminReceiver (org.flyve.mdm.agent.receivers.FlyveAdminReceiver)2 AndroidPolicies (org.flyve.policies.manager.AndroidPolicies)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Location (android.location.Location)1 TelephonyManager (android.telephony.TelephonyManager)1 CompoundButton (android.widget.CompoundButton)1 EditText (android.widget.EditText)1 ImageButton (android.widget.ImageButton)1