Android serial 39 – a brief analysis of Hal and dial


1、 Analysis of Hal structure

  • Hal is a service program located on the operating system and driver and running in user space.
  • Purpose: to provide a unified interface for querying hardware devices for upper layer applications.
  • Benefit: simplifies the logic for applications to query hardware
  • Note: the so-called abstraction of Hal does not provide the actual operation of hardware, and the operation of hardware is still completed by specific drivers.

1. Why does Android introduce Hal

  • Android is developed based on the Linux kernel, and the Linux kernel uses the GPL license, which requires that the software using this license must open source any modification and expansion of the open source software. If Hal is introduced, the Android system layer and kernel can be separated by Hal. Hal follows the APL license, which is not required, The modification of open source software must be open source, so it can ensure the interests of some developers.

2. Hal running structure in Android

  • RIL (radio interface layer)
  • Operation principle of Hal stub: the upper layer calls the lower layer through the functions provided by the lower layer Hal, and the lower layer calls back to the upper layer after processing the upper layer request or when the hardware state changes, which is completed through the callback interface provided by the runtime.
  • Hal stub has an inclusion relationship, that is, Hal contains many stubs. As long as the runtime specifies the request type, it can obtain and operate the operations method corresponding to the stub. Its implementation is in hardware. C and hardware. H. In essence, it loads the. So dynamic link library through the dlopen method, so as to call the symbol implementation in *. So.

2、 In depth analysis of call flow

  • Andoridtelephone mainly includes four aspects of mobile phone communication capabilities:

    • Servicestate / SIM (network service, pack SIM)
    • Call (call capability)
    • Datacall (mobile data Internet access capability)
    • SMS / MMS (SMS / MMS capability)

1. Click the dial

@DialtactsActivity.......##   Omit the above code   @ Override    protected   void   onCreate(Bundle   savedInstanceState)   {      Trace.beginSection(TAG  +  "   onCreate");      LogUtil.enterBlock("DialtactsActivity.onCreate");      super.onCreate(savedInstanceState);      firstLaunch  =  true;      isLastTabEnabled  =         ConfigProviderComponent.get(this).getConfigProvider().getBoolean("last_tab_enabled",   false);........#   Register the floatingactionbutton according to your ID in the layout   floatingActionButton  =  findViewById(;      floatingActionButton.setOnClickListener(this);      floatingActionButtonController  =  new   FloatingActionButtonController(this,   floatingActionButton);...........#   View onclick method private of dialacksactivity class   void   showDialpadFragment(boolean   animate)   {...........      final   FragmentTransaction   ft  =  getFragmentManager().beginTransaction();      if   (dialpadFragment  ==  null)   {        dialpadFragment  =  new   DialpadFragment();        ft.add(,   dialpadFragment,   TAG_DIALPAD_FRAGMENT);     }  else   {;     }..........     setTitle(R.string.launcherDialpadActivityLabel);   }
@DialpadFragment..........  @Override  public void onClick(View view) {    int resId = view.getId();    if (resId == {      view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);      handleDialButtonPressed();    } else if (resId == {      keyPressed(KeyEvent.KEYCODE_DEL);    } else if (resId == {      if (!isDigitsEmpty()) {        digits.setCursorVisible(true);      }    } else if (resId == {;    } else {      LogUtil.w("DialpadFragment.onClick", "Unexpected event from: " + view);    }  }
  • Logic in the dial
  • Unfinished to be continued

3、 Source code: