blob: a6c754d971e3cd8b644ae15249bd246fa0fbecd5 [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
destradaa78cebca2016-04-14 18:40:14 -070019import android.annotation.NonNull;
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080020import android.annotation.SystemApi;
21import android.os.Parcel;
22import android.os.Parcelable;
23
destradaa78cebca2016-04-14 18:40:14 -070024import libcore.util.EmptyArray;
25
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080026/**
kopriva82c591b2018-10-08 15:57:00 -070027 * Describes an instance of a nanoapp, used by the internal state managed by ContextHubService.
Arthur Ishigurofb9e4c72017-11-21 15:33:21 -080028 *
29 * TODO(b/69270990) Remove this class once the old API is deprecated.
Arthur Ishigurofb9e4c72017-11-21 15:33:21 -080030 *
Arthur Ishiguro581950c2018-01-05 10:57:46 -080031 * @deprecated Use {@link android.hardware.location.NanoAppState} instead.
32 *
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080033 * @hide
34 */
35@SystemApi
Arthur Ishiguro581950c2018-01-05 10:57:46 -080036@Deprecated
Arthur Ishigurof3ab9cd2018-02-28 11:27:50 -080037public class NanoAppInstanceInfo implements Parcelable {
Arthur Ishiguroc8b470462017-12-18 13:23:49 -080038 private String mPublisher = "Unknown";
39 private String mName = "Unknown";
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080040
Arthur Ishigurofb9e4c72017-11-21 15:33:21 -080041 private int mHandle;
Ashutosh Joshib741e3b2016-03-29 09:19:56 -070042 private long mAppId;
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080043 private int mAppVersion;
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080044 private int mContexthubId;
Arthur Ishigurofb9e4c72017-11-21 15:33:21 -080045
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 Joshi1d1ac542016-01-18 17:19:27 -080052
53 public NanoAppInstanceInfo() {
Arthur Ishigurofb9e4c72017-11-21 15:33:21 -080054 }
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 Joshi1d1ac542016-01-18 17:19:27 -080064 }
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 Joshi1d1ac542016-01-18 17:19:27 -080075 /**
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 Joshi1d1ac542016-01-18 17:19:27 -080085 * Get the application identifier
86 *
87 * @return int - application identifier
88 */
Ashutosh Joshib741e3b2016-03-29 09:19:56 -070089 public long getAppId() {
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080090 return mAppId;
91 }
92
93 /**
Greg Kaiserfe6d4f52016-08-19 10:24:07 -070094 * Get the application version
95 *
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080096 * @return int - version of the app
97 */
98 public int getAppVersion() {
99 return mAppVersion;
100 }
101
102 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800103 * 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 Joshi1d1ac542016-01-18 17:19:27 -0800112 * 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 Joshi1d1ac542016-01-18 17:19:27 -0800121 * 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 Joshi1d1ac542016-01-18 17:19:27 -0800130 * Get the sensors needed by this app
131 *
132 * @return int[] all the required sensors needed by this app
133 */
destradaa78cebca2016-04-14 18:40:14 -0700134 @NonNull
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800135 public int[] getNeededSensors() {
136 return mNeededSensors;
137 }
138
139 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800140 * get the events generated by this app
141 *
142 * @return all the events that can be generated by this app
143 */
destradaa78cebca2016-04-14 18:40:14 -0700144 @NonNull
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800145 public int[] getOutputEvents() {
146 return mOutputEvents;
147 }
148
149 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800150 * 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 Joshi1d1ac542016-01-18 17:19:27 -0800159 * 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 Joshi1d1ac542016-01-18 17:19:27 -0800167 private NanoAppInstanceInfo(Parcel in) {
168 mPublisher = in.readString();
169 mName = in.readString();
170
Arthur Ishiguro9acb5402017-09-18 12:07:44 -0700171 mHandle = in.readInt();
Ashutosh Joshib741e3b2016-03-29 09:19:56 -0700172 mAppId = in.readLong();
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800173 mAppVersion = in.readInt();
Arthur Ishiguro9acb5402017-09-18 12:07:44 -0700174 mContexthubId = in.readInt();
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800175 mNeededReadMemBytes = in.readInt();
176 mNeededWriteMemBytes = in.readInt();
177 mNeededExecMemBytes = in.readInt();
178
destradaa78cebca2016-04-14 18:40:14 -0700179 int neededSensorsLength = in.readInt();
180 mNeededSensors = new int[neededSensorsLength];
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800181 in.readIntArray(mNeededSensors);
182
destradaa78cebca2016-04-14 18:40:14 -0700183 int outputEventsLength = in.readInt();
184 mOutputEvents = new int[outputEventsLength];
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800185 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 Ishiguro9acb5402017-09-18 12:07:44 -0700195
196 out.writeInt(mHandle);
Ashutosh Joshib741e3b2016-03-29 09:19:56 -0700197 out.writeLong(mAppId);
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800198 out.writeInt(mAppVersion);
199 out.writeInt(mContexthubId);
200 out.writeInt(mNeededReadMemBytes);
201 out.writeInt(mNeededWriteMemBytes);
202 out.writeInt(mNeededExecMemBytes);
203
destradaa78cebca2016-04-14 18:40:14 -0700204 // arrays are never null
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800205 out.writeInt(mNeededSensors.length);
206 out.writeIntArray(mNeededSensors);
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800207 out.writeInt(mOutputEvents.length);
208 out.writeIntArray(mOutputEvents);
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800209 }
210
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700211 public static final @android.annotation.NonNull Parcelable.Creator<NanoAppInstanceInfo> CREATOR
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800212 = 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 Joshi6239cc62016-04-04 16:19:29 -0700221
222 @Override
223 public String toString() {
224 String retVal = "handle : " + mHandle;
225 retVal += ", Id : 0x" + Long.toHexString(mAppId);
Arthur Ishiguroc8b470462017-12-18 13:23:49 -0800226 retVal += ", Version : 0x" + Integer.toHexString(mAppVersion);
Ashutosh Joshi6239cc62016-04-04 16:19:29 -0700227
228 return retVal;
229 }
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800230}