OSDN Git Service

f1926eaa2195bfd944e6ccdea830bc725e252e77
[android-x86/frameworks-base.git] / core / java / android / hardware / location / NanoAppInstanceInfo.java
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
19 import android.annotation.NonNull;
20 import android.annotation.SystemApi;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23
24 import libcore.util.EmptyArray;
25
26 /**
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.
30  *
31  * @deprecated Use {@link android.hardware.location.NanoAppState} instead.
32  *
33  * @hide
34  */
35 @SystemApi
36 @Deprecated
37 public class NanoAppInstanceInfo {
38     private String mPublisher = "Unknown";
39     private String mName = "Unknown";
40
41     private int mHandle;
42     private long mAppId;
43     private int mAppVersion;
44     private int mContexthubId;
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;
52
53     public NanoAppInstanceInfo() {
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;
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
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     /**
85      * Get the application identifier
86      *
87      * @return int - application identifier
88      */
89     public long getAppId() {
90         return mAppId;
91     }
92
93     /**
94      * Get the application version
95      *
96      * @return int - version of the app
97      */
98     public int getAppVersion() {
99         return mAppVersion;
100     }
101
102     /**
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     /**
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     /**
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     /**
130      * Get the sensors needed by this app
131      *
132      * @return int[] all the required sensors needed by this app
133      */
134     @NonNull
135     public int[] getNeededSensors() {
136         return mNeededSensors;
137     }
138
139     /**
140      * get the events generated by this app
141      *
142      * @return all the events that can be generated by this app
143      */
144     @NonNull
145     public int[] getOutputEvents() {
146         return mOutputEvents;
147     }
148
149     /**
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     /**
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
167     private NanoAppInstanceInfo(Parcel in) {
168         mPublisher = in.readString();
169         mName = in.readString();
170
171         mHandle = in.readInt();
172         mAppId = in.readLong();
173         mAppVersion = in.readInt();
174         mContexthubId = in.readInt();
175         mNeededReadMemBytes = in.readInt();
176         mNeededWriteMemBytes = in.readInt();
177         mNeededExecMemBytes = in.readInt();
178
179         int neededSensorsLength = in.readInt();
180         mNeededSensors = new int[neededSensorsLength];
181         in.readIntArray(mNeededSensors);
182
183         int outputEventsLength = in.readInt();
184         mOutputEvents = new int[outputEventsLength];
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);
195
196         out.writeInt(mHandle);
197         out.writeLong(mAppId);
198         out.writeInt(mAppVersion);
199         out.writeInt(mContexthubId);
200         out.writeInt(mNeededReadMemBytes);
201         out.writeInt(mNeededWriteMemBytes);
202         out.writeInt(mNeededExecMemBytes);
203
204         // arrays are never null
205         out.writeInt(mNeededSensors.length);
206         out.writeIntArray(mNeededSensors);
207         out.writeInt(mOutputEvents.length);
208         out.writeIntArray(mOutputEvents);
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     };
221
222     @Override
223     public String toString() {
224         String retVal = "handle : " + mHandle;
225         retVal += ", Id : 0x" + Long.toHexString(mAppId);
226         retVal += ", Version : 0x" + Integer.toHexString(mAppVersion);
227
228         return retVal;
229     }
230 }