diff --git a/IOIOLibAndroid/build.gradle b/IOIOLibAndroid/build.gradle index 96eb8e574..90625011e 100644 --- a/IOIOLibAndroid/build.gradle +++ b/IOIOLibAndroid/build.gradle @@ -17,12 +17,12 @@ dependencies { api 'androidx.appcompat:appcompat:1.6.1' } -project.afterEvaluate { - publishing { - publications { - release(MavenPublication) { - from components.release +publishing { + publications { + release(MavenPublication) { + afterEvaluate { + from components.findByName('release') } } } -} +} \ No newline at end of file diff --git a/IOIOLibAndroidAccessory/build.gradle b/IOIOLibAndroidAccessory/build.gradle index 28d60c291..acaf70027 100644 --- a/IOIOLibAndroidAccessory/build.gradle +++ b/IOIOLibAndroidAccessory/build.gradle @@ -16,11 +16,11 @@ dependencies { api project(":IOIOLibAndroid") } -project.afterEvaluate { - publishing { - publications { - release(MavenPublication) { - from components.release +publishing { + publications { + release(MavenPublication) { + afterEvaluate { + from components.findByName('release') } } } diff --git a/IOIOLibAndroidAccessory/src/main/java/ioio/lib/android/accessory/AccessoryConnectionBootstrap.java b/IOIOLibAndroidAccessory/src/main/java/ioio/lib/android/accessory/AccessoryConnectionBootstrap.java index bdf52c3a8..ef3c6ae3e 100644 --- a/IOIOLibAndroidAccessory/src/main/java/ioio/lib/android/accessory/AccessoryConnectionBootstrap.java +++ b/IOIOLibAndroidAccessory/src/main/java/ioio/lib/android/accessory/AccessoryConnectionBootstrap.java @@ -53,6 +53,7 @@ import android.content.ContextWrapper; import android.content.Intent; import android.content.IntentFilter; +import android.os.Build; import android.os.ParcelFileDescriptor; import android.util.Log; @@ -154,7 +155,7 @@ public Object getExtra() { return null; } - private synchronized void waitForConnect(Connection connection) throws ConnectionLostException { + private synchronized void waitForConnect() throws ConnectionLostException { // In order to simplify the connection process in face of many different sequences of events // that might occur, we collapsed the entire sequence into one non-blocking method, // tryOpen(), which tries the entire process from the beginning, undoes everything if @@ -196,8 +197,15 @@ private boolean tryOpen() { if (!usbManager_.hasPermission(accessory)) { if (pendingIntent_ == null) { Log.v(TAG, "Requesting permission."); - pendingIntent_ = PendingIntent.getBroadcast(activity_, 0, new Intent( - ACTION_USB_PERMISSION), 0); + + int pendingIntentFlags; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + pendingIntentFlags = PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT; + } else { + pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT; + } + + pendingIntent_ = PendingIntent.getBroadcast(activity_, 0, new Intent(ACTION_USB_PERMISSION), pendingIntentFlags); usbManager_.requestPermission(accessory, pendingIntent_); } return false; @@ -233,7 +241,7 @@ private boolean tryOpen() { // bug: // http://code.google.com/p/android/issues/detail?id=20545 while (inputStream_.read() != 1) { - trySleep(1000); + trySleep(); } success = true; @@ -268,11 +276,11 @@ private void unregisterReceiver() { activity_.unregisterReceiver(this); } - private void trySleep(long time) { + private void trySleep() { synchronized (AccessoryConnectionBootstrap.this) { try { - AccessoryConnectionBootstrap.this.wait(time); - } catch (InterruptedException e) { + AccessoryConnectionBootstrap.this.wait(1000); + } catch (InterruptedException ignored) { } } } @@ -285,12 +293,12 @@ private class Connection implements IOIOConnection { private InstanceState instanceState_ = InstanceState.INIT; @Override - public InputStream getInputStream() throws ConnectionLostException { + public InputStream getInputStream() { return inputStream_; } @Override - public OutputStream getOutputStream() throws ConnectionLostException { + public OutputStream getOutputStream() { return outputStream_; } @@ -307,7 +315,7 @@ public void waitForConnect() throws ConnectionLostException { } try { - AccessoryConnectionBootstrap.this.waitForConnect(this); + AccessoryConnectionBootstrap.this.waitForConnect(); instanceState_ = InstanceState.CONNECTED; } catch (ConnectionLostException e) { instanceState_ = InstanceState.DEAD; @@ -327,7 +335,7 @@ public void disconnect() { } @Override - protected void finalize() throws Throwable { + protected void finalize() { disconnect(); } } diff --git a/IOIOLibAndroidAccessory/src/main/java/ioio/lib/android/accessory/Adapter.java b/IOIOLibAndroidAccessory/src/main/java/ioio/lib/android/accessory/Adapter.java index ac6e58536..012ec5c97 100644 --- a/IOIOLibAndroidAccessory/src/main/java/ioio/lib/android/accessory/Adapter.java +++ b/IOIOLibAndroidAccessory/src/main/java/ioio/lib/android/accessory/Adapter.java @@ -31,12 +31,10 @@ import ioio.lib.spi.NoRuntimeSupportException; -import android.annotation.TargetApi; import android.app.PendingIntent; import android.content.Context; import android.content.ContextWrapper; import android.hardware.usb.UsbManager; -import android.os.Build; import android.os.ParcelFileDescriptor; /** @@ -50,22 +48,22 @@ * UsbAccessory. */ class Adapter { - Support support_ = Support.NONE; + Support support_; Adapter() throws NoRuntimeSupportException { try { Class.forName("android.hardware.usb.UsbManager"); support_ = Support.NEW; return; - } catch (ClassNotFoundException e) { + } catch (ClassNotFoundException ignored) { } try { Class.forName("android.hardware.usb.UsbManager"); support_ = Support.LEGACY; return; - } catch (ClassNotFoundException e) { + } catch (ClassNotFoundException ignored) { } - throw new NoRuntimeSupportException("No support for USB accesory mode."); + throw new NoRuntimeSupportException("No support for USB accessory mode."); } AbstractUsbManager getManager(ContextWrapper wrapper) { @@ -79,7 +77,6 @@ AbstractUsbManager getManager(ContextWrapper wrapper) { } } - @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) private AbstractUsbManager getManagerNew(ContextWrapper wrapper) { final android.hardware.usb.UsbManager manager = (android.hardware.usb.UsbManager) wrapper .getSystemService(Context.USB_SERVICE); @@ -92,7 +89,7 @@ private AbstractUsbManager getManagerLegacy(ContextWrapper wrapper) { } private enum Support { - NEW, LEGACY, NONE + NEW, LEGACY } interface UsbAccessoryInterface { @@ -101,8 +98,7 @@ interface UsbAccessoryInterface { static abstract class AbstractUsbManager { final String EXTRA_PERMISSION_GRANTED; - protected AbstractUsbManager(String action_usb_accessory_detached, - String extra_permission_granted) { + protected AbstractUsbManager(String extra_permission_granted) { EXTRA_PERMISSION_GRANTED = extra_permission_granted; } @@ -127,7 +123,7 @@ private static final class LegacyUsbManager extends AbstractUsbManager { private final android.hardware.usb.UsbManager manager_; private LegacyUsbManager(android.hardware.usb.UsbManager manager) { - super(android.hardware.usb.UsbManager.ACTION_USB_ACCESSORY_DETACHED, + super( android.hardware.usb.UsbManager.EXTRA_PERMISSION_GRANTED); manager_ = manager; } @@ -161,18 +157,17 @@ UsbAccessoryInterface[] getAccessoryList() { return null; UsbAccessoryInterface[] result = new UsbAccessoryInterface[accs.length]; for (int i = 0; i < accs.length; ++i) { - result[i] = new UsbAccessoryAdapter(accs[i]); + result[i] = new UsbAccessoryAdapter<>(accs[i]); } return result; } } - @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) private static final class NewUsbManager extends AbstractUsbManager { private final android.hardware.usb.UsbManager manager_; private NewUsbManager(android.hardware.usb.UsbManager manager) { - super(android.hardware.usb.UsbManager.ACTION_USB_ACCESSORY_DETACHED, + super( android.hardware.usb.UsbManager.EXTRA_PERMISSION_GRANTED); manager_ = manager; } @@ -206,7 +201,7 @@ UsbAccessoryInterface[] getAccessoryList() { return null; UsbAccessoryInterface[] result = new UsbAccessoryInterface[accs.length]; for (int i = 0; i < accs.length; ++i) { - result[i] = new UsbAccessoryAdapter(accs[i]); + result[i] = new UsbAccessoryAdapter<>(accs[i]); } return result; } diff --git a/IOIOLibAndroidBluetooth/build.gradle b/IOIOLibAndroidBluetooth/build.gradle index 661415182..6cbe0df0f 100644 --- a/IOIOLibAndroidBluetooth/build.gradle +++ b/IOIOLibAndroidBluetooth/build.gradle @@ -16,11 +16,11 @@ dependencies { api project(":IOIOLibAndroid") } -project.afterEvaluate { - publishing { - publications { - release(MavenPublication) { - from components.release +publishing { + publications { + release(MavenPublication) { + afterEvaluate { + from components.findByName('release') } } } diff --git a/IOIOLibAndroidDevice/build.gradle b/IOIOLibAndroidDevice/build.gradle index 6ea94b050..1b6cc5652 100644 --- a/IOIOLibAndroidDevice/build.gradle +++ b/IOIOLibAndroidDevice/build.gradle @@ -16,11 +16,11 @@ dependencies { api project(":IOIOLibAndroid") } -project.afterEvaluate { - publishing { - publications { - release(MavenPublication) { - from components.release +publishing { + publications { + release(MavenPublication) { + afterEvaluate { + from components.findByName('release') } } } diff --git a/IOIOLibAndroidDevice/src/main/java/ioio/lib/android/device/DeviceConnectionBootstrap.java b/IOIOLibAndroidDevice/src/main/java/ioio/lib/android/device/DeviceConnectionBootstrap.java index 8e39907f0..71b63c5b0 100644 --- a/IOIOLibAndroidDevice/src/main/java/ioio/lib/android/device/DeviceConnectionBootstrap.java +++ b/IOIOLibAndroidDevice/src/main/java/ioio/lib/android/device/DeviceConnectionBootstrap.java @@ -66,7 +66,6 @@ * @author Nadir Izrael * @author Ytai Ben-Tsvi */ -@TargetApi(12) public class DeviceConnectionBootstrap extends BroadcastReceiver implements ContextWrapperDependent, IOIOConnectionBootstrap { private static final String TAG = "DevConnBootstrap"; @@ -92,10 +91,8 @@ public class DeviceConnectionBootstrap extends BroadcastReceiver implements private UsbEndpoint epOut_; private InputStream inputStream_; private OutputStream outputStream_; + public DeviceConnectionBootstrap() { - if (Build.VERSION.SDK_INT < 12) { - throw new NoRuntimeSupportException("OTG is not supported on this device."); - } } @Override @@ -474,8 +471,13 @@ private void checkPermission() { if (usbManager_.hasPermission(device_)) { permission_ = Permission.GRANTED; } else { - pendingIntent_ = PendingIntent.getBroadcast(activity_, 0, new Intent( - ACTION_USB_PERMISSION), 0); + int pendingIntentFlags; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + pendingIntentFlags = PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT; + } else { + pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT; + } + pendingIntent_ = PendingIntent.getBroadcast(activity_, 0, new Intent(ACTION_USB_PERMISSION), pendingIntentFlags); usbManager_.requestPermission(device_, pendingIntent_); permission_ = Permission.PENDING; } @@ -553,12 +555,12 @@ public boolean canClose() { } @Override - public InputStream getInputStream() throws ConnectionLostException { + public InputStream getInputStream() { return inputStream_; } @Override - public OutputStream getOutputStream() throws ConnectionLostException { + public OutputStream getOutputStream() { return outputStream_; } } diff --git a/applications/HelloIOIOService/src/main/java/ioio/examples/hello_service/HelloIOIOService.java b/applications/HelloIOIOService/src/main/java/ioio/examples/hello_service/HelloIOIOService.java index 256fbcb70..7d4289a7d 100644 --- a/applications/HelloIOIOService/src/main/java/ioio/examples/hello_service/HelloIOIOService.java +++ b/applications/HelloIOIOService/src/main/java/ioio/examples/hello_service/HelloIOIOService.java @@ -11,6 +11,7 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.os.Build; import android.os.IBinder; import androidx.core.app.NotificationCompat; @@ -56,6 +57,13 @@ public int onStartCommand(Intent intent, int flags, int startId) { } else { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getBaseContext()); + int pendingIntentFlags; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + pendingIntentFlags = PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT; + } else { + pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT; + } + notificationBuilder .setSmallIcon(R.drawable.ic_launcher) .setTicker("IOIO service running") @@ -63,7 +71,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { .setContentTitle("IOIO Service") .setContentText("Click to stop") .setContentIntent(PendingIntent.getService(this, 0, new Intent( - "stop", null, this, this.getClass()), 0)); + "stop", null, this, this.getClass()), pendingIntentFlags)); if (notificationManager != null) { notificationManager.notify(1, notificationBuilder.build()); diff --git a/build.gradle b/build.gradle index 0e61a2f78..e2958e586 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { maven { url 'https://jitpack.io' } } dependencies { - classpath 'com.android.tools.build:gradle:7.4.2' + classpath 'com.android.tools.build:gradle:8.4.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.github.hannesa2:gradle-one-jar:1.7" } diff --git a/gradle.properties b/gradle.properties index 27a2b05cd..b547cf7ed 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,3 +2,7 @@ android.useAndroidX=true android.enableJetifier=true org.gradle.jvmargs=-Xmx1536m + +android.defaults.buildfeatures.buildconfig=true +android.nonTransitiveRClass=false +android.nonFinalResIds=false diff --git a/jitpack.yml b/jitpack.yml index 6415312f3..b5fbff1fc 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -1,5 +1,5 @@ jdk: - - openjdk11 + - openjdk17 install: - ./gradlew :IOIOLibAndroid:build :IOIOLibAndroid:publishToMavenLocal - ./gradlew :IOIOLibAndroidBluetooth:build :IOIOLibAndroidBluetooth:publishToMavenLocal