start checking for BT permissions

This commit is contained in:
Eric House 2022-11-13 11:39:35 -08:00
parent c888e2621b
commit 347e54d2e7
5 changed files with 23 additions and 10 deletions

View file

@ -79,7 +79,7 @@ public class AboutAlert extends XWDialogFragment {
sb = new StringBuilder( getString( R.string.about_devid_fmt,
XwJNI.dvc_getMQTTDevID(null) ) );
if ( BuildConfig.NON_RELEASE ) {
String[] pair = BTUtils.getBTNameAndAddress();
String[] pair = BTUtils.getBTNameAndAddress( context );
if ( null != pair && 2 >= pair.length && null != pair[1] ) {
sb.append( "\n\n" ).append( getString( R.string.about_btaddr_fmt, pair[1] ) );
}

View file

@ -130,6 +130,10 @@ public class BTUtils {
}
};
public static final Perms23.Perm[] BTPerms = { Perms23.Perm.BLUETOOTH_CONNECT,
Perms23.Perm.BLUETOOTH_SCAN,
};
public static boolean BTAvailable()
{
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
@ -161,6 +165,13 @@ public class BTUtils {
}
}
public static boolean havePermissions( Context context )
{
boolean result = Perms23.havePermissions( context, BTPerms );
Log.d( TAG, "havePermissions() => %b", result );
return result;
}
public static void disabledChanged( Context context )
{
boolean disabled = XWPrefs.getBTDisabled( context );
@ -221,12 +232,14 @@ public class BTUtils {
return result;
}
public static String[] getBTNameAndAddress()
public static String[] getBTNameAndAddress( Context context )
{
String[] result = null;
BluetoothAdapter adapter = getAdapterIf();
if ( null != adapter ) {
result = new String[] { adapter.getName(), sMyMacAddr };
if ( havePermissions( context ) ) {
BluetoothAdapter adapter = getAdapterIf();
if ( null != adapter ) {
result = new String[] { adapter.getName(), sMyMacAddr };
}
}
return result;
}

View file

@ -1582,7 +1582,7 @@ public class BoardDelegate extends DelegateBase
nli.addRelayInfo( room, inviteID );
break;
case COMMS_CONN_BT:
nli.addBTInfo();
nli.addBTInfo( m_activity );
break;
case COMMS_CONN_SMS:
nli.addSMSInfo( m_activity );

View file

@ -326,7 +326,7 @@ public class NetLaunchInfo implements Serializable {
// Log.d( TAG, "NetLaunchInfo(): got type %s", typ );
switch( typ ) {
case COMMS_CONN_BT:
addBTInfo();
addBTInfo( context );
break;
case COMMS_CONN_RELAY:
addRelayInfo( summary.roomName, summary.relayID );
@ -700,9 +700,9 @@ public class NetLaunchInfo implements Serializable {
add( CommsConnType.COMMS_CONN_RELAY );
}
public void addBTInfo()
public void addBTInfo( Context context )
{
String[] got = BTUtils.getBTNameAndAddress();
String[] got = BTUtils.getBTNameAndAddress( context );
if ( null != got ) {
btName = got[0];
btAddress = got[1];

View file

@ -491,7 +491,7 @@ public class CommsAddrRec implements Serializable {
Assert.failDbg();
break;
case COMMS_CONN_BT:
String[] strs = BTUtils.getBTNameAndAddress();
String[] strs = BTUtils.getBTNameAndAddress( context );
if ( null != strs ) {
bt_hostName = strs[0];
bt_btAddr = strs[1];