Skip to content

Commit e7c0032

Browse files
committed
Implement ACCESS_LOCAL_NETWORK permission
1 parent 89fe189 commit e7c0032

13 files changed

Lines changed: 48 additions & 3 deletions

File tree

‎app/build.gradle‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
defaultConfig {
77
applicationId "com.blogspot.developersu.ns_usbloader"
88
minSdkVersion 15
9-
versionCode 8
10-
versionName "6.0"
9+
versionCode 9
10+
versionName "6.1"
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1212
android.defaultConfig.vectorDrawables.useSupportLibrary = true
1313
}

‎app/src/main/AndroidManifest.xml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
1111

1212
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <!--for Android 13+; API >= 33-->
13+
<uses-permission android:name="android.permission.ACCESS_LOCAL_NETWORK" /> <!-- Android 17; API >= 37-->
1314
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
1415
<!-- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" /> -->
1516
<!-- <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> for Android 8+ -->
@@ -19,7 +20,7 @@
1920
android:icon="@mipmap/ic_launcher"
2021
android:label="@string/app_name"
2122
android:roundIcon="@mipmap/ic_launcher_round"
22-
android:supportsRtl="true"
23+
android:supportsRtl="false"
2324
android:theme="@style/AppTheme"
2425
android:resizeableActivity="true"
2526
android:supportsPictureInPicture="true"

‎app/src/main/java/com/blogspot/developersu/ns_usbloader/MainActivity.java‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.blogspot.developersu.ns_usbloader;
22

3+
import static android.Manifest.permission.ACCESS_LOCAL_NETWORK;
34
import static android.Manifest.permission.POST_NOTIFICATIONS;
45
import static com.blogspot.developersu.ns_usbloader.NsConstants.DEFAULT_NS_IP;
56
import static com.blogspot.developersu.ns_usbloader.NsConstants.DEFAULT_PHONE_IP;
@@ -77,6 +78,7 @@ public class MainActivity extends AppCompatActivity implements
7778
public static final boolean IS_AFTER_KIT_KAT = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
7879
public static final boolean IS_AFTER_TIRAMISU = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU;
7980
public static final boolean IS_AFTER_JELLY_BEAN = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
81+
public static final boolean IS_AFTER_CINNAMON_BUN = Build.VERSION.SDK_INT >= Build.VERSION_CODES.CINNAMON_BUN;
8082

8183
private RecyclerView recyclerView;
8284
private NspItemsAdapter nspItemsAdapter;
@@ -257,6 +259,7 @@ public void handleOnBackPressed() {
257259
readFile(getIntent());
258260

259261
requestNotificationsPermission();
262+
requestIntranetPermission();
260263
}
261264

262265
private boolean requestNotificationsPermission() {
@@ -284,6 +287,31 @@ private boolean requestNotificationsPermission() {
284287
return true;
285288
}
286289

290+
private boolean requestIntranetPermission() {
291+
if (!IS_AFTER_CINNAMON_BUN)
292+
return false;
293+
294+
if (ActivityCompat.checkSelfPermission(this, ACCESS_LOCAL_NETWORK) == PackageManager.PERMISSION_GRANTED)
295+
return false;
296+
297+
if (shouldShowRequestPermissionRationale(ACCESS_LOCAL_NETWORK)) {
298+
Snackbar.make(getWindow().getDecorView(), R.string.application_needs_local_net, BaseTransientBottomBar.LENGTH_LONG)
299+
.setAction(R.string.settings, view -> {
300+
Intent intent = new Intent();
301+
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
302+
intent.setData(
303+
Uri.fromParts("package", getPackageName(), null));
304+
startActivity(intent);
305+
})
306+
.show();
307+
}
308+
else {
309+
ActivityCompat.requestPermissions(this, new String[]{ACCESS_LOCAL_NETWORK}, 1);
310+
}
311+
312+
return true;
313+
}
314+
287315
private void updateUploadBtnState(){ // TODO: this function is bad. It multiplies entropy and sorrow.
288316
uploadToNsBtn.setEnabled(nspItemsAdapter.getItemCount() > 0);
289317
}
@@ -382,6 +410,9 @@ private void uploadFiles() {
382410
serviceStartIntent.putExtra(NSS_PROTOCOL, selector.getSelected());
383411

384412
if (selector.isNet()) {
413+
if (requestIntranetPermission())
414+
return;
415+
385416
SharedPreferences sp = getSharedPreferences("NSUSBloader", MODE_PRIVATE);
386417

387418
serviceStartIntent.putExtra(NSS_NS_IP, sp.getString("SNsIP", DEFAULT_NS_IP));

‎app/src/main/res/values-it-rIT/strings.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,6 @@
5050
<string name="about_line_1">NS-USBloader mobile</string>
5151
<string name="application_needs_usb">Application requires permission to access USB device</string>
5252
<string name="application_needs_notifications">Application requires permission to show notifications</string>
53+
<string name="application_needs_local_net">Application requires permission to access devices within local network</string>
54+
5355
</resources>

‎app/src/main/res/values-ja-ryu/strings.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@
4949
<string name="about_line_contributors">寄稿者とぅまじゅん:</string>
5050
<string name="application_needs_usb">Application requires permission to access USB device</string>
5151
<string name="application_needs_notifications">Application requires permission to show notifications</string>
52+
<string name="application_needs_local_net">Application requires permission to access devices within local network</string>
5253
</resources>

‎app/src/main/res/values-ja/strings.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@
4949
<string name="about_line_contributors">寄稿者とともに:</string>
5050
<string name="application_needs_usb">Application requires permission to access USB device</string>
5151
<string name="application_needs_notifications">Application requires permission to show notifications</string>
52+
<string name="application_needs_local_net">Application requires permission to access devices within local network</string>
5253
</resources>

‎app/src/main/res/values-ko-rKR/strings.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@
4949
<string name="about_line_contributors">참여자:</string>
5050
<string name="application_needs_usb">Application requires permission to access USB device</string>
5151
<string name="application_needs_notifications">Application requires permission to show notifications</string>
52+
<string name="application_needs_local_net">Application requires permission to access devices within local network</string>
5253
</resources>

‎app/src/main/res/values-ru/strings.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@
5050
<string name="about_line_1">NS-USBloader мобильный</string>
5151
<string name="application_needs_usb">Приложению требуется разрешение на доступ к USB</string>
5252
<string name="application_needs_notifications">Приложению требуется разрешение на показ уведомлений</string>
53+
<string name="application_needs_local_net">Приложению требуется разрешение на использование локальной сети</string>
5354
</resources>

‎app/src/main/res/values-zh-rCN/strings.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,6 @@
5050
<string name="about_line_1">NS-USBloader mobile</string>
5151
<string name="application_needs_usb">Application requires permission to access USB device</string>
5252
<string name="application_needs_notifications">Application requires permission to show notifications</string>
53+
<string name="application_needs_local_net">Application requires permission to access devices within local network</string>
54+
5355
</resources>

‎app/src/main/res/values-zh-rTW/strings.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@
4545
<string name="about_line_1">NS-USBloader mobile</string>
4646
<string name="application_needs_usb">Application requires permission to access USB device</string>
4747
<string name="application_needs_notifications">Application requires permission to show notifications</string>
48+
<string name="application_needs_local_net">Application requires permission to access devices within local network</string>
49+
4850
</resources>

0 commit comments

Comments
 (0)