Skip to content

Commit

Permalink
Check for phone permissions when using call intent (#2344)
Browse files Browse the repository at this point in the history
  • Loading branch information
dshokouhi committed Mar 6, 2022
1 parent eae2c6e commit d05920d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,16 @@ class MessagingManager @Inject constructor(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(context))
notifyMissingPermission(data[MESSAGE].toString())
else
else if (ContextCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED && data["tag"] == Intent.ACTION_CALL) {
Handler(Looper.getMainLooper()).post {
Toast.makeText(
context,
context.getString(commonR.string.missing_phone_permission),
Toast.LENGTH_LONG
).show()
}
navigateAppDetails()
} else
processActivityCommand(data)
} else
processActivityCommand(data)
Expand Down Expand Up @@ -1626,7 +1635,16 @@ class MessagingManager @Inject constructor(
COMMAND_MEDIA -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
requestNotificationPermission()
}
COMMAND_BLUETOOTH -> navigateAppDetails()
COMMAND_BLUETOOTH -> {
Handler(Looper.getMainLooper()).post {
Toast.makeText(
context,
context.getString(commonR.string.missing_bluetooth_permission),
Toast.LENGTH_LONG
).show()
}
navigateAppDetails()
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
<string name="message_some_installed">The Wear app is installed on some of your wear devices: (%1$s)\n\nClick the button below to install the app on the other devices.\n\nNote: Currently the Wear OS app requires you to be enrolled in the beta for the phone app. If the button does not work then please join the beta: https://play.google.com/apps/testing/io.homeassistant.companion.android</string>
<string name="mfa_title">Two-factor\nAuthentication</string>
<string name="mfa_hint">Code</string>
<string name="missing_command_permission">Please open the Home Assistant app and send the command again in order to grant the proper permissions. You will be taken to a page to either grant the Home Assistant app the permission, or you will need to select Permissions from the details page and then grant the missing permission. For command_bluetooth the name of the permission is Nearby devices.</string>
<string name="missing_command_permission">Please open the Home Assistant app and send the command again in order to grant the proper permissions. You will be taken to a page to either grant the Home Assistant app the permission, or you will need to select Permissions from the details page and then grant the missing permission. For command_bluetooth the name of the permission is Nearby devices. If you are attempting to use command_activity to make a phone call you will also need to grant Phone permissions.</string>
<string name="areas">Areas</string>
<string name="more_entities">More entities</string>
<string name="need_help">Need Help?</string>
Expand Down Expand Up @@ -791,4 +791,6 @@
<string name="sensor_update_notification">In order for the app to send sensor updates in the background a notification will be created during the update. You may use the button below to manage the appearance of this notification. It is recommended to minimize the notification to hide the icon.</string>
<string name="sensor_worker_notification_channel">Manage Sensor Worker Notification</string>
<string name="sensor_update_frequency_summary">Change the frequency of updates for sensors that do not update instantly.</string>
<string name="missing_phone_permission">Please grant Phone permission to make a phone call</string>
<string name="missing_bluetooth_permission">Please grant Nearby devices permission to control bluetooth</string>
</resources>

0 comments on commit d05920d

Please sign in to comment.