Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 18c29885 authored by Tudor Măgirescu's avatar Tudor Măgirescu Committed by Android (Google) Code Review
Browse files

Merge "Add ExemptAidlInterfacesGenerator for PermissionAnnotationDetector" into main

parents 5620e115 9f5ec621
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -24,20 +24,31 @@ import com.intellij.psi.PsiReferenceList
import org.jetbrains.uast.UMethod

/**
 * Given a UMethod, determine if this method is the entrypoint to an interface
 * generated by AIDL, returning the interface name if so, otherwise returning
 * null
 * Given a UMethod, determine if this method is the entrypoint to an interface generated by AIDL,
 * returning the interface name if so, otherwise returning null.
 */
fun getContainingAidlInterface(context: JavaContext, node: UMethod): String? {
    return containingAidlInterfacePsiClass(context, node)?.name
}

/**
 * Given a UMethod, determine if this method is the entrypoint to an interface generated by AIDL,
 * returning the fully qualified interface name if so, otherwise returning null.
 */
fun getContainingAidlInterfaceQualified(context: JavaContext, node: UMethod): String? {
    return containingAidlInterfacePsiClass(context, node)?.qualifiedName
}

private fun containingAidlInterfacePsiClass(context: JavaContext, node: UMethod): PsiClass? {
    val containingStub = containingStub(context, node) ?: return null
    val superMethod = node.findSuperMethods(containingStub)
    if (superMethod.isEmpty()) return null
    return containingStub.containingClass?.name
    return containingStub.containingClass
}

/* Returns the containing Stub class if any. This is not sufficient to infer
 * that the method itself extends an AIDL generated method. See
 * getContainingAidlInterface for that purpose.
/**
 * Returns the containing Stub class if any. This is not sufficient to infer that the method itself
 * extends an AIDL generated method. See getContainingAidlInterface for that purpose.
 */
fun containingStub(context: JavaContext, node: UMethod?): PsiClass? {
    var superClass = node?.containingClass?.superClass
@@ -48,7 +59,7 @@ fun containingStub(context: JavaContext, node: UMethod?): PsiClass? {
    return null
}

private fun isStub(context: JavaContext, psiClass: PsiClass?): Boolean {
fun isStub(context: JavaContext, psiClass: PsiClass?): Boolean {
    if (psiClass == null) return false
    if (psiClass.name != "Stub") return false
    if (!context.evaluator.isStatic(psiClass)) return false
Loading