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 | |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 20 | import android.annotation.SystemApi; |
| 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 24 | import libcore.util.EmptyArray; |
| 25 | |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 26 | /** |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 27 | * Describes an instance of a nanoapp, used by the internal state manged by ContextHubService. |
| 28 | * |
| 29 | * TODO(b/69270990) Remove this class once the old API is deprecated. |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 30 | * |
Arthur Ishiguro | 581950c | 2018-01-05 10:57:46 -0800 | [diff] [blame] | 31 | * @deprecated Use {@link android.hardware.location.NanoAppState} instead. |
| 32 | * |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 33 | * @hide |
| 34 | */ |
| 35 | @SystemApi |
Arthur Ishiguro | 581950c | 2018-01-05 10:57:46 -0800 | [diff] [blame] | 36 | @Deprecated |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 37 | public class NanoAppInstanceInfo { |
Arthur Ishiguro | c8b47046 | 2017-12-18 13:23:49 -0800 | [diff] [blame] | 38 | private String mPublisher = "Unknown"; |
| 39 | private String mName = "Unknown"; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 40 | |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 41 | private int mHandle; |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 42 | private long mAppId; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 43 | private int mAppVersion; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 44 | private int mContexthubId; |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 45 | |
| 46 | private int mNeededReadMemBytes = 0; |
| 47 | private int mNeededWriteMemBytes = 0; |
| 48 | private int mNeededExecMemBytes = 0; |
| 49 | |
| 50 | private int[] mNeededSensors = EmptyArray.INT; |
| 51 | private int[] mOutputEvents = EmptyArray.INT; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 52 | |
| 53 | public NanoAppInstanceInfo() { |
Arthur Ishiguro | fb9e4c7 | 2017-11-21 15:33:21 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @hide |
| 58 | */ |
| 59 | public NanoAppInstanceInfo(int handle, long appId, int appVersion, int contextHubId) { |
| 60 | mHandle = handle; |
| 61 | mAppId = appId; |
| 62 | mAppVersion = appVersion; |
| 63 | mContexthubId = contextHubId; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /** |
| 67 | * get the publisher of this app |
| 68 | * |
| 69 | * @return String - name of the publisher |
| 70 | */ |
| 71 | public String getPublisher() { |
| 72 | return mPublisher; |
| 73 | } |
| 74 | |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 75 | /** |
| 76 | * get the name of the app |
| 77 | * |
| 78 | * @return String - name of the app |
| 79 | */ |
| 80 | public String getName() { |
| 81 | return mName; |
| 82 | } |
| 83 | |
| 84 | /** |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 85 | * Get the application identifier |
| 86 | * |
| 87 | * @return int - application identifier |
| 88 | */ |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 89 | public long getAppId() { |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 90 | return mAppId; |
| 91 | } |
| 92 | |
| 93 | /** |
Greg Kaiser | fe6d4f5 | 2016-08-19 10:24:07 -0700 | [diff] [blame] | 94 | * Get the application version |
| 95 | * |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 96 | * @return int - version of the app |
| 97 | */ |
| 98 | public int getAppVersion() { |
| 99 | return mAppVersion; |
| 100 | } |
| 101 | |
| 102 | /** |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 103 | * Get the read memory needed by the app |
| 104 | * |
| 105 | * @return int - readable memory needed in bytes |
| 106 | */ |
| 107 | public int getNeededReadMemBytes() { |
| 108 | return mNeededReadMemBytes; |
| 109 | } |
| 110 | |
| 111 | /** |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 112 | * get writable memory needed by the app |
| 113 | * |
| 114 | * @return int - writable memory needed by the app |
| 115 | */ |
| 116 | public int getNeededWriteMemBytes() { |
| 117 | return mNeededWriteMemBytes; |
| 118 | } |
| 119 | |
| 120 | /** |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 121 | * get executable memory needed by the app |
| 122 | * |
| 123 | * @return int - executable memory needed by the app |
| 124 | */ |
| 125 | public int getNeededExecMemBytes() { |
| 126 | return mNeededExecMemBytes; |
| 127 | } |
| 128 | |
| 129 | /** |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 130 | * Get the sensors needed by this app |
| 131 | * |
| 132 | * @return int[] all the required sensors needed by this app |
| 133 | */ |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 134 | @NonNull |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 135 | public int[] getNeededSensors() { |
| 136 | return mNeededSensors; |
| 137 | } |
| 138 | |
| 139 | /** |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 140 | * get the events generated by this app |
| 141 | * |
| 142 | * @return all the events that can be generated by this app |
| 143 | */ |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 144 | @NonNull |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 145 | public int[] getOutputEvents() { |
| 146 | return mOutputEvents; |
| 147 | } |
| 148 | |
| 149 | /** |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 150 | * get the context hub identifier |
| 151 | * |
| 152 | * @return int - system unique hub identifier |
| 153 | */ |
| 154 | public int getContexthubId() { |
| 155 | return mContexthubId; |
| 156 | } |
| 157 | |
| 158 | /** |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 159 | * get a handle to the nano app instance |
| 160 | * |
| 161 | * @return int - handle to this instance |
| 162 | */ |
| 163 | public int getHandle() { |
| 164 | return mHandle; |
| 165 | } |
| 166 | |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 167 | private NanoAppInstanceInfo(Parcel in) { |
| 168 | mPublisher = in.readString(); |
| 169 | mName = in.readString(); |
| 170 | |
Arthur Ishiguro | 9acb540 | 2017-09-18 12:07:44 -0700 | [diff] [blame] | 171 | mHandle = in.readInt(); |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 172 | mAppId = in.readLong(); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 173 | mAppVersion = in.readInt(); |
Arthur Ishiguro | 9acb540 | 2017-09-18 12:07:44 -0700 | [diff] [blame] | 174 | mContexthubId = in.readInt(); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 175 | mNeededReadMemBytes = in.readInt(); |
| 176 | mNeededWriteMemBytes = in.readInt(); |
| 177 | mNeededExecMemBytes = in.readInt(); |
| 178 | |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 179 | int neededSensorsLength = in.readInt(); |
| 180 | mNeededSensors = new int[neededSensorsLength]; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 181 | in.readIntArray(mNeededSensors); |
| 182 | |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 183 | int outputEventsLength = in.readInt(); |
| 184 | mOutputEvents = new int[outputEventsLength]; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 185 | in.readIntArray(mOutputEvents); |
| 186 | } |
| 187 | |
| 188 | public int describeContents() { |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | public void writeToParcel(Parcel out, int flags) { |
| 193 | out.writeString(mPublisher); |
| 194 | out.writeString(mName); |
Arthur Ishiguro | 9acb540 | 2017-09-18 12:07:44 -0700 | [diff] [blame] | 195 | |
| 196 | out.writeInt(mHandle); |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 197 | out.writeLong(mAppId); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 198 | out.writeInt(mAppVersion); |
| 199 | out.writeInt(mContexthubId); |
| 200 | out.writeInt(mNeededReadMemBytes); |
| 201 | out.writeInt(mNeededWriteMemBytes); |
| 202 | out.writeInt(mNeededExecMemBytes); |
| 203 | |
destradaa | 78cebca | 2016-04-14 18:40:14 -0700 | [diff] [blame] | 204 | // arrays are never null |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 205 | out.writeInt(mNeededSensors.length); |
| 206 | out.writeIntArray(mNeededSensors); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 207 | out.writeInt(mOutputEvents.length); |
| 208 | out.writeIntArray(mOutputEvents); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | public static final Parcelable.Creator<NanoAppInstanceInfo> CREATOR |
| 212 | = new Parcelable.Creator<NanoAppInstanceInfo>() { |
| 213 | public NanoAppInstanceInfo createFromParcel(Parcel in) { |
| 214 | return new NanoAppInstanceInfo(in); |
| 215 | } |
| 216 | |
| 217 | public NanoAppInstanceInfo[] newArray(int size) { |
| 218 | return new NanoAppInstanceInfo[size]; |
| 219 | } |
| 220 | }; |
Ashutosh Joshi | 6239cc6 | 2016-04-04 16:19:29 -0700 | [diff] [blame] | 221 | |
| 222 | @Override |
| 223 | public String toString() { |
| 224 | String retVal = "handle : " + mHandle; |
| 225 | retVal += ", Id : 0x" + Long.toHexString(mAppId); |
Arthur Ishiguro | c8b47046 | 2017-12-18 13:23:49 -0800 | [diff] [blame] | 226 | retVal += ", Version : 0x" + Integer.toHexString(mAppVersion); |
Ashutosh Joshi | 6239cc6 | 2016-04-04 16:19:29 -0700 | [diff] [blame] | 227 | |
| 228 | return retVal; |
| 229 | } |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 230 | } |