ProviderRequest.java revision 6fa9ad4afcd762aea519ff61811386c23d18ddb2
1/* 2 * Copyright (C) 2012 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 com.android.internal.location; 18 19import java.util.ArrayList; 20import java.util.List; 21 22import android.location.LocationRequest; 23import android.os.Parcel; 24import android.os.Parcelable; 25import android.util.TimeUtils; 26 27/** @hide */ 28public final class ProviderRequest implements Parcelable { 29 /** Location reporting is requested (true) */ 30 public boolean reportLocation = false; 31 32 /** The smallest requested interval */ 33 public long interval = Long.MAX_VALUE; 34 35 /** 36 * A more detailed set of requests. 37 * <p>Location Providers can optionally use this to 38 * fine tune location updates, for example when there 39 * is a high power slow interval request and a 40 * low power fast interval request. 41 */ 42 public List<LocationRequest> locationRequests = null; 43 44 public ProviderRequest() { 45 } 46 47 public static final Parcelable.Creator<ProviderRequest> CREATOR = 48 new Parcelable.Creator<ProviderRequest>() { 49 @Override 50 public ProviderRequest createFromParcel(Parcel in) { 51 ProviderRequest request = new ProviderRequest(); 52 request.reportLocation = in.readInt() == 1; 53 request.interval = in.readLong(); 54 int count = in.readInt(); 55 request.locationRequests = new ArrayList<LocationRequest>(count); 56 for (int i = 0; i < count; i++) { 57 request.locationRequests.add(LocationRequest.CREATOR.createFromParcel(in)); 58 } 59 return request; 60 } 61 @Override 62 public ProviderRequest[] newArray(int size) { 63 return new ProviderRequest[size]; 64 } 65 }; 66 67 @Override 68 public int describeContents() { 69 return 0; 70 } 71 72 @Override 73 public void writeToParcel(Parcel parcel, int flags) { 74 parcel.writeInt(reportLocation ? 1 : 0); 75 parcel.writeLong(interval); 76 parcel.writeParcelableArray(locationRequests.toArray( 77 new LocationRequest[locationRequests.size()]), 0); 78 } 79 80 @Override 81 public String toString() { 82 StringBuilder s = new StringBuilder(); 83 s.append("ProviderRequest["); 84 if (reportLocation) { 85 s.append("ON"); 86 s.append(" interval="); 87 TimeUtils.formatDuration(interval, s); 88 } else { 89 s.append("OFF"); 90 } 91 s.append(']'); 92 return s.toString(); 93 } 94} 95