Skip to content

Commit

Permalink
Attempted fix for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
aardappel committed Oct 28, 2024
1 parent a062141 commit bd65a7b
Show file tree
Hide file tree
Showing 13 changed files with 1,578 additions and 1,104 deletions.
5 changes: 3 additions & 2 deletions dev/android-project/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ else {
}

android {
namespace "org.libsdl.app"
compileSdkVersion 26
defaultConfig {
if (buildAsApplication) {
applicationId "org.libsdl.app"
}
minSdkVersion 18 // ES3.0
minSdkVersion 21 // ES3.0
targetSdkVersion 26
versionCode 1
versionName "1.0"
externalNativeBuild {
ndkBuild {
arguments "APP_PLATFORM=android-18", "-j8" // ES3.0
arguments "APP_PLATFORM=android-21", "-j8" // ES3.0
abiFilters 'arm64-v8a'//, 'armeabi-v7a', 'x86', 'x86_64'
}
}
Expand Down
3 changes: 2 additions & 1 deletion dev/android-project/app/jni/Application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ APP_ABI := arm64-v8a # armeabi-v7a x86 x86_64
# Min runtime API level (ES3.0 == 18)
APP_PLATFORM=android-18

APP_CPPFLAGS += -frtti -std=c++17 -Wno-c++17-extensions -fexceptions -Wno-switch
APP_CPPFLAGS += -fsigned-char -frtti -std=c++17 -Wno-c++17-extensions -fexceptions -Wno-switch
APP_CFLAGS += -fsigned-char
8 changes: 4 additions & 4 deletions dev/android-project/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
android:versionName="1.0"
android:installLocation="auto">

<!-- OpenGL ES 2.0 -->
<uses-feature android:glEsVersion="0x00020000" />
<!-- OpenGL ES 3.0 -->
<uses-feature android:glEsVersion="0x00030000" />

<!-- Touchscreen support -->
<uses-feature
Expand All @@ -36,7 +36,7 @@

<!-- Create a Java class extending SDLActivity and place it in a
directory under app/src/main/java matching the package, e.g. app/src/main/java/com/gamemaker/game/MyGame.java
then replace "SDLActivity" with the name of your class (e.g. "MyGame")
in the XML below.
Expand All @@ -51,7 +51,7 @@
<!-- Example of setting SDL hints from AndroidManifest.xml:
<meta-data android:name="SDL_ENV.SDL_ACCELEROMETER_AS_JOYSTICK" android:value="0"/>
-->

<activity android:name="SDLActivity"
android:label="@string/app_name"
android:alwaysRetainTaskState="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.libsdl.app;

import android.hardware.usb.UsbDevice;

interface HIDDevice
{
public int getId();
Expand All @@ -9,6 +11,7 @@ interface HIDDevice
public int getVersion();
public String getManufacturerName();
public String getProductName();
public UsbDevice getDevice();
public boolean open();
public int sendFeatureReport(byte[] report);
public int sendOutputReport(byte[] report);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothGattService;
import android.hardware.usb.UsbDevice;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
Expand Down Expand Up @@ -165,13 +166,13 @@ public HIDDeviceBLESteamController(HIDDeviceManager manager, BluetoothDevice dev
mHandler = new Handler(Looper.getMainLooper());

mGatt = connectGatt();
final HIDDeviceBLESteamController finalThis = this;
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
finalThis.checkConnectionForChromebookIssue();
}
}, CHROMEBOOK_CONNECTION_CHECK_INTERVAL);
// final HIDDeviceBLESteamController finalThis = this;
// mHandler.postDelayed(new Runnable() {
// @Override
// public void run() {
// finalThis.checkConnectionForChromebookIssue();
// }
// }, CHROMEBOOK_CONNECTION_CHECK_INTERVAL);
}

public String getIdentifier() {
Expand All @@ -185,7 +186,7 @@ public BluetoothGatt getGatt() {
// Because on Chromebooks we show up as a dual-mode device, it will attempt to connect TRANSPORT_AUTO, which will use TRANSPORT_BREDR instead
// of TRANSPORT_LE. Let's force ourselves to connect low energy.
private BluetoothGatt connectGatt(boolean managed) {
if (Build.VERSION.SDK_INT >= 23) {
if (Build.VERSION.SDK_INT >= 23 /* Android 6.0 (M) */) {
try {
return mDevice.connectGatt(mManager.getContext(), managed, this, TRANSPORT_LE);
} catch (Exception e) {
Expand Down Expand Up @@ -428,7 +429,7 @@ public void run() {
}
});
}
}
}
else if (newState == 0) {
mIsConnected = false;
}
Expand Down Expand Up @@ -469,7 +470,7 @@ public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristi
// Only register controller with the native side once it has been fully configured
if (!isRegistered()) {
Log.v(TAG, "Registering Steam Controller with ID: " + getId());
mManager.HIDDeviceConnected(getId(), getIdentifier(), getVendorId(), getProductId(), getSerialNumber(), getVersion(), getManufacturerName(), getProductName(), 0);
mManager.HIDDeviceConnected(getId(), getIdentifier(), getVendorId(), getProductId(), getSerialNumber(), getVersion(), getManufacturerName(), getProductName(), 0, 0, 0, 0);
setRegistered();
}
}
Expand Down Expand Up @@ -563,6 +564,11 @@ public String getProductName() {
return "Steam Controller";
}

@Override
public UsbDevice getDevice() {
return null;
}

@Override
public boolean open() {
return true;
Expand Down
Loading

0 comments on commit bd65a7b

Please sign in to comment.