Skip to content

Commit 9ac79ec

Browse files
Merge branch 'feature'
2 parents 9dcb696 + 89204c7 commit 9ac79ec

21 files changed

+769
-229
lines changed

app/build.properties

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
#
2+
# WiFiAnalyzer
3+
# Copyright (C) 2019 VREM Software Development <[email protected]>
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>
17+
#
18+
119
#Build Properties
2-
#Sat Jun 29 11:42:08 EDT 2019
20+
#Mon Jul 08 19:27:35 EDT 2019
321
version_minor=0
4-
version_build=0
22+
version_build=7
523
version_patch=5
6-
version_store=46
724
version_major=2
25+
version_store=46

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
android:label="@string/app_name"
5656
android:launchMode="singleTop">
5757
<intent-filter>
58-
<action android:name="com.vrem.wifianalyzer.MAINACTIVITY"/>
5958
<category android:name="android.intent.category.DEFAULT"/>
6059
</intent-filter>
6160
</activity>

app/src/main/java/com/vrem/wifianalyzer/MainActivity.java

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package com.vrem.wifianalyzer;
2020

2121
import android.content.Context;
22-
import android.content.Intent;
2322
import android.content.SharedPreferences;
2423
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
2524
import android.content.res.Configuration;
@@ -40,6 +39,7 @@
4039
import com.vrem.wifianalyzer.navigation.NavigationMenuControl;
4140
import com.vrem.wifianalyzer.navigation.NavigationMenuController;
4241
import com.vrem.wifianalyzer.navigation.options.OptionMenu;
42+
import com.vrem.wifianalyzer.permission.ApplicationPermission;
4343
import com.vrem.wifianalyzer.settings.Repository;
4444
import com.vrem.wifianalyzer.settings.Settings;
4545
import com.vrem.wifianalyzer.wifi.accesspoint.ConnectionView;
@@ -56,7 +56,7 @@ public class MainActivity extends AppCompatActivity implements NavigationMenuCon
5656
private NavigationMenu navigationMenu;
5757
private OptionMenu optionMenu;
5858
private String currentCountryCode;
59-
private PermissionChecker permissionChecker;
59+
private ApplicationPermission applicationPermission;
6060

6161
@Override
6262
protected void attachBaseContext(Context newBase) {
@@ -92,16 +92,15 @@ protected void onCreate(Bundle savedInstanceState) {
9292
drawerNavigation = new DrawerNavigation(this, toolbar);
9393

9494
navigationMenu = settings.getSelectedMenu();
95-
NavigationMenuController navigationMenuController = new NavigationMenuController(this);
95+
navigationMenuController = new NavigationMenuController(this);
9696
navigationMenuController.setCurrentNavigationMenu(navigationMenu);
97-
setNavigationMenuController(navigationMenuController);
9897
onNavigationItemSelected(getCurrentMenuItem());
9998

10099
ConnectionView connectionView = new ConnectionView(this);
101100
mainContext.getScannerService().register(connectionView);
102101

103-
permissionChecker = new PermissionChecker(this);
104-
permissionChecker.check();
102+
applicationPermission = new ApplicationPermission(this);
103+
applicationPermission.check();
105104
}
106105

107106
@Override
@@ -118,7 +117,7 @@ public void onConfigurationChanged(Configuration newConfig) {
118117

119118
@Override
120119
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
121-
if (!permissionChecker.isGranted(requestCode, grantResults)) {
120+
if (!applicationPermission.isGranted(requestCode, grantResults)) {
122121
finish();
123122
}
124123
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
@@ -145,7 +144,8 @@ private boolean isLargeScreen() {
145144
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
146145
MainContext mainContext = MainContext.INSTANCE;
147146
if (mainReload.shouldReload(mainContext.getSettings())) {
148-
reloadActivity();
147+
MainContext.INSTANCE.getScannerService().stop();
148+
recreate();
149149
} else {
150150
ActivityUtils.keepScreenOn(this);
151151
setWiFiChannelPairs(mainContext);
@@ -158,14 +158,6 @@ public void update() {
158158
updateActionBar();
159159
}
160160

161-
private void reloadActivity() {
162-
finish();
163-
Intent intent = new Intent(this, MainActivity.class);
164-
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP |
165-
Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
166-
startActivity(intent);
167-
}
168-
169161
@Override
170162
public void onBackPressed() {
171163
if (!closeDrawer()) {
@@ -180,13 +172,9 @@ public void onBackPressed() {
180172

181173
@Override
182174
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
183-
try {
184-
closeDrawer();
185-
NavigationMenu navigationMenu = EnumUtils.find(NavigationMenu.class, menuItem.getItemId(), NavigationMenu.ACCESS_POINTS);
186-
navigationMenu.activateNavigationMenu(this, menuItem);
187-
} catch (Exception e) {
188-
reloadActivity();
189-
}
175+
closeDrawer();
176+
NavigationMenu currentNavigationMenu = EnumUtils.find(NavigationMenu.class, menuItem.getItemId(), NavigationMenu.ACCESS_POINTS);
177+
currentNavigationMenu.activateNavigationMenu(this, menuItem);
190178
return true;
191179
}
192180

@@ -208,13 +196,9 @@ protected void onPause() {
208196

209197
@Override
210198
protected void onResume() {
211-
try {
212-
super.onResume();
213-
MainContext.INSTANCE.getScannerService().resume();
214-
updateActionBar();
215-
} catch (Exception e) {
216-
reloadActivity();
217-
}
199+
super.onResume();
200+
MainContext.INSTANCE.getScannerService().resume();
201+
updateActionBar();
218202
}
219203

220204
@Override

app/src/main/java/com/vrem/wifianalyzer/PermissionChecker.java renamed to app/src/main/java/com/vrem/wifianalyzer/permission/ApplicationPermission.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>
1717
*/
1818

19-
package com.vrem.wifianalyzer;
19+
package com.vrem.wifianalyzer.permission;
2020

2121
import android.Manifest;
2222
import android.app.Activity;
@@ -25,23 +25,23 @@
2525

2626
import com.vrem.util.BuildUtils;
2727

28-
class PermissionChecker {
28+
public class ApplicationPermission {
2929
static final String[] PERMISSIONS = {Manifest.permission.ACCESS_COARSE_LOCATION};
3030
static final int REQUEST_CODE = 0x123450;
3131

3232
private final Activity activity;
3333
private final PermissionDialog permissionDialog;
3434

35-
PermissionChecker(@NonNull Activity activity) {
35+
public ApplicationPermission(@NonNull Activity activity) {
3636
this(activity, new PermissionDialog(activity));
3737
}
3838

39-
PermissionChecker(@NonNull Activity activity, @NonNull PermissionDialog permissionDialog) {
39+
ApplicationPermission(@NonNull Activity activity, @NonNull PermissionDialog permissionDialog) {
4040
this.activity = activity;
4141
this.permissionDialog = permissionDialog;
4242
}
4343

44-
void check() {
44+
public void check() {
4545
if (isGranted()) {
4646
return;
4747
}
@@ -51,11 +51,11 @@ void check() {
5151
permissionDialog.show();
5252
}
5353

54-
boolean isGranted(int requestCode, @NonNull int[] grantResults) {
54+
public boolean isGranted(int requestCode, @NonNull int[] grantResults) {
5555
return requestCode == REQUEST_CODE && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
5656
}
5757

58-
private boolean isGranted() {
58+
boolean isGranted() {
5959
return isGranted(Manifest.permission.ACCESS_COARSE_LOCATION) || isGranted(Manifest.permission.ACCESS_FINE_LOCATION);
6060
}
6161

app/src/main/java/com/vrem/wifianalyzer/PermissionDialog.java renamed to app/src/main/java/com/vrem/wifianalyzer/permission/PermissionDialog.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* WiFiAnalyzer
3-
* Copyright (C) 2018 VREM Software Development <[email protected]>
3+
* Copyright (C) 2019 VREM Software Development <[email protected]>
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>
1717
*/
1818

19-
package com.vrem.wifianalyzer;
19+
package com.vrem.wifianalyzer.permission;
2020

2121
import android.app.Activity;
2222
import android.app.AlertDialog;
@@ -26,6 +26,7 @@
2626
import android.view.View;
2727

2828
import com.vrem.util.BuildUtils;
29+
import com.vrem.wifianalyzer.R;
2930

3031
class PermissionDialog {
3132
private final Activity activity;
@@ -58,7 +59,7 @@ static class OkClick implements OnClickListener {
5859
public void onClick(DialogInterface dialog, int which) {
5960
dialog.dismiss();
6061
if (BuildUtils.isMinVersionM()) {
61-
activity.requestPermissions(PermissionChecker.PERMISSIONS, PermissionChecker.REQUEST_CODE);
62+
activity.requestPermissions(ApplicationPermission.PERMISSIONS, ApplicationPermission.REQUEST_CODE);
6263
}
6364
}
6465
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* WiFiAnalyzer
3+
* Copyright (C) 2019 VREM Software Development <[email protected]>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>
17+
*/
18+
19+
package com.vrem.wifianalyzer.permission;
20+
21+
import android.app.Activity;
22+
import android.support.annotation.NonNull;
23+
24+
import com.vrem.util.BuildUtils;
25+
26+
public class RequirementPermission {
27+
private SystemPermission systemPermission;
28+
private ApplicationPermission applicationPermission;
29+
30+
public RequirementPermission(@NonNull Activity activity) {
31+
this.applicationPermission = new ApplicationPermission(activity);
32+
this.systemPermission = new SystemPermission(activity);
33+
}
34+
35+
public boolean isEnabled() {
36+
if (BuildUtils.isMinVersionM()) {
37+
return systemPermission.isEnabled() && applicationPermission.isGranted();
38+
} else {
39+
return true;
40+
}
41+
}
42+
43+
void setSystemPermission(SystemPermission systemPermission) {
44+
this.systemPermission = systemPermission;
45+
}
46+
47+
void setApplicationPermission(ApplicationPermission applicationPermission) {
48+
this.applicationPermission = applicationPermission;
49+
}
50+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* WiFiAnalyzer
3+
* Copyright (C) 2019 VREM Software Development <[email protected]>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>
17+
*/
18+
19+
package com.vrem.wifianalyzer.permission;
20+
21+
import android.app.Activity;
22+
import android.content.Context;
23+
import android.location.LocationManager;
24+
import android.support.annotation.NonNull;
25+
26+
import com.vrem.util.BuildUtils;
27+
28+
public class SystemPermission {
29+
private final Activity activity;
30+
31+
public SystemPermission(@NonNull Activity activity) {
32+
this.activity = activity;
33+
}
34+
35+
public boolean isEnabled() {
36+
if (BuildUtils.isMinVersionM()) {
37+
return isProviderEnabled();
38+
} else {
39+
return true;
40+
}
41+
}
42+
43+
private boolean isProviderEnabled() {
44+
try {
45+
LocationManager locationManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
46+
return isLocationEnabled(locationManager) || isNetworkProviderEnabled(locationManager) || isGPSProviderEnabled(locationManager);
47+
} catch (Exception e) {
48+
return false;
49+
}
50+
}
51+
52+
private boolean isGPSProviderEnabled(@NonNull LocationManager locationManager) {
53+
try {
54+
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
55+
} catch (Exception e) {
56+
return false;
57+
}
58+
}
59+
60+
private boolean isNetworkProviderEnabled(@NonNull LocationManager locationManager) {
61+
try {
62+
return locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
63+
} catch (Exception e) {
64+
return false;
65+
}
66+
}
67+
68+
private boolean isLocationEnabled(@NonNull LocationManager locationManager) {
69+
if (BuildUtils.isMinVersionP()) {
70+
try {
71+
return locationManager.isLocationEnabled();
72+
} catch (Exception e) {
73+
return false;
74+
}
75+
} else {
76+
return false;
77+
}
78+
}
79+
}

app/src/main/java/com/vrem/wifianalyzer/settings/Settings.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public int getScanSpeed() {
6969
return scanSpeed;
7070
}
7171

72+
public boolean isWiFiThrottleDisabled() {
73+
return repository.getBoolean(R.string.wifi_throttle_disabled_key, repository.getResourceBoolean(R.bool.wifi_throttle_disabled_default));
74+
}
75+
7276
public int getGraphMaximumY() {
7377
int defaultValue = repository.getStringAsInteger(R.string.graph_maximum_y_default, GRAPH_Y_DEFAULT);
7478
int result = repository.getStringAsInteger(R.string.graph_maximum_y_key, defaultValue);

app/src/main/java/com/vrem/wifianalyzer/settings/SettingsFragment.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
import android.os.Bundle;
2222
import android.support.v7.preference.PreferenceFragmentCompat;
2323

24+
import com.vrem.util.BuildUtils;
2425
import com.vrem.wifianalyzer.R;
2526

2627
public class SettingsFragment extends PreferenceFragmentCompat {
2728

2829
@Override
2930
public void onCreatePreferences(Bundle bundle, String rootKey) {
3031
addPreferencesFromResource(R.xml.settings);
32+
findPreference(getString(R.string.experimental_key)).setVisible(BuildUtils.isMinVersionP());
3133
}
3234

3335
}

0 commit comments

Comments
 (0)