标签:
目标:在PackageManagerService加入方法public String getHello();
第一步:在IPackageManager.aidl增加getHello()方法声明
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(); }
public abstract class PackageManager { /** * This exception is thrown when a given package, application, or component * name can not be found. */ public static class NameNotFoundException extends AndroidException { public NameNotFoundException() { } public NameNotFoundException(String name) { super(name); } } . . . . . . /** * @hide */ public abstract String getHello(); }
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"; } }
final class ApplicationPackageManager extends PackageManager { private static final String TAG = "ApplicationPackageManager"; 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.currentToCanonicalPackageNames(names); } catch (RemoteException e) { throw new RuntimeException("Package manager has died", e); } } . . . . . . . /** * @hide */ @Override public String getHello() { // TODO Auto-generated method stub try { return mPM.isThirdParty(name); } catch (RemoteException e) { throw new RuntimeException("Package manager has died", e); } } }
为Android中PackageManagerService添加方法
标签:
原文地址:http://blog.csdn.net/zqz19891031/article/details/43306045