Debian Codegraph @

core/java/android/service/controls/actions/ModeAction.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package android.service.controls.actions;
18
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.os.Bundle;
22 import android.service.controls.Control;
23 import android.service.controls.templates.TemperatureControlTemplate;
24
25 /**
26 * Action sent by the user to indicate a change of mode.
27 *
28 * This action is available when the {@link Control} was created with a
29 * {@link TemperatureControlTemplate}.
30 */
31 public final class ModeAction extends ControlAction {
32
33 private static final @ActionType int TYPE = TYPE_MODE;
34 private static final String KEY_MODE = "key_mode";
35
36 private final int mNewMode;
37
38 /**
39 * @return {@link ControlAction#TYPE_MODE}.
40 */
41 @Override
42 public int getActionType() {
43 return TYPE;
44 }
45
46 /**
47 * @param templateId the identifier of the {@link TemperatureControlTemplate} that originated
48 * this action.
49 * @param newMode new value for the mode.
50 * @param challengeValue a value sent by the user along with the action to authenticate. {@code}
51 * null is sent when no authentication is needed or has not been
52 * requested.
53 */
54 public ModeAction(@NonNull String templateId, int newMode, @Nullable String challengeValue) {
55 super(templateId, challengeValue);
56 mNewMode = newMode;
57 }
58
59 /**
60 * @param templateId the identifier of the {@link TemperatureControlTemplate} that originated
61 * this action.
62 * @param newMode new value for the mode.
63 */
64 public ModeAction(@NonNull String templateId, int newMode) {
65 this(templateId, newMode, null);
66 }
67
68 /**
69 * @param b
70 * @hide
71 */
72 ModeAction(Bundle b) {
73 super(b);
74 mNewMode = b.getInt(KEY_MODE);
75 }
76
77 /**
78 * @return
79 * @hide
80 */
81 @Override
82 @NonNull
83 Bundle getDataBundle() {
84 Bundle b = super.getDataBundle();
85 b.putInt(KEY_MODE, mNewMode);
86 return b;
87 }
88
89 public int getNewMode() {
90 return mNewMode;
91 }
92 }