remove BT perms crashes and fix so BT invitations work

This commit is contained in:
Eric House 2022-11-14 19:48:52 -08:00
parent 8ca83ae871
commit b999da1a92
7 changed files with 28 additions and 46 deletions

View file

@ -22,10 +22,8 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Required for wifi-direct -->
<!-- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> -->
<!-- <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-feature android:name="android.hardware.telephony"
android:required = "false"

View file

@ -20,14 +20,15 @@
package org.eehouse.android.xw4;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass.Device.Major;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
@ -170,10 +171,16 @@ public class BTUtils {
return havePermissions( getContext() );
}
// If I build for 31 but run on an older phone, these permissions don't
// show up in settings->app->permissions, but I get back false from
// havePermissions(). There seems to be no way to grant them, so let's see
// if on older phones we can proceed without crashing. Test well....
public static boolean havePermissions( Context context )
{
boolean result = Perms23.havePermissions( context, BTPerms );
Log.d( TAG, "havePermissions() => %b", result );
final int sdk = Build.VERSION.SDK_INT;
boolean result = sdk < Build.VERSION_CODES.Q
|| Perms23.havePermissions( context, BTPerms );
Log.d( TAG, "havePermissions(sdk=%d) => %b", sdk, result );
return result;
}
@ -316,9 +323,10 @@ public class BTUtils {
getPA( btAddr ).addPing( gameID );
}
public static void inviteRemote( Context context, String btAddr,
NetLaunchInfo nli )
public static void sendInvite( Context context, String btAddr,
NetLaunchInfo nli )
{
Log.d( TAG, "sendInvite(addr=%s, nli=%s)", btAddr, nli );
getPA( btAddr ).addInvite( nli );
}
@ -856,7 +864,7 @@ public class BTUtils {
// appropriate based on backoff logic, and be awakened when
// something new comes in or there's reason to hope a send try
// will succeed.
while ( BTEnabled() ) {
while ( BTEnabled() && havePermissions() ) {
synchronized ( this ) {
if ( mExitWhenEmpty && 0 == mElems.size() ) {
break;

View file

@ -119,7 +119,6 @@ public class BoardDelegate extends DelegateBase
private int[] m_missingCounts;
private boolean m_remotesAreRobots;
private InviteMeans m_missingMeans = null;
private boolean m_progressShown = false;
private boolean m_isFirstLaunch;
private boolean m_firingPrefs;
private BoardUtilCtxt m_utils;
@ -1346,14 +1345,12 @@ public class BoardDelegate extends DelegateBase
@SuppressWarnings("fallthrough")
public void eventOccurred( MultiService.MultiEvent event, final Object ... args )
{
boolean doStopProgress = false;
switch( event ) {
case MESSAGE_ACCEPTED:
case MESSAGE_REFUSED:
ConnStatusHandler.
updateStatusIn( m_activity, this, CommsConnType.COMMS_CONN_BT,
MultiService.MultiEvent.MESSAGE_ACCEPTED == event);
doStopProgress = true;
break;
case MESSAGE_NOGAME:
final int gameID = (Integer)args[0];
@ -1376,7 +1373,7 @@ public class BoardDelegate extends DelegateBase
Log.w( TAG, "failed to create game" );
break;
case NEWGAME_DUP_REJECTED:
doStopProgress = true;
post( new Runnable() {
@Override
public void run() {
@ -1404,15 +1401,9 @@ public class BoardDelegate extends DelegateBase
break;
default:
doStopProgress = true; // in case it's a BT invite
super.eventOccurred( event, args );
break;
}
if ( doStopProgress && m_progressShown ) {
m_progressShown = false;
stopProgress();
}
}
//////////////////////////////////////////////////
@ -1614,9 +1605,7 @@ public class BoardDelegate extends DelegateBase
private void deleteAndClose()
{
if ( null == m_jniThread ) { // test probably no longer necessary
Assert.failDbg();
} else {
if ( null != m_jniThread ) { // this does still happen
GameUtils.deleteGame( m_activity, m_jniThread.getLock(), false, false );
}
waitCloseGame( false );
@ -2720,19 +2709,10 @@ public class BoardDelegate extends DelegateBase
switch ( m_missingMeans ) {
case BLUETOOTH:
if ( ! m_progressShown ) {
m_progressShown = true;
String progMsg = BTUtils.nameForAddr( dev );
progMsg = getString( R.string.invite_progress_bt_fmt, progMsg );
startProgress( R.string.invite_progress_title, progMsg,
new OnCancelListener() {
public void onCancel( DialogInterface dlg )
{
m_progressShown = false;
}
});
}
BTUtils.inviteRemote( m_activity, dev, nli );
CommsAddrRec destAddr = new CommsAddrRec(CommsConnType.COMMS_CONN_BT)
.setBTParams( dev, null );
XwJNI.comms_invite( m_jniGamePtr, nli, destAddr );
dev = null; // don't record
break;
case SMS_DATA:
sendNBSInviteIf( dev, nli, true );
@ -2747,6 +2727,7 @@ public class BoardDelegate extends DelegateBase
case MQTT:
// MQTTUtils.inviteRemote( m_activity, dev, nli );
MQTTUtils.addInvite( m_jniGamePtr, dev, nli );
Assert.failDbg(); // not getting here, right?
break;
default:
Assert.failDbg();

View file

@ -166,7 +166,7 @@ public class MultiMsgSink implements TransportProcs {
}
break;
case COMMS_CONN_BT:
BTUtils.inviteRemote( context, addr.bt_btAddr, nli );
BTUtils.sendInvite( context, addr.bt_btAddr, nli );
success = true;
break;
default:

View file

@ -345,12 +345,13 @@ public class CommsAddrRec implements Serializable {
ip_relay_advertiseRoom = false;
}
public void setBTParams( String btAddr, String btName )
public CommsAddrRec setBTParams( String btAddr, String btName )
{
bt_hostName = btName;
if ( ! BTUtils.isBogusAddr( btAddr ) ) {
bt_btAddr = btAddr;
}
return this;
}
public void setSMSParams( String phone )

View file

@ -1597,10 +1597,6 @@
nearby devices -->
<string name="button_scan">Rescan</string>
<!-- -->
<string name="invite_progress_title">Connecting…</string>
<string name="invite_progress_bt_fmt">Sending Bluetooth invitation
to CrossWords on %1$s</string>
<!-- -->
<string name="summary_wait_host">Waiting for guest[s]</string>
<!-- -->
<string name="summary_wait_guest">Unconnected</string>
@ -2396,7 +2392,7 @@
displayed.
</string>
<string name="nearbydev_rationale">CrossWords needs permission to
discover nearby devices in order to use Bluetooth.</string>
interact with nearby devices in order to use Bluetooth.</string>
<string name="move_dict_rationale">Storing a wordlist in the
Downloads area requires Storage permission.</string>
<string name="remove_sms">Remove SMS</string>

View file

@ -9,8 +9,6 @@
<!-- GooglePlay version no longer allowed to have these (after 9 March 2019) -->
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<!-- for crittercism -->
<uses-permission android:name="android.permission.GET_TASKS"/>