Compare commits

..

No commits in common. "master" and "testing" have entirely different histories.

5 changed files with 3 additions and 35 deletions

2
.gitignore vendored
View File

@ -1,3 +1 @@
classes/
cb.ast

BIN
Ble.jar

Binary file not shown.

View File

@ -35,7 +35,6 @@ public class BlessedConnect extends Fragment {
final int PERMISSION_REQUEST = 1;
final int REQUEST_ENABLE_BT = 2;
final int PERMISSION_REQUEST_BLE = 3;
public BlessedConnect() {
Log.d("gio", "BlessedConnect()");
@ -51,12 +50,8 @@ public class BlessedConnect extends Fragment {
Activity act = (Activity)ctx;
FragmentTransaction ft = act.getFragmentManager().beginTransaction();
ft.add(inst, "BlessedConnect");
if (android.os.Build.VERSION.SDK_INT >= 24) {
ft.commitNowAllowingStateLoss();
} else {
ft.commitNow();
}
}
});
}
@ -64,15 +59,7 @@ public class BlessedConnect extends Fragment {
super.onAttach(ctx);
Log.d("gio", "BlessedConnect: onAttach()");
ctx.registerReceiver(receiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
if (android.os.Build.VERSION.SDK_INT >= 31) {
// BLE on Android 12+ needs the BLUETOOTH_SCAN/CONNECT runtime
// permissions. BLUETOOTH_SCAN is declared with
// usesPermissionFlags="neverForLocation", so no location
// permission is required for scanning.
requestPermissions(new String[]{
"android.permission.BLUETOOTH_SCAN",
"android.permission.BLUETOOTH_CONNECT"}, PERMISSION_REQUEST_BLE);
} else if (ctx.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
if (ctx.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST);
}
central = new BluetoothCentral(ctx, centralCallback, null);
@ -277,7 +264,7 @@ public class BlessedConnect extends Fragment {
@Override
public void onRequestPermissionsResult (int requestCode, String[] permissions, int[] grantResults) {
Log.d("gio", "BlessedConnect: onRequestPermissionsResult");
if (requestCode == PERMISSION_REQUEST || requestCode == PERMISSION_REQUEST_BLE) {
if (requestCode == PERMISSION_REQUEST) {
boolean granted = true;
for (int x : grantResults) {
if (x == PackageManager.PERMISSION_DENIED) {

View File

@ -225,15 +225,6 @@ func NewBLE() *BLE {
//Enable
func (b *BLE) Enable(view uintptr) {
log.Printf("ble.Enable()")
// view == 0 is Gio's detach signal (GioView.onDestroyView sends
// ViewEvent{View: 0} when the view is destroyed, e.g. the activity
// going away on a recents-wipe). Nothing to register; passing the null
// ref on would abort in JNI (GetObjectClass on null). A re-attach
// arrives as a fresh event with a live view. Callers that forward the
// event unfiltered are protected by this guard.
if view == 0 {
return
}
setJVM(app.JavaVM())
runInJVM(func(env *JNIEnv) {
log.Printf("ble.Enable(): inside runInJVM()")

View File

@ -5,14 +5,6 @@
void
registerFragment(JNIEnv *env, jobject view) {
if (view == NULL) {
// Detach signal (Gio sends ViewEvent{View: 0} when the view is
// destroyed, e.g. the activity going away on a recents-wipe).
// The Go side already filters these; this guard keeps the JNI
// calls safe if one ever slips through (GetObjectClass on null
// aborts the process).
return;
}
jclass cls = (*env)->GetObjectClass(env, view);
jmethodID mid = (*env)->GetMethodID(env, cls, "getContext", "()Landroid/content/Context;");
jobject ctx = (*env)->CallObjectMethod(env, view, mid);