From 456d255ce99e9389f6baed90baf91a5ed26ff0db Mon Sep 17 00:00:00 2001 From: Victor Ng Date: Mon, 11 Feb 2019 11:23:12 -0500 Subject: [PATCH] bumped to 1.8.8 and applied runtime permissions checking --- android/build.gradle | 8 +- .../client/navdrawer/MainDrawerActivity.java | 102 +++++++++++++++--- libraries/stumbler/build.gradle | 2 +- 3 files changed, 92 insertions(+), 20 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 5a21d7633..e068012c5 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,7 +1,7 @@ // each of the version numbers must be 0-99 def versionMajor = 1 def versionMinor = 8 // minor feature releases -def versionPatch = 6 // This should be bumped for hot fixes +def versionPatch = 8 // This should be bumped for hot fixes // Double check the versioning for (versionPart in [versionPatch, versionMinor, versionMajor]) { @@ -32,6 +32,8 @@ repositories { android { compileSdkVersion 28 buildToolsVersion "28.0.3" + useLibrary 'org.apache.http.legacy' + def gitHash = "git rev-parse --short HEAD".execute().text.trim() def hasModifiedDeletedOrOtherFiles = !"git ls-files -mdo --exclude-standard".execute().text.trim().isEmpty() @@ -49,8 +51,8 @@ android { } defaultConfig { - minSdkVersion 10 - targetSdkVersion 22 + minSdkVersion 14 + targetSdkVersion 26 applicationId "org.mozilla.mozstumbler" diff --git a/android/src/main/java/org/mozilla/mozstumbler/client/navdrawer/MainDrawerActivity.java b/android/src/main/java/org/mozilla/mozstumbler/client/navdrawer/MainDrawerActivity.java index bd725ad9a..ed03638c6 100644 --- a/android/src/main/java/org/mozilla/mozstumbler/client/navdrawer/MainDrawerActivity.java +++ b/android/src/main/java/org/mozilla/mozstumbler/client/navdrawer/MainDrawerActivity.java @@ -9,9 +9,12 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.res.Configuration; +import android.Manifest; import android.os.Build; import android.os.Bundle; +import android.content.pm.PackageManager; import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; @@ -26,6 +29,8 @@ import android.widget.CompoundButton; import android.widget.Switch; +import java.util.LinkedList; + import org.mozilla.mozstumbler.BuildConfig; import org.mozilla.mozstumbler.R; import org.mozilla.mozstumbler.client.ClientPrefs; @@ -43,17 +48,32 @@ public class MainDrawerActivity extends ActionBarActivity - implements IMainActivity { + implements IMainActivity, + ActivityCompat.OnRequestPermissionsResultCallback +{ private ILogger Log = (ILogger) ServiceLocator.getInstance().getService(ILogger.class); private static final String LOG_TAG = LoggerUtil.makeLogTag(MainDrawerActivity.class); + private static boolean GOT_PERMS = false; + private static final int MENU_START_STOP = 1; private DrawerLayout mDrawerLayout; private ActionBarDrawerToggle mDrawerToggle; private MetricsView mMetricsView; private MapFragment mMapFragment; private MenuItem mMenuItemStartStop; + + String[] PERMS = {Manifest.permission.ACCESS_COARSE_LOCATION + ,Manifest.permission.ACCESS_FINE_LOCATION + ,Manifest.permission.ACCESS_NETWORK_STATE + ,Manifest.permission.ACCESS_WIFI_STATE + ,Manifest.permission.CHANGE_NETWORK_STATE + ,Manifest.permission.CHANGE_WIFI_STATE + ,Manifest.permission.INTERNET + ,Manifest.permission.WAKE_LOCK + ,Manifest.permission.WRITE_EXTERNAL_STORAGE}; + final CompoundButton.OnCheckedChangeListener mStartStopButtonListener = new CompoundButton.OnCheckedChangeListener() { @Override @@ -169,18 +189,7 @@ public void onDrawerOpened(View drawerView) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); - FragmentManager fragmentManager = getSupportFragmentManager(); - Fragment fragment = fragmentManager.findFragmentById(R.id.content_frame); - if (fragment == null) { - mMapFragment = new MapFragment(); - FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); - fragmentTransaction.add(R.id.content_frame, mMapFragment); - fragmentTransaction.commit(); - } else { - mMapFragment = (MapFragment) fragment; - } - getApp().setMainActivity(this); if (BuildConfig.GITHUB) { Updater upd = new Updater(); @@ -188,6 +197,19 @@ public void onDrawerOpened(View drawerView) { } mMetricsView = new MetricsView(findViewById(R.id.left_drawer)); + + // Request all permissions + ActivityCompat.requestPermissions(this, + PERMS, + 100); + + FragmentManager fragmentManager = getSupportFragmentManager(); + Fragment fragment = fragmentManager.findFragmentById(R.id.content_frame); + if (fragment != null) { + mMapFragment = (MapFragment) fragment; + } + + getApp().setMainActivity(this); } @Override @@ -245,7 +267,9 @@ private void updateStartStopMenuItemState() { } } - mMapFragment.dimToolbar(); + if (mMapFragment != null) { + mMapFragment.dimToolbar(); + } } @@ -254,7 +278,10 @@ protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); - mMetricsView.setMapLayerToggleListener(mMapFragment); + + if (mMapFragment != null) { + mMetricsView.setMapLayerToggleListener(mMapFragment); + } } @Override @@ -282,7 +309,11 @@ public void onPostResume() { findViewById(android.R.id.content).postDelayed(new Runnable() { @Override public void run() { - getApp().startScanning(); + if (GOT_PERMS) { + getApp().startScanning(); + } else { + getApp().stopScanning(); + } } }, 750); } @@ -307,7 +338,9 @@ public boolean onOptionsItemSelected(MenuItem item) { } switch (item.getItemId()) { case MENU_START_STOP: - mMapFragment.toggleScanning(item); + if (mMapFragment != null) { + mMapFragment.toggleScanning(item); + } return true; default: return super.onOptionsItemSelected(item); @@ -330,6 +363,10 @@ public void run() { } private void updateNumberDisplay(boolean updateMetrics) { + if (mMapFragment == null) { + return; + } + // TODO: this is silly. we can just ask for everything in one // request. broadcastSvcDataRequest(StumblerServiceIntentActions.SVC_REQ_VISIBLE_CELL); @@ -377,6 +414,7 @@ public void keepScreenOn(boolean isEnabled) { @Override public void isPausedDueToNoMotion(boolean isPaused) { + if (mMapFragment == null) { return; } mMapFragment.showPausedDueToNoMotionMessage(isPaused); } @@ -386,11 +424,43 @@ public void start() { @Override public void stop() { + if (mMapFragment == null) { return; } mMapFragment.stop(); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { mMetricsView.update(); } + + + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) + { + LinkedList where = new LinkedList(); + for (int idx = 0; idx < permissions.length; idx++) { + int grantResult = grantResults[idx]; + String perm = permissions[idx]; + + if (grantResult != PackageManager.PERMISSION_GRANTED) { + where.add(perm); + } + } + + if (where.size() > 0) { + ActivityCompat.requestPermissions(this, + PERMS, + 100); + + } else { + // Initialize the map fragment + FragmentManager fragmentManager = getSupportFragmentManager(); + mMapFragment = new MapFragment(); + FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); + fragmentTransaction.add(R.id.content_frame, mMapFragment); + fragmentTransaction.commit(); + + GOT_PERMS = true; + } + } } diff --git a/libraries/stumbler/build.gradle b/libraries/stumbler/build.gradle index f0817dd2b..753bcb85f 100644 --- a/libraries/stumbler/build.gradle +++ b/libraries/stumbler/build.gradle @@ -32,7 +32,7 @@ android { buildToolsVersion "28.0.3" defaultConfig { - minSdkVersion 10 + minSdkVersion 14 targetSdkVersion 28 }