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 * Whether provider shall make stronger than normal tradeoffs to substantially restrict power 37 * use. 38 */ 39 public boolean lowPowerMode = false; 40 41 /** 42 * A more detailed set of requests. 43 * <p>Location Providers can optionally use this to 44 * fine tune location updates, for example when there 45 * is a high power slow interval request and a 46 * low power fast interval request. 47 */ 48 public List<LocationRequest> locationRequests = new ArrayList<LocationRequest>(); 49 50 public ProviderRequest() { 51 } 52 53 public static final Parcelable.Creator<ProviderRequest> CREATOR = 54 new Parcelable.Creator<ProviderRequest>() { 55 @Override 56 public ProviderRequest createFromParcel(Parcel in) { 57 ProviderRequest request = new ProviderRequest(); 58 request.reportLocation = in.readInt() == 1; 59 request.interval = in.readLong(); 60 request.lowPowerMode = in.readBoolean(); 61 int count = in.readInt(); 62 for (int i = 0; i < count; i++) { 63 request.locationRequests.add(LocationRequest.CREATOR.createFromParcel(in)); 64 } 65 return request; 66 } 67 68 @Override 69 public ProviderRequest[] newArray(int size) { 70 return new ProviderRequest[size]; 71 } 72 }; 73 74 @Override 75 public int describeContents() { 76 return 0; 77 } 78 79 @Override 80 public void writeToParcel(Parcel parcel, int flags) { 81 parcel.writeInt(reportLocation ? 1 : 0); 82 parcel.writeLong(interval); 83 parcel.writeBoolean(lowPowerMode); 84 parcel.writeInt(locationRequests.size()); 85 for (LocationRequest request : locationRequests) { 86 request.writeToParcel(parcel, flags); 87 } 88 } 89 90 @Override 91 public String toString() { 92 StringBuilder s = new StringBuilder(); 93 s.append("ProviderRequest["); 94 if (reportLocation) { 95 s.append("ON"); 96 s.append(" interval="); 97 TimeUtils.formatDuration(interval, s); 98 s.append(" lowPowerMode=" + lowPowerMode); 99 } else { 100 s.append("OFF"); 101 } 102 s.append(']'); 103 return s.toString(); 104 } 105 } 106