• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.annotation.UnsupportedAppUsage;
20 import android.location.LocationRequest;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import android.util.TimeUtils;
24 
25 import java.util.ArrayList;
26 import java.util.List;
27 
28 /** @hide */
29 public final class ProviderRequest implements Parcelable {
30     /** Location reporting is requested (true) */
31     @UnsupportedAppUsage
32     public boolean reportLocation = false;
33 
34     /** The smallest requested interval */
35     @UnsupportedAppUsage
36     public long interval = Long.MAX_VALUE;
37 
38     /**
39      * When this flag is true, providers should ignore all location settings, user consents, power
40      * restrictions or any other restricting factors and always satisfy this request to the best of
41      * their ability. This flag should only be used in event of an emergency.
42      */
43     public boolean locationSettingsIgnored = false;
44 
45     /**
46      * Whether provider shall make stronger than normal tradeoffs to substantially restrict power
47      * use.
48      */
49     public boolean lowPowerMode = false;
50 
51     /**
52      * A more detailed set of requests.
53      * <p>Location Providers can optionally use this to
54      * fine tune location updates, for example when there
55      * is a high power slow interval request and a
56      * low power fast interval request.
57      */
58     @UnsupportedAppUsage
59     public final List<LocationRequest> locationRequests = new ArrayList<>();
60 
61     @UnsupportedAppUsage
ProviderRequest()62     public ProviderRequest() {
63     }
64 
65     public static final Parcelable.Creator<ProviderRequest> CREATOR =
66             new Parcelable.Creator<ProviderRequest>() {
67                 @Override
68                 public ProviderRequest createFromParcel(Parcel in) {
69                     ProviderRequest request = new ProviderRequest();
70                     request.reportLocation = in.readInt() == 1;
71                     request.interval = in.readLong();
72                     request.lowPowerMode = in.readBoolean();
73                     request.locationSettingsIgnored = in.readBoolean();
74                     int count = in.readInt();
75                     for (int i = 0; i < count; i++) {
76                         request.locationRequests.add(LocationRequest.CREATOR.createFromParcel(in));
77                     }
78                     return request;
79                 }
80 
81                 @Override
82                 public ProviderRequest[] newArray(int size) {
83                     return new ProviderRequest[size];
84                 }
85             };
86 
87     @Override
describeContents()88     public int describeContents() {
89         return 0;
90     }
91 
92     @Override
writeToParcel(Parcel parcel, int flags)93     public void writeToParcel(Parcel parcel, int flags) {
94         parcel.writeInt(reportLocation ? 1 : 0);
95         parcel.writeLong(interval);
96         parcel.writeBoolean(lowPowerMode);
97         parcel.writeBoolean(locationSettingsIgnored);
98         parcel.writeInt(locationRequests.size());
99         for (LocationRequest request : locationRequests) {
100             request.writeToParcel(parcel, flags);
101         }
102     }
103 
104     @Override
toString()105     public String toString() {
106         StringBuilder s = new StringBuilder();
107         s.append("ProviderRequest[");
108         if (reportLocation) {
109             s.append("ON");
110             s.append(" interval=");
111             TimeUtils.formatDuration(interval, s);
112             if (lowPowerMode) {
113                 s.append(" lowPowerMode");
114             }
115             if (locationSettingsIgnored) {
116                 s.append(" locationSettingsIgnored");
117             }
118         } else {
119             s.append("OFF");
120         }
121         s.append(']');
122         return s.toString();
123     }
124 }
125