Skip to content

Commit

Permalink
Merge pull request #1850 from mozilla/runtime-perms
Browse files Browse the repository at this point in the history
bumped to 1.8.8 and applied runtime permissions checking
  • Loading branch information
crankycoder authored Feb 11, 2019
2 parents cc14845 + 456d255 commit be9da93
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 20 deletions.
8 changes: 5 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -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]) {
Expand Down Expand Up @@ -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()
Expand All @@ -49,8 +51,8 @@ android {
}

defaultConfig {
minSdkVersion 10
targetSdkVersion 22
minSdkVersion 14
targetSdkVersion 26

applicationId "org.mozilla.mozstumbler"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -169,25 +189,27 @@ 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();
upd.checkForUpdates(this, BuildConfig.MOZILLA_API_KEY);
}

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
Expand Down Expand Up @@ -245,7 +267,9 @@ private void updateStartStopMenuItemState() {
}
}

mMapFragment.dimToolbar();
if (mMapFragment != null) {
mMapFragment.dimToolbar();
}
}


Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -377,6 +414,7 @@ public void keepScreenOn(boolean isEnabled) {

@Override
public void isPausedDueToNoMotion(boolean isPaused) {
if (mMapFragment == null) { return; }
mMapFragment.showPausedDueToNoMotionMessage(isPaused);
}

Expand All @@ -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<String> where = new LinkedList<String>();
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;
}
}
}

2 changes: 1 addition & 1 deletion libraries/stumbler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android {
buildToolsVersion "28.0.3"

defaultConfig {
minSdkVersion 10
minSdkVersion 14
targetSdkVersion 28
}

Expand Down

0 comments on commit be9da93

Please sign in to comment.