Skip to content

Commit

Permalink
Show location notice that can redirect to location settings, in order…
Browse files Browse the repository at this point in the history
… to inform the user.
  • Loading branch information
BramBonne committed Mar 31, 2016
1 parent 51ecbc1 commit 1a27f92
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 18 deletions.
4 changes: 4 additions & 0 deletions privacypolice/src/main/AndroidManifest.xml
Expand Up @@ -35,6 +35,10 @@ uses-permission android:name="android.permission.INTERNET" />
android:name=".MACManagerActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name=".LocationNoticeActivity"
android:label="@string/app_name" >
</activity>
<!-- Receive all scan results in ScanResultsChecker class -->
<receiver
android:name=".ScanResultsChecker"
Expand Down
@@ -0,0 +1,29 @@
package be.uhasselt.privacypolice;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;

/**
* Activity that shows the user why location access might be needed, and that allows to take action
* (either open location settings or disable the notification from showing)
*/
public class LocationNoticeActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_locationnotice);
}

public void openLocationSettings(View view) {
Intent locationSettingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(locationSettingsIntent);
}

public void disableNotification(View view) {
// TODO
}
}
Expand Up @@ -100,8 +100,8 @@ public void cancelPermissionRequest() {
public void askLocationPermission() {
Log.d("PrivacyPolice", "Asking location permission");
Resources res = context.getResources();
Intent locationSettingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 3, locationSettingsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent locationNoticeIntent = new Intent(context, LocationNoticeActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 3, locationNoticeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_notification)
.setPriority(Notification.PRIORITY_HIGH)
Expand Down
Expand Up @@ -30,6 +30,8 @@
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

/**
* Since PrivacyPolice does not need a real MainActivity, this class is used to modify the
Expand All @@ -43,12 +45,27 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_preferences);

// Display the preferences fragment as the main content.
FragmentManager mFragmentManager = getFragmentManager();
FragmentTransaction mFragmentTransaction = mFragmentManager
.beginTransaction();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
PrefsFragment prefsFragment = new PrefsFragment();
mFragmentTransaction.replace(R.id.inflatable_prefs, prefsFragment);
mFragmentTransaction.commit();
fragmentTransaction.replace(R.id.inflatable_prefs, prefsFragment);
fragmentTransaction.commit();

// Show the location notice if location is disabled
TextView locationNotice = (TextView) findViewById(R.id.location_notice);
LocationAccess locationAccess = new LocationAccess();
if (!locationAccess.isNetworkLocationEnabled(getApplicationContext()))
locationNotice.setVisibility(View.VISIBLE);
else
locationNotice.setVisibility(View.GONE);
}

/**
* Called when location notification is clicked
*/
public void openLocationNotice(View view) {
Intent intent = new Intent(this, LocationNoticeActivity.class);
startActivity(intent);
}

/**
Expand Down
Expand Up @@ -92,12 +92,6 @@ public void onReceive(Context ctx, Intent intent) {
init(ctx);
// Make sure the wakelockHandler keeps running (to prevent Android 6.0 and up from completely suspending our operations)
WakelockHandler.getInstance(ctx).ensureAwake();
// Make sure coarse location access is enabled (needed to get scan results on Android 5.0 and up)
if (!(new LocationAccess()).isNetworkLocationEnabled(ctx)) {
notificationHandler.askLocationPermission();
// Keep last known configuration
return;
}

// WiFi scan performed
// Older devices might try to scan constantly. Allow them some rest by checking max. once every 0.5 seconds
Expand Down
30 changes: 30 additions & 0 deletions privacypolice/src/main/res/layout/activity_locationnotice.xml
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/location_permission_full_explanation"
android:id="@+id/location_explanation"
android:padding="@dimen/activity_horizontal_margin" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/location_open_settings"
android:id="@+id/open_location_settings"
android:padding="@dimen/activity_horizontal_margin"
android:onClick="openLocationSettings" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/location_ignore_notice"
android:id="@+id/button2"
android:padding="@dimen/activity_horizontal_margin"
android:onClick="disableNotification" />
</LinearLayout>
22 changes: 19 additions & 3 deletions privacypolice/src/main/res/layout/activity_preferences.xml
@@ -1,7 +1,23 @@
<FrameLayout
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/inflatable_prefs"
xmlns:android="http://schemas.android.com/apk/res/android">
</FrameLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/location_permission_explanation"
android:id="@+id/location_notice"
android:background="#dcedc8"
android:padding="@dimen/activity_horizontal_margin"
android:visibility="gone"
android:onClick="openLocationNotice" />

<FrameLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/inflatable_prefs">
</FrameLayout>
</LinearLayout>
6 changes: 4 additions & 2 deletions privacypolice/src/main/res/values/strings.xml
Expand Up @@ -25,6 +25,8 @@
<string name="dialog_removetrustedmac">Are you sure you want to remove hotspot \"%1$s\"?</string>
<string name="dialog_remove">Remove</string>
<string name="location_permission_header">Location access disabled</string>
<string name="location_permission_explanation">Wi-Fi PrivacyPolice needs (limited) location access in order to function correctly. Click here to resolve the problem.</string>

<string name="location_permission_explanation">Wi-Fi PrivacyPolice might need (limited) location access in order to function correctly. Click here for more info.</string>
<string name="location_permission_full_explanation">Starting with Android version 6.0 (Marshmallow), apps can only view the list of Wi-Fi networks that are in range if location access is disabled. Your mileage may vary (depending on the device you\'re using, this might not be the case), but if you experience problems when using Wi-Fi PrivacyPolice, consider enabling location access. Coarse location access (only using Wi-Fi networks and cell towers, and not your actual GPS chip) should be sufficient.</string>
<string name="location_open_settings">Open location settings</string>
<string name="location_ignore_notice">Disable location notification</string>
</resources>

0 comments on commit 1a27f92

Please sign in to comment.