Skip to content
New issue

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

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

Already on GitHub? # to your account

SDL 0088 System Capability Manager #916

Merged
merged 34 commits into from
Apr 18, 2018

Conversation

NicoleYarroch
Copy link
Contributor

@NicoleYarroch NicoleYarroch commented Mar 27, 2018

Fixes #720

This PR is ready for review.

Risk

This PR makes minor API changes.

Testing Plan

Added the SDLSystemCapabilityManagerSpec file

Summary

This PR creates a centralized manager for accessing all system capabilities. These capabilities were previously scattered between the RegisterAppInterfaceResponse, SetDisplayLayoutResponse and SDLGetSystemCapabilityResponse.

Changelog

Breaking Changes

None

Bug Fixes
  • Fixed broken test cases in the SDLScreenManagerSpec file.
  • Fixed broken change registration test cases in the SDLLifecycleManagerSpec file.
  • Fixed failed verification checks in the SDLLifecycleManagerSpec file. The failed tests were due to notifications for the SDLManagerDelegate being sent on the main thread, creating a slight delay in sending the notification. The tests are now forced to run immediately on the main thread.

Tasks Remaining:

  • Add test cases to SDLLifecycleMangerSpec
  • Use new API in Example app
  • Review documentation

CLA

@NicoleYarroch NicoleYarroch self-assigned this Mar 27, 2018
@NicoleYarroch NicoleYarroch added enhancement proposal Accepted SDL Evolution Proposal labels Mar 27, 2018
@NicoleYarroch NicoleYarroch added this to the 5.3.0 milestone Mar 27, 2018
* Used the `SDLSystemCapabilityManager` to:
    * check if the head unit supports graphics
    * check if the head unit supports making phone calls
Fixed failed verification checks in the SDLLifecycleManagerSpec file. The failed tests were due to notifications for the SDLManagerDelegate being sent on the main thread, causing a slight delay in sending the notification. The tests are now forced to run immediately on the main thread.
@NicoleYarroch NicoleYarroch changed the title WIP: SDL 0088 System Capability Manager SDL 0088 System Capability Manager Mar 29, 2018
@@ -95,8 +96,16 @@ typedef void (^SDLManagerReadyBlock)(BOOL success, NSError *_Nullable error);
*/
@property (strong, nonatomic, readonly, nullable) SDLStreamingMediaManager *streamManager;

/**
* The screen manager for sending SDLShow RPCs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually for UI related RPCs, we just started with Show

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

*
* Optional, Array of length 1 - 100, of SDLPrerecordedSpeech
*/
@property (nullable, copy, nonatomic, readonly) NSArray<SDLPrerecordedSpeech> *prerecordedSpeech;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a better name for this, like supportedPrerecordedSpeechTypes, or to match with the others prerecordedSpeechCapabilities.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Renamed var to prerecordedSpeechCapabilities

*
* Optional, Array of length 1 - 100, of SDLVRCapabilities
*/
@property (nullable, copy, nonatomic, readonly) NSArray<SDLVRCapabilities> *vrCapabilities;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this even do? We only have one enum defined...if it's defined it's supported? Should we change this to a BOOL in the manager? Why is it an array...gah.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Changed to a BOOL.

*
* @param error The error returned if the request for a capability type failed. The error is nil if the request was successful.
*/
typedef void (^SDLUpdateCapabilityHandler)(NSError * _Nullable error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see this pass back the manager as well, so that the dev doesn't have to do the weak / strong dance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


NS_ASSUME_NONNULL_BEGIN

@interface SDLSystemCapabilityManager : NSObject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to get a callback when capabilities have changed, either to observe an individual one, or a group, or all. It wasn't a part of the proposal, but we should record in an issue that these would be nice enhancements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added issue #925.


- (void)updateCapabilityType:(SDLSystemCapabilityType)type completionHandler:(SDLUpdateCapabilityHandler)handler {
SDLGetSystemCapability *getSystemCapability = [[SDLGetSystemCapability alloc] initWithType:type];
[self.connectionManager sendConnectionManagerRequest:getSystemCapability withResponseHandler:^(__kindof SDLRPCRequest *request, __kindof SDLRPCResponse *response, NSError *error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to use the manager version? This is an API available to devs and therefore allows them to bypass the checks we have in the lifecycle manager.

Copy link
Contributor Author

@NicoleYarroch NicoleYarroch Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Now using sendConnectionRequest:withResponseHandler.

} else if ([systemCapabilityType isEqualToEnum:SDLSystemCapabilityTypeVideoStreaming]) {
self.videoStreamingCapability = systemCapabilityResponse.videoStreamingCapability;
} else {
NSAssert(NO, @"Received response for unknown SDLSystemCapabilityType: %@", systemCapabilityType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to decide if we should assert or do nothing...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the assert and replaced it with a log message.


- (void)updateCapabilityType:(SDLSystemCapabilityType)type completionHandler:(SDLUpdateCapabilityHandler)handler {
SDLGetSystemCapability *getSystemCapability = [[SDLGetSystemCapability alloc] initWithType:type];
[self.connectionManager sendConnectionManagerRequest:getSystemCapability withResponseHandler:^(__kindof SDLRPCRequest *request, __kindof SDLRPCResponse *response, NSError *error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should observe the response handler for the GetSystemCapabilities so that we can pull those which the dev uses outside of our manager and capture them as well. Then we can move this response handler code to that method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an example of how this works somewhere the library? I'm now sure how to intercept a request sent outside of this manager.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're doing it with SetDisplayLayout in this manager

testSetDisplayLayoutResponse.presetBankCapabilities = testPresetBankCapabilities;
});

afterEach(^{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to figure out how this worked. While it's pretty clever, I'm not really a fan because it depends on the order of the its and it is quite brittle and doesn't allow for very much flexibility. If we add a new it, or rearrange the order of the its, it could require a refactor, or be quite confusing to a new contributor.

Copy link
Contributor Author

@NicoleYarroch NicoleYarroch Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by the order of the its. Since all values being tested get reset to nil in the topmost beforeEach, the order in which the tests are performed doesn't matter.

If we have to check all 15 vars in each test, it is going to be a pain to keep the tests updated when new system capabilities are added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess what I'm wondering is why you're using afterEach so much instead of beforeEach

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't beforeEach and afterEach both exist to avoid writing redundant code? Each test case only has two afterEachs that get's called which doesn't seem like a lot to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, my question is what the purpose of afterEach is rather than using a beforeEach in this case.

[manager.systemCapabilityManager updateCapabilityType:SDLSystemCapabilityTypePhoneCall completionHandler:^(NSError * _Nullable error) {
if (error == nil) {
SDLLogD(@"Dialing number");
[self.class sdlex_sendDialNumberWithManager:manager];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to check the permission manager. Most apps don't have permission for this, probably including this app.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Renamed var prerecordedSpeech to prerecordedSpeechCapabilities
Renamed vrCapabilities to vrCapability
@joeljfischer
Copy link
Contributor

The above changelog should include the enhancements of this proposal implementation so it's easier to copy it into CHANGELOG.md when the release comes.

@property (nullable, copy, nonatomic, readwrite) NSArray<SDLPrerecordedSpeech> *prerecordedSpeechCapabilities;
@property (nonatomic, readwrite) BOOL vrCapability;
@property (nullable, copy, nonatomic, readwrite) NSArray<SDLAudioPassThruCapabilities *> *audioPassThruCapabilities;
@property (nullable, copy, nonatomic, readwrite) SDLAudioPassThruCapabilities *pcmStreamCapability;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-array ones should be strong, not copy, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


return self;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have a stop method so that internal data can be cleared when the lifecycle manager stops.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

* @param error The error returned if the request for a capability type failed. The error is nil if the request was successful.
* @param systemCapabilityManager The system capability manager
*/
typedef void (^SDLUpdateCapabilityHandler)(NSError * _Nullable error, SDLSystemCapabilityManager *systemCapabilityManager);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be up at the top, outside of the interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Signed-off-by: NicoleYarroch <nicole@livio.io>
Signed-off-by: NicoleYarroch <nicole@livio.io>

- (void)stop {
SDLLogD(@"System Capability manager stopped");
[[NSNotificationCenter defaultCenter] removeObserver:self];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should not remove the observer, or else if you disconnect and reconnect, the observers will never fire, because this is not re-inited. This should clear all the internal capability data however. Or else, all this data will continue to be available while we disconnect and will still be there on a reconnect, even if it's to a different head unit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

*
* True if the head unit supports voice recognition; false if not.
*/
@property (nonatomic, readonly) BOOL vrCapability;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nonatomic, assign, readonly)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Signed-off-by: NicoleYarroch <nicole@livio.io>
@joeljfischer joeljfischer merged commit 2a3fb78 into develop Apr 18, 2018
@joeljfischer joeljfischer deleted the feature/issue_720_system_capability_manager branch April 18, 2018 20:28
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
proposal Accepted SDL Evolution Proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants