Skip to content

Commit

Permalink
Fix several Lint errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Oct 28, 2023
1 parent f937ba5 commit 56506b9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
namespace "org.cgutman.usbipserverforandroid"
compileSdk 19
compileSdk 34

defaultConfig {
applicationId "org.cgutman.usbipserverforandroid"
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
<uses-feature android:name="android.hardware.usb.host" android:required="true" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />

<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

Expand All @@ -25,6 +21,7 @@

<activity
android:name="org.cgutman.usbip.config.UsbIpConfig"
android:exported="true"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class UsbIpServer {
private UsbRequestHandler handler;
private Thread serverThread;
private ServerSocket serverSock;
private ConcurrentHashMap<Socket, Thread> connections = new ConcurrentHashMap<Socket, Thread>();
private ConcurrentHashMap<Socket, Thread> connections = new ConcurrentHashMap<>();

// Returns true if a device is now attached
private boolean handleRequest(Socket s) throws IOException {
Expand Down
42 changes: 28 additions & 14 deletions app/src/main/java/org/cgutman/usbip/service/UsbIpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import android.hardware.usb.UsbManager;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.WifiLock;
import android.os.Build;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
Expand Down Expand Up @@ -82,7 +83,6 @@ public void onReceive(Context context, Intent intent) {
}
};

@SuppressWarnings("deprecation")
private void updateNotification() {
Intent intent = new Intent(this, UsbIpConfig.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Expand Down Expand Up @@ -113,21 +113,35 @@ public void onCreate() {
super.onCreate();

usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
connections = new SparseArray<AttachedDeviceContext>();
permission = new SparseArray<Boolean>();
socketMap = new HashMap<Socket, AttachedDeviceContext>();

usbPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
connections = new SparseArray<>();
permission = new SparseArray<>();
socketMap = new HashMap<>();

int intentFlags = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// This PendingIntent must be mutable to allow the framework to populate EXTRA_DEVICE and EXTRA_PERMISSION_GRANTED.
intentFlags |= PendingIntent.FLAG_MUTABLE;
}

Intent i = new Intent(ACTION_USB_PERMISSION);
i.setPackage(getPackageName());

usbPermissionIntent = PendingIntent.getBroadcast(this, 0, i, intentFlags);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
registerReceiver(usbReceiver, filter);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
registerReceiver(usbReceiver, filter, RECEIVER_NOT_EXPORTED);
}
else {
registerReceiver(usbReceiver, filter);
}

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);

cpuWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "USB/IP Service");
cpuWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "USBIPServerForAndroid:Service");
cpuWakeLock.acquire();

wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "USB/IP Service");
wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "USBIPServerForAndroid:Service");
wifiLock.acquire();

server = new UsbIpServer();
Expand Down Expand Up @@ -327,7 +341,7 @@ private UsbDeviceInfo getInfoForDevice(UsbDevice dev, UsbDeviceConnection devCon

@Override
public List<UsbDeviceInfo> getDevices() {
ArrayList<UsbDeviceInfo> list = new ArrayList<UsbDeviceInfo>();
ArrayList<UsbDeviceInfo> list = new ArrayList<>();

for (UsbDevice dev : usbManager.getDeviceList().values()) {
AttachedDeviceContext context = connections.get(dev.getDeviceId());
Expand Down Expand Up @@ -699,11 +713,11 @@ public boolean attachToDevice(Socket s, String busId) {

// Use a thread pool with a thread per endpoint
context.requestPool = new ThreadPoolExecutor(endpointCount, endpointCount,
Long.MAX_VALUE, TimeUnit.DAYS,
new LinkedBlockingQueue<Runnable>(), new ThreadPoolExecutor.DiscardPolicy());
Long.MAX_VALUE, TimeUnit.DAYS,
new LinkedBlockingQueue<>(), new ThreadPoolExecutor.DiscardPolicy());

// Create the active message set
context.activeMessages = new HashSet<UsbIpSubmitUrb>();
context.activeMessages = new HashSet<>();

connections.put(dev.getDeviceId(), context);
socketMap.put(s, context);
Expand Down
31 changes: 13 additions & 18 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<!--
<resources>

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme"></style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>

0 comments on commit 56506b9

Please sign in to comment.