Skip to content

Commit

Permalink
geofence: Low power geofence HW implementation
Browse files Browse the repository at this point in the history
HW implemntation overwrites the SW implementation

Change-Id: I8762b0b2e3c5001622f9c8aa2a845ee64104faa3
  • Loading branch information
Dante Russo authored and hyperb1iss committed Jul 27, 2013
1 parent 639c99d commit a7b5ab9
Show file tree
Hide file tree
Showing 10 changed files with 554 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ LOCAL_SRC_FILES += \
location/java/android/location/ICountryListener.aidl \
location/java/android/location/IGeocodeProvider.aidl \
location/java/android/location/IGeofenceProvider.aidl \
location/java/android/location/IGeoFencer.aidl \
location/java/android/location/IGeoFenceListener.aidl \
location/java/android/location/IGpsStatusListener.aidl \
location/java/android/location/IGpsStatusProvider.aidl \
location/java/android/location/ILocationListener.aidl \
Expand Down
3 changes: 3 additions & 0 deletions core/res/res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,9 @@
<item>com.android.location.fused</item>
</string-array>

<!-- Component name of the service providing geofence API support. -->
<string name="config_geofenceProvider" translatable="false">com.qualcomm.services.location</string>

<!-- Boolean indicating if current platform supports bluetooth SCO for off call
use cases -->
<bool name="config_bluetooth_sco_off_call">true</bool>
Expand Down
1 change: 1 addition & 0 deletions core/res/res/values/symbols.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,7 @@
<java-symbol type="string" name="config_geocoderProviderPackageName" />
<java-symbol type="string" name="config_geofenceProviderPackageName" />
<java-symbol type="string" name="config_networkLocationProviderPackageName" />
<java-symbol type="string" name="config_geofenceProvider" />
<java-symbol type="string" name="config_wimaxManagerClassname" />
<java-symbol type="string" name="config_wimaxNativeLibLocation" />
<java-symbol type="string" name="config_wimaxServiceClassname" />
Expand Down
23 changes: 23 additions & 0 deletions location/java/android/location/GeoFenceParams.aidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
*
* Not a Contribution, Apache license notifications and license are retained
* for attribution purposes only.
*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package android.location;

parcelable GeoFenceParams;
132 changes: 132 additions & 0 deletions location/java/android/location/GeoFenceParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
*
* Not a Contribution, Apache license notifications and license are retained
* for attribution purposes only.
*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package android.location;

import android.app.PendingIntent;
import android.os.Binder;
import android.os.Parcel;
import android.os.Parcelable;
import java.io.PrintWriter;

/**
* GeoFenceParams for internal use
* {@hide}
*/
public class GeoFenceParams implements Parcelable {
public static final int ENTERING = 1;
public static final int LEAVING = 2;
public final int mUid;
public final double mLatitude;
public final double mLongitude;
public final float mRadius;
public final long mExpiration;
public final PendingIntent mIntent;
public final String mPackageName;

public static final Parcelable.Creator<GeoFenceParams> CREATOR = new Parcelable.Creator<GeoFenceParams>() {
public GeoFenceParams createFromParcel(Parcel in) {
return new GeoFenceParams(in);
}

@Override
public GeoFenceParams[] newArray(int size) {
return new GeoFenceParams[size];
}
};

public GeoFenceParams(double lat, double lon, float r,
long expire, PendingIntent intent, String packageName) {
this(Binder.getCallingUid(), lat, lon, r, expire, intent, packageName);
}

public GeoFenceParams(int uid, double lat, double lon, float r,
long expire, PendingIntent intent, String packageName) {
mUid = uid;
mLatitude = lat;
mLongitude = lon;
mRadius = r;
mExpiration = expire;
mIntent = intent;
mPackageName = packageName;
}

private GeoFenceParams(Parcel in) {
mUid = in.readInt();
mLatitude = in.readDouble();
mLongitude = in.readDouble();
mRadius = in.readFloat();
mExpiration = in.readLong();
mIntent = in.readParcelable(null);
mPackageName = in.readString();
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mUid);
dest.writeDouble(mLatitude);
dest.writeDouble(mLongitude);
dest.writeFloat(mRadius);
dest.writeLong(mExpiration);
dest.writeParcelable(mIntent, 0);
dest.writeString(mPackageName);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("GeoFenceParams:\n\tmUid - ");
sb.append(mUid);
sb.append("\n\tmLatitide - ");
sb.append(mLatitude);
sb.append("\n\tmLongitude - ");
sb.append(mLongitude);
sb.append("\n\tmRadius - ");
sb.append(mRadius);
sb.append("\n\tmExpiration - ");
sb.append(mExpiration);
sb.append("\n\tmIntent - ");
sb.append(mIntent);
return sb.toString();
}

public long getExpiration() {
return mExpiration;
}

public PendingIntent getIntent() {
return mIntent;
}

