-
Notifications
You must be signed in to change notification settings - Fork 103
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
SDL 0088 System Capability Manager #916
Conversation
* added `SDLSystemCapabilitiesManager` to .podspec files * added `SDLSystemCapabilitiesManager` to SmartDeviceLink.h file * made `SDLSystemCapabilitiesManager` header public
* 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.
SmartDeviceLink/SDLManager.h
Outdated
@@ -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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(^{ |
There was a problem hiding this comment.
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 it
s 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 it
s, it could require a refactor, or be quite confusing to a new contributor.
There was a problem hiding this comment.
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 it
s. 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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 afterEach
s that get's called which doesn't seem like a lot to me.
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
- Replaced with error message
Renamed the pcmStreamCapabilities variable in the SDLSystemCapabilityManager
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
return self; | ||
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nonatomic, assign, readonly)
There was a problem hiding this comment.
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>
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
andSDLGetSystemCapabilityResponse
.Changelog
Breaking Changes
None
Bug Fixes
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:
CLA