|
1 | 1 | package org.appdevforall.k2go.redesign; |
2 | 2 |
|
3 | | -import android.Manifest; |
4 | 3 | import android.content.ClipData; |
5 | 4 | import android.content.ClipboardManager; |
6 | 5 | import android.content.Context; |
7 | 6 | import android.content.Intent; |
8 | | -import android.content.pm.PackageManager; |
9 | 7 | import android.graphics.Color; |
10 | 8 | import android.graphics.drawable.GradientDrawable; |
11 | 9 | import android.net.Uri; |
|
42 | 40 | import org.appdevforall.k2go.SyncHandshakeHelper; |
43 | 41 | import org.appdevforall.k2go.env.EnvironmentLock; |
44 | 42 | import org.appdevforall.k2go.sync.domain.ApkShareName; |
| 43 | +import org.appdevforall.k2go.hotspot.HotspotPermissions; |
45 | 44 | import org.appdevforall.k2go.hotspot.LocalHotspotManager; |
46 | 45 | import org.appdevforall.k2go.sync.domain.ShareConfig; |
47 | 46 | import org.appdevforall.k2go.sync.presentation.SyncProgressRepository; |
@@ -109,7 +108,7 @@ private enum Page { PREPARE, COPY } |
109 | 108 | private ApkServer apkServer; |
110 | 109 | private String apkFileName; |
111 | 110 |
|
112 | | - private ActivityResultLauncher<String> locationPerm; |
| 111 | + private ActivityResultLauncher<String[]> hotspotPerm; |
113 | 112 | // ADFA-5146: request the location permission at most once per attempt. ensureHotspot() runs on every |
114 | 113 | // render, and the permission callback re-renders; on OEMs that return a denied permission result |
115 | 114 | // synchronously that becomes unbounded recursion (render -> ensureHotspot -> launch -> sync-deny -> |
@@ -170,9 +169,14 @@ private enum RStage { JOIN, START } |
170 | 169 | @Override |
171 | 170 | public void onCreate(@Nullable Bundle s) { |
172 | 171 | super.onCreate(s); |
173 | | - locationPerm = registerForActivityResult( |
174 | | - new ActivityResultContracts.RequestPermission(), |
175 | | - granted -> { if (granted) hs.start(requireContext().getApplicationContext()); render(); }); |
| 172 | + hotspotPerm = registerForActivityResult( |
| 173 | + new ActivityResultContracts.RequestMultiplePermissions(), |
| 174 | + result -> { |
| 175 | + if (HotspotPermissions.granted(requireContext())) { |
| 176 | + hs.start(requireContext().getApplicationContext()); |
| 177 | + } |
| 178 | + render(); |
| 179 | + }); |
176 | 180 | barcodeLauncher = registerForActivityResult(new ScanContract(), r -> onScan(r.getContents())); |
177 | 181 | } |
178 | 182 |
|
@@ -445,14 +449,13 @@ private void ensureHotspot() { |
445 | 449 | // (the "Caller already has an active LocalOnlyHotspot request" log spam). |
446 | 450 | LocalHotspotManager.State st = hs.state().getValue(); |
447 | 451 | if (st != null && st.phase == LocalHotspotManager.Phase.STARTING) return; |
448 | | - if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.ACCESS_FINE_LOCATION) |
449 | | - == PackageManager.PERMISSION_GRANTED) { |
| 452 | + if (HotspotPermissions.granted(requireContext())) { |
450 | 453 | hs.start(requireContext().getApplicationContext()); |
451 | 454 | } else if (!locationAsked) { |
452 | 455 | // ADFA-5146: launch the request exactly once. Do NOT re-launch on later renders (incl. the one |
453 | | - // the permission callback triggers) — a synchronous deny would otherwise recurse into overflow. |
| 456 | + // the permission callback triggers): a synchronous deny would otherwise recurse into overflow. |
454 | 457 | locationAsked = true; |
455 | | - locationPerm.launch(Manifest.permission.ACCESS_FINE_LOCATION); |
| 458 | + hotspotPerm.launch(HotspotPermissions.required()); |
456 | 459 | } |
457 | 460 | } |
458 | 461 |
|
@@ -727,7 +730,10 @@ private void renderPrepare() { |
727 | 730 | secJoin.setFallback(requireContext(), null); |
728 | 731 | secJoin.caption.setText(getString(R.string.k2go_connect_hotspot_unsupported)); |
729 | 732 | secJoin.subCaption.setText(getString(R.string.k2go_connect_try_wifi)); |
730 | | - } 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). |
731 | 737 | secJoin.frame.setVisibility(View.GONE); |
732 | 738 | secJoin.setFallback(requireContext(), null); |
733 | 739 | secJoin.caption.setText(getString(R.string.k2go_connect_hotspot_failed)); |
|
0 commit comments