Companion App Find peer service not found?

Hello,

I try to connect my Galaxy watch (native application) to a dedicated android app, but I don’t understand why it doesn’t work:
I started with HelloAccessory example: Consumer(Android), Provider(Tizen) (SSAgentV2)
I changed step by step this example to be as close as possible to my android application

  • the only differences in accessoryservices.xml files between modified “HelloAccessory” and my dedicated android application are: “application name” and “serviceImpl”
    All other settings are exactky the same
  • Communication between android sample application (modified) and galaxy watch with my dedicated service profile Works

Then if I “clone” everything in my android application, it can’t find peer service…

I have integrated in my dedicated application the modifications below in manifest:

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="com.samsung.accessory.permission.ACCESSORY_FRAMEWORK" />
<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />
<uses-permission android:name="com.samsung.WATCH_APP_TYPE.Companion" />
<uses-permission android:name="com.samsung.wmanager.ENABLE_NOTIFICATION" />

<application
	...
	...

    <service android:name="com.samsung.android.sdk.accessory.SAService"/>
    <service android:name="com.samsung.android.sdk.accessory.SAJobService"
        android:permission="android.permission.BIND_JOB_SERVICE"></service>
    <receiver android:name="com.samsung.android.sdk.accessory.RegisterUponInstallReceiver" >
        <intent-filter>
            <action android:name="com.samsung.accessory.action.REGISTER_AGENT" />
        </intent-filter>
    </receiver>
    <receiver android:name="com.samsung.android.sdk.accessory.ServiceConnectionIndicationBroadcastReceiver" >
        <intent-filter>
            <action android:name="com.samsung.accessory.action.SERVICE_CONNECTION_REQUESTED" />
        </intent-filter>
    </receiver>
    <meta-data
        android:name="AccessoryServicesLocation"
        android:value="/res/xml/accessoryservices.xml" />
</application>

SDK libraries are integrated in my app.
Every function included in “ConsumerService” of the example are integrated in my Service Class

=> it’s an existing application that already have a communication plugin which exchange data with wearOS watches, so I don’t launch SSAgent directly from main app, but from communication plugin
(SAAgentV2.RequestAgentCallback and SAAgentV2.requestAgent are in this plugin)

My SAAgent is launched (this point is OK)

But when I execute findpeer() function, I always receive the same error: “FINDPEER_SERVICE_NOT_FOUND”

If I install again my modified “HelloAccessory application”, connection works immediatly… (to avoid conflicts in my smartphone, I uninstall HelloAccessory example used for testing before trying to connect with my application).
I can’t find what’s wrong in my application :disappointed: and why I can’t connect!

Can someone help me ?

Thank’s

Hard to say what is wrong without seeing your code. There are a lot of things they might not work in case sap engine.

Did you add this privilege: http://developer.samsung.com/tizen/privilege/accessoryprotocol to tizen-manfest.xml file?

Make sure the name is the same as the Android manifest file is. Once I had an issue with that.

Thank’s for your help.

I think the problem is link to existing bugs (or wrong informations) in current Accessory SDK:

  • application name allows up to 30 characters in documentation (cf. ProgrammingGuide_Accessory.pdf §3.3.2)
    but with 28 or 29 characters it doesn’t work!
  • with a shorter “application name” (I replaced my previous with a shorter one with only 10 characters), the error “FINDPEER_SERVICE_NOT_FOUND” disappeared! (I found the solution last night after serching more than 1 week!)
  • I found the same problem with serviceProfile id and name… it doesn’t work if string size is too close to 30 characters! (I don’t know today if limit is 20 or 25 characters, but I’m sure it’s less than 30)

I still can’t connect to my watch (now I have a “Service Connection Failure” message :disappointed: ), but I am one step further (setting communication is very “tricky”, but if there is wrong information in documentation that doesn’t help us…)

(Note, my android application is developped with Android Studio, and my watch application is today with Tizen Studio in native mode)

I spent more that one week on previous error(s), so, if you have advices on this new one I would appreciate…

