Skip to content

Commit

Permalink
small fixes in code
Browse files Browse the repository at this point in the history
  • Loading branch information
nisrulz committed Mar 19, 2021
1 parent 8f69eaf commit fcda874
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 26 deletions.
4 changes: 3 additions & 1 deletion easydeviceinfo-base/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
~ limitations under the License.
-->

<manifest package="github.nisrulz.easydeviceinfo.base"/>
<manifest package="github.nisrulz.easydeviceinfo.base">
<uses-permission name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,17 @@ public final String getOSCodename() {
codename = "Nougat";
break;
case VERSION_CODES.O:
codename = "O";
case VERSION_CODES.O_MR1:
codename = "Oreo";
break;
case VERSION_CODES.P:
codename = "Pie";
break;
case VERSION_CODES.Q:
codename = "10";
break;
case VERSION_CODES.R:
codename = "11";
break;
default:
codename = EasyDeviceInfo.notFoundVal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.RequiresApi;
import androidx.annotation.RequiresPermission;

import github.nisrulz.easydeviceinfo.common.EasyDeviceInfo;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
Expand All @@ -42,6 +42,8 @@
import java.util.List;
import java.util.Locale;

import github.nisrulz.easydeviceinfo.common.EasyDeviceInfo;

/**
* EasyNetwork Mod Class
*/
Expand Down Expand Up @@ -121,16 +123,16 @@ public final String getIPv6Address() {

/**
* Gets network type.
*
* <p>
* You need to declare the below permission in the manifest file to use this properly
*
* <p>
* <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
* <uses-permission android:name="android.permission.INTERNET"/>
*
* @return the network type
*/
@RequiresPermission(allOf = {
permission.ACCESS_NETWORK_STATE, permission.INTERNET
permission.ACCESS_NETWORK_STATE, permission.INTERNET, permission.READ_PHONE_STATE
})
@NetworkType
public final int getNetworkType() {
Expand Down Expand Up @@ -178,7 +180,12 @@ public final int getNetworkType() {
break;
// Cellular Data 4G
case TelephonyManager.NETWORK_TYPE_LTE:
result = NetworkType.CELLULAR_4G;
case TelephonyManager.NETWORK_TYPE_IWLAN:
result = NetworkType.CELLULAR_4G_OR_5G_NSA;
break;
// Cellular Data 5G
case TelephonyManager.NETWORK_TYPE_NR:
result = NetworkType.CELLULAR_5G_SA;
break;
// Cellular Data Unknown Generation
default:
Expand All @@ -194,9 +201,9 @@ public final int getNetworkType() {

/**
* Gets BSSID of Connected WiFi
*
* <p>
* You need to declare the below permission in the manifest file to use this properly
*
* <p>
* <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
* <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
*
Expand Down Expand Up @@ -233,9 +240,9 @@ public final String getWifiBSSID() {

/**
* Gets Link Speed of Connected WiFi
*
* <p>
* You need to declare the below permission in the manifest file to use this properly
*
* <p>
* <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
* <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
*
Expand Down Expand Up @@ -272,9 +279,9 @@ public final String getWifiLinkSpeed() {

/**
* Gets WiFi MAC Address
*
* <p>
* You need to declare the below permission in the manifest file to use this properly
*
* <p>
* <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
*
* @return the wifi mac
Expand Down Expand Up @@ -334,9 +341,9 @@ public final String getWifiMAC() {

/**
* Gets SSID of Connected WiFi
*
* <p>
* You need to declare the below permission in the manifest file to use this properly
*
* <p>
* <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
* <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
*
Expand Down Expand Up @@ -373,9 +380,9 @@ public final String getWifiSSID() {

/**
* Is network available boolean.
*
* <p>
* You need to declare the below permission in the manifest file to use this properly
*
* <p>
* <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
* <uses-permission android:name="android.permission.INTERNET"/>
*
Expand All @@ -401,6 +408,7 @@ public final boolean isNetworkAvailable() {
* @return true if a Wi-Fi Aware compatible chipset is present in the device.
* @see <a href="https://developer.android.com/guide/topics/connectivity/wifi-aware.html">https://developer.android.com/guide/topics/connectivity/wifi-aware.html</a>
*/
@RequiresApi(api = Build.VERSION_CODES.O)
public final boolean isWifiAwareAvailable() {
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) && this.context.getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_WIFI_AWARE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,31 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import static github.nisrulz.easydeviceinfo.base.NetworkType.CELLULAR_2G;
import static github.nisrulz.easydeviceinfo.base.NetworkType.CELLULAR_3G;
import static github.nisrulz.easydeviceinfo.base.NetworkType.CELLULAR_4G_OR_5G_NSA;
import static github.nisrulz.easydeviceinfo.base.NetworkType.CELLULAR_5G_SA;
import static github.nisrulz.easydeviceinfo.base.NetworkType.CELLULAR_UNIDENTIFIED_GEN;
import static github.nisrulz.easydeviceinfo.base.NetworkType.CELLULAR_UNKNOWN;
import static github.nisrulz.easydeviceinfo.base.NetworkType.UNKNOWN;
import static github.nisrulz.easydeviceinfo.base.NetworkType.WIFI_WIFIMAX;

@IntDef({
NetworkType.WIFI_WIFIMAX, NetworkType.CELLULAR_4G, NetworkType.CELLULAR_3G,
NetworkType.CELLULAR_2G, NetworkType.CELLULAR_UNIDENTIFIED_GEN,
NetworkType.CELLULAR_UNKNOWN, NetworkType.UNKNOWN
WIFI_WIFIMAX, CELLULAR_4G_OR_5G_NSA,
CELLULAR_3G, CELLULAR_5G_SA,
CELLULAR_2G, CELLULAR_UNIDENTIFIED_GEN,
CELLULAR_UNKNOWN, UNKNOWN
})
@Retention(RetentionPolicy.CLASS)
public @interface NetworkType {

int UNKNOWN = 0;
int WIFI_WIFIMAX = 1;
int CELLULAR_UNKNOWN = 2;
int CELLULAR_2G = 3;
int CELLULAR_3G = 4;
int CELLULAR_4G = 5;
int CELLULAR_UNIDENTIFIED_GEN = 6;
int CELLULAR_UNIDENTIFIED_GEN = 1;
int WIFI_WIFIMAX = 2;
int CELLULAR_UNKNOWN = 3;
int CELLULAR_2G = 4;
int CELLULAR_3G = 5;
int CELLULAR_4G_OR_5G_NSA = 6;
int CELLULAR_5G_SA = 7;
int CELLULAR_6G = 8;
}

0 comments on commit fcda874

Please sign in to comment.