16fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly/*
26fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * Copyright (C) 2012 The Android Open Source Project
36fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly *
46fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * Licensed under the Apache License, Version 2.0 (the "License");
56fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * you may not use this file except in compliance with the License.
66fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * You may obtain a copy of the License at
76fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly *
86fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly *      http://www.apache.org/licenses/LICENSE-2.0
96fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly *
106fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * Unless required by applicable law or agreed to in writing, software
116fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * distributed under the License is distributed on an "AS IS" BASIS,
126fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * See the License for the specific language governing permissions and
146fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * limitations under the License.
156fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly */
166fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
176fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pellypackage com.android.internal.location;
186fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
196fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pellyimport java.util.ArrayList;
206fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pellyimport java.util.List;
216fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
226fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pellyimport android.location.LocationRequest;
236fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pellyimport android.os.Parcel;
246fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pellyimport android.os.Parcelable;
256fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pellyimport android.util.TimeUtils;
266fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
276fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly/** @hide */
286fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pellypublic final class ProviderRequest implements Parcelable {
296fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    /** Location reporting is requested (true) */
306fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    public boolean reportLocation = false;
316fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
326fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    /** The smallest requested interval */
336fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    public long interval = Long.MAX_VALUE;
346fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
356fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    /**
366fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly     * A more detailed set of requests.
376fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly     * <p>Location Providers can optionally use this to
386fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly     * fine tune location updates, for example when there
396fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly     * is a high power slow interval request and a
406fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly     * low power fast interval request.
416fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly     */
4208ca1046fe4f1890f91241f8d082a024ef6cfd93Nick Pelly    public List<LocationRequest> locationRequests = new ArrayList<LocationRequest>();
436fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
4408ca1046fe4f1890f91241f8d082a024ef6cfd93Nick Pelly    public ProviderRequest() { }
456fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
466fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    public static final Parcelable.Creator<ProviderRequest> CREATOR =
476fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            new Parcelable.Creator<ProviderRequest>() {
486fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        @Override
496fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        public ProviderRequest createFromParcel(Parcel in) {
506fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            ProviderRequest request = new ProviderRequest();
516fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            request.reportLocation = in.readInt() == 1;
526fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            request.interval = in.readLong();
536fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            int count = in.readInt();
546fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            for (int i = 0; i < count; i++) {
556fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly                request.locationRequests.add(LocationRequest.CREATOR.createFromParcel(in));
566fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            }
576fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            return request;
586fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        }
596fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        @Override
606fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        public ProviderRequest[] newArray(int size) {
616fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            return new ProviderRequest[size];
626fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        }
636fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    };
646fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
656fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    @Override
666fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    public int describeContents() {
676fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        return 0;
686fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    }
696fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
706fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    @Override
716fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    public void writeToParcel(Parcel parcel, int flags) {
726fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        parcel.writeInt(reportLocation ? 1 : 0);
736fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        parcel.writeLong(interval);
7408ca1046fe4f1890f91241f8d082a024ef6cfd93Nick Pelly        parcel.writeInt(locationRequests.size());
7508ca1046fe4f1890f91241f8d082a024ef6cfd93Nick Pelly        for (LocationRequest request : locationRequests) {
7608ca1046fe4f1890f91241f8d082a024ef6cfd93Nick Pelly            request.writeToParcel(parcel, flags);
7708ca1046fe4f1890f91241f8d082a024ef6cfd93Nick Pelly        }
786fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    }
796fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
806fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    @Override
816fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    public String toString() {
826fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        StringBuilder s = new StringBuilder();
836fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        s.append("ProviderRequest[");
846fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        if (reportLocation) {
856fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            s.append("ON");
866fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            s.append(" interval=");
876fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            TimeUtils.formatDuration(interval, s);
886fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        } else {
896fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            s.append("OFF");
906fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        }
916fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        s.append(']');
926fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        return s.toString();
936fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    }
946fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly}
95