Buggy code:
public String getClassName ( ) { } private enum Methods { getInstalledApplications , getInstalledPackages , getPackagesForUid , getPackagesHoldingPermissions , getPreferredActivities , getPreferredPackages , queryBroadcastReceivers , queryContentProviders , queryIntentActivities , queryIntentActivityOptions , queryIntentContentProviders , queryIntentServices , checkPermission , checkUidPermission , Srv_getPackageInfo , Srv_getApplicationInfo , Srv_getInstalledApplications , Srv_getInstalledPackages , Srv_getPackagesForUid , Srv_getPackagesHoldingPermissions , Srv_getPersistentApplications , Srv_getPreferredPackages , Srv_queryContentProviders , Srv_queryIntentActivities , Srv_queryIntentActivityOptions , Srv_queryIntentContentProviders , Srv_queryIntentReceivers , Srv_queryIntentServices ; } public static List < XHook > getInstances ( String className ) { } @ Override protected void before ( XParam param ) throws Throwable { } @ Override @ SuppressWarnings ( "unchecked" ) protected void after ( XParam param ) throws Throwable { switch ( mMethod ) { case Srv_getPackageInfo : case Srv_getApplicationInfo : if ( ( ( ( param . args . length ) > 0 ) && ( ( param . args [ 0 ] ) instanceof String ) ) && ( ( param . getResult ( ) ) != null ) ) { int uid = - 1 ; if ( ( mMethod ) == ( XPackageManager . Methods . Srv_getPackageInfo ) ) { PackageInfo pInfo = ( ( PackageInfo ) ( param . getResult ( ) ) ) ; if ( ( pInfo . applicationInfo ) != null ) uid = pInfo . applicationInfo . uid ; } else if ( ( mMethod ) == ( XPackageManager . Methods . Srv_getApplicationInfo ) ) { ApplicationInfo aInfo = ( ( ApplicationInfo ) ( param . getResult ( ) ) ) ; uid = aInfo . uid ; } if ( uid == ( Binder . getCallingUid ( ) ) ) return ; String packageName = ( ( String ) ( param . args [ 0 ] ) ) ; if ( ! ( XPackageManager . class . getPackage ( ) . getName ( ) . equals ( packageName ) ) ) if ( isRestrictedExtra ( param , packageName ) ) if ( ! ( XPackageManager . isPackageAllowed ( uid , packageName ) ) ) param . setResult ( null ) ; } break ; case Srv_getInstalledApplications : if ( ( param . getResult ( ) ) != null ) if ( isRestricted ( param ) ) { Method mGetList = param . getResult ( ) . getClass ( ) . getDeclaredMethod ( "getList" ) ; List < ApplicationInfo > listAppInfo = ( ( List < ApplicationInfo > ) ( mGetList . invoke ( param . getResult ( ) ) ) ) ; Constructor < ? > constructor = param . getResult ( ) . getClass ( ) . getConstructor ( List . class ) ; param . setResult ( constructor . newInstance ( filterApplicationInfo ( listAppInfo ) ) ) ; } break ; case Srv_getInstalledPackages : case Srv_getPackagesHoldingPermissions : if ( ( param . getResult ( ) ) != null ) if ( isRestricted ( param ) ) { Method mGetList = param . getResult ( ) . getClass ( ) . getDeclaredMethod ( "getList" ) ; List < PackageInfo > listPkgInfo = ( ( List < PackageInfo > ) ( mGetList . invoke ( param . getResult ( ) ) ) ) ; Constructor < ? > constructor = param . getResult ( ) . getClass ( ) . getConstructor ( List . class ) ; param . setResult ( constructor . newInstance ( filterPackageInfo ( listPkgInfo ) ) ) ; } break ; case getPackagesForUid : case Srv_getPackagesForUid : if ( ( ( ( param . args . length ) > 0 ) && ( ( param . args [ 0 ] ) instanceof Integer ) ) && ( ( param . getResult ( ) ) != null ) ) { int uid = ( ( Integer ) ( param . args [ 0 ] ) ) ; if ( uid != ( Binder . getCallingUid ( ) ) ) if ( isRestrictedExtra ( param , Integer . toString ( uid ) ) ) { List < String > lstResult = new ArrayList < String > ( ) ; if ( ( param . getResult ( ) ) instanceof String [ ] ) for ( String packageName : ( ( String [ ] ) ( param . getResult ( ) ) ) ) <START_BUG> if ( XPackageManager . isPackageAllowed ( uid , packageName ) ) <END_BUG> lstResult . add ( packageName ) ; if ( ( lstResult . size ( ) ) == 0 ) param . setResult ( null ) ; else param . setResult ( lstResult . toArray ( new String [ 0 ] ) ) ; } } break ; case Srv_getPersistentApplications : if ( ( param . getResult ( ) ) != null ) if ( isRestricted ( param ) ) param . setResult ( filterApplicationInfo ( ( ( List < ApplicationInfo > ) ( param . getResult ( ) ) ) ) ) ; break ; case Srv_getPreferredPackages : if ( ( param . getResult ( ) ) != null ) if ( isRestricted ( param ) ) param . setResult ( filterPackageInfo ( ( ( List < PackageInfo > ) ( param . getResult ( ) ) ) ) ) ; break ; case Srv_queryIntentActivities : case Srv_queryIntentActivityOptions : case Srv_queryIntentContentProviders : case Srv_queryIntentReceivers : case Srv_queryIntentServices : if ( ( param . getResult ( ) ) != null ) if ( isRestricted ( param ) ) param . setResult ( filterResolveInfo ( ( ( List < ResolveInfo > ) ( param . getResult ( ) ) ) ) ) ; break ; case getInstalledApplications : if ( ( param . getResult ( ) ) != null ) if ( isRestricted ( param ) ) param . setResult ( filterApplicationInfo ( ( ( List < ApplicationInfo > ) ( param . getResult ( ) ) ) ) ) ; break ; case getPreferredActivities : break ;

Fix:
if ( XPackageManager . isPackageAllowed ( Binder . getCallingUid ( ) , packageName ) )