Skip to content

Commit a95b803

Browse files
K2GO-439 fix(hotspot): apply code-review findings on the NEARBY_WIFI slice
Point LocalHotspotManager's doc at HotspotPermissions (not FINE location); note requiredFor assumes targetSdk >= 33; scope FINE/COARSE to maxSdkVersion 32 (NEARBY covers 33+); and show the retry hint on permission-denied instead of a perpetual "starting" (Connect and Clone), the hint now naming Wi-Fi and the permission (34 locales).
1 parent 7c1b9e7 commit a95b803

39 files changed

Lines changed: 60 additions & 46 deletions

File tree

‎controller/app/src/main/AndroidManifest.xml‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
77
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
88
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
9-
<!-- ADFA-4520: LocalOnlyHotspot requires location at runtime on targetSdk 32 and below -->
10-
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
11-
<!-- K2GO-438: Android 12+ lets the user grant COARSE only, so declare it with FINE (CoarseFineLocation). -->
12-
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
9+
<!-- ADFA-4520 / K2GO-439: location gated LocalOnlyHotspot only on API 32 and below; API 33+ uses
10+
NEARBY_WIFI_DEVICES below, so scope FINE/COARSE (the hotspot is their only consumer) to API 32. -->
11+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="32" />
12+
<!-- K2GO-438: Android 12 and below let the user grant COARSE only, so declare it with FINE (CoarseFineLocation). -->
13+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="32" />
1314
<!-- K2GO-439: targetSdk 33+ needs NEARBY_WIFI_DEVICES for startLocalOnlyHotspot (FINE only sufficed on 32 and below).
1415
neverForLocation: the hotspot does not derive location from Wi-Fi scans. -->
1516
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"

‎controller/app/src/main/java/org/appdevforall/k2go/hotspot/HotspotPermissions.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public static String[] required() {
3030
return requiredFor(Build.VERSION.SDK_INT);
3131
}
3232

33-
/** The rule as a pure function of the API level. Package-private for unit testing. */
33+
/**
34+
* The rule as a pure function of the API level. Package-private for unit testing.
35+
* Keyed off the device API: startLocalOnlyHotspot bases its requirement on the app
36+
* targetSdk, and keying off the device API matches only because the app targets >= 33.
37+
*/
3438
static String[] requiredFor(int sdkInt) {
3539
if (sdkInt >= Build.VERSION_CODES.TIRAMISU) {
3640
return new String[]{ Manifest.permission.NEARBY_WIFI_DEVICES };

‎controller/app/src/main/java/org/appdevforall/k2go/hotspot/LocalHotspotManager.java‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
* the carrier tethering-entitlement check, so it works with no SIM and
99
* no data plan. The reservation is process-bound: it stays up while this
1010
* app process is alive and is torn down on close() or process death.
11-
* API 26+ only; callers must gate on Build.VERSION and hold
12-
* CHANGE_WIFI_STATE + ACCESS_FINE_LOCATION (with Location services on).
11+
* API 26+ only; callers must gate on Build.VERSION and hold CHANGE_WIFI_STATE
12+
* plus the hotspot permission from HotspotPermissions (NEARBY_WIFI_DEVICES on
13+
* API 33+, or ACCESS_FINE_LOCATION with Location services on 32 and below).
1314
*
1415
* V1 scope (ADFA-4520): manual opt-in from Advanced settings, plus a
1516
* contextual recommendation surfaced only when BOTH conditions hold
@@ -110,13 +111,15 @@ public boolean isOn() {
110111
}
111112

112113
/**
113-
* Starts a LocalOnlyHotspot. Caller must have already granted CHANGE_WIFI_STATE +
114-
* ACCESS_FINE_LOCATION and enabled Location services; otherwise onFailed fires.
114+
* Starts a LocalOnlyHotspot. Caller must have already granted CHANGE_WIFI_STATE and the
115+
* hotspot permission (see HotspotPermissions); on API 32 and below that also needs Location
116+
* services on. Otherwise onFailed fires.
115117
*/
116118
// NewApi is suppressed because every API-26 reference below is protected by the
117119
// explicit Build.VERSION.SDK_INT guard (lint cannot see through isSupported(), and
118120
// @RequiresApi does not cover the anonymous callback class). MissingPermission is
119-
// suppressed because CHANGE_WIFI_STATE + ACCESS_FINE_LOCATION are requested at runtime.
121+
// suppressed because CHANGE_WIFI_STATE and the hotspot permission (HotspotPermissions) are
122+
// requested at runtime.
120123
@SuppressLint({"MissingPermission", "NewApi"})
121124
public void start(Context context) {
122125
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {

‎controller/app/src/main/java/org/appdevforall/k2go/redesign/CloneFragment.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,10 @@ private void renderPrepare() {
730730
secJoin.setFallback(requireContext(), null);
731731
secJoin.caption.setText(getString(R.string.k2go_connect_hotspot_unsupported));
732732
secJoin.subCaption.setText(getString(R.string.k2go_connect_try_wifi));
733-
} else if (phase == LocalHotspotManager.Phase.FAILED) {
733+
} else if (phase == LocalHotspotManager.Phase.FAILED
734+
|| (phase != LocalHotspotManager.Phase.ON && !HotspotPermissions.granted(requireContext()))) {
735+
// FAILED, or the hotspot permission is not granted (denied): show the hint instead of a
736+
// perpetual "starting" placeholder (K2GO-439).
734737
secJoin.frame.setVisibility(View.GONE);
735738
secJoin.setFallback(requireContext(), null);
736739
secJoin.caption.setText(getString(R.string.k2go_connect_hotspot_failed));

‎controller/app/src/main/java/org/appdevforall/k2go/redesign/ConnectFragment.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,10 @@ private void renderHotspot() {
216216
singleStatus(getString(R.string.k2go_connect_hotspot_unsupported), getString(R.string.k2go_connect_try_wifi));
217217
return;
218218
}
219-
if (phase == LocalHotspotManager.Phase.FAILED) {
219+
// FAILED, or the hotspot permission is not granted (denied): show the hint instead of a
220+
// perpetual "starting" placeholder (K2GO-439).
221+
if (phase == LocalHotspotManager.Phase.FAILED
222+
|| (phase != LocalHotspotManager.Phase.ON && !HotspotPermissions.granted(requireContext()))) {
220223
singleStatus(getString(R.string.k2go_connect_hotspot_failed), getString(R.string.k2go_connect_enable_location));
221224
return;
222225
}

‎controller/app/src/main/res/values-ar/strings.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@
799799
<string name="k2go_connect_starting_hotspot">جارٍ بدء نقطة الاتصال…</string>
800800
<string name="k2go_connect_resolving_address">جارٍ العثور على عنوان نقطة الاتصال…</string>
801801
<string name="k2go_connect_hotspot_failed">تعذّر بدء نقطة الاتصال</string>
802-
<string name="k2go_connect_enable_location">تأكد من تشغيل Wi-Fi، ثم حاول مرة أخرى.</string>
802+
<string name="k2go_connect_enable_location">فعّل Wi-Fi وامنح الإذن، ثم حاول مرة أخرى.</string>
803803
<string name="k2go_connect_no_wifi">لست على شبكة Wi-Fi</string>
804804
<string name="k2go_connect_join_wifi">انضم إلى نفس شبكة Wi-Fi أو اتصل بنقطة اتصال المكتبة.</string>
805805
<string name="k2go_fallback_wifi">Wi-Fi: %1$s</string>

‎controller/app/src/main/res/values-az/strings.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@
819819
<string name="k2go_connect_starting_hotspot">Hotspot başladılır…</string>
820820
<string name="k2go_connect_resolving_address">Hotspot ünvanı tapılır…</string>
821821
<string name="k2go_connect_hotspot_failed">Hotspot başladıla bilmədi</string>
822-
<string name="k2go_connect_enable_location">Wi-Fi-nin aktiv olduğundan əmin olun, sonra yenidən cəhd edin.</string>
822+
<string name="k2go_connect_enable_location">Wi-Fi-ni yandırın və icazəni verin, sonra yenidən cəhd edin.</string>
823823
<string name="k2go_connect_no_wifi">Wi-Fi şəbəkəsində deyil</string>
824824
<string name="k2go_connect_join_wifi">Eyni Wi-Fi-yə və ya kitabxananın hotspotuna qoşulun.</string>
825825
<string name="k2go_fallback_wifi">Wi-Fi: %1$s</string>

‎controller/app/src/main/res/values-bg/strings.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@
806806
<string name="k2go_connect_starting_hotspot">Стартиране на точката за достъп…</string>
807807
<string name="k2go_connect_resolving_address">Търсене на адрес на точката за достъп…</string>
808808
<string name="k2go_connect_hotspot_failed">Неуспешно стартиране на точката за достъп</string>
809-
<string name="k2go_connect_enable_location">Уверете се, че Wi-Fi е включен, след което опитайте отново.</string>
809+
<string name="k2go_connect_enable_location">Включете Wi-Fi и дайте разрешението, след което опитайте отново.</string>
810810
<string name="k2go_connect_no_wifi">Не сте в Wi-Fi мрежа</string>
811811
<string name="k2go_connect_join_wifi">Свържете се със същата Wi-Fi или с точката за достъп на библиотеката.</string>
812812
<string name="k2go_fallback_wifi">Wi-Fi: %1$s</string>

‎controller/app/src/main/res/values-bn/strings.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@
812812
<string name="k2go_connect_starting_hotspot">হটস্পট শুরু হচ্ছে…</string>
813813
<string name="k2go_connect_resolving_address">হটস্পট ঠিকানা খোঁজা হচ্ছে…</string>
814814
<string name="k2go_connect_hotspot_failed">হটস্পট শুরু করা যায়নি</string>
815-
<string name="k2go_connect_enable_location">Wi-Fi চালু আছে কিনা নিশ্চিত করুন, তারপর আবার চেষ্টা করুন।</string>
815+
<string name="k2go_connect_enable_location">Wi-Fi চালু করুন এবং অনুমতি দিন, তারপর আবার চেষ্টা করুন।</string>
816816
<string name="k2go_connect_no_wifi">কোনো Wi-Fi নেটওয়ার্কে নেই</string>
817817
<string name="k2go_connect_join_wifi">একই Wi-Fi-তে বা লাইব্রেরির হটস্পটে যুক্ত হন।</string>
818818
<string name="k2go_fallback_wifi">Wi-Fi: %1$s</string>

‎controller/app/src/main/res/values-cs/strings.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@
806806
<string name="k2go_connect_starting_hotspot">Spouštění hotspotu…</string>
807807
<string name="k2go_connect_resolving_address">Hledání adresy hotspotu…</string>
808808
<string name="k2go_connect_hotspot_failed">Nepodařilo se spustit hotspot</string>
809-
<string name="k2go_connect_enable_location">Zkontrolujte, že je Wi-Fi zapnutá, a zkuste to znovu.</string>
809+
<string name="k2go_connect_enable_location">Zapněte Wi-Fi a udělte oprávnění, poté to zkuste znovu.</string>
810810
<string name="k2go_connect_no_wifi">Nepřipojeno k síti Wi-Fi</string>
811811
<string name="k2go_connect_join_wifi">Připoj se ke stejné Wi-Fi nebo k hotspotu knihovny.</string>
812812
<string name="k2go_fallback_wifi">Wi-Fi: %1$s</string>

0 commit comments

Comments
 (0)