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