1. 程式人生 > >Linux下service的命令用法

Linux下service的命令用法

一、用法概述:

# service

service

Usage: service [-h|-?]

       service list

       service check SERVICE

       service call SERVICE CODE [i32 INT | s16 STR] [intent] ...

Options:

   i32: Write the integer INT into the send parcel.

   s16: Write the UTF-16 string STR into the send parcel.

   intent: Write and Intent int the send parcel. ARGS can be/n"

   action=STR data=STR type=STR launchFlags=INT component=STR categories=STR[,STR,...]/n

二、詳解:

1. service list

會列出本機所有正在執行的service, 如:

Found 42 services:

0       phone: [com.Android.internal.telephony.ITelephony]

1       iphonesubinfo: [com.android.internal.telephony.IPhoneSubInfo]

2       isms: [com.android.internal.telephony.gsm.ISms]

3       simphonebook: [com.android.internal.telephony.gsm.ISimPhoneBook]

4       appwidget: [com.android.internal.appwidget.IAppWidgetService]

5       audio: [android.media.IAudioService]

6       wallpaper: [android.app.IWallpaperService]

7       checkin: [android.os.ICheckinService]

8       search: [android.app.ISearchManager]

9       location: [android.location.ILocationManager]

10      devicestoragemonitor: []

11      mount: [android.os.IMountService]

12      notification: [android.app.INotificationManager]

13      connectivity: [android.NET.IConnectivityManager]

14      wifi: [android.net.wifi.IWifiManager]

15      netstat: [android.os.INetStatService]

16      input_method: [com.android.internal.view.IInputMethodManager]

17      clipboard: [android.text.IClipboard]

18      statusbar: [android.app.IStatusBar]

19      window: [android.view.IWindowManager]

20      sensor: [android.hardware.ISensorService]

21      alarm: [android.app.IAlarmManager]

22      hardware: [android.os.IHardwareService]

23      battery: []

24      content: [android.content.IContentService]

25      permission: [android.os.IPermissionController]

26      activity.providers: []

27      activity.senders: []

28      activity.services: []

29      activity.broadcasts: []

30      cpuinfo: []

31      meminfo: []

32      activity: [android.app.IActivityManager]

33      package: [android.content.pm.IPackageManager]

34      telephony.registry: [com.android.internal.telephony.ITelephonyRegistry]

35      usagestats: [com.android.internal.app.IUsageStats]

36      batteryinfo: [com.android.internal.app.IBatteryStats]

37      power: [android.os.IPowerManager]

38      SurfaceFlinger: [android.ui.ISurfaceComposer]

39      media.camera: [android.hardware.ICameraService]

40      media.player: [android.hardware.IMediaPlayerService]

41      media.audio_flinger: [android.media.IAudioFlinger]

2、service check "service name" 檢查service是否存在

如:

 # service check phone

Service phone: found

# service check dd

Service dd: not found

3、service call "service name" code intent ....

   service call SERVICE CODE [i32 INT | s16 STR] ...

   i32: Write the integer INT into the send parcel.

   s16: Write the UTF-16 string STR into the send parcel.

在網路上查找了一下使用adb命令來控制真機的橫豎屏的命令,普遍找到的結果是:

  adb shell service call window 2013 i32 0(設定橫屏)

  adb shell service call window 2013 i32 1(設定豎屏)

  但是在真機(root過)上測試普遍沒有通過,會有出錯資訊。(Result: Parcel(Error: 0xffffffb6 "Not a data message"))

SERVICE可從list中獲取,CODE的獲取方法(,CODE列表:),但是發現看到的不是很準確,(這個可以自己寫個迴圈指令碼試驗一下)。i32代表數字,s16代表字串。

  本人找不到真正代表window橫豎屏的CODE,所以寫了個迴圈指令碼,通過觀察現象,找到了對應的CODE,那就是74。

  adb shell service call window 74 i32 0(設定橫屏)

  adb shell service call window 74 i32 1(設定豎屏)

  符上指令碼程式碼:

  #!bin/bash count=0 while [ "$count" -lt 1000 ]; do echo "$count" adb shell service call window "$count" i32 0 count=$(($count+1)) done

如:service call power 1

service call phone 2 s16  "10086"