Skip to content

Commit 63d30b9

Browse files
committed
add basic starter code to the project
1 parent d0a1a95 commit 63d30b9

File tree

7 files changed

+99
-10
lines changed

7 files changed

+99
-10
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88

99
defaultConfig {
1010
applicationId "com.lcl.lclmeasurementtool"
11-
minSdkVersion 28
11+
minSdkVersion 29
1212
targetSdkVersion 30
1313
versionCode 1
1414
versionName "1.0"

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.lcl.lclmeasurementtool">
44

5+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
56
<application
67
android:allowBackup="true"
78
android:icon="@mipmap/ic_launcher"

app/src/main/java/com/lcl/lclmeasurementtool/Functionality/Ping.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
*/
77

88
public class Ping {
9+
910
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
package com.lcl.lclmeasurementtool.Managers;
2+
import android.content.Context;
3+
import android.telephony.SignalStrength;
24
import android.telephony.TelephonyManager;
35

6+
import com.lcl.lclmeasurementtool.Utils.SignalStrengthLevel;
7+
48
/**
59
* CellularManager monitors changes in device's signal strength and
610
* report changes(callback) to front-end UI
711
*/
812

913
public class CellularManager {
14+
15+
private TelephonyManager telephonyManager;
16+
17+
public CellularManager(Context context) {
18+
this.telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
19+
}
20+
21+
public SignalStrength getSignalStrength() {
22+
return this.telephonyManager.getSignalStrength();
23+
}
24+
25+
public SignalStrengthLevel getSignalStrengthLevel() {
26+
int level = getSignalStrength().getLevel();
27+
return SignalStrengthLevel.init(level);
28+
}
1029
}
Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,47 @@
11
package com.lcl.lclmeasurementtool.Managers;
2+
23
import android.net.ConnectivityManager;
4+
import android.content.Context;
5+
import android.net.Network;
6+
import android.net.NetworkCapabilities;
7+
import android.net.NetworkInfo;
8+
import android.os.Build;
9+
import android.util.Log;
10+
11+
import androidx.annotation.RequiresApi;
312

413
/**
514
* NetworkManager manages all network related information, including but not limited to
615
* connectivity states, active network information(wifi, cellular) and
716
* listen to changes in network states.
817
*/
9-
1018
public class NetworkManager {
1119

20+
private static final String TAG = "Network Manager Info";
21+
22+
// TODO: finish comment
23+
private ConnectivityManager connectivityManager;
24+
private NetworkCapabilities capabilities;
25+
private boolean isCellularConnected;
26+
27+
/**
28+
* TODO: finish comment
29+
* @param context
30+
*/
31+
public NetworkManager(Context context) {
32+
this.connectivityManager =
33+
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
34+
35+
Network network = this.connectivityManager.getActiveNetwork();
36+
this.capabilities = this.connectivityManager.getNetworkCapabilities(network);
37+
this.isCellularConnected = capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR);
38+
}
39+
40+
public boolean isCellularConnected() {
41+
return isCellularConnected;
42+
}
43+
44+
public int getNumericSignalStrength() {
45+
return this.capabilities.getSignalStrength();
46+
}
1247
}

app/src/main/java/com/lcl/lclmeasurementtool/Utils/ConvertUtils.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,30 @@ public class ConvertUtils {
66
public static final int CONVERSION_RATE = 8;
77

88
/**
9-
* Convert data in MBps to Mbps
9+
* Convert data in MBps to Mbps.
1010
*
11-
* @param MBps the data to be converted in MBps
12-
* @return corresponding data in Mbps
11+
* @param MBps the data to be converted in MBps.
12+
* @throws IllegalArgumentException if MBps is less than 0.
13+
* @return corresponding data in Mbps.
1314
*/
1415
public static double toMbps(double MBps) {
16+
if (MBps < 0) {
17+
throw new IllegalArgumentException("the input parameter MBps should be greater than 0");
18+
}
1519
return MBps * CONVERSION_RATE;
1620
}
1721

1822
/**
19-
* Convert data in Mbps to MBps
23+
* Convert data in Mbps to MBps.
2024
*
21-
* @param Mbps the data to be converted in Mbps
22-
* @return corresponding data in MBps
25+
* @param Mbps the data to be converted in Mbps.
26+
* @throws IllegalArgumentException if Mbps is less than 0.
27+
* @return corresponding data in MBps.
2328
*/
2429
public static double toMBps(double Mbps) {
30+
if (Mbps < 0) {
31+
throw new IllegalArgumentException("the input parameter Mbps should be greater than 0");
32+
}
2533
return Mbps / CONVERSION_RATE;
2634
}
2735
}

app/src/main/java/com/lcl/lclmeasurementtool/Utils/SignalStrength.java renamed to app/src/main/java/com/lcl/lclmeasurementtool/Utils/SignalStrengthLevel.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.lcl.lclmeasurementtool.Utils;
22

3-
public enum SignalStrength {
3+
/**
4+
* The SignalStrength represents the cellular signal strength
5+
* received from the mobile network system.
6+
*/
7+
public enum SignalStrengthLevel {
48
NONE(0), // the signal strength is none or unknown
59
POOR(1), // the signal strength is poor
610
MODERATE(2), // the signal strength is moderate
@@ -11,10 +15,31 @@ public enum SignalStrength {
1115
private final int levelCode;
1216

1317
// constructor
14-
SignalStrength(int levelCode) {
18+
SignalStrengthLevel(int levelCode) {
1519
this.levelCode = levelCode;
1620
}
1721

22+
/**
23+
* TODO: finish comment
24+
* @param levelCode
25+
* @return
26+
*/
27+
public static SignalStrengthLevel init(int levelCode) {
28+
switch (levelCode) {
29+
case 0:
30+
return SignalStrengthLevel.NONE;
31+
case 1:
32+
return SignalStrengthLevel.POOR;
33+
case 2:
34+
return SignalStrengthLevel.MODERATE;
35+
case 3:
36+
return SignalStrengthLevel.GOOD;
37+
case 4:
38+
return SignalStrengthLevel.GREAT;
39+
default: throw new IllegalArgumentException("Signal Strength levelCode should be >=0 and <= 4 ");
40+
}
41+
}
42+
1843
/**
1944
* Get the numerical level code corresponding to the signal strength
2045
* @return an integer associates with the signal strength

0 commit comments

Comments
 (0)