Now you have to check all fields in accessory.xml files both on Android side and watch. Channels number, supportedTransports (TRANSPORT_BT, WIFI, etc), service names. Try to avoid any spaces in names. Check again all required permissions (Android) and privileges (Tizen) respectively. Try to make configurations so simple as possible in order to find an error. I hope it helps.

And one more thing. Maybe it sounds stupid try to add versionCode and versionName to AndroidManifest.xml. Of course it is obsolete and not recommended anymore because build.gradle supports it but worth to check.

Example:
manifest xmlns:android=“http://schemas.android.com/apk/res/android
package=“com.acme.myapp”
android:versionCode=“10”
android:versionName=“1.0” >

If you have a field master_app_min_version in tizen-manifes.xml make sure value (versionCode ) is equal or less than that one in AndroidManifes.xml/gradle file.

:sob: unfortunatly I wrote too quickly, my FINDPEER_SERVICE_NOT_FOUND is still back!

I tried in parallel 2 configurations:
Android producer / consumer Tizen
and
Android consumer / Tizen provider

On both, I have the connection that works with the helloaccessory sample.
I modified the accessoryservices.xml of these references so that they are close to my application (I can therefore copy / paste the whole file except for serviceImpl.)
I didn’t have any cross conflicts between these 2 helloaccessory configurations

I could connect my application with the Android producer / Tizen consumer, but I want the other configuration (Android consumer / Tizen producer) because it’s an existing application that already has a communication service with WearOS, and I want the management of connections / disconnections on android side.

When I changed the size of application’s name last night in accessoryservices file, FINDPEER_SERVICE_NOT_FOUND disappeared, but when I uninstalled this morning my “Tizen consumer” version (working with Android producer hello accessory) the error comes back!
=> I modified the id of both tests configuration to avoid conflict, my 2 references configurations “helloaccessory” still works with different id now.
That way I can test connections using the same Tizen application.
=> Once my android consumer “helloaccessory” can communicate with my watch, I uninstall it from my phone to avoid conflict and I try to connect with my application.

On Android side, I have exactly the same manifest between “producer” version (that can establish connection with tizen “consumer”) and “consumer” version (that still have “find peer service not found” with tizen “producer”)…

When the FINDPEER_SERVICE_NOT_FOUND error occurs, does this mean that a device is found but the machting serviceProfile is not in it?

I modified my HelloAccessory sample to have exactly the same ServiceProfile as that of my application (id, name, channels, everything).

My HelloAccessory application established communication immediately, so ServiceProfile exists in my gear device and is correct.

What can explain why I receive FINDPEER_SERVICE_NOT_FOUND error when I try to communicate from my android application?

If you app configuration is like HelloAccessory example but still doesn’t work I think you have to check very carefully all names in configurations. As I said: avoid spaces, case sensitive names etc.

I already checked this: to be as close as possible, I modified helloaccessory to have exactly the same profile than required in my application.

I checked that communication was ok between android and Gear watch, and I uninstalled android application to avoid conflict.

I made a copy / paste from hello accessory of all profile (application name, Service profile name, id, all channels, …). To avoid typos, I didn’t manualy copy settings in accessoryservices, but pasted them from HelloAccessory
=> the only gap between the 2 files is for “serviceImpl” (also verified carefully)

Same for manifest I made a “copy / paste” of dedicated lines to avoid typos

That’s why I don’t understand what could be wrong :disappointed:

Without seeing your code is very hard to help you more. I could check your code for sap communication on my computer if you like it. Probably there is some minor error in your configruation/code.

Thank you so much for your help

See below a zip file with Modified Hello Accessory (Android and Tizen) and 2 additionnal folder to help comparison
Main_Files.zip (284.0 KB)

Source code for my Android application is too large, here is a github link in my fork: https://github.com/Philoul/AndroidAPS/tree/Tizen_Consumer_for_tests

Note: I’m not the author of this health application for diabet. (I contribute to this project by trying to add the interface with Tizen watches, this function interests hundreds of users…)

