1/*
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
19import android.annotation.SystemApi;
20import android.os.Parcel;
21import android.os.Parcelable;
22import android.util.Log;
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    private static final String TAG = "ContextHubMessage";
36
37
38    /**
39     * Get the message type
40     *
41     * @return int - message type
42     */
43    public int getMsgType() {
44        return mType;
45    }
46
47    /**
48     * get message version
49     *
50     * @return int - message version
51     */
52    public int getVersion() {
53        return mVersion;
54    }
55
56    /**
57     * get message data
58     *
59     * @return byte[] - message data buffer
60     */
61    public byte[] getData() {
62        return Arrays.copyOf(mData, mData.length);
63    }
64
65    /**
66     * set message type
67     *
68     * @param msgType - message type
69     */
70    public void setMsgType(int msgType) {
71        mType = msgType;
72    }
73
74    /**
75     * Set message version
76     *
77     * @param version - message version
78     */
79    public void setVersion(int version) {
80        mVersion = version;
81    }
82
83    /**
84     * set message data
85     *
86     * @param data - message buffer
87     */
88    public void setMsgData(byte[] data) {
89        mData = Arrays.copyOf(data, data.length);
90    }
91
92    /**
93     * Constructor for a context hub message
94     *
95     * @param msgType - message type
96     * @param version - version
97     * @param data    - message buffer
98     */
99    public ContextHubMessage(int msgType, int version, byte[] data) {
100        mType = msgType;
101        mVersion = version;
102        mData = Arrays.copyOf(data, data.length);
103    }
104
105    public int describeContents() {
106        return 0;
107    }
108
109    private ContextHubMessage(Parcel in) {
110        mType = in.readInt();
111        mVersion = in.readInt();
112        int bufferLength = in.readInt();
113        mData = new byte[bufferLength];
114        in.readByteArray(mData);
115    }
116
117    public void writeToParcel(Parcel out, int flags) {
118        out.writeInt(mType);
119        out.writeInt(mVersion);
120        out.writeInt(mData.length);
121        out.writeByteArray(mData);
122    }
123
124    public static final Parcelable.Creator<ContextHubMessage> CREATOR
125            = new Parcelable.Creator<ContextHubMessage>() {
126        public ContextHubMessage createFromParcel(Parcel in) {
127            return new ContextHubMessage(in);
128        }
129
130        public ContextHubMessage[] newArray(int size) {
131            return new ContextHubMessage[size];
132        }
133    };
134}
135