Skip to content

Commit

Permalink
Add dialogs and strings for other sensitive data permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
peyman-mohtashami committed May 10, 2023
1 parent 71a1f19 commit 03f8fa7
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,10 @@ open class PermissionHandler(
}

private fun requestBackgroundLocationPermissions() {
alertDialog {
setTitle(R.string.enable_location_title)
setMessage(R.string.enable_location_background)
setPositiveButton(android.R.string.ok) { dialog, _ ->
dialog.dismiss()
requestPermissions(setOf(ACCESS_BACKGROUND_LOCATION_COMPAT))
}
setNegativeButton(android.R.string.cancel) { dialog, _ ->
dialog.cancel()
requestPermissions()
}
show()
}
requestPermissions(setOf(ACCESS_BACKGROUND_LOCATION_COMPAT))
}

private fun requestLocationPermissions(locationPermissions: Set<String>) {

alertDialog {
setView(R.layout.location_dialog)
setPositiveButton(android.R.string.ok) { dialog, _ ->
Expand Down Expand Up @@ -205,8 +192,7 @@ open class PermissionHandler(

private fun requestLocationProvider() {
alertDialog {
setTitle(R.string.enable_location_title)
setMessage(R.string.enable_location_instruction)
setView(R.layout.location_dialog)
setPositiveButton(android.R.string.ok) { dialog, _ ->
dialog.dismiss()
Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
Expand All @@ -216,17 +202,26 @@ open class PermissionHandler(
dialog.cancel()
requestPermissions()
}
setIcon(android.R.drawable.ic_dialog_alert)
}
}

private fun requestSystemWindowPermissions() {
// Show alert dialog to the user saying a separate permission is needed
// Launch the settings activity if the user prefers
Intent(
Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + activity.packageName)
).startActivityForResult(ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE)
alertDialog {
setView(R.layout.system_window_dialog)
setPositiveButton(android.R.string.ok) { dialog, _ ->
dialog.dismiss()
Intent(
Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + activity.packageName)
).startActivityForResult(ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE)
}
setNegativeButton(android.R.string.cancel) { dialog, _ ->
dialog.cancel()
requestPermissions()
}
}
}

private fun Intent.startActivityForResult(code: Int) {
Expand All @@ -242,16 +237,25 @@ open class PermissionHandler(

@SuppressLint("BatteryLife")
private fun requestDisableBatteryOptimization() {
Intent(
Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
Uri.parse("package:" + activity.packageName)
).startActivityForResult(BATTERY_OPT_CODE)
alertDialog {
setView(R.layout.disable_battery_optimization_dialog)
setPositiveButton(android.R.string.ok) { dialog, _ ->
dialog.dismiss()
Intent(
Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
Uri.parse("package:" + activity.packageName)
).startActivityForResult(BATTERY_OPT_CODE)
}
setNegativeButton(android.R.string.cancel) { dialog, _ ->
dialog.cancel()
requestPermissions()
}
}
}

private fun requestPackageUsageStats() {
alertDialog {
setTitle(R.string.enable_package_usage_title)
setMessage(R.string.enable_package_usage)
setView(R.layout.usage_tracking_dialog)
setPositiveButton(android.R.string.ok) { dialog, _ ->
dialog.dismiss()
var intent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
Expand All @@ -264,7 +268,6 @@ open class PermissionHandler(
dialog.cancel()
requestPermissions()
}
setIcon(android.R.drawable.ic_dialog_alert)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="48dp" android:tint="#388E3C" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="48dp">

<path android:fillColor="@android:color/white" android:pathData="M4,8h4L8,4L4,4v4zM10,20h4v-4h-4v4zM4,20h4v-4L4,16v4zM4,14h4v-4L4,10v4zM10,14h4v-4h-4v4zM16,4v4h4L20,4h-4zM10,8h4L14,4h-4v4zM16,14h4v-4h-4v4zM16,20h4v-4h-4v4z"/>

</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="48dp" android:tint="#388E3C" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="48dp">

<path android:fillColor="@android:color/white" android:pathData="M15.67,4L14,4L14,2h-4v2L8.33,4C7.6,4 7,4.6 7,5.33v15.33C7,21.4 7.6,22 8.33,22h7.33c0.74,0 1.34,-0.6 1.34,-1.33L17,5.33C17,4.6 16.4,4 15.67,4zM13,18h-2v-2h2v2zM13,14h-2L11,9h2v5z"/>

</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="48dp" android:tint="#FBC02D" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="48dp">

<path android:fillColor="@android:color/white" android:pathData="M1,21h22L12,2 1,21zM13,18h-2v-2h2v2zM13,14h-2v-4h2v4z"/>

</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingVertical="64dp"
android:paddingHorizontal="16dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/baseline_battery_alert_green_700_48dp"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_gravity="center"
android:text="@string/disable_battery_optimization_dialog_title"
android:textSize="20sp"
android:textStyle="bold" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/disable_battery_optimization_dialog_message"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/disable_battery_optimization_dialog_help"
/>

</LinearLayout>
8 changes: 4 additions & 4 deletions radar-commons-android/src/main/res/layout/location_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_gravity="center"
android:text="@string/location_dialog_title"
android:text="@string/location_bg_dialog_title"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/location_dialog_message"
android:text="@string/location_bg_dialog_message"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/location_dialog_usage"
android:text="@string/dialog_usage"
/>

</LinearLayout>
46 changes: 46 additions & 0 deletions radar-commons-android/src/main/res/layout/system_window_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingVertical="64dp"
android:paddingHorizontal="16dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/baseline_apps_green_700_48dp"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/system_window_dialog_title"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/system_window_dialog_message"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/dialog_usage"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/system_window_dialog_help"
/>


</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingVertical="64dp"
android:paddingHorizontal="16dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/baseline_warning_yellow_700_48dp"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_gravity="center"
android:text="@string/usage_tracking_dialog_title"
android:textSize="20sp"
android:textStyle="bold" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/usage_tracking_dialog_message"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/dialog_usage"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/usage_tracking_dialog_help"
/>

</LinearLayout>
32 changes: 24 additions & 8 deletions radar-commons-android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,37 @@
<string name="filter_split_regex">,</string>
<string name="retry_oauth_login">Failed to login to authorization service, please retry</string>
<string name="login_failed">Failed to log in</string>
<string name="enable_location">
Location information is needed to enable Bluetooth Low Energy and/or location tracking as
part of the study.
</string>

<string name="location_bg_dialog_title">pRMT App uses your \"Location in Background\"</string>
<string name="location_bg_dialog_message">This app collects location data to enable Bluetooth Low Energy and/or location tracking as
part of the study even when the app is closed or not in use.</string>
<string name="dialog_usage">The researcher(s) only use the collected data in the study you consented to.</string>

<string name="location_dialog_title">pRMT App uses your \"Location\"</string>
<string name="location_dialog_message">Location information is needed to enable Bluetooth Low Energy and/or location tracking as part of the study.</string>

<string name="usage_tracking_dialog_title">Enable \"Usage tracking\"</string>
<string name="usage_tracking_dialog_message">Enable usage access to keep track of what kind of applications you use.</string>
<string name="usage_tracking_dialog_help">After click \"OK\", select RADAR pRMT from the list and enable \"Usage access\"</string>

<string name="system_window_dialog_title">Enable \"Display over other apps\"</string>
<string name="system_window_dialog_message">Allow this app to display on top of other apps.</string>
<string name="system_window_dialog_help">After click \"OK\", select RADAR pRMT from the list and enable \"Display over other apps\".</string>


<string name="disable_battery_optimization_dialog_title">Enable \"No Restrictions\" for background apps</string>
<string name="disable_battery_optimization_dialog_message">\"No Restrictions for background apps\" means that the battery saver does not restrict app\'s activity.</string>
<string name="disable_battery_optimization_dialog_help">After click \"OK\", select \"No restrictions\".</string>

<string name="enable_location">Location information is needed to enable Bluetooth Low Energy and/or location tracking as part of the study.</string>
<string name="enable_location_background">
Background location is needed to keep passively collecting data while the app is in the background, either for Bluetooth devices or for actual, relative location.
</string>
<string name="location_dialog_title">pRMT App uses your location</string>
<string name="location_dialog_message">This app collects location data to enable Bluetooth Low Energy and/or location tracking as
part of the study even when the app is closed or not in use.</string>
<string name="location_dialog_usage">The researcher(s) only use the collected data in the study you consented to.</string>

<string name="enable_location_instruction">
<![CDATA[Location information needed to enable Bluetooth Low Energy and location tracking. Enable location settings in Settings -> Location]]></string>
<string name="enable_package_usage">Enable usage access to keep track of what kind of applications you use.</string>

<string name="enable_location_title">Enable location tracking</string>
<string name="enable_package_usage_title">Enable usage tracking</string>

Expand Down

0 comments on commit 03f8fa7

Please sign in to comment.