0

I'm using SAP: Watch as consumer, Phone as provider.

Usually communication in between them is perfect, but I have a bottleneck now: If I send a large data from phone to watch (with SASocket.secureSend), I can't interrupt it.

Consider this:

I'm sending a big transaction from phone to watch, and in the middle, I want to send a message back to phone from the watch: this is working, so watch's message reaches my phone during this other huge transaction. Ie.: SAP seems to handle duplex communication

Problem:

My phone can't reply to this watch message, it needs to wait first until the huge transfer finishes. I tried using different channels (one channel for commands, one channel for big data), but still big data has to finish sending first before command sending can take place (doesn't matter it goes on different channel).

Can I somehow interrupt big data sending/start a parallel sending of the command?

Sending currently spawns a thread as it was recommended:

new Thread(new Runnable() {
    public void run() {
        Log.d(LOG_TAG, "run: SEND START!");
        try {
            mSASocket.secureSend(getServiceChannelId(0), data.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
        Log.d(LOG_TAG, "run: SEND END!");
    }
}).start();

I've tried interrupting this thread, but it didn't stopped the huge transaction, so it didn't help.

How can I either interrupt the huge transaction, or send another message parallel (with higher priority) to the watch?

Daniel
  • 2,318
  • 2
  • 22
  • 53

1 Answers1

0

SAP maintains single session queue per service channel as defined in accessoryservice.xml.

Every service channel can have different priorities.

So to solve the problem, please declare the high priority for the service channel used by the smaller size data. so that even if the bigger data is still transmitting, phone can send other high priority messages to watch on different channel. Please refer below snippet for the same.

<serviceProfile
.

.
    <serviceChannel
        dataRate="low"
        id="104"
        priority="low"
        reliability="enable" />

 

// create a new service channel with high priority and different id

    <serviceChannel
        dataRate="low"
        id="105"
        priority="high"
        reliability="enable" />
</serviceProfile>
Nightswatch
  • 133
  • 1
  • 8
  • Priority doesn't work on my watch and phone. If there is a transmission on `low` priority channel, it will **have to** finish its process before `high` priority can start sending. You can verify this if you investigate SAP's resources in Android Studio. `send` has a loop, and won't be interrupted until it finishes. – Daniel May 18 '21 at 11:08
  • I also tried creating two different `serviceProfiles`: this way I can `close` the socket on the profile which I need to interrupt. But still it needs 5-10 seconds for the other profile to be able to send data. – Daniel May 18 '21 at 11:09
  • A separate service (Samsung Accessory Service) runs on phone which takes care of priority handling while sending the data to watch. The loop inside send is available in SDK. As I mentioned above, for every service channel there is a separate queue. Based on some algorithm, the service picks more data packets from high priority queue than low priority queue for transmitting to watch. This is how it works. You can run this on the device for some time and see the difference. – Nightswatch May 27 '21 at 09:02
  • The question is how can I interrupt the *low* priority send **and** immediately send something on *high* priority? Now the *low* priority send needs considerable amount of time before it gets ended (thus letting the other *high* prio send happen) – Daniel May 28 '21 at 19:24
  • Please call the SASocket.close() API to close the existing service connection. It will clear the queue and terminate the service connection. https://img-developer.samsung.com/onlinedocs/sms/accessory/com/samsung/android/sdk/accessory/SASocket.html#close-- And you can send the high priority data on other socket. – Nightswatch Jun 01 '21 at 07:18
  • Yes, I'm doing it right now, but still experience a bit of (2-3s) delay before high priority message reaches my watch. Maybe my order is wrong? 1.) Send low prio huge data, 2.) Send high priority small data AND immediately 3.) close the other low prio send. Maybe I'll have to change 2 and 3? – Daniel Jun 01 '21 at 14:08