Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
refactor(*): update airplane mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelje authored and Hector Rondon committed Nov 28, 2017
1 parent fc259a9 commit 12833a4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cache.setConnectivityAirplaneModeDisable(isChecked);
if(isChecked) {
ConnectivityHelper.disableAirplaneMode(isChecked);
}
ConnectivityHelper.disableAirplaneMode(isChecked);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void run() {
}, TIME);

return;
}
}

// if user is not enrolled show help
setContentView(R.layout.activity_splash);
Expand Down
65 changes: 34 additions & 31 deletions app/src/main/java/org/flyve/mdm/agent/utils/ConnectivityHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,24 @@ public static void disableGps(boolean disable) {
if(disable) {
String[] cmds = {"cd /system/bin", "settings put secure location_providers_allowed -gps", "settings put secure location_providers_allowed -network" };
executecmd(cmds);
} else {
String[] cmds = {"cd /system/bin", "settings put secure location_providers_allowed +gps", "settings put secure location_providers_allowed +network" };
executecmd(cmds);
}
}

public static void disableRoaming(boolean disable){

if(Build.VERSION.SDK_INT>=21) {
new FlyveDeviceAdminUtils(MDMAgent.getInstance()).disableRoaming(disable);
} else {
// ROOT OPTION
String value = "0"; // disable
if (disable) {
String value = "0";
String[] cmds = {"cd /system/bin", "settings put global data_roaming0 " + value};

executecmd(cmds);

value = "1"; // disable
}

String[] cmds = {"cd /system/bin", "settings put global data_roaming0 " + value};
executecmd(cmds);
}
}

Expand All @@ -95,52 +97,53 @@ public static void disableNFC(boolean disable) {
}

String[] cmds = {"svc nfc " + value};

executecmd(cmds);
}

public static void disableMobileLine(boolean disable) {
String value = "enable";
if(disable) {
String value = "disable";

try {
TelephonyManager tm = (TelephonyManager) MDMAgent.getInstance().getApplicationContext().getSystemService(TELEPHONY_SERVICE);
value = "disable";
}

Method m1 = tm.getClass().getDeclaredMethod("getITelephony");
m1.setAccessible(true);
Object iTelephony = m1.invoke(tm);
try {
TelephonyManager tm = (TelephonyManager) MDMAgent.getInstance().getApplicationContext().getSystemService(TELEPHONY_SERVICE);

Method m2 = iTelephony.getClass().getDeclaredMethod("setRadio", boolean.class);
Method m1 = tm.getClass().getDeclaredMethod("getITelephony");
m1.setAccessible(true);
Object iTelephony = m1.invoke(tm);

m2.invoke(iTelephony, false);
} catch (Exception ex) {
FlyveLog.e(ex.getMessage());
}
Method m2 = iTelephony.getClass().getDeclaredMethod("setRadio", boolean.class);

String[] cmds = {"svc data " + value};
executecmd(cmds);
m2.invoke(iTelephony, false);
} catch (Exception ex) {
FlyveLog.e(ex.getMessage());
}

String[] cmds = {"svc data " + value};
executecmd(cmds);

}

public static void disableAirplaneMode(boolean disable) {
if (disable) {
String value = "1"; // enable
String value = "1"; // enable
if(disable) {
value = "0"; // disable

String[] cmds = {"cd /system/bin", "settings put global airplane_mode_on " + value};
executecmd(cmds);

// disable wifi
disableWifi(disable);
disableBluetooth(disable);
disableMobileLine(disable);
disableNFC(disable);
//disableWifi(disable);
//disableBluetooth(disable);
//disableMobileLine(disable);
//disableNFC(disable);
}
}

public static void disableHostpotTethering(boolean disable) {
if(disable) {
disableWifi(disable);
disableBluetooth(disable);
}
disableWifi(disable);
disableBluetooth(disable);
}

public static void disableUsbFileTransferProtocols(boolean disable) {
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/org/flyve/mdm/agent/utils/MQTTHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ public void disableConnectivity(JSONObject json) {
if (jsonConnectivity.has("disableGPS")) {
boolean disable = jsonConnectivity.getBoolean("disableGPS");
cache.setConnectivityGPSDisable(disable);
if(disable) {
ConnectivityHelper.disableGps(disable);
}
ConnectivityHelper.disableGps(disable);
broadcastReceivedLog(Helpers.broadCastMessage(MQTT_SEND, "GPS", "GPS is disable: " + disable));
}

Expand Down

0 comments on commit 12833a4

Please sign in to comment.