1 /*
2  * Copyright (C) 2017 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 com.android.cts.mockime;
18 
19 import android.os.Bundle;
20 
21 import androidx.annotation.NonNull;
22 
23 public final class ImeCommand {
24 
25     private static final String NAME_KEY = "name";
26     private static final String ID_KEY = "id";
27     private static final String DISPATCH_TO_MAIN_THREAD_KEY = "dispatchToMainThread";
28     private static final String EXTRA_KEY = "extra";
29 
30     @NonNull
31     private final String mName;
32     private final long mId;
33     private final boolean mDispatchToMainThread;
34     @NonNull
35     private final Bundle mExtras;
36 
ImeCommand(@onNull String name, long id, boolean dispatchToMainThread, @NonNull Bundle extras)37     ImeCommand(@NonNull String name, long id, boolean dispatchToMainThread,
38             @NonNull Bundle extras) {
39         mName = name;
40         mId = id;
41         mDispatchToMainThread = dispatchToMainThread;
42         mExtras = extras;
43     }
44 
ImeCommand(@onNull Bundle bundle)45     private ImeCommand(@NonNull Bundle bundle) {
46         mName = bundle.getString(NAME_KEY);
47         mId = bundle.getLong(ID_KEY);
48         mDispatchToMainThread = bundle.getBoolean(DISPATCH_TO_MAIN_THREAD_KEY);
49         mExtras = bundle.getParcelable(EXTRA_KEY);
50     }
51 
fromBundle(@onNull Bundle bundle)52     static ImeCommand fromBundle(@NonNull Bundle bundle) {
53         return new ImeCommand(bundle);
54     }
55 
toBundle()56     Bundle toBundle() {
57         final Bundle bundle = new Bundle();
58         bundle.putString(NAME_KEY, mName);
59         bundle.putLong(ID_KEY, mId);
60         bundle.putBoolean(DISPATCH_TO_MAIN_THREAD_KEY, mDispatchToMainThread);
61         bundle.putParcelable(EXTRA_KEY, mExtras);
62         return bundle;
63     }
64 
65     @NonNull
getName()66     public String getName() {
67         return mName;
68     }
69 
getId()70     public long getId() {
71         return mId;
72     }
73 
shouldDispatchToMainThread()74     public boolean shouldDispatchToMainThread() {
75         return mDispatchToMainThread;
76     }
77 
78     @NonNull
getExtras()79     public Bundle getExtras() {
80         return mExtras;
81     }
82 }
83