Skip to content

Commit 2079512

Browse files
committed
Fix Codacy complaints
1 parent d125cd9 commit 2079512

File tree

12 files changed

+118
-132
lines changed

12 files changed

+118
-132
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@
148148
android:configChanges="orientation|screenSize|uiMode"
149149
android:label="@string/setting"
150150
android:name=".ui.activities.PreferencesActivity"
151-
android:theme="@style/appCompatBlack"
152-
android:exported="false">
151+
android:theme="@style/appCompatBlack">
153152
<intent-filter>
154153
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
155154
<category android:name="android.intent.category.DEFAULT" />
@@ -161,8 +160,7 @@
161160
android:label="@string/textreader"
162161
android:name=".ui.activities.texteditor.TextEditorActivity"
163162
android:configChanges="uiMode"
164-
android:theme="@style/appCompatBlack"
165-
android:exported="true">
163+
android:theme="@style/appCompatBlack">
166164
<intent-filter
167165
tools:ignore="AppLinkUrlError"
168166
android:label="Amaze Text Editor">
@@ -295,8 +293,7 @@
295293
android:exported="true"
296294
android:icon="@drawable/ic_ftp_dark"
297295
android:label="@string/ftp"
298-
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
299-
android:exported="false">
296+
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
300297
<intent-filter>
301298
<action
302299
android:name="android.service.quicksettings.action.QS_TILE" />

app/src/main/java/com/amaze/filemanager/ui/activities/MainActivity.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -884,10 +884,8 @@ public synchronized ArrayList<StorageDirectoryParcelable> getStorageDirectoriesL
884884
File usb = getUsbDrive();
885885
if (usb != null && !rv.contains(usb.getPath())) rv.add(usb.getPath());
886886