public int getCallerUid() {
return mUid;
}

public void dump(PrintWriter pw, String prefix) {
pw.println(prefix + this);
pw.println(prefix + "mLatitude=" + mLatitude + " mLongitude=" + mLongitude);
pw.println(prefix + "mRadius=" + mRadius + " mExpiration=" + mExpiration);
}
}
30 changes: 30 additions & 0 deletions location/java/android/location/IGeoFenceListener.aidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
*
* Not a Contribution, Apache license notifications and license are retained
* for attribution purposes only.
*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package android.location;

import android.app.PendingIntent;

/**
* {@hide}
*/
oneway interface IGeoFenceListener {
void geoFenceExpired(in PendingIntent intent);
}
33 changes: 33 additions & 0 deletions location/java/android/location/IGeoFencer.aidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
*
* Not a Contribution, Apache license notifications and license are retained
* for attribution purposes only.
*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package android.location;

import android.location.GeoFenceParams;
import android.app.PendingIntent;

/**
* {@hide}
*/
interface IGeoFencer {
boolean setGeoFence(in IBinder who, in GeoFenceParams params);
void clearGeoFence(in IBinder who, in PendingIntent fence);
void clearGeoFenceUser(int uid);
}
38 changes: 35 additions & 3 deletions services/java/com/android/server/LocationManagerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import android.location.Criteria;
import android.location.GeocoderParams;
import android.location.Geofence;
import android.location.GeoFenceParams;
import android.location.IGpsStatusListener;
import android.location.IGpsStatusProvider;
import android.location.ILocationListener;
Expand Down Expand Up @@ -66,6 +67,8 @@
import com.android.server.location.GeocoderProxy;
import com.android.server.location.GeofenceProxy;
import com.android.server.location.GeofenceManager;
import com.android.server.location.GeoFencerBase;
import com.android.server.location.GeoFencerProxy;
import com.android.server.location.GpsLocationProvider;
import com.android.server.location.LocationBlacklist;
import com.android.server.location.LocationFudger;
Expand Down Expand Up @@ -135,6 +138,8 @@ public class LocationManagerService extends ILocationManager.Stub {
// --- fields below are final after systemReady() ---
private LocationFudger mLocationFudger;
private GeofenceManager mGeofenceManager;
private String mGeoFencerPackageName;
private GeoFencerBase mGeoFencer;
private PackageManager mPackageManager;
private PowerManager mPowerManager;
private GeocoderProxy mGeocodeProvider;
Expand Down Expand Up @@ -427,6 +432,15 @@ Load package name(s) containing location provider support.
Slog.e(TAG, "no geofence provider found");
}

mGeoFencerPackageName = resources.getString(
com.android.internal.R.string.config_geofenceProvider);
if (mGeoFencerPackageName != null &&
mPackageManager.resolveService(new Intent(mGeoFencerPackageName), 0) != null) {
mGeoFencer = GeoFencerProxy.getGeoFencerProxy(mContext, mGeoFencerPackageName);
} else {
mGeoFencer = null;
}

}

/**
Expand Down Expand Up @@ -1488,8 +1502,19 @@ public void requestGeofence(LocationRequest request, Geofence geofence, PendingI
}
long identity = Binder.clearCallingIdentity();
try {
mGeofenceManager.addFence(sanitizedRequest, geofence, intent, allowedResolutionLevel,
uid, packageName);
if (mGeoFencer != null) {
long expiration;
if (sanitizedRequest.getExpireAt() == Long.MAX_VALUE) {
expiration = -1; // -1 means forever
} else {
expiration = sanitizedRequest.getExpireAt() - SystemClock.elapsedRealtime();
}
mGeoFencer.add(new GeoFenceParams(uid, geofence.getLatitude(), geofence.getLongitude(),
geofence.getRadius(), expiration, intent, packageName));
} else {
mGeofenceManager.addFence(sanitizedRequest, geofence, intent, allowedResolutionLevel,
uid, packageName);
}
} finally {
Binder.restoreCallingIdentity(identity);
}
Expand All @@ -1506,7 +1531,11 @@ public void removeGeofence(Geofence geofence, PendingIntent intent, String packa
// geo-fence manager uses the public location API, need to clear identity
long identity = Binder.clearCallingIdentity();
try {
mGeofenceManager.removeFence(geofence, intent);
if (mGeoFencer != null) {
mGeoFencer.remove(intent);
} else {
mGeofenceManager.removeFence(geofence, intent);
}
} finally {
Binder.restoreCallingIdentity(identity);
}
Expand Down Expand Up @@ -2204,6 +2233,9 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
}

mGeofenceManager.dump(pw);
if (mGeoFencer != null) {
mGeoFencer.dump(pw, "");
}

if (mEnabledProviders.size() > 0) {
pw.println(" Enabled Providers:");
Expand Down
Loading

0 comments on commit a7b5ab9

Please sign in to comment.