Files
frameworks_base/services/java/com/android/server/location/FusedProxy.java
destradaa 1af4b0280a Add FlpHal layer to support Location Batching.
Change-Id: Ia3a57d869dfb3f067a1b95fa66d54f311ddcfdc3
2013-08-08 15:27:38 -07:00

117 lines
4.1 KiB
Java

/*
* Copyright (C) 2013 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 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 com.android.server.location;
import com.android.server.ServiceWatcher;
import android.Manifest;
import android.content.Context;
import android.hardware.location.IFusedLocationHardware;
import android.location.IFusedProvider;
import android.os.Handler;
import android.os.RemoteException;
import android.util.Log;
/**
* Proxy that helps bind GCore FusedProvider implementations to the Fused Hardware instances.
*
* @hide
*/
public final class FusedProxy {
private final String TAG = "FusedProxy";
private ServiceWatcher mServiceWatcher;
private FusedLocationHardwareSecure mLocationHardware;
/**
* Constructor of the class.
* This is private as the class follows a factory pattern for construction.
*
* @param context The context needed for construction.
* @param handler The handler needed for construction.
* @param locationHardware The instance of the Fused location hardware assigned to the proxy.
*/
private FusedProxy(Context context, Handler handler, IFusedLocationHardware locationHardware) {
mLocationHardware = new FusedLocationHardwareSecure(
locationHardware,
context,
Manifest.permission.LOCATION_HARDWARE);
Runnable newServiceWork = new Runnable() {
@Override
public void run() {
bindProvider(mLocationHardware);
}
};
// prepare the connection to the provider
mServiceWatcher = new ServiceWatcher(
context,
TAG,
"com.android.location.service.FusedProvider",
com.android.internal.R.bool.config_enableFusedLocationOverlay,
com.android.internal.R.string.config_fusedLocationProviderPackageName,
com.android.internal.R.array.config_locationProviderPackageNames,
newServiceWork,
handler);
}
/**
* Creates an instance of the proxy and binds it to the appropriate FusedProvider.
*
* @param context The context needed for construction.
* @param handler The handler needed for construction.
* @param locationHardware The instance of the Fused location hardware assigned to the proxy.
*
* @return An instance of the proxy if it could be bound, null otherwise.
*/
public static FusedProxy createAndBind(
Context context,
Handler handler,
IFusedLocationHardware locationHardware
) {
FusedProxy fusedProxy = new FusedProxy(context, handler, locationHardware);
// try to bind the Fused provider
if (!fusedProxy.mServiceWatcher.start()) {
return null;
}
return fusedProxy;
}
/**
* Helper function to bind the FusedLocationHardware to the appropriate FusedProvider instance.
*
* @param locationHardware The FusedLocationHardware instance to use for the binding operation.
*/
private void bindProvider(IFusedLocationHardware locationHardware) {
IFusedProvider provider = IFusedProvider.Stub.asInterface(mServiceWatcher.getBinder());
if (provider == null) {
Log.e(TAG, "No instance of FusedProvider found on FusedLocationHardware connected.");
return;
}
try {
provider.onFusedLocationHardwareChange(locationHardware);
} catch (RemoteException e) {
Log.e(TAG, e.toString());
}
}
}