Chinaunix首页 | 论坛 | 博客
  • 博客访问: 695294
  • 博文数量: 182
  • 博客积分: 2088
  • 博客等级: 大尉
  • 技术积分: 1698
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-16 15:09
个人简介

.

文章分类

全部博文(182)

文章存档

2016年(1)

2015年(18)

2014年(14)

2013年(20)

2012年(129)

分类: Android平台

2014-08-20 13:54:53

Android系统不光在host上为我们提供了一些好用的命令, 同时device也有一些隐藏着的命令, 通常它是被系统调用,但是由于权限设置的原因, 普通的进程也能通过命令行去使用它们.
比如,我之前提到的<Android性能测试工具之dumpsys>及<Android调试工具之adbs>

在device中, 有一个service命令, 可以看到当前所有的service, 同时也可以使用它来往一些activity发送一些信息
如下所示,  service的用法
[plain] view plaincopy
  1. root@android:/ # service                                                         
  2. Usage: service [-h|-?]  
  3.        service list  
  4.        service check SERVICE  
  5.        service call SERVICE CODE [i32 INT | s16 STR] ...  
  6. Options:  
  7.    i32: Write the integer INT into the send parcel.  
  8.    s16: Write the UTF-16 string STR into the send parcel.  
当前运行的service
[plain] view plaincopy
  1. root@android:/ # service list                                                    
  2. Found 61 services:  
  3. 0   sip: [android.net.sip.ISipService]  
  4. 1   phone: [com.android.internal.telephony.ITelephony]  
  5. 2   iphonesubinfo: [com.android.internal.telephony.IPhoneSubInfo]  
  6. 3   simphonebook: [com.android.internal.telephony.IIccPhoneBook]  
  7. 4   isms: [com.android.internal.telephony.ISms]  
  8. 5   nfc: [android.nfc.INfcAdapter]  
  9. 6   samplingprofiler: []  
  10. 7   diskstats: []  
  11. 8   appwidget: [com.android.internal.appwidget.IAppWidgetService]  
  12. 9   backup: [android.app.backup.IBackupManager]  
  13. 10  uimode: [android.app.IUiModeManager]  
  14. 11  usb: [android.hardware.usb.IUsbManager]  
  15. 12  audio: [android.media.IAudioService]  
  16. 13  wallpaper: [android.app.IWallpaperManager]  
  17. 14  dropbox: [com.android.internal.os.IDropBoxManagerService]  
  18. 15  search: [android.app.ISearchManager]  
  19. 16  country_detector: [android.location.ICountryDetector]  
  20. 17  location: [android.location.ILocationManager]  
  21. 18  devicestoragemonitor: []  
  22. 19  notification: [android.app.INotificationManager]  
  23. 20  mount: [IMountService]  
  24. 21  throttle: [android.net.IThrottleManager]  
  25. 22  connectivity: [android.net.IConnectivityManager]  
  26. ......  

使用service的phone来打电话
[plain] view plaincopy
  1. root@android:/ # service call phone 2 s16 "123"                                  
  2. Result: Parcel(00000000    '....')  
此时, 就直接拨号了:), 但是这里注意, 紧急号码在这里是不work的.

下面再来一个用来发短信的
[plain] view plaincopy
  1. root@android:/ # service call isms 4 s16 "12345678" s16 "" s16 "hello world!" s16 "" s16 ""  

下面就说一下原理
大家先找到代码frameworks/base/telephony/java/com/android/internal/telephony/ITelephony.aidl和ISms.aidl,
这两个文件都是给OEM厂商集成用的, 代码我这里就不贴了,细心的童鞋一眼就能看出来, 上面的"2", "4"就是指定了是哪一个函数
比如, 2 就是
[plain] view plaincopy
  1. /**  
  2.      * Place a call to the specified number.  
  3.      * @param number the number to be called.  
  4.      */  
  5.     void call(String number);  
4就是
[plain] view plaincopy
  1. /**  
  2.     * Send an SMS.  
  3.     *  
  4.     * @param smsc the SMSC to send the message through, or NULL for the  
  5.     *  default SMSC  
  6.     * @param text the body of the message to send  
  7.     * @param sentIntent if not NULL this PendingIntent is  
  8.     *  broadcast when the message is sucessfully sent, or failed.  
  9.     *  The result code will be Activity.RESULT_OK for success,  
  10.     *  or one of these errors:
      
  11.     *  RESULT_ERROR_GENERIC_FAILURE
      
  12.     *  RESULT_ERROR_RADIO_OFF
      
  13.     *  RESULT_ERROR_NULL_PDU
      
  14.     *  For RESULT_ERROR_GENERIC_FAILURE the sentIntent may include  
  15.     *  the extra "errorCode" containing a radio technology specific value,  
  16.     *  generally only useful for troubleshooting.
      
  17.     *  The per-application based SMS control checks sentIntent. If sentIntent  
  18.     *  is NULL the caller will be checked against all unknown applications,  
  19.     *  which cause smaller number of SMS to be sent in checking period.  
  20.     * @param deliveryIntent if not NULL this PendingIntent is  
  21.     *  broadcast when the message is delivered to the recipient.  The  
  22.     *  raw pdu of the status report is in the extended data ("pdu").  
  23.     */  
  24.    void sendText(in String destAddr, in String scAddr, in String text,  
  25.            in PendingIntent sentIntent, in PendingIntent deliveryIntent);  

所以, 以后要想在后台发短信,打电话,可以直接调用Java的Runtime Exec来调用service提供的命令, 这样就可以部分绕过framework中的一些java service, 而直接跟更底层的c++/C实现的service直接交互:)

转载网址 :http://blog.csdn.net/melody_lu123/article/details/7401744
                
阅读(1287) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~