Skip to content

Commit 9fe10b7

Browse files
author
hannianqiao
committed
add javaSE code
1 parent 6bff21a commit 9fe10b7

3 files changed

Lines changed: 69 additions & 15 deletions

File tree

hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,45 @@ public void onError(SdlManager sdlManager, String info, Exception e) {
138138
}
139139

140140
@Override
141-
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language){
142-
String appName;
141+
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language) {
142+
return null;
143+
}
144+
145+
@Override
146+
public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language, Language hmiLanguage) {
147+
boolean isNeedUpdate = false;
148+
String appName = APP_NAME;
149+
String ttsName = APP_NAME;
143150
switch (language) {
144151
case ES_MX:
152+
isNeedUpdate = true;
153+
ttsName = APP_NAME_ES;
154+
break;
155+
case FR_CA:
156+
isNeedUpdate = true;
157+
ttsName = APP_NAME_FR;
158+
break;
159+
default:
160+
break;
161+
}
162+
switch (hmiLanguage) {
163+
case ES_MX:
164+
isNeedUpdate = true;
145165
appName = APP_NAME_ES;
146166
break;
147167
case FR_CA:
168+
isNeedUpdate = true;
148169
appName = APP_NAME_FR;
149170
break;
150171
default:
151-
return null;
172+
break;
173+
}
174+
if (isNeedUpdate) {
175+
return new LifecycleConfigurationUpdate(appName, null, TTSChunkFactory.createSimpleTTSChunks(ttsName), null);
176+
} else {
177+
return null;
152178
}
153179

154-
return new LifecycleConfigurationUpdate(appName,null,TTSChunkFactory.createSimpleTTSChunks(appName), null);
155180
}
156181
};
157182

javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,25 +230,36 @@ public void onComplete(boolean success) {
230230
}
231231

232232
@Override
233-
protected void checkLifecycleConfiguration() {
234-
final Language actualLanguage = lifecycleManager.getRegisterAppInterfaceResponse().getLanguage();
235-
236-
if (actualLanguage != null && !actualLanguage.equals(hmiLanguage)) {
237-
238-
final LifecycleConfigurationUpdate lcu = managerListener.managerShouldUpdateLifecycle(actualLanguage);
233+
protected void checkLifecycleConfiguration(){
234+
final Language actualLanguage = this.getRegisterAppInterfaceResponse().getLanguage();
235+
final Language actualHMILanguage = this.getRegisterAppInterfaceResponse().getHmiDisplayLanguage();
236+
237+
if ((actualLanguage != null && !actualLanguage.equals(language)) || (actualHMILanguage != null && !actualHMILanguage.equals(hmiLanguage))) {
238+
239+
LifecycleConfigurationUpdate lcuNew = managerListener.managerShouldUpdateLifecycle(actualLanguage, actualHMILanguage);
240+
LifecycleConfigurationUpdate lcuOld = managerListener.managerShouldUpdateLifecycle(actualLanguage);
241+
final LifecycleConfigurationUpdate lcu;
242+
ChangeRegistration changeRegistration;
243+
if (lcuNew == null) {
244+
lcu = lcuOld;
245+
changeRegistration = new ChangeRegistration(actualLanguage, actualLanguage);
246+
} else {
247+
lcu = lcuNew;
248+
changeRegistration = new ChangeRegistration(actualLanguage, actualHMILanguage);
249+
}
239250

240251
if (lcu != null) {
241-
ChangeRegistration changeRegistration = new ChangeRegistration(actualLanguage, actualLanguage);
242252
changeRegistration.setAppName(lcu.getAppName());
243253
changeRegistration.setNgnMediaScreenAppName(lcu.getShortAppName());
244254
changeRegistration.setTtsName(lcu.getTtsName());
245255
changeRegistration.setVrSynonyms(lcu.getVoiceRecognitionCommandNames());
246256
changeRegistration.setOnRPCResponseListener(new OnRPCResponseListener() {
247257
@Override
248258
public void onResponse(int correlationId, RPCResponse response) {
249-
if (response.getSuccess()) {
259+
if (response.getSuccess()){
250260
// go through and change sdlManager properties that were changed via the LCU update
251-
hmiLanguage = actualLanguage;
261+
hmiLanguage = actualHMILanguage;
262+
language = actualLanguage;
252263

253264
if (lcu.getAppName() != null) {
254265
appName = lcu.getAppName();
@@ -631,8 +642,9 @@ public Builder setMinimumRPCVersion(final Version minimumRPCVersion) {
631642
* Sets the Language of the App
632643
* @param hmiLanguage the desired language to be used on the display/HMI of the connected module
633644
*/
634-
public Builder setLanguage(final Language hmiLanguage){
645+
public Builder setLanguage(final Language hmiLanguage) {
635646
sdlManager.hmiLanguage = hmiLanguage;
647+
sdlManager.language = hmiLanguage;
636648
return this;
637649
}
638650

@@ -775,8 +787,9 @@ public SdlManager build() {
775787
sdlManager.isMediaApp = false;
776788
}
777789

778-
if (sdlManager.hmiLanguage == null){
790+
if (sdlManager.hmiLanguage == null) {
779791
sdlManager.hmiLanguage = Language.EN_US;
792+
sdlManager.language = Language.EN_US;
780793
}
781794

782795
if (sdlManager.minimumProtocolVersion == null){

javaSE/src/main/java/com/smartdevicelink/managers/SdlManagerListener.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ public interface SdlManagerListener extends BaseSdlManagerListener {
6363
* @param language The language of the connected head unit the manager is trying to update the configuration.
6464
* @return An object of LifecycleConfigurationUpdate if the head unit language is supported,
6565
* otherwise null to indicate that the language is not supported.
66+
* @deprecated use {@link #managerShouldUpdateLifecycle(Language language, Language hmiLanguage)} instead
6667
*/
68+
@Deprecated
6769
LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language);
70+
71+
/**
72+
* Called when the SDL manager detected a language mismatch. In case of a language mismatch the
73+
* manager should change the apps registration by updating the lifecycle configuration to the
74+
* specified language. If the app can support the specified language it should return an Object
75+
* of LifecycleConfigurationUpdate, otherwise it should return null to indicate that the language
76+
* is not supported.
77+
*
78+
* @param language The VR+TTS language of the connected head unit the manager is trying to update the configuration.
79+
* @param hmiLanguage The HMI display language of the connected head unit the manager is trying to update the configuration.
80+
* @return An object of LifecycleConfigurationUpdate if the head unit language is supported,
81+
* otherwise null to indicate that the language is not supported.
82+
*/
83+
LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language, Language hmiLanguage);
6884
}

0 commit comments

Comments
 (0)