android aidl工具,Android aidl 工具及远程调用 (一)

最近工作之余,看到ANDROID系统中的一些系统服务,比如Audio,WIFI,Location. 他们都采用了ANDROID的系统工具AIDL工具来实现。

AIDL的实现方法如下:(下面以LocationManager为例)

1.编写AIDL文件,这个文件和普通的接口文件一样,只不过扩展名称为AIDL。代码如下,ILocationManger.aidl/*

* 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.location.Address;

import android.location.GeocoderParams;

import android.location.IGeocodeProvider;

import android.location.IGpsStatusListener;

import android.location.ILocationListener;

import android.location.Location;

import android.os.Bundle;

/**

* System private API for talking with the location service.

*

* {@hide}

*/

interface ILocationManager

{

List getAllProviders();

List getProviders(boolean enabledOnly);

void requestLocationUpdates(String provider, long minTime, float minDistance,

in ILocationListener listener);

void requestLocationUpdatesPI(String provider, long minTime, float minDistance,

in PendingIntent intent);

void removeUpdates(in ILocationListener listener);

void removeUpdatesPI(in PendingIntent intent);

boolean addGpsStatusListener(IGpsStatusListener listener);

void removeGpsStatusListener(IGpsStatusListener listener);

// for reporting callback completion

void locationCallbackFinished(ILocationListener listener);

boolean sendExtraCommand(String provider, String command, inout Bundle extras);

void addProximityAlert(double latitude, double longitude, float distance,

long expiration, in PendingIntent intent);

void removeProximityAlert(in PendingIntent intent);

Bundle getProviderInfo(String provider);

boolean isProviderEnabled(String provider);

Location getLastKnownLocation(String provider);

// Used by location providers to tell the location manager when it has a new location.

// Passive is true if the location is coming from the passive provider, in which case

// it need not be shared with other providers.

void reportLocation(in Location location, boolean passive);

String getFromLocation(double latitude, double longitude, int maxResults,

in GeocoderParams params, out List

addrs);

String getFromLocationName(String locationName,

double lowerLeftLatitude, double lowerLeftLongitude,

double upperRightLatitude, double upperRightLongitude, int maxResults,

in GeocoderParams params, out List

addrs);

void addTestProvider(String name, boolean requiresNetwork, boolean requiresSatellite,

boolean requiresCell, boolean hasMonetaryCost, boolean supportsAltitude,

boolean supportsSpeed, boolean supportsBearing, int powerRequirement, int accuracy);

void removeTestProvider(String provider);

void setTestProviderLocation(String provider, in Location loc);

void clearTestProviderLocation(String provider);

void setTestProviderEnabled(String provider, boolean enabled);

void clearTestProviderEnabled(String provider);

void setTestProviderStatus(String provider, int status, in Bundle extras, long updateTime);

void clearTestProviderStatus(String provider);

// for NI support

boolean sendNiResponse(int notifId, int userResponse);

}

2.经过编译后,android的aidl工具会编译成ILocationManager.java.

3.编写要完成实际任务的Service类,在这个类中实现真正的业务,LocationManagerService.java

public class LocationManagerService extends ILocationManager.Stub implements Runnable {

}

4.在LocationManager,会去bind这个service,从而实现真正的IPC远程调用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值