protectedvoidanalyzeMethodForViewPagers() { // We need at least one fragment base class if (scSupportViewPager == null && scAndroidXViewPager == null) return; // We need at least one class with a method to register a fragment if (scFragmentStatePagerAdapter == null && scAndroidXFragmentStatePagerAdapter == null && scFragmentPagerAdapter == null && scAndroidXFragmentPagerAdapter == null) return;
// get argument Valuepa= SootUtils.getInvokeExp(unit).getArg(0); if (!(pa.getType() instanceof RefType)) return; RefTypert= (RefType) pa.getType();
// check whether argument is of type FragmentStatePagerAdapter if (!safeIsType(pa, scFragmentStatePagerAdapter) && !safeIsType(pa, scAndroidXFragmentStatePagerAdapter) && !safeIsType(pa, scFragmentPagerAdapter) && !safeIsType(pa, scAndroidXFragmentPagerAdapter)) return;
// now analyze getItem() to find possible Fragments SootMethodgetItem= rt.getSootClass().getMethodUnsafe("android.support.v4.app.Fragment getItem(int)"); if (getItem == null) getItem = rt.getSootClass().getMethodUnsafe("androidx.fragment.app.Fragment getItem(int)"); if (getItem == null || !getItem.isConcrete()) return;
Bodyb= getItem.retrieveActiveBody(); if (b == null) return;
// iterate and add any returned Fragment classes for (Unit getItemUnit : b.getUnits()) { if (getItemUnit instanceof ReturnStmt) { ReturnStmtrs= (ReturnStmt) getItemUnit; Valuerv= rs.getOp(); Typetype= rv.getType(); if (type instanceof RefType) { SootClassrtClass= ((RefType) type).getSootClass(); if (rv instanceof Local && (rtClass.getName().startsWith("android.") || rtClass.getName().startsWith("androidx."))) analyzeFragmentCandidates(rs, getItem, (Local) rv); else checkAndAddFragment(rtClass); } } } }