blob: 954e97dc7fce7bc918b8f72fc06afdb8f6a29fa0 [file] [log] [blame]
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -08001/*
2 * Copyright (C) 2016 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
17package android.hardware.location;
18
19
20import android.annotation.SystemApi;
21import android.os.Parcel;
22import android.os.Parcelable;
23
24import java.util.Arrays;
25
26/**
27 * @hide
28 */
29@SystemApi
30public class ContextHubMessage {
31 private int mType;
32 private int mVersion;
33 private byte[]mData;
34
35 /**
36 * Get the message type
37 *
38 * @return int - message type
39 */
40 public int getMsgType() {
41 return mType;
42 }
43
44 /**
45 * get message version
46 *
47 * @return int - message version
48 */
49 public int getVersion() {
50 return mVersion;
51 }
52
53 /**
54 * get message data
55 *
56 * @return byte[] - message data buffer
57 */
58 public byte[] getData() {
59 return Arrays.copyOf(mData, mData.length);
60 }
61
62 /**
63 * set message type
64 *
65 * @param msgType - message type
66 */
67 public void setMsgType(int msgType) {
68 mType = msgType;
69 }
70
71 /**
72 * Set message version
73 *
74 * @param version - message version
75 */
76 public void setVersion(int version) {
77 mVersion = version;
78 }
79
80 /**
81 * set message data
82 *
83 * @param data - message buffer
84 */
85 public void setMsgData(byte[] data) {
86 mData = Arrays.copyOf(data, data.length);
87 }
88
89 /**
90 * Constructor for a context hub message
91 *
92 * @param msgType - message type
93 * @param version - version
94 * @param data - message buffer
95 */
96 public ContextHubMessage(int msgType, int version, byte[] data) {
97 mType = msgType;
98 mVersion = version;
99 mData = Arrays.copyOf(data, data.length);
100 }
101
102 public int describeContents() {
103 return 0;
104 }
105
106 private ContextHubMessage(Parcel in) {
107 mType = in.readInt();
108 mVersion = in.readInt();
109 byte[] byteBuffer = new byte[in.readInt()];
110 in.readByteArray(byteBuffer);
111 }
112 public void writeToParcel(Parcel out, int flags) {
113 out.writeInt(mType);
114 out.writeInt(mVersion);
115 out.writeInt(mData.length);
116 out.writeByteArray(mData);
117 }
118
119 public static final Parcelable.Creator<ContextHubMessage> CREATOR
120 = new Parcelable.Creator<ContextHubMessage>() {
121 public ContextHubMessage createFromParcel(Parcel in) {
122 return new ContextHubMessage(in);
123 }
124
125 public ContextHubMessage[] newArray(int size) {
126 return new ContextHubMessage[size];
127 }
128 };
129}