Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to startPearDiscovery - Android 10 #101

Open
BRAVO68WEB opened this issue Jul 6, 2024 · 7 comments
Open

Unable to startPearDiscovery - Android 10 #101

BRAVO68WEB opened this issue Jul 6, 2024 · 7 comments

Comments

@BRAVO68WEB
Copy link

Env

Device Name: POCO F1
Android Version: 10
React Native Version: 0.74.2

Issue

I am not able to start peer discovery on Andorid 10. It is working on Android 13+

Code sample

  • Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission
               android:required="true"
               android:name="android.permission.ACCESS_COARSE_LOCATION"/>
   <uses-permission
           android:required="true"
           android:name="android.permission.ACCESS_WIFI_STATE"/>
   <uses-permission
           android:required="true"
           android:name="android.permission.CHANGE_WIFI_STATE"/>
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />     
   <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
   <uses-feature
        android:name="android.hardware.wifi.direct"
        android:required="true" />
           
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
   <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
   <uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"
        android:usesPermissionFlags="neverForLocation" />    
    <application
        android:usesCleartextTraffic="true"
        tools:targetApi="28"
        tools:ignore="GoogleAppIndexingWarning"/>
</manifest>
  • p2pconnection.ts
public constructor() {
    this.isInitialized = false;
    this.startedPeerDiscovery = false;
  }

  public init = async () => {
    if (this.isInitialized) {
      return;
    }
    try {
      await initialize().then(() => {
        console.log('WifiP2P initialized');

        this.isInitialized = true;
      });
      const cl = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
        {
          title: 'Access to wi-fi P2P mode',
          message: 'ACCESS_COARSE_LOCATION',
        } as Rationale,
      );
      const fl = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
        {
          title: 'Access to wi-fi P2P mode',
          message: 'ACCESS_FINE_LOCATION',
        } as Rationale,
      );
      const nwd = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.NEARBY_WIFI_DEVICES,
        {
          title: 'Access to wi-fi P2P mode',
          message: 'NEARBY_WIFI_DEVICES',
        } as Rationale,
      );

      const abl = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION,
        {
          title: 'Access to wi-fi P2P mode',
          message: 'ACCESS_BACKGROUND_LOCATION',
        } as Rationale,
      );

      console.log('Permissions', cl, fl, nwd, abl);
    } catch (e) {
      console.error(e);
    }
  };

  public startPeerDiscovery = async () => {
    if (!this.isInitialized) {
      console.error('WifiP2P not initialized');
      return;
    }
    if (this.startedPeerDiscovery) {
      return;
    }
    try {
      await startDiscoveringPeers().then(() => {
        this.startedPeerDiscovery = true;
        console.log('Peer discovery started');
      });
    } catch (e) {
      console.log(e);
    }
  };
  • Error Log
 LOG  WifiP2P initialized
 LOG  Permissions granted never_ask_again never_ask_again granted
 LOG  {"code": 0, "message": "Operation failed due to an internal error."}
 LOG  {"code": 0, "message": "Operation failed due to an internal error."}

Looks like ACCESS_COARSE_LOCATION and ACCESS_BACKGROUND_LOCATION is granted, but others are never_ask_again

Adb Logcat

logcat.log

@kirillzyusko
Copy link
Owner

Hello 👋

From the logs:

WifiPermissionsUtil: UID 10413 has no location permission

I think you need to grant permissions properly 🤔

@BRAVO68WEB
Copy link
Author

I gave it BTW @kirillzyusko

@kirillzyusko
Copy link
Owner

@BRAVO68WEB but according to logs the service doesn't have a permission and because of that it can not be started 🤷‍♂️

@BRAVO68WEB
Copy link
Author

But my ACCESS_FINE_LOCATION says granted

@kirillzyusko
Copy link
Owner

@BRAVO68WEB my expectation is that never_ask_again !== granted. Again, I would trust logcat output - if it's saying that location permission is not granted, then it means it's not granted and you need to figure out what's going wrong there...

@BRAVO68WEB
Copy link
Author

Any hints what and where to check?

My background in not from Android but Web and DevOps

@kirillzyusko
Copy link
Owner

@BRAVO68WEB try to grant proper location permission. Can't give more exact direction - I don't have real Android 10 device.The only one way here is trial and error. Maybe try to use react-native-permission library 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants