This repository was archived by the owner on Apr 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Add support for Android 9 #227
Open
shobhitagarwal1612
wants to merge
14
commits into
getodk:master
Choose a base branch
from
shobhitagarwal1612:issue-191
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ea99aeb
Enable gcm to schedule tasks in devices without play-services
shobhitagarwal1612 f832c65
Publish wifi hotspot enable/disable event to RxBus
shobhitagarwal1612 5f22886
Add null check and minor code refactor
shobhitagarwal1612 08fc778
Get wifi access point ip using network interface
shobhitagarwal1612 ac7954f
Remove defaults from preferences
shobhitagarwal1612 0a18e0f
Add instructions to configure hotspot ssid/password for Android 9
shobhitagarwal1612 2292734
Use shared preferences for configuring QRCode in android 9
shobhitagarwal1612 b6f2856
Add a new class to handle diversity across android versions
shobhitagarwal1612 7647e46
Rename WifiActivity to ReceiverActivity
shobhitagarwal1612 c0a3d67
Remove redundant code
shobhitagarwal1612 0251a26
Code quality fixes
shobhitagarwal1612 f5d4595
Fix bug in QR Code Scanner
shobhitagarwal1612 9272d93
Disable notifications for android oreo and above
shobhitagarwal1612 9e8fc60
Fix bugs
shobhitagarwal1612 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,6 @@ | |
import org.odk.share.services.ReceiverService; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
|
@@ -58,12 +57,13 @@ | |
import timber.log.Timber; | ||
|
||
import static com.google.zxing.integration.android.IntentIntegrator.QR_CODE_TYPES; | ||
import static org.odk.share.utilities.QRCodeUtils.IP; | ||
import static org.odk.share.utilities.QRCodeUtils.PASSWORD; | ||
import static org.odk.share.utilities.QRCodeUtils.PORT; | ||
import static org.odk.share.utilities.QRCodeUtils.PROTECTED; | ||
import static org.odk.share.utilities.QRCodeUtils.SSID; | ||
|
||
public class WifiActivity extends InjectableActivity implements OnItemClickListener, WifiStateListener { | ||
public class ReceiverActivity extends InjectableActivity implements OnItemClickListener, WifiStateListener { | ||
|
||
private static final int DIALOG_DOWNLOAD_PROGRESS = 1; | ||
private static final int DIALOG_CONNECTING = 2; | ||
|
@@ -101,7 +101,7 @@ public class WifiActivity extends InjectableActivity implements OnItemClickListe | |
private int port; | ||
|
||
private boolean isQRCodeScanned; | ||
private String ssidScanned; | ||
private String ip; | ||
private boolean isProtected; | ||
private String passwordScanned; | ||
|
||
|
@@ -121,10 +121,7 @@ protected void onCreate(Bundle savedInstanceState) { | |
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
|
||
isQRCodeScanned = false; | ||
ssidScanned = null; | ||
isProtected = false; | ||
passwordScanned = null; | ||
lastConnectedWifiInfo = null; | ||
port = -1; | ||
|
||
scanResultList = new ArrayList<>(); | ||
|
@@ -141,18 +138,19 @@ protected void onCreate(Bundle savedInstanceState) { | |
} else { | ||
lastConnectedWifiInfo = wifiConnector.getActiveConnection(); | ||
} | ||
|
||
startScan(); | ||
} | ||
|
||
private boolean isPossibleHotspot(String ssid) { | ||
/*private boolean isPossibleHotspot(String ssid) { | ||
return ssid.contains(getString(R.string.hotspot_name_suffix)) || | ||
ssid.contains(getString(R.string.hotspot_name_prefix_oreo)); | ||
} | ||
ssid.startsWith(getString(R.string.hotspot_name_prefix_oreo)); | ||
}*/ | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
wifiStateBroadcastReceiver.register(); | ||
startScan(); | ||
compositeDisposable.add(addDownloadEventSubscription()); | ||
} | ||
|
||
|
@@ -313,8 +311,12 @@ private void setEmptyViewVisibility(String text) { | |
|
||
private void startReceiveTask() { | ||
showDialog(DIALOG_DOWNLOAD_PROGRESS); | ||
String dstAddress = wifiConnector.getAccessPointIpAddress(); | ||
receiverService.startDownloading(dstAddress, port); | ||
|
||
if (ip == null || ip.isEmpty()) { | ||
ip = wifiConnector.getAccessPointIpAddress(); | ||
} | ||
|
||
receiverService.startDownloading(ip, port); | ||
} | ||
|
||
@OnClick(R.id.bScan) | ||
|
@@ -397,19 +399,25 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
// request was canceled... | ||
Timber.i("QR code scanning cancelled"); | ||
} else { | ||
Timber.d("RESULT " + result); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same as above. |
||
Timber.d("Result: %s", result); | ||
try { | ||
JSONObject obj = new JSONObject(result.getContents()); | ||
ssidScanned = (String) obj.get(SSID); | ||
ip = (String) obj.get(IP); | ||
wifiNetworkSSID = (String) obj.get(SSID); | ||
port = (Integer) obj.get(PORT); | ||
isProtected = (boolean) obj.get(PROTECTED); | ||
if (isProtected) { | ||
passwordScanned = (String) obj.get(PASSWORD); | ||
} | ||
|
||
Timber.d("Scanned results " + ssidScanned + " " + port + " " + isProtected + " " + passwordScanned); | ||
Timber.d("Scanned results " + wifiNetworkSSID + " " + port + " " + isProtected + " " + passwordScanned); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest removing all the test log if they are only used for debugging, or just comment them. |
||
isQRCodeScanned = true; | ||
startScan(); | ||
|
||
if (wifiConnector.getAccessPointIpAddress() != null && wifiConnector.getAccessPointIpAddress().equals(ip)) { | ||
onConnected(); | ||
} else { | ||
startScan(); | ||
} | ||
} catch (JSONException e) { | ||
Timber.e(e); | ||
} | ||
|
@@ -419,7 +427,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
|
||
@Override | ||
public void onStateUpdate(NetworkInfo.DetailedState detailedState) { | ||
|
||
String connectedSsid = wifiConnector.getWifiSSID(); | ||
|
||
Timber.d(wifiNetworkSSID + " " + connectedSsid + " " + detailedState.toString()); | ||
|
@@ -430,7 +437,6 @@ public void onStateUpdate(NetworkInfo.DetailedState detailedState) { | |
wifiResultAdapter.notifyItemChanged(scanResultList.indexOf(wifiNetworkInfo)); | ||
|
||
if (!isConnected) { | ||
isConnected = true; | ||
onConnected(); | ||
} | ||
|
||
|
@@ -440,6 +446,8 @@ public void onStateUpdate(NetworkInfo.DetailedState detailedState) { | |
} | ||
|
||
private void onConnected() { | ||
isConnected = true; | ||
|
||
Toast.makeText(getApplicationContext(), "Connected to " + wifiNetworkSSID, Toast.LENGTH_LONG).show(); | ||
|
||
removeDialog(DIALOG_CONNECTING); | ||
|
@@ -462,17 +470,13 @@ public void onScanResultsAvailable() { | |
ArrayList<WifiNetworkInfo> list = new ArrayList<>(); | ||
|
||
for (ScanResult scanResult : scanResults) { | ||
if (isPossibleHotspot(scanResult.SSID)) { | ||
WifiNetworkInfo wifiNetworkInfo = new WifiNetworkInfo(); | ||
wifiNetworkInfo.setSsid(scanResult.SSID); | ||
wifiNetworkInfo.setRssi(WifiManager.calculateSignalLevel(scanResult.level, 100)); | ||
wifiNetworkInfo.setSecurityType(wifiConnector.getScanResultSecurity(scanResult)); | ||
list.add(wifiNetworkInfo); | ||
} | ||
WifiNetworkInfo wifiNetworkInfo = new WifiNetworkInfo(); | ||
wifiNetworkInfo.setSsid(scanResult.SSID); | ||
wifiNetworkInfo.setRssi(WifiManager.calculateSignalLevel(scanResult.level, 100)); | ||
wifiNetworkInfo.setSecurityType(wifiConnector.getScanResultSecurity(scanResult)); | ||
list.add(wifiNetworkInfo); | ||
} | ||
|
||
Timber.d(Arrays.toString(list.toArray())); | ||
|
||
wifiListAvailable(list); | ||
} | ||
|
||
|
@@ -491,12 +495,12 @@ private void wifiListAvailable(ArrayList<WifiNetworkInfo> list) { | |
if (isQRCodeScanned) { | ||
isQRCodeScanned = false; | ||
for (WifiNetworkInfo info : list) { | ||
if (info.getSsid().equals(ssidScanned)) { | ||
if (info.getSsid().equals(wifiNetworkSSID)) { | ||
if (info.getState() != NetworkInfo.DetailedState.CONNECTED) { | ||
Toast.makeText(this, "attempting connection", Toast.LENGTH_SHORT).show(); | ||
connectToNetwork(info.getSecurityType(), ssidScanned, passwordScanned); | ||
connectToNetwork(info.getSecurityType(), wifiNetworkSSID, passwordScanned); | ||
} else { | ||
Toast.makeText(this, "already connected to " + ssidScanned, Toast.LENGTH_SHORT).show(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we extract the toasts into something like |
||
Toast.makeText(this, "already connected to " + wifiNetworkSSID, Toast.LENGTH_SHORT).show(); | ||
} | ||
return; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the code is useless, please remove them or making comments to clarify the reason for keeping them.