Skip to content

Commit cfa56a7

Browse files
committed
remove perms
1 parent 7a4762f commit cfa56a7

File tree

3 files changed

+37
-185
lines changed

3 files changed

+37
-185
lines changed

src/plugins/browser/android/com/foxdebug/browser/Browser.java

Lines changed: 37 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ public class Browser extends LinearLayout {
8888

8989
ValueCallback<Uri[]> filePathCallback;
9090
final int REQUEST_SELECT_FILE = 1;
91-
92-
private BrowserActivity permissionHandler;
9391

9492
public Browser(Context context, Ui.Theme theme, Boolean onlyConsole) {
9593
super(context);
@@ -422,14 +420,6 @@ public void setConsoleVisible(boolean visible) {
422420
public void setProgressBarVisible(boolean visible) {
423421
loading.setVisibility(visible ? View.VISIBLE : View.GONE);
424422
}
425-
426-
public void setPermissionHandler(BrowserActivity handler) {
427-
this.permissionHandler = handler;
428-
}
429-
430-
public BrowserActivity getPermissionHandler() {
431-
return this.permissionHandler;
432-
}
433423

434424
private void updateViewportDimension(int width, int height) {
435425
String script =
@@ -632,9 +622,6 @@ public void exit() {
632622
class BrowserChromeClient extends WebChromeClient {
633623

634624
Browser browser;
635-
636-
// Cache granted permissions per origin to avoid re-prompting (e.g., when switching cameras)
637-
private java.util.Set<String> grantedPermissions = new java.util.HashSet<>();
638625

639626
public BrowserChromeClient(Browser browser) {
640627
super();
@@ -695,77 +682,56 @@ public boolean onShowFileChooser(
695682
public void onPermissionRequest(final PermissionRequest request) {
696683
final String[] resources = request.getResources();
697684
final Uri origin = request.getOrigin();
698-
final String originKey = origin != null ? origin.toString() : "";
699-
700-
// Check if all requested permissions are already granted for this origin
701-
boolean allCached = true;
702-
for (String resource : resources) {
703-
String cacheKey = originKey + "|" + resource;
704-
if (!grantedPermissions.contains(cacheKey)) {
705-
allCached = false;
706-
break;
707-
}
708-
}
709-
710-
if (allCached) {
711-
request.grant(resources);
712-
return;
713-
}
714685

715-
// Build a human-readable list with emojis for better visual appeal
686+
// Build a human-readable list of requested permissions
716687
StringBuilder permissionList = new StringBuilder();
717688
for (String resource : resources) {
718689
if (resource.equals(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) {
719-
permissionList.append("📷 Camera\n");
690+
permissionList.append(" Camera\n");
720691
} else if (resource.equals(PermissionRequest.RESOURCE_AUDIO_CAPTURE)) {
721-
permissionList.append("🎤 Microphone\n");
692+
permissionList.append(" Microphone\n");
722693
} else if (resource.equals(PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID)) {
723-
permissionList.append("🔐 Protected Media\n");
694+
permissionList.append(" Protected Media\n");
724695
} else if (resource.equals(PermissionRequest.RESOURCE_MIDI_SYSEX)) {
725-
permissionList.append("🎹 MIDI Device\n");
696+
permissionList.append(" MIDI Device\n");
726697
} else {
727-
permissionList.append("🔧 ").append(resource).append("\n");
698+
permissionList.append(" ").append(resource).append("\n");
728699
}
729700
}
730701

731-
// Get the site name from origin
702+
// Get the site URL
703+
final String siteUrl = origin != null ? origin.toString() : "";
732704
String siteName = origin != null ? origin.getHost() : "This site";
733705
if (siteName == null || siteName.isEmpty()) {
734706
siteName = "This site";
735707
}
736708

737-
final String message = siteName + " wants to access:\n\n" + permissionList.toString();
709+
final String message = siteName + " is requesting access to:\n\n" + permissionList.toString() +
710+
"\n\nThese permissions are not available in the in-app browser. " +
711+
"Please open this page in an external browser to use these features.";
738712

739713
new Handler(Looper.getMainLooper()).post(() -> {
740-
AlertDialog dialog = new AlertDialog.Builder(browser.context)
741-
.setTitle("🔔 Permission Request")
714+
new AlertDialog.Builder(browser.context)
715+
.setTitle("⚠️ Permission Not Available")
742716
.setMessage(message)
743-
.setPositiveButton("Allow", (dlg, which) -> {
744-
// Cache the granted permissions for this origin
745-
for (String resource : resources) {
746-
String cacheKey = originKey + "|" + resource;
747-
grantedPermissions.add(cacheKey);
748-
}
749-
750-
// Check if we have a permission handler (activity) to handle runtime permissions
751-
BrowserActivity handler = browser.getPermissionHandler();
752-
if (handler != null) {
753-
handler.handlePermissionRequest(request, resources);
754-
} else {
755-
// Fallback: directly grant if no handler
756-
request.grant(resources);
717+
.setPositiveButton("Open in Browser", (dlg, which) -> {
718+
request.deny();
719+
// Open in external browser
720+
try {
721+
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(siteUrl));
722+
browser.context.startActivity(browserIntent);
723+
} catch (Exception e) {
724+
Toast.makeText(browser.context, "Could not open browser", Toast.LENGTH_SHORT).show();
757725
}
758726
})
759-
.setNegativeButton("Block", (dlg, which) -> {
727+
.setNegativeButton("Cancel", (dlg, which) -> {
760728
request.deny();
761729
})
762730
.setOnCancelListener(dlg -> {
763731
request.deny();
764732
})
765733
.setCancelable(true)
766-
.create();
767-
768-
dialog.show();
734+
.show();
769735
});
770736
}
771737

@@ -779,14 +745,6 @@ public void onPermissionRequestCanceled(PermissionRequest request) {
779745
public void onGeolocationPermissionsShowPrompt(final String origin,
780746
final android.webkit.GeolocationPermissions.Callback callback) {
781747

782-
String cacheKey = origin + "|geolocation";
783-
784-
// Check if already granted
785-
if (grantedPermissions.contains(cacheKey)) {
786-
callback.invoke(origin, true, false);
787-
return;
788-
}
789-
790748
// Get site name from origin
791749
String siteName = origin;
792750
try {
@@ -797,22 +755,25 @@ public void onGeolocationPermissionsShowPrompt(final String origin,
797755
}
798756

799757
final String displayName = siteName;
758+
final String message = displayName + " is requesting access to your location.\n\n" +
759+
"Location access is not available in the in-app browser. " +
760+
"Please open this page in an external browser to use location features.";
800761

801762
new Handler(Looper.getMainLooper()).post(() -> {
802763
new AlertDialog.Builder(browser.context)
803-
.setTitle("📍 Location Request")
804-
.setMessage(displayName + " wants to access your location")
805-
.setPositiveButton("Allow", (dialog, which) -> {
806-
grantedPermissions.add(cacheKey);
807-
// Check Android runtime location permission
808-
BrowserActivity handler = browser.getPermissionHandler();
809-
if (handler != null) {
810-
handler.handleGeolocationPermission(origin, callback);
811-
} else {
812-
callback.invoke(origin, true, false);
764+
.setTitle("📍 Location Not Available")
765+
.setMessage(message)
766+
.setPositiveButton("Open in Browser", (dialog, which) -> {
767+
callback.invoke(origin, false, false);
768+
// Open in external browser
769+
try {
770+
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(origin));
771+
browser.context.startActivity(browserIntent);
772+
} catch (Exception e) {
773+
Toast.makeText(browser.context, "Could not open browser", Toast.LENGTH_SHORT).show();
813774
}
814775
})
815-
.setNegativeButton("Block", (dialog, which) -> {
776+
.setNegativeButton("Cancel", (dialog, which) -> {
816777
callback.invoke(origin, false, false);
817778
})
818779
.setOnCancelListener(dialog -> {

src/plugins/browser/android/com/foxdebug/browser/BrowserActivity.java

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,21 @@
22

33
import android.app.Activity;
44
import android.content.Intent;
5-
import android.content.pm.PackageManager;
65
import android.graphics.Color;
76
import android.os.Build;
87
import android.os.Bundle;
98
import android.util.Log;
109
import android.view.View;
1110
import android.view.Window;
1211
import android.view.WindowInsetsController;
13-
import android.webkit.PermissionRequest;
1412
import android.webkit.WebChromeClient;
15-
import android.Manifest;
16-
import androidx.core.app.ActivityCompat;
17-
import androidx.core.content.ContextCompat;
1813
import com.foxdebug.system.Ui;
1914
import org.json.JSONObject;
20-
import java.util.ArrayList;
21-
import java.util.List;
2215

2316
public class BrowserActivity extends Activity {
2417

2518
private Browser browser;
2619
private Ui.Theme theme;
27-
28-
private static final int PERMISSION_REQUEST_CODE = 100;
29-
private PermissionRequest pendingPermissionRequest;
30-
private String[] pendingResources;
3120

3221
@Override
3322
public void onCreate(Bundle savedInstanceState) {
@@ -46,7 +35,6 @@ public void onCreate(Bundle savedInstanceState) {
4635
}
4736

4837
browser = new Browser(this, theme, onlyConsole);
49-
browser.setPermissionHandler(this);
5038
browser.setUrl(url);
5139
setContentView(browser);
5240
setSystemTheme(theme.get("primaryColor"));
@@ -60,95 +48,6 @@ public void onBackPressed() {
6048
browser.exit();
6149
}
6250
}
63-
64-
/**
65-
* Handle WebView permission request by checking/requesting Android runtime permissions
66-
*/
67-
public void handlePermissionRequest(PermissionRequest request, String[] resources) {
68-
this.pendingPermissionRequest = request;
69-
this.pendingResources = resources;
70-
71-
List<String> permissionsToRequest = new ArrayList<>();
72-
73-
for (String resource : resources) {
74-
if (resource.equals(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) {
75-
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
76-
!= PackageManager.PERMISSION_GRANTED) {
77-
permissionsToRequest.add(Manifest.permission.CAMERA);
78-
}
79-
} else if (resource.equals(PermissionRequest.RESOURCE_AUDIO_CAPTURE)) {
80-
if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO)
81-
!= PackageManager.PERMISSION_GRANTED) {
82-
permissionsToRequest.add(Manifest.permission.RECORD_AUDIO);
83-
}
84-
}
85-
}
86-
87-
if (permissionsToRequest.isEmpty()) {
88-
// All permissions already granted, grant to WebView
89-
request.grant(resources);
90-
} else {
91-
// Request the needed Android permissions
92-
ActivityCompat.requestPermissions(
93-
this,
94-
permissionsToRequest.toArray(new String[0]),
95-
PERMISSION_REQUEST_CODE
96-
);
97-
}
98-
}
99-
100-
// Geolocation permission handling
101-
private static final int GEOLOCATION_PERMISSION_REQUEST_CODE = 101;
102-
private android.webkit.GeolocationPermissions.Callback pendingGeolocationCallback;
103-
private String pendingGeolocationOrigin;
104-
105-
public void handleGeolocationPermission(String origin, android.webkit.GeolocationPermissions.Callback callback) {
106-
this.pendingGeolocationCallback = callback;
107-
this.pendingGeolocationOrigin = origin;
108-
109-
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
110-
!= PackageManager.PERMISSION_GRANTED) {
111-
ActivityCompat.requestPermissions(
112-
this,
113-
new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
114-
GEOLOCATION_PERMISSION_REQUEST_CODE
115-
);
116-
} else {
117-
// Already granted
118-
callback.invoke(origin, true, false);
119-
pendingGeolocationCallback = null;
120-
pendingGeolocationOrigin = null;
121-
}
122-
}
123-
124-
@Override
125-
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
126-
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
127-
128-
if (requestCode == PERMISSION_REQUEST_CODE && pendingPermissionRequest != null) {
129-
boolean allGranted = true;
130-
for (int result : grantResults) {
131-
if (result != PackageManager.PERMISSION_GRANTED) {
132-
allGranted = false;
133-
break;
134-
}
135-
}
136-
137-
if (allGranted) {
138-
pendingPermissionRequest.grant(pendingResources);
139-
} else {
140-
pendingPermissionRequest.deny();
141-
}
142-
143-
pendingPermissionRequest = null;
144-
pendingResources = null;
145-
} else if (requestCode == GEOLOCATION_PERMISSION_REQUEST_CODE && pendingGeolocationCallback != null) {
146-
boolean granted = grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
147-
pendingGeolocationCallback.invoke(pendingGeolocationOrigin, granted, false);
148-
pendingGeolocationCallback = null;
149-
pendingGeolocationOrigin = null;
150-
}
151-
}
15251

15352
private void setSystemTheme(int systemBarColor) {
15453
try {

src/plugins/browser/plugin.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@
1919
</activity>
2020
</config-file>
2121

22-
<config-file target="AndroidManifest.xml" parent="/*">
23-
<uses-permission android:name="android.permission.CAMERA"/>
24-
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
25-
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
26-
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
27-
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
28-
</config-file>
29-
3022
<hook type="after_prepare" src="utils/updatePackage.js" />
3123

3224
<resource-file src="res/android/menu_enter.xml" target="res/anim/menu_enter.xml" />

0 commit comments

Comments
 (0)