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 17 package com.android.internal.location; 18 19 import java.util.ArrayList; 20 import java.util.List; 21 22 import android.location.LocationRequest; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 import android.util.TimeUtils; 26 27 /** @hide */ 28 public 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 = new ArrayList<LocationRequest>(); 43 ProviderRequest()44 public ProviderRequest() { } 45 46 public static final Parcelable.Creator<ProviderRequest> CREATOR = 47 new Parcelable.Creator<ProviderRequest>() { 48 @Override 49 public ProviderRequest createFromParcel(Parcel in) { 50 ProviderRequest request = new ProviderRequest(); 51 request.reportLocation = in.readInt() == 1; 52 request.interval = in.readLong(); 53 int count = in.readInt(); 54 for (int i = 0; i < count; i++) { 55 request.locationRequests.add(LocationRequest.CREATOR.createFromParcel(in)); 56 } 57 return request; 58 } 59 @Override 60 public ProviderRequest[] newArray(int size) { 61 return new ProviderRequest[size]; 62 } 63 }; 64 65 @Override describeContents()66 public int describeContents() { 67 return 0; 68 } 69 70 @Override writeToParcel(Parcel parcel, int flags)71 public void writeToParcel(Parcel parcel, int flags) { 72 parcel.writeInt(reportLocation ? 1 : 0); 73 parcel.writeLong(interval); 74 parcel.writeInt(locationRequests.size()); 75 for (LocationRequest request : locationRequests) { 76 request.writeToParcel(parcel, flags); 77 } 78 } 79 80 @Override toString()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