VancedMicroG/play-services-core/src/main/java/org/microg/gms/BaseService.java

57 lines
2.1 KiB
Java
Raw Normal View History

/*
* Copyright 2013-2015 microG Project Team
*
* 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 org.microg.gms;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import com.google.android.gms.common.internal.GetServiceRequest;
import com.google.android.gms.common.internal.IGmsCallbacks;
import com.google.android.gms.common.internal.IGmsServiceBroker;
public abstract class BaseService extends Service {
private final IGmsServiceBroker broker;
protected final String TAG;
public BaseService(String tag, Integer supportedServiceId, Integer... supportedServiceIds) {
this.TAG = tag;
broker = new AbstractGmsServiceBroker(supportedServiceId, supportedServiceIds) {
@Override
public void handleServiceRequest(IGmsCallbacks callback, GetServiceRequest request) throws RemoteException {
2015-10-09 18:51:17 +00:00
try {
request.extras.keySet(); // call to unparcel()
} catch (Exception e) {
// Sometimes we need to define the correct ClassLoader before unparcel(). Ignore those.
}
Log.d(TAG, "bound by: " + request);
BaseService.this.handleServiceRequest(callback, request);
}
};
}
@Override
public IBinder onBind(Intent intent) {
Log.d(TAG, "onBind: " + intent);
return broker.asBinder();
}
public abstract void handleServiceRequest(IGmsCallbacks callback, GetServiceRequest request) throws RemoteException;
}