Skip to content

Commit 56506b9

Browse files
committed
Fix several Lint errors and warnings
1 parent f937ba5 commit 56506b9

File tree

5 files changed

+44
-38
lines changed

5 files changed

+44
-38
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
22

33
android {
44
namespace "org.cgutman.usbipserverforandroid"
5-
compileSdk 19
5+
compileSdk 34
66

77
defaultConfig {
88
applicationId "org.cgutman.usbipserverforandroid"

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
<uses-feature android:name="android.hardware.usb.host" android:required="true" />
77
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
88

9-
<uses-sdk
10-
android:minSdkVersion="12"
11-
android:targetSdkVersion="19" />
12-
139
<uses-permission android:name="android.permission.INTERNET" />
1410
<uses-permission android:name="android.permission.WAKE_LOCK" />
1511

@@ -25,6 +21,7 @@
2521

2622
<activity
2723
android:name="org.cgutman.usbip.config.UsbIpConfig"
24+
android:exported="true"
2825
android:label="@string/app_name" >
2926
<intent-filter>
3027
<action android:name="android.intent.action.MAIN" />

app/src/main/java/org/cgutman/usbip/server/UsbIpServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class UsbIpServer {
2121
private UsbRequestHandler handler;
2222
private Thread serverThread;
2323
private ServerSocket serverSock;
24-
private ConcurrentHashMap<Socket, Thread> connections = new ConcurrentHashMap<Socket, Thread>();
24+
private ConcurrentHashMap<Socket, Thread> connections = new ConcurrentHashMap<>();
2525

2626
// Returns true if a device is now attached
2727
private boolean handleRequest(Socket s) throws IOException {

app/src/main/java/org/cgutman/usbip/service/UsbIpService.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import android.hardware.usb.UsbManager;
4646
import android.net.wifi.WifiManager;
4747
import android.net.wifi.WifiManager.WifiLock;
48+
import android.os.Build;
4849
import android.os.IBinder;
4950
import android.os.PowerManager;
5051
import android.os.PowerManager.WakeLock;
@@ -82,7 +83,6 @@ public void onReceive(Context context, Intent intent) {
8283
}
8384
};
8485

85-
@SuppressWarnings("deprecation")
8686
private void updateNotification() {
8787
Intent intent = new Intent(this, UsbIpConfig.class);
8888
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
@@ -113,21 +113,35 @@ public void onCreate() {
113113
super.onCreate();
114114

115115
usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
116-
connections = new SparseArray<AttachedDeviceContext>();
117-
permission = new SparseArray<Boolean>();
118-
socketMap = new HashMap<Socket, AttachedDeviceContext>();
119-
120-
usbPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
116+
connections = new SparseArray<>();
117+
permission = new SparseArray<>();
118+
socketMap = new HashMap<>();
119+
120+
int intentFlags = 0;
121+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
122+
// This PendingIntent must be mutable to allow the framework to populate EXTRA_DEVICE and EXTRA_PERMISSION_GRANTED.
123+
intentFlags |= PendingIntent.FLAG_MUTABLE;
124+
}
125+
126+
Intent i = new Intent(ACTION_USB_PERMISSION);
127+
i.setPackage(getPackageName());
128+
129+
usbPermissionIntent = PendingIntent.getBroadcast(this, 0, i, intentFlags);
121130
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
122-
registerReceiver(usbReceiver, filter);
131+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
132+
registerReceiver(usbReceiver, filter, RECEIVER_NOT_EXPORTED);
133+
}
134+
else {
135+
registerReceiver(usbReceiver, filter);
136+
}
123137

124138
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
125-
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
139+
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
126140

127-
cpuWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "USB/IP Service");
141+
cpuWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "USBIPServerForAndroid:Service");
128142
cpuWakeLock.acquire();
129143

130-
wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "USB/IP Service");
144+
wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "USBIPServerForAndroid:Service");
131145
wifiLock.acquire();
132146

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

328342
@Override
329343
public List<UsbDeviceInfo> getDevices() {
330-
ArrayList<UsbDeviceInfo> list = new ArrayList<UsbDeviceInfo>();
344+
ArrayList<UsbDeviceInfo> list = new ArrayList<>();
331345

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

700714
// Use a thread pool with a thread per endpoint
701715
context.requestPool = new ThreadPoolExecutor(endpointCount, endpointCount,
702-
Long.MAX_VALUE, TimeUnit.DAYS,
703-
new LinkedBlockingQueue<Runnable>(), new ThreadPoolExecutor.DiscardPolicy());
716+
Long.MAX_VALUE, TimeUnit.DAYS,
717+
new LinkedBlockingQueue<>(), new ThreadPoolExecutor.DiscardPolicy());
704718

705719
// Create the active message set
706-
context.activeMessages = new HashSet<UsbIpSubmitUrb>();
720+
context.activeMessages = new HashSet<>();
707721

708722
connections.put(dev.getDeviceId(), context);
709723
socketMap.put(s, context);

app/src/main/res/values/styles.xml

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<resources>
3-
4-
<!--
2+
<resources>
3+
4+
<!--
55
Base application theme, dependent on API level. This theme is replaced
6-
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
7-
-->
8-
<style name="AppBaseTheme" parent="android:Theme">
9-
<!--
10-
Theme customizations available in newer API levels can go in
11-
res/values-vXX/styles.xml, while customizations related to
12-
backward-compatibility can go here.
13-
-->
14-
</style>
15-
16-
<!-- Application theme. -->
17-
<style name="AppTheme" parent="AppBaseTheme">
18-
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
19-
</style>
20-
</resources>
6+
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
7+
8+
-->
9+
<style name="AppBaseTheme" parent="android:Theme"></style>
10+
11+
<!-- Application theme. -->
12+
<style name="AppTheme" parent="AppBaseTheme">
13+
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
14+
</style>
15+
</resources>

0 commit comments

Comments
 (0)