I added in zip file 2 additional folders with the 4 main files concerning with SAP settings:

  • AndroidManifest.xml
  • accessoryservices.xml
  • TizenUpdaterService.java <=> ConsumerService.java
  • Wearplugin.java <=> ConsumerActivity.java
    => I made big clean in Wearplugin.java file compared to master branch (all communication with WearOS watches removed, to have cleaner code for tests)

For testing it’s necessary to activate “WearPlugin” in upper left menu => Config Builder => Wear
Once Wear plugin is enabled, in Wear tab (top of main sreen), the button “Resend All Data” lauches “findpeers” to establish communication with Tizen Watch.

OK, you can delete all. I have downloaded files. I will try to check today or later tomorrow… I let you know about results asap or ask you questions if need.

1 Like

Unfortunately, but news. Both project HelloAccesorry and downloaed from GitHub work on my Android phone and Gear S3. Please look at attached screenshots from Tizen Studio and Android Studio 3.6.2.
I used Samsung J5 2018 with Android 7.1.1 (API 24) and Gear S3 with Tizen 4.0.2. I didn’t have to change anything because it worked right after importing and launching both projects for phone (Android) and watch (Tizen Native).

Tizen profile configuration works good with HelloAccessory and Wear project.

Make sure you don’t use obfuscation in your Java code (Android Studio). Tizen SAP lib doesn’t like it.

If I find something new I let you know.

Very strange my config is:
Gear S3 Classic SM-R770
Version One UI 1.0
Version Tizen 4.0.0.4 (no update available, but I think there was a version switch during last update pushed by samsung because during the last factory restart, it was an Asian version (unreadable) and not an European version… => I see your firmware is newer, I don’t know if it’s the root cause of my problem and I don’t know how to update my watch).

My phone is Samsung A40 (Android 9, I just received update for Android 10 but not installed yet)


I tried (among all tests done), to add these lines in proguard-rules.pro file (but I’m not sure syntax is correct) but it didn’t work :disappointed: (Do I have something else to set in androidStudio for obfuscation ?).

-keepclassmembers class com.samsung.** {*;}
-keep class com.samsung.** {*;}
-dontwarn com.samsung.**
-keepclassmembers class  info.nightscout.androidaps.plugins.general.wear.** {*;}
-keep class info.nightscout.androidaps.plugins.general.wear.** {*;}

My android studio version is 3.6.1, I’ll try to update to 3.6.2, may be it’s the reason…

Same result after Android Studio update…

Obfuscation is not set as default in Android Studio. However, a lot of developers enable it to decrease final build size. I had to update my Android Studio due to your project to last one (3.6.2), imported the github project and all run smoothly without any changes. I compared HelloAccessory configuration and github project config and all looks identical.

Maybe there is something wrong with this big github project on Android 9. I mean sth makes mess. Simple example HelloAcc… works ok on your devices.

My only phone with Android 9 is out of office for some time (serviced). I can check on this Android later on.

I didn’t change anything in android studio configuration, and in build.gradle file minifyEnabled is false, so I think the problem is probably elsewhere…

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        testCoverageEnabled(project.hasProperty('coverage'))
    }
    firebaseDisable {
        System.setProperty("disableFirebase", "true")
    }
}

Android SDK that should be installed for this app is Android 9.0 (API 28) (information from the developer team), but application run on Android 6.0 and newer versions

My Android version is 9.0 on my phone, I will upgrade it to android 10 to see if it works better…
(but it’s annoying for me (development) and for users if I can’t guarantee it works according to their configurations)

I can also make a new factory reset of my watch (asian characters are only before Galaxy Wearable connection!)

Now I’m with A40 and Android 10 (latest android version installed this evening)

=> Same problem but now I have more time between “Agent Ok, try to find peer” and “FINDPEER_SERVICE_NOT_FOUND” (first message remains 3 or 4 s, with Android 9 it was in flash)…

Hello,
I updated my code to use SAAgent in background mode (clode is closer than existing one for WearOS Watch)


(and new testing HelloAccessory is also available in my Github account)

I still have the same “wrong message” FINDPEER_SERVICE_NOT_FOUND
=> I opened a Support Request yesterday (#21951)

Hey, did you find any solutions?, because i have the same problem.