887-
if (SDK_INT >= KITKAT) {
888-
if (SingletonUsbOtg.getInstance().isDeviceConnected()) {
889-
rv.add(OTGUtil.PREFIX_OTG + "/");
890-
}
887+
if (SDK_INT >= KITKAT && SingletonUsbOtg.INSTANCE.isDeviceConnected()) {
888+
rv.add(OTGUtil.PREFIX_OTG + "/");
891889
}
892890

893891
// Assign a label and icon to each directory
@@ -1383,28 +1381,27 @@ private void updateUsbInformation() {
13831381
List<UsbOtgRepresentation> connectedDevices = OTGUtil.getMassStorageDevicesConnected(this);
13841382

13851383
if (!connectedDevices.isEmpty()) {
1386-
if (SingletonUsbOtg.getInstance().getUsbOtgRoot() != null
1387-
&& OTGUtil.isUsbUriAccessible(this)) {
1384+
if (SingletonUsbOtg.INSTANCE.getUsbOtgRoot() != null && OTGUtil.isUsbUriAccessible(this)) {
13881385
for (UsbOtgRepresentation device : connectedDevices) {
1389-
if (SingletonUsbOtg.getInstance().checkIfRootIsFromDevice(device)) {
1386+
if (SingletonUsbOtg.INSTANCE.checkIfRootIsFromDevice(device)) {
13901387
isInformationUpdated = true;
13911388
break;
13921389
}
13931390
}
13941391

13951392
if (!isInformationUpdated) {
1396-
SingletonUsbOtg.getInstance().resetUsbOtgRoot();
1393+
SingletonUsbOtg.INSTANCE.resetUsbOtgRoot();
13971394
}
13981395
}
13991396

14001397
if (!isInformationUpdated) {
1401-
SingletonUsbOtg.getInstance().setConnectedDevice(connectedDevices.get(0));
1398+
SingletonUsbOtg.INSTANCE.setConnectedDevice(connectedDevices.get(0));
14021399
isInformationUpdated = true;
14031400
}
14041401
}
14051402

14061403
if (!isInformationUpdated) {
1407-
SingletonUsbOtg.getInstance().resetUsbOtgRoot();
1404+
SingletonUsbOtg.INSTANCE.resetUsbOtgRoot();
14081405
drawer.refreshDrawer();
14091406
}
14101407

@@ -1424,12 +1421,12 @@ public void onReceive(Context context, Intent intent) {
14241421
List<UsbOtgRepresentation> connectedDevices =
14251422
OTGUtil.getMassStorageDevicesConnected(MainActivity.this);
14261423
if (!connectedDevices.isEmpty()) {
1427-
SingletonUsbOtg.getInstance().resetUsbOtgRoot();
1428-
SingletonUsbOtg.getInstance().setConnectedDevice(connectedDevices.get(0));
1424+
SingletonUsbOtg.INSTANCE.resetUsbOtgRoot();
1425+
SingletonUsbOtg.INSTANCE.setConnectedDevice(connectedDevices.get(0));
14291426
drawer.refreshDrawer();
14301427
}
14311428
} else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
1432-
SingletonUsbOtg.getInstance().resetUsbOtgRoot();
1429+
SingletonUsbOtg.INSTANCE.resetUsbOtgRoot();
14331430
drawer.refreshDrawer();
14341431
goToMain(null);
14351432
}
@@ -1695,7 +1692,7 @@ protected void onActivityResult(int requestCode, int responseCode, Intent intent
16951692
if (responseCode == Activity.RESULT_OK && intent.getData() != null) {
16961693
// otg access
16971694
Uri usbOtgRoot = intent.getData();
1698-
SingletonUsbOtg.getInstance().setUsbOtgRoot(usbOtgRoot);
1695+
SingletonUsbOtg.INSTANCE.setUsbOtgRoot(usbOtgRoot);
16991696
mainFragment.loadlist(OTGUtil.PREFIX_OTG, false, OpenMode.OTG, true);
17001697
drawer.closeIfNotLocked();
17011698
if (drawer.isLocked()) drawer.onDrawerClosed();
@@ -2048,7 +2045,7 @@ public void onNewIntent(Intent i) {
20482045

20492046
if (SDK_INT >= KITKAT) {
20502047
if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
2051-
SingletonUsbOtg.getInstance().resetUsbOtgRoot();
2048+
SingletonUsbOtg.INSTANCE.resetUsbOtgRoot();
20522049
drawer.refreshDrawer();
20532050
}
20542051
}

app/src/main/java/com/amaze/filemanager/ui/views/drawer/Drawer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
828828
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
829829
&& (meta.path.contains(OTGUtil.PREFIX_OTG)
830830
|| meta.path.startsWith(OTGUtil.PREFIX_MEDIA_REMOVABLE))
831-
&& SingletonUsbOtg.getInstance().getUsbOtgRoot() == null) {
831+
&& SingletonUsbOtg.INSTANCE.getUsbOtgRoot() == null) {
832832
MaterialDialog dialog = GeneralDialogCreation.showOtgSafExplanationDialog(mainActivity);
833833
dialog
834834
.getActionButton(DialogAction.POSITIVE)

app/src/main/java/com/amaze/filemanager/utils/OTGUtil.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ object OTGUtil {
9393
fileFound: OnFileFound,
9494
) {
9595
val rootUriString =
96-
SingletonUsbOtg.getInstance().usbOtgRoot
96+
SingletonUsbOtg.getUsbOtgRoot()
9797
?: throw NullPointerException("USB OTG root not set!")
9898
return getDocumentFiles(rootUriString, path, context, OpenMode.OTG, fileFound)
9999
}
@@ -163,7 +163,7 @@ object OTGUtil {
163163
createRecursive: Boolean,
164164
): DocumentFile? {
165165
val rootUriString =
166-
SingletonUsbOtg.getInstance().usbOtgRoot
166+
SingletonUsbOtg.getUsbOtgRoot()
167167
?: throw NullPointerException("USB OTG root not set!")
168168

169169
return getDocumentFile(path, rootUriString, context, OpenMode.OTG, createRecursive)
@@ -208,7 +208,7 @@ object OTGUtil {
208208
@RequiresApi(api = KITKAT)
209209
@JvmStatic
210210
fun isUsbUriAccessible(context: Context?): Boolean {
211-
val rootUriString = SingletonUsbOtg.getInstance().usbOtgRoot
211+
val rootUriString = SingletonUsbOtg.getUsbOtgRoot()
212212
return DocumentsContract.isDocumentUri(context, rootUriString)
213213
}
214214

app/src/test/java/com/amaze/filemanager/filesystem/usb/SingletonUsbOtgTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ public void usbConnectionTest() {
5858

5959
Uri rootBefore = Uri.parse("ssh://testuser:testpassword@127.0.0.1:22222");
6060

61-
SingletonUsbOtg.getInstance().setUsbOtgRoot(rootBefore);
61+
SingletonUsbOtg.INSTANCE.setUsbOtgRoot(rootBefore);
6262

6363
controller.pause().resume().get();
6464

65-
Uri rootAfter = SingletonUsbOtg.getInstance().getUsbOtgRoot();
65+
Uri rootAfter = SingletonUsbOtg.INSTANCE.getUsbOtgRoot();
6666

6767
assertEquals(
6868
"Uris are different: (before:) " + rootBefore + " (after:) " + rootAfter,

file_operations/src/main/java/com/amaze/filemanager/fileoperations/filesystem/cloud/CloudStreamServer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
*
9292
* See the end of the source file for distribution license (Modified BSD licence)
9393
*/
94+
@SuppressWarnings("PMD")
9495
public abstract class CloudStreamServer {
9596
private static final Logger LOG = LoggerFactory.getLogger(CloudStreamServer.class);
9697

file_operations/src/main/java/com/amaze/filemanager/fileoperations/filesystem/smbstreamer/StreamServer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
*
9292
* See the end of the source file for distribution license (Modified BSD licence)
9393
*/
94+
@SuppressWarnings("PMD")
9495
public abstract class StreamServer {
9596

9697
private static final Logger LOG = LoggerFactory.getLogger(StreamServer.class);

file_operations/src/main/java/com/amaze/filemanager/fileoperations/filesystem/usb/SingletonUsbOtg.kt

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,53 @@
1717
* You should have received a copy of the GNU General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20+
package com.amaze.filemanager.fileoperations.filesystem.usb
2021

21-
package com.amaze.filemanager.fileoperations.filesystem.usb;
22+
import android.net.Uri
2223

23-
import android.net.Uri;
24-
25-
import androidx.annotation.NonNull;
26-
import androidx.annotation.Nullable;
27-
28-
public class SingletonUsbOtg {
29-
private static SingletonUsbOtg instance = null;
30-
31-
public static SingletonUsbOtg getInstance() {
32-
if (instance == null) instance = new SingletonUsbOtg();
33-
return instance;
34-
}
35-
36-
private UsbOtgRepresentation connectedDevice = null;
37-
private @Nullable Uri usbOtgRoot;
38-
39-
private SingletonUsbOtg() {}
40-
41-
public void setConnectedDevice(UsbOtgRepresentation connectedDevice) {
42-
this.connectedDevice = connectedDevice;
43-
}
24+
/**
25+
* USB OTG device representation.
26+
*/
27+
object SingletonUsbOtg {
28+
var connectedDevice: UsbOtgRepresentation? = null
29+
var _usbOtgRoot: Uri? = null
4430

45-
public boolean isDeviceConnected() {
46-
return connectedDevice != null;
47-
}
31+
val isDeviceConnected: Boolean
32+
get() = connectedDevice != null
4833

49-
public void setUsbOtgRoot(@Nullable Uri root) {
50-
if (connectedDevice == null) throw new IllegalStateException("No device connected!");
51-
usbOtgRoot = root;
52-
}
34+
/**
35+
* Get the root of the connected USB OTG device.
36+
*
37+
* @return the root URI of the connected USB OTG device, or null if no device is connected.
38+
*/
39+
fun getUsbOtgRoot(): Uri? {
40+
return _usbOtgRoot
41+
}
5342

54-
public void resetUsbOtgRoot() {
55-
connectedDevice = null;
56-
usbOtgRoot = null;
57-
}
43+
/**
44+
* Set the root of the connected USB OTG device. Will throw exception if no device is connected.
45+
*
46+
* @param root the root URI of the connected USB OTG device.
47+
*/
48+
fun setUsbOtgRoot(root: Uri?) {
49+
checkNotNull(connectedDevice) { "No device connected!" }
50+
_usbOtgRoot = root
51+
}
5852

59-
public @Nullable Uri getUsbOtgRoot() {
60-
return usbOtgRoot;
61-
}
53+
/**
54+
* Clear the reference to connected device and root.
55+
*/
56+
fun resetUsbOtgRoot() {
57+
connectedDevice = null
58+
_usbOtgRoot = null
59+
}
6260

63-
public boolean checkIfRootIsFromDevice(@NonNull UsbOtgRepresentation device) {
64-
return usbOtgRoot != null && connectedDevice.hashCode() == device.hashCode();
65-
}
61+
/**
62+
* Check if the root is from the given device.
63+
*
64+
* Used by [MainActivity.updateUsbInformation].
65+
*/
66+
fun checkIfRootIsFromDevice(device: UsbOtgRepresentation): Boolean {
67+
return _usbOtgRoot != null && connectedDevice.hashCode() == device.hashCode()
68+
}
6669
}

file_operations/src/main/java/com/amaze/filemanager/fileoperations/filesystem/usb/UsbOtgRepresentation.kt

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,33 @@
1717
* You should have received a copy of the GNU General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
21-
package com.amaze.filemanager.fileoperations.filesystem.usb;
22-
23-
import androidx.annotation.Nullable;
20+
package com.amaze.filemanager.fileoperations.filesystem.usb
2421

2522
/**
2623
* This class replesents a usb device.
2724
*
28-
* @see UsbOtgRepresentation#equals(Object)
25+
* @see UsbOtgRepresentation.equals
2926
*/
30-
public class UsbOtgRepresentation {
31-
32-
public final int productID, vendorID;
33-
public final @Nullable String serialNumber;
34-
35-
public UsbOtgRepresentation(int productID, int vendorID, @Nullable String serialNumber) {
36-
this.productID = productID;
37-
this.vendorID = vendorID;
38-
this.serialNumber = serialNumber;
39-
}
40-
41-
/**
42-
* This does not ensure a device is equal to another! This tests parameters to know to a certain
43-
* degree of certanty that a device is "similar enough" to another one to be the same one.
44-
*/
45-
@Override
46-
public boolean equals(Object obj) {
47-
if (!(obj instanceof UsbOtgRepresentation)) return false;
48-
49-
UsbOtgRepresentation other = (UsbOtgRepresentation) obj;
50-
return productID == other.productID
51-
&& vendorID == other.vendorID
52-
&& ((serialNumber == null && other.serialNumber == null)
53-
|| serialNumber.equals(other.serialNumber));
54-
}
55-
56-
@Override
57-
public int hashCode() {
58-
int result = productID;
59-
result = 37 * result + vendorID;
60-
result = 37 * result + (serialNumber != null ? serialNumber.hashCode() : 0);
61-
return result;
62-
}
27+
data class UsbOtgRepresentation(val productID: Int, val vendorID: Int, val serialNumber: String?) {
28+
/**
29+
* This does not ensure a device is equal to another! This tests parameters to know to a certain
30+
* degree of certainty that a device is "similar enough" to another one to be the same one.
31+
*/
32+
override fun equals(obj: Any?): Boolean {
33+
if (obj !is UsbOtgRepresentation) return false
34+
35+
return productID == obj.productID &&
36+
vendorID == obj.vendorID &&
37+
(
38+
(serialNumber == null && obj.serialNumber == null) ||
39+
serialNumber == obj.serialNumber
40+
)
41+
}
42+
43+
override fun hashCode(): Int {
44+
var result = productID
45+
result = 37 * result + vendorID
46+
result = 37 * result + (serialNumber?.hashCode() ?: 0)
47+
return result
48+
}
6349
}

0 commit comments

Comments
 (0)