Packagemanagerservice Related class structure
Analysis can be seen if you want to add a method for Packagemanagerservice to make the following changes 1, Add the declaration of the method in the Ipackagemanager.aidl file, 2, add the abstract method description in the Packagemanager class, 3, add the method in Applicationpackagemanager, implement to call the remote Packagemanagerserv Ice method; 4, the concrete realization of the method is added in Packagemanagerservice;
Note: Since the Mockpackagemanager class also inherits the Packagemanager class, it is also necessary to add some implementation code, the added method to be set to hide, or to change the Api-list add New method
Demo
Goal: Add method public String Gethello () in Packagemanagerservice;
Step one: Add Gethello () method declaration in Ipackagemanager.aidl
interface Ipackagemanager {packageinfo getpackageinfo (String packagename, int flags); int Getpackageuid (String packagename); Int[] Getpackagegids (String packagename); String[] Currenttocanonicalpackagenames (in string[] names); String[] Canonicaltocurrentpackagenames (in string[] names); Permissioninfo Getpermissioninfo (String name, int flags); List<permissioninfo> Querypermissionsbygroup (String Group, int flags); Permissiongroupinfo Getpermissiongroupinfo (String name, int flags); list<permissiongroupinfo> getallpermissiongroups (int flags); ApplicationInfo Getapplicationinfo (String packagename, int flags); Activityinfo Getactivityinfo (in componentname className, int flags); Activityinfo Getreceiverinfo (in componentname className, int flags); . . . . . . String Gethello ();}
Step Two: Add abstract method description in Packagemanager class
Public abstract class Packagemanager { /** * This exception are thrown when a given package, application, or Compon ENT * Name can not be found. * /public static class Namenotfoundexception extends Androidexception {public namenotfoundexception () { } Public namenotfoundexception (String name) { super (name); } } ... /** * @hide * * /public abstract String Gethello ();}
Step Three: the implementation of adding Gethello () method in Packagemanagerservice
public class Packagemanagerservice extends Ipackagemanager.stub { static final String TAG = "Packagemanager"; Static Final Boolean debug_settings = false; Private static Final Boolean debug_preferred = false; Static Final Boolean debug_upgrade = false; Private static Final Boolean debug_install = false; Private static Final Boolean debug_remove = false; Private static Final Boolean debug_show_info = false; Private static Final Boolean debug_package_info = false; Public String Gethello () { return ' Hello,pms '; }}
Fourth Step: Add the Gethello () method to the Applicationpackagemanager to implement the Gethello () method that calls the remote Packagemanagerservice
Final class Applicationpackagemanager extends Packagemanager {private static final String TAG = "Applicationpackageman Ager "; Private Final Static Boolean DEBUG = false; Private Final Static Boolean debug_icons = false; @Override public PackageInfo getpackageinfo (String packagename, int flags) throws Namenotfoundexception { try {packageinfo pi = mpm.getpackageinfo (PackageName, flags); if (pi! = null) {return pi; }} catch (RemoteException e) {throw new RuntimeException ("Package manager has died", e); } throw new Namenotfoundexception (PackageName); } @Override Public string[] Currenttocanonicalpackagenames (string[] names) {try {return Mpm.curr Enttocanonicalpackagenames (names); } catch (RemoteException e) {throw new RuntimeException ("Package manager has died", e); } } . . . . . . . /** * @hide */@Overridepublic String Gethello () {//TODO auto-generated method Stubtry {return Mpm.isthirdparty (name) ;} catch (RemoteException e) {throw new RuntimeException ("Package manager has died", e);}}
Adding methods to Packagemanagerservice in Android