summaryrefslogtreecommitdiff
path: root/base/src/main/java/com/smartdevicelink/proxy/rpc/RegisterAppInterfaceResponse.java
blob: 6dbbbe9e89421265ee773f059cc9d6c1c3bd7435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
/*
 * Copyright (c) 2017 - 2019, SmartDeviceLink Consortium, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided with the
 * distribution.
 *
 * Neither the name of the SmartDeviceLink Consortium, Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package com.smartdevicelink.proxy.rpc;

import androidx.annotation.NonNull;

import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.proxy.RPCResponse;
import com.smartdevicelink.proxy.rpc.enums.ButtonName;
import com.smartdevicelink.proxy.rpc.enums.HmiZoneCapabilities;
import com.smartdevicelink.proxy.rpc.enums.Language;
import com.smartdevicelink.proxy.rpc.enums.PrerecordedSpeech;
import com.smartdevicelink.proxy.rpc.enums.Result;
import com.smartdevicelink.proxy.rpc.enums.SpeechCapabilities;
import com.smartdevicelink.proxy.rpc.enums.VrCapabilities;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

/**
 * Register AppInterface Response is sent, when RegisterAppInterface has been called
 *
 * @since SmartDeviceLink 1.0
 */
public class RegisterAppInterfaceResponse extends RPCResponse {
    @Deprecated
    public static final String KEY_VEHICLE_TYPE = "vehicleType";
    public static final String KEY_SPEECH_CAPABILITIES = "speechCapabilities";
    public static final String KEY_VR_CAPABILITIES = "vrCapabilities";
    public static final String KEY_AUDIO_PASS_THRU_CAPABILITIES = "audioPassThruCapabilities";
    public static final String KEY_HMI_ZONE_CAPABILITIES = "hmiZoneCapabilities";
    public static final String KEY_PRERECORDED_SPEECH = "prerecordedSpeech";
    public static final String KEY_SUPPORTED_DIAG_MODES = "supportedDiagModes";
    public static final String KEY_SDL_MSG_VERSION = "syncMsgVersion";
    public static final String KEY_LANGUAGE = "language";
    @Deprecated
    public static final String KEY_BUTTON_CAPABILITIES = "buttonCapabilities";
    @Deprecated
    public static final String KEY_DISPLAY_CAPABILITIES = "displayCapabilities";
    public static final String KEY_HMI_DISPLAY_LANGUAGE = "hmiDisplayLanguage";
    @Deprecated
    public static final String KEY_SOFT_BUTTON_CAPABILITIES = "softButtonCapabilities";
    @Deprecated
    public static final String KEY_PRESET_BANK_CAPABILITIES = "presetBankCapabilities";
    public static final String KEY_HMI_CAPABILITIES = "hmiCapabilities"; //As of v4.0
    public static final String KEY_SDL_VERSION = "sdlVersion"; //As of v4.0
    @Deprecated
    public static final String KEY_SYSTEM_SOFTWARE_VERSION = "systemSoftwareVersion"; //As of v4.0
    public static final String KEY_ICON_RESUMED = "iconResumed";
    public static final String KEY_PCM_STREAM_CAPABILITIES = "pcmStreamCapabilities";

    /**
     * Constructs a new RegisterAppInterfaceResponse object
     */
    public RegisterAppInterfaceResponse() {
        super(FunctionID.REGISTER_APP_INTERFACE.toString());
    }

    /**
     * Constructs a new RegisterAppInterfaceResponse object indicated by the Hashtable
     * parameter
     * <p>
     *
     * @param hash The Hashtable to use
     */
    public RegisterAppInterfaceResponse(Hashtable<String, Object> hash) {
        super(hash);
    }

    /**
     * Constructs a new RegisterAppInterfaceResponse object
     *
     * @param success    whether the request is successfully processed
     * @param resultCode whether the request is successfully processed
     */
    public RegisterAppInterfaceResponse(@NonNull Boolean success, @NonNull Result resultCode) {
        this();
        setSuccess(success);
        setResultCode(resultCode);
    }

    @Override
    public void format(com.smartdevicelink.util.Version rpcVersion, boolean formatParams) {
        //Add in 5.0.0 of the rpc spec
        if (getIconResumed() == null) {
            setIconResumed(Boolean.FALSE);
        }

        List<ButtonCapabilities> capabilities = getButtonCapabilities();
        if (capabilities != null) {
            List<ButtonCapabilities> additions = new ArrayList<>();
            for (ButtonCapabilities capability : capabilities) {
                if (ButtonName.OK.equals(capability.getName())) {
                    if (rpcVersion == null || rpcVersion.getMajor() < 5) {
                        //If version is < 5, the play pause button must also be added
                        additions.add(new ButtonCapabilities(ButtonName.PLAY_PAUSE, capability.getShortPressAvailable(), capability.getLongPressAvailable(), capability.getUpDownAvailable()));
                    }
                }
            }
            capabilities.addAll(additions);
            setButtonCapabilities(capabilities);
        }


        super.format(rpcVersion, formatParams);
    }


    /**
     * Gets the version of the SDL&reg; SmartDeviceLink interface
     *
     * @return SdlMsgVersion -a SdlMsgVersion object representing version of
     * the SDL&reg; SmartDeviceLink interface
     */
    public SdlMsgVersion getSdlMsgVersion() {
        return (SdlMsgVersion) getObject(SdlMsgVersion.class, KEY_SDL_MSG_VERSION);
    }

    /**
     * Sets the version of the SDL&reg; SmartDeviceLink interface
     *
     * @param sdlMsgVersion a SdlMsgVersion object representing version of the SDL&reg;
     *                      SmartDeviceLink interface
     *                      <p></p>
     *                      <b>Notes: </b>To be compatible, app msg major version number
     *                      must be less than or equal to SDL&reg; major version number.
     *                      If msg versions are incompatible, app has 20 seconds to
     *                      attempt successful RegisterAppInterface (w.r.t. msg version)
     *                      on underlying protocol session, else will be terminated. Major
     *                      version number is a compatibility declaration. Minor version
     *                      number indicates minor functional variations (e.g. features,
     *                      capabilities, bug fixes) when sent from SDL&reg; to app (in
     *                      RegisterAppInterface response). However, the minor version
     *                      number sent from the app to SDL&reg; (in RegisterAppInterface
     *                      request) is ignored by SDL&reg;
     */
    public RegisterAppInterfaceResponse setSdlMsgVersion(SdlMsgVersion sdlMsgVersion) {
        setParameters(KEY_SDL_MSG_VERSION, sdlMsgVersion);
        return this;
    }

    /**
     * Gets a Language enumeration indicating what language the application
     * intends to use for user interaction (Display, TTS and VR)
     *
     * @return Enumeration -a language enumeration
     */
    public Language getLanguage() {
        return (Language) getObject(Language.class, KEY_LANGUAGE);
    }

    /**
     * Sets an enumeration indicating what language the application intends to
     * use for user interaction (Display, TTS and VR)
     *
     * @param language a Language Enumeration
     */
    public RegisterAppInterfaceResponse setLanguage(Language language) {
        setParameters(KEY_LANGUAGE, language);
        return this;
    }

    /**
     * Gets an enumeration indicating what language the application intends to
     * use for user interaction ( Display)
     *
     * @return Language - a Language value representing an enumeration
     * indicating what language the application intends to use for user
     * interaction ( Display)
     * @since SmartDeviceLink 2.0
     */
    public Language getHmiDisplayLanguage() {
        return (Language) getObject(Language.class, KEY_HMI_DISPLAY_LANGUAGE);
    }

    /**
     * Sets an enumeration indicating what language the application intends to
     * use for user interaction ( Display)
     *
     * @param hmiDisplayLanguage
     * @since SmartDeviceLink 2.0
     */
    public RegisterAppInterfaceResponse setHmiDisplayLanguage(Language hmiDisplayLanguage) {
        setParameters(KEY_HMI_DISPLAY_LANGUAGE, hmiDisplayLanguage);
        return this;
    }

    /**
     * Gets getDisplayCapabilities set when application interface is registered.
     *
     * @return DisplayCapabilities
     */
    @Deprecated
    public DisplayCapabilities getDisplayCapabilities() {
        return (DisplayCapabilities) getObject(DisplayCapabilities.class, KEY_DISPLAY_CAPABILITIES);
    }

    /**
     * Sets Display Capabilities
     *
     * @param displayCapabilities
     */
    @Deprecated
    public RegisterAppInterfaceResponse setDisplayCapabilities(DisplayCapabilities displayCapabilities) {
        setParameters(KEY_DISPLAY_CAPABILITIES, displayCapabilities);
        return this;
    }

    /**
     * Gets buttonCapabilities set when application interface is registered.
     *
     * @return buttonCapabilities
     */
    @Deprecated
    @SuppressWarnings("unchecked")
    public List<ButtonCapabilities> getButtonCapabilities() {
        return (List<ButtonCapabilities>) getObject(ButtonCapabilities.class, KEY_BUTTON_CAPABILITIES);
    }

    /**
     * Sets Button Capabilities
     *
     * @param buttonCapabilities
     */
    @Deprecated
    public RegisterAppInterfaceResponse setButtonCapabilities(List<ButtonCapabilities> buttonCapabilities) {
        setParameters(KEY_BUTTON_CAPABILITIES, buttonCapabilities);
        return this;
    }

    /**
     * Gets getSoftButtonCapabilities set when application interface is registered.
     *
     * @return SoftButtonCapabilities
     */
    @Deprecated
    @SuppressWarnings("unchecked")
    public List<SoftButtonCapabilities> getSoftButtonCapabilities() {
        return (List<SoftButtonCapabilities>) getObject(SoftButtonCapabilities.class, KEY_SOFT_BUTTON_CAPABILITIES);
    }

    /**
     * Sets softButtonCapabilities
     *
     * @param softButtonCapabilities
     */
    @Deprecated
    public RegisterAppInterfaceResponse setSoftButtonCapabilities(List<SoftButtonCapabilities> softButtonCapabilities) {
        setParameters(KEY_SOFT_BUTTON_CAPABILITIES, softButtonCapabilities);
        return this;
    }

    /**
     * Gets getPresetBankCapabilities set when application interface is registered.
     *
     * @return PresetBankCapabilities
     */
    @Deprecated
    public PresetBankCapabilities getPresetBankCapabilities() {
        return (PresetBankCapabilities) getObject(PresetBankCapabilities.class, KEY_PRESET_BANK_CAPABILITIES);
    }

    /**
     * Sets presetBankCapabilities
     *
     * @param presetBankCapabilities
     */
    @Deprecated
    public RegisterAppInterfaceResponse setPresetBankCapabilities(PresetBankCapabilities presetBankCapabilities) {
        setParameters(KEY_PRESET_BANK_CAPABILITIES, presetBankCapabilities);
        return this;
    }

    /**
     * Gets hmiZoneCapabilities set when application interface is registered.
     *
     * @return HmiZoneCapabilities
     */
    @SuppressWarnings("unchecked")
    public List<HmiZoneCapabilities> getHmiZoneCapabilities() {
        return (List<HmiZoneCapabilities>) getObject(HmiZoneCapabilities.class, KEY_HMI_ZONE_CAPABILITIES);
    }

    /**
     * Sets hmiZoneCapabilities
     *
     * @param hmiZoneCapabilities
     */
    public RegisterAppInterfaceResponse setHmiZoneCapabilities(List<HmiZoneCapabilities> hmiZoneCapabilities) {
        setParameters(KEY_HMI_ZONE_CAPABILITIES, hmiZoneCapabilities);
        return this;
    }

    /**
     * Gets speechCapabilities set when application interface is registered.
     *
     * @return SpeechCapabilities
     */
    @SuppressWarnings("unchecked")
    public List<SpeechCapabilities> getSpeechCapabilities() {
        Object speechCapabilities = getObject(SpeechCapabilities.class, KEY_SPEECH_CAPABILITIES);
        if (speechCapabilities instanceof List<?>) {
            return (List<SpeechCapabilities>) speechCapabilities;
        } else if (speechCapabilities instanceof SpeechCapabilities) {
            // this is a known issue observed with some core implementations
            List<SpeechCapabilities> newSpeechCapList = new ArrayList<>();
            newSpeechCapList.add((SpeechCapabilities) speechCapabilities);
            return newSpeechCapList;
        }
        return null;
    }

    /**
     * Sets speechCapabilities
     *
     * @param speechCapabilities
     */
    public RegisterAppInterfaceResponse setSpeechCapabilities(List<SpeechCapabilities> speechCapabilities) {
        setParameters(KEY_SPEECH_CAPABILITIES, speechCapabilities);
        return this;
    }


    @SuppressWarnings("unchecked")
    public List<PrerecordedSpeech> getPrerecordedSpeech() {
        return (List<PrerecordedSpeech>) getObject(PrerecordedSpeech.class, KEY_PRERECORDED_SPEECH);
    }

    public RegisterAppInterfaceResponse setPrerecordedSpeech(List<PrerecordedSpeech> prerecordedSpeech) {
        setParameters(KEY_PRERECORDED_SPEECH, prerecordedSpeech);
        return this;
    }


    /**
     * Gets vrCapabilities set when application interface is registered.
     *
     * @return VrCapabilities
     */
    @SuppressWarnings("unchecked")
    public List<VrCapabilities> getVrCapabilities() {
        return (List<VrCapabilities>) getObject(VrCapabilities.class, KEY_VR_CAPABILITIES);
    }

    /**
     * Sets VrCapabilities
     *
     * @param vrCapabilities
     */
    public RegisterAppInterfaceResponse setVrCapabilities(List<VrCapabilities> vrCapabilities) {
        setParameters(KEY_VR_CAPABILITIES, vrCapabilities);
        return this;
    }

    /**
     * Gets getVehicleType set when application interface is registered.
     *
     * @return vehicleType
     * @deprecated in SmartDeviceLink 7.1.0
     */
    @Deprecated
    public VehicleType getVehicleType() {
        return (VehicleType) getObject(VehicleType.class, KEY_VEHICLE_TYPE);
    }

    /**
     * Sets vehicleType
     *
     * @param vehicleType
     * @deprecated in SmartDeviceLink 7.1.0
     */
    @Deprecated
    public RegisterAppInterfaceResponse setVehicleType(VehicleType vehicleType) {
        setParameters(KEY_VEHICLE_TYPE, vehicleType);
        return this;
    }

    /**
     * Gets AudioPassThruCapabilities set when application interface is registered.
     *
     * @return AudioPassThruCapabilities
     */
    @SuppressWarnings("unchecked")
    public List<AudioPassThruCapabilities> getAudioPassThruCapabilities() {
        return (List<AudioPassThruCapabilities>) getObject(AudioPassThruCapabilities.class, KEY_AUDIO_PASS_THRU_CAPABILITIES);
    }

    /**
     * Sets AudioPassThruCapabilities
     *
     * @param audioPassThruCapabilities
     */
    public RegisterAppInterfaceResponse setAudioPassThruCapabilities(List<AudioPassThruCapabilities> audioPassThruCapabilities) {
        setParameters(KEY_AUDIO_PASS_THRU_CAPABILITIES, audioPassThruCapabilities);
        return this;
    }

    /**
     * Gets pcmStreamingCapabilities set when application interface is registered.
     *
     * @return pcmStreamingCapabilities
     */
    public AudioPassThruCapabilities getPcmStreamingCapabilities() {
        return (AudioPassThruCapabilities) getObject(AudioPassThruCapabilities.class, KEY_PCM_STREAM_CAPABILITIES);
    }

    /**
     * Sets pcmStreamingCapabilities
     *
     * @param pcmStreamingCapabilities
     */
    public RegisterAppInterfaceResponse setPcmStreamingCapabilities(AudioPassThruCapabilities pcmStreamingCapabilities) {
        setParameters(KEY_PCM_STREAM_CAPABILITIES, pcmStreamingCapabilities);
        return this;
    }

    public RegisterAppInterfaceResponse setSupportedDiagModes(List<Integer> supportedDiagModes) {
        setParameters(KEY_SUPPORTED_DIAG_MODES, supportedDiagModes);
        return this;
    }

    @SuppressWarnings("unchecked")
    public List<Integer> getSupportedDiagModes() {
        return (List<Integer>) getObject(Integer.class, KEY_SUPPORTED_DIAG_MODES);
    }

    public RegisterAppInterfaceResponse setHmiCapabilities(HMICapabilities hmiCapabilities) {
        setParameters(KEY_HMI_CAPABILITIES, hmiCapabilities);
        return this;
    }

    public HMICapabilities getHmiCapabilities() {
        return (HMICapabilities) getObject(HMICapabilities.class, KEY_HMI_CAPABILITIES);
    }

    public RegisterAppInterfaceResponse setSdlVersion(String sdlVersion) {
        setParameters(KEY_SDL_VERSION, sdlVersion);
        return this;
    }

    public String getSdlVersion() {
        return getString(KEY_SDL_VERSION);
    }

    /**
     * The software version of the connected device.
     *
     * @param systemSoftwareVersion the version of software on the connected device
     * @return RegisterAppInterface
     * @deprecated in SmartDeviceLink 7.1.0
     */
    @Deprecated
    public RegisterAppInterfaceResponse setSystemSoftwareVersion(String systemSoftwareVersion) {
        setParameters(KEY_SYSTEM_SOFTWARE_VERSION, systemSoftwareVersion);
        return this;
    }

    /**
     * The software version of the connected device.
     *
     * @return String the version of software on the connected device
     * @deprecated in SmartDeviceLink 7.1.0
     */
    @Deprecated
    public String getSystemSoftwareVersion() {
        return getString(KEY_SYSTEM_SOFTWARE_VERSION);
    }

    /**
     * Sets Icon Resumed Boolean
     *
     * @param iconResumed - if param not included, set to false
     */
    public RegisterAppInterfaceResponse setIconResumed(Boolean iconResumed) {
        if (iconResumed == null) {
            iconResumed = false;
        }
        setParameters(KEY_ICON_RESUMED, iconResumed);
        return this;
    }

    /**
     * Tells developer whether or not their app icon has been resumed on core.
     *
     * @return boolean - true if icon was resumed, false if not
     */
    public Boolean getIconResumed() {
        return getBoolean(KEY_ICON_RESUMED);
    }
}