2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.hardware.location;
19 import android.annotation.SystemApi;
20 import android.os.Parcel;
21 import android.os.Parcelable;
23 import java.util.Arrays;
26 * @deprecated Use {@link android.hardware.location.NanoAppMessage} instead to send messages with
27 * {@link android.hardware.location.ContextHubClient#sendMessageToNanoApp(
28 * NanoAppMessage)} and receive messages with
29 * {@link android.hardware.location.ContextHubClientCallback#onMessageFromNanoApp(
30 * ContextHubClient, NanoAppMessage)}.
36 public class ContextHubMessage {
37 private static final int DEBUG_LOG_NUM_BYTES = 16;
43 * Get the message type
45 * @return int - message type
47 public int getMsgType() {
54 * @return int - message version
56 public int getVersion() {
63 * @return byte[] - message data buffer
65 public byte[] getData() {
66 return Arrays.copyOf(mData, mData.length);
72 * @param msgType - message type
74 public void setMsgType(int msgType) {
81 * @param version - message version
83 public void setVersion(int version) {
90 * @param data - message buffer
92 public void setMsgData(byte[] data) {
93 mData = Arrays.copyOf(data, data.length);
97 * Constructor for a context hub message
99 * @param msgType - message type
100 * @param version - version
101 * @param data - message buffer
103 public ContextHubMessage(int msgType, int version, byte[] data) {
106 mData = Arrays.copyOf(data, data.length);
109 public int describeContents() {
113 private ContextHubMessage(Parcel in) {
114 mType = in.readInt();
115 mVersion = in.readInt();
116 int bufferLength = in.readInt();
117 mData = new byte[bufferLength];
118 in.readByteArray(mData);
121 public void writeToParcel(Parcel out, int flags) {
123 out.writeInt(mVersion);
124 out.writeInt(mData.length);
125 out.writeByteArray(mData);
128 public static final Parcelable.Creator<ContextHubMessage> CREATOR
129 = new Parcelable.Creator<ContextHubMessage>() {
130 public ContextHubMessage createFromParcel(Parcel in) {
131 return new ContextHubMessage(in);
134 public ContextHubMessage[] newArray(int size) {
135 return new ContextHubMessage[size];
140 public String toString() {
141 int length = mData.length;
144 "ContextHubMessage[type = " + mType + ", length = " + mData.length + " bytes](";
148 for (int i = 0; i < Math.min(length, DEBUG_LOG_NUM_BYTES); i++) {
149 ret += Byte.toHexString(mData[i], true /* upperCase */);
151 if ((i + 1) % 4 == 0) {
155 if (length > DEBUG_LOG_NUM_BYTES) {