Created
May 5, 2019 02:28
-
-
Save luthfihariz/701f43ba8668bb014eb76c44d2628a9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (isIpAddressDifferentWithLastRecorded(latestIpAddress)) { | |
Log.d( | |
WorkManagerHelper.TAG, | |
"Different IP Address ($latestIpAddress}." | |
) | |
insertNewRecordToDb(latestIpAddress) | |
} else { | |
if (connManager.getNetworkClass() == ConnectionManager.NETWORK_WIFI) { | |
// check if its on wifi more than one hour | |
if (isRecordedMoreThanOneHourAgo()) { | |
Log.d(WorkManagerHelper.TAG, "It's on wifi for more than one hour ago. So turn off wifi") | |
connManager.toggleWifi() | |
Log.d(WorkManagerHelper.TAG, "Wait for $WAITING_INTERVAL seconds after turning wifi off.") | |
Thread.sleep(WAITING_INTERVAL) | |
latestIpAddress = connManager.getPublicIpAddress().blockingGet() | |
if (isIpAddressDifferentWithLastRecorded(latestIpAddress)) { | |
Log.d(WorkManagerHelper.TAG, "Different IP Address ($latestIpAddress}.") | |
insertNewRecordToDb(latestIpAddress) | |
} | |
Log.d(WorkManagerHelper.TAG, "Wait for $WAITING_INTERVAL seconds before turning wifi on.") | |
Thread.sleep(WAITING_INTERVAL) | |
Log.d(WorkManagerHelper.TAG, "Turn wifi on.") | |
connManager.toggleWifi() | |
Log.d(WorkManagerHelper.TAG, "Wait for $WAITING_INTERVAL seconds after turning wifi on.") | |
Thread.sleep(WAITING_INTERVAL) | |
latestIpAddress = connManager.getPublicIpAddress().blockingGet() | |
if (isIpAddressDifferentWithLastRecorded(latestIpAddress)) { | |
Log.d(WorkManagerHelper.TAG, "Different IP Address ($latestIpAddress}.") | |
insertNewRecordToDb(latestIpAddress) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment