Updated Permissions requests to split into 3 groups, and made the rationale screens consistent with the 'Prominent Disclosure' text required by Google Play Store.

This commit is contained in:
Graham Jones
2022-03-05 16:16:05 +00:00
parent 952a4a9304
commit 1bd7eb7314
4 changed files with 117 additions and 65 deletions

View File

@@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="uk.org.openseizuredetector"
android:versionCode="95"
android:versionName="4.0.0s">
android:versionCode="96"
android:versionName="4.0.0t">
<!-- android:allowBackup="false" -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

View File

@@ -76,22 +76,6 @@ public class OsdUtil {
private final String ALARMLOG = "AlarmLog";
private final String DATALOG = "DataLog";
public final String[] REQUIRED_PERMISSIONS = {
//Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.WAKE_LOCK,
};
public final String[] SMS_PERMISSIONS = {
Manifest.permission.SEND_SMS,
Manifest.permission.ACCESS_FINE_LOCATION,
//Manifest.permission.ACCESS_BACKGROUND_LOCATION,
Manifest.permission.READ_PHONE_STATE,
};
public final String[] SMS_PERMISSIONS_2 = {
Manifest.permission.ACCESS_BACKGROUND_LOCATION,
};
/**
* Based on http://stackoverflow.com/questions/7440473/android-how-to-check-if-the-intent-service-is-still-running-or-has-stopped-running
*/

View File

@@ -24,7 +24,7 @@
*/
package uk.org.openseizuredetector;
import android.app.Activity;
import android.Manifest;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
@@ -51,7 +51,6 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.google.android.material.snackbar.Snackbar;
import com.rohitss.uceh.UCEHandler;
import java.util.Timer;
@@ -82,9 +81,34 @@ public class StartupActivity extends AppCompatActivity {
private String mPebbleAppPackageName = null;
private boolean mBatteryOptDialogDisplayed = false;
private AlertDialog mBatteryOptDialog;
private boolean mSMSPermissionsRequested;
private boolean mLocationPermissions1Requested;
private boolean mLocationPermissions2Requested;
private boolean mSmsPermissionsRequested;
private boolean mPermissionsRequested;
private boolean mSMSPermissions2Requested;
public final String[] REQUIRED_PERMISSIONS = {
//Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.WAKE_LOCK,
};
public final String[] SMS_PERMISSIONS_1 = {
Manifest.permission.SEND_SMS,
Manifest.permission.READ_PHONE_STATE,
};
public final String[] LOCATION_PERMISSIONS_1 = {
Manifest.permission.SEND_SMS,
Manifest.permission.ACCESS_FINE_LOCATION,
//Manifest.permission.ACCESS_BACKGROUND_LOCATION,
Manifest.permission.READ_PHONE_STATE,
};
public final String[] LOCATION_PERMISSIONS_2 = {
Manifest.permission.ACCESS_BACKGROUND_LOCATION,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -161,13 +185,6 @@ public class StartupActivity extends AppCompatActivity {
mUtil.writeToSysLogFile("StartupActivity.onStart()");
TextView tv;
if (arePermissionsOK()) {
Log.i(TAG, "onStart() - Permissions OK");
} else {
Log.i(TAG, "onStart() - Permissions Not OK - requesting them");
requestPermissions(this);
}
String versionName = mUtil.getAppVersionName();
tv = (TextView) findViewById(R.id.appNameTv);
tv.setText("OpenSeizureDetector V" + versionName);
@@ -273,7 +290,7 @@ public class StartupActivity extends AppCompatActivity {
tv = (TextView) findViewById(R.id.textItem1);
pb = (ProgressBar) findViewById(R.id.progressBar1);
if (arePermissionsOK()) {
if (smsAlarmsActive && !areSMSPermissionsOK()) {
if (smsAlarmsActive && !areSMSPermissions1OK()) {
Log.i(TAG,"SMS permissions NOT OK");
tv.setText(getString(R.string.SmsPermissionWarning));
tv.setBackgroundColor(alarmColour);
@@ -281,14 +298,20 @@ public class StartupActivity extends AppCompatActivity {
//pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
//pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server));
requestSMSPermissions();
//requestSMSPermissions2();
allOk = false;
} else if (smsAlarmsActive && !areSMSPermissions2OK()) {
} else if (smsAlarmsActive && !areLocationPermissions1OK()) {
Log.i(TAG,"Location permissions NOT OK");
tv.setText(getString(R.string.SmsPermissionWarning));
tv.setBackgroundColor(alarmColour);
tv.setTextColor(alarmTextColour);
requestLocationPermissions1();
allOk = false;
} else if (smsAlarmsActive && !areLocationPermissions2OK()) {
Log.i(TAG,"SMS permissions2 NOT OK");
tv.setText(getString(R.string.SmsPermissionWarning));
tv.setBackgroundColor(alarmColour);
tv.setTextColor(alarmTextColour);
requestSMSPermissions2();
requestLocationPermissions2();
allOk = false;
} else {
tv.setText(getString(R.string.AppPermissionsOk));
@@ -535,36 +558,50 @@ public class StartupActivity extends AppCompatActivity {
public boolean arePermissionsOK() {
boolean allOk = true;
Log.v(TAG, "arePermissionsOK");
for (int i = 0; i < mUtil.REQUIRED_PERMISSIONS.length; i++) {
if (ContextCompat.checkSelfPermission(this, mUtil.REQUIRED_PERMISSIONS[i])
for (int i = 0; i < REQUIRED_PERMISSIONS.length; i++) {
if (ContextCompat.checkSelfPermission(this, REQUIRED_PERMISSIONS[i])
!= PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, mUtil.REQUIRED_PERMISSIONS[i] + " Permission Not Granted");
Log.i(TAG, REQUIRED_PERMISSIONS[i] + " Permission Not Granted");
allOk = false;
}
}
return allOk;
}
public boolean areSMSPermissionsOK() {
public boolean areSMSPermissions1OK() {
boolean allOk = true;
Log.v(TAG, "areSMSPermissionsOK()");
for (int i = 0; i < mUtil.SMS_PERMISSIONS.length; i++) {
if (ContextCompat.checkSelfPermission(this, mUtil.SMS_PERMISSIONS[i])
Log.v(TAG, "areSMSPermissions1 OK()");
for (int i = 0; i < SMS_PERMISSIONS_1.length; i++) {
if (ContextCompat.checkSelfPermission(this, SMS_PERMISSIONS_1[i])
!= PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, mUtil.SMS_PERMISSIONS[i] + " Permission Not Granted");
Log.i(TAG, "areSMSPermissions1OK: "+SMS_PERMISSIONS_1[i] + " Permission Not Granted");
allOk = false;
}
}
return allOk;
}
public boolean areSMSPermissions2OK() {
public boolean areLocationPermissions1OK() {
boolean allOk = true;
Log.v(TAG, "areLocationPermissions1 OK()");
for (int i = 0; i < LOCATION_PERMISSIONS_1.length; i++) {
if (ContextCompat.checkSelfPermission(this, LOCATION_PERMISSIONS_1[i])
!= PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, LOCATION_PERMISSIONS_1[i] + " Permission Not Granted");
allOk = false;
}
}
return allOk;
}
public boolean areLocationPermissions2OK() {
boolean allOk = true;
Log.v(TAG, "areSMSPermissions2OK()");
for (int i = 0; i < mUtil.SMS_PERMISSIONS_2.length; i++) {
if (ContextCompat.checkSelfPermission(this, mUtil.SMS_PERMISSIONS_2[i])
for (int i = 0; i < LOCATION_PERMISSIONS_2.length; i++) {
if (ContextCompat.checkSelfPermission(this, LOCATION_PERMISSIONS_2[i])
!= PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, mUtil.SMS_PERMISSIONS_2[i] + " Permission Not Granted");
Log.i(TAG, LOCATION_PERMISSIONS_2[i] + " Permission Not Granted");
allOk = false;
}
}
@@ -576,62 +613,87 @@ public class StartupActivity extends AppCompatActivity {
Log.i(TAG, "requestPermissions() - request already sent - not doing anything");
} else {
Log.i(TAG, "requestPermissions() - requesting permissions");
for (int i = 0; i < mUtil.REQUIRED_PERMISSIONS.length; i++) {
for (int i = 0; i < REQUIRED_PERMISSIONS.length; i++) {
if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
mUtil.REQUIRED_PERMISSIONS[i])) {
Log.i(TAG, "shouldShowRationale for permission" + mUtil.REQUIRED_PERMISSIONS[i]);
REQUIRED_PERMISSIONS[i])) {
Log.i(TAG, "shouldShowRationale for permission" + REQUIRED_PERMISSIONS[i]);
}
}
ActivityCompat.requestPermissions(activity,
mUtil.REQUIRED_PERMISSIONS,
REQUIRED_PERMISSIONS,
42);
mPermissionsRequested = true;
}
}
public void requestSMSPermissions() {
if (mSMSPermissionsRequested) {
if (mSmsPermissionsRequested) {
Log.i(TAG, "requestSMSPermissions() - request already sent - not doing anything");
} else {
Log.i(TAG, "requestSMSPermissions() - requesting permissions");
mSMSPermissionsRequested = true;
mSmsPermissionsRequested = true;
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
this);
alertDialogBuilder
.setTitle(R.string.permissions_required)
.setMessage(R.string.SMS_permissions_rationale_1)
.setMessage(R.string.sms_permissions_rationale_1)
.setCancelable(false)
.setPositiveButton(getString(R.string.okBtnTxt), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
Log.i(TAG,"requestSMSPermissions(): Launching ActivityCompat.requestPermissions()");
ActivityCompat.requestPermissions(StartupActivity.this,
mUtil.SMS_PERMISSIONS,
SMS_PERMISSIONS_1,
45);
}
}).create().show();
}
}
public void requestLocationPermissions1() {
if (mLocationPermissions1Requested) {
Log.i(TAG, "requestLocationPermissions1() - request already sent - not doing anything");
} else {
Log.i(TAG, "requestLocationPermissions1() - requesting permissions");
mLocationPermissions1Requested = true;
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
this);
alertDialogBuilder
.setTitle(R.string.permissions_required)
.setMessage(R.string.location_permissions_rationale_1)
.setCancelable(false)
.setPositiveButton(getString(R.string.okBtnTxt), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
Log.i(TAG,"requestLocationPermissions1(): Launching ActivityCompat.requestPermissions()");
ActivityCompat.requestPermissions(StartupActivity.this,
LOCATION_PERMISSIONS_1,
43);
}
}).create().show();
}
}
public void requestSMSPermissions2() {
if (mSMSPermissions2Requested) {
public void requestLocationPermissions2() {
if (mLocationPermissions2Requested) {
Log.i(TAG, "requestSMSPermissions2() - request already sent - not doing anything");
} else {
Log.i(TAG, "requestSMSPermissions2() - requesting permissions");
mSMSPermissions2Requested = true;
mLocationPermissions2Requested = true;
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
this);
alertDialogBuilder
.setTitle(R.string.permissions_required)
.setMessage(R.string.sms_permissions_2_rationale)
.setMessage(R.string.location_permissions_2_rationale)
.setCancelable(false)
.setPositiveButton(getString(R.string.okBtnTxt), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
Log.i(TAG,"requestSMSPermissions(): Launching ActivityCompat.requestPermissions()");
ActivityCompat.requestPermissions(StartupActivity.this,
mUtil.SMS_PERMISSIONS_2,
LOCATION_PERMISSIONS_2,
44);
}
}).create().show();

View File

@@ -397,17 +397,23 @@
https://openseizuredetector.org.uk web site.
</string>
<string name="SMS_permissions_rationale_1">
OpenSeizureDetector needs permission to <b>control your phone and send SMS messages</b> to be able to send SMS alerts.\n\n
It needs <b>access to your location</b> so that the SMS alert can include a Google Maps link so your carer knows where you are to offer assistance.\n\n
<string name="sms_permissions_rationale_1">
OpenSeizureDetector needs permission to <b>read your phone state and send SMS messages</b> to enable it to send SMS alerts when it detects a seizure.\n\n
With this permission enabled the App will <b>send an SMS message to the phone numbers you enter on th Alarm settings page of the app when it detects a seizure</b>.\n\n
Please grant the permissions in the following screens after pressing \'OK\' below....\n\n
You can change this later by going into the phone settings and selecting Apps->OpenSeizureDetector->Permissions
</string>
<string name="sms_permissions_2_rationale">
OpenSeizureDetector needs your permission to access your location when it is <b>running in the background</b>.\n\n
This is so it can send <b>SMS location alert</b> messages even if you do not have the OpenSeizureDetector main screen displayed on your phone when you have a seizure.\n\n
<string name="location_permissions_rationale_1">
This App collects location data to enable it to send <b>SMS location alert</b> messages when it detects a seizure.\n\n
With this permission enabled the App will send an SMS message to the phone numbers you enter on the Alarm settings page of the app when it detects a seizure. <b>The message will include a Google Maps link to show your location</b>.\n\n
Please grant the permissions in the following screens after pressing \'OK\' below....\n\n
You can change this later by going into the phone settings and selecting Apps->OpenSeizureDetector->Permissions
</string>
<string name="location_permissions_2_rationale">
This App collects location data to enable it to send <b>SMS location alert</b> messages when it detects a seizure, <b>even even when the app is closed or not in use</b>.\n\n
With this permission enabled the App will send an SMS message to the phone numbers you enter on the Alarm settings page of the app when it detects a seizure. <b>The message will include a Google Maps link to show your location</b>.\n\n
Please grant the required permission by selecting "Allow all the time" on the next screen, after pressing \'OK\' below....\n\n
You can change this later by going into the phone settings and selecting Apps->OpenSeizureDetector->Permissions
</string>
<string name="permissions_required">Permissions Required</string>
<string name="permissions_required">Permissions Disclosure, Prominent :)</string>
</resources>