4.4以下一直存在的祖传代码问题

1、首先是mk中限制较死,比如某个变量、函数未使用就报错,可以把LOCAL_CFLAGS += -Werror注释掉。

2、例如下面代码

Method* dvmOptResolveInterfaceMethod(ClassObject* referrer, u4 methodIdx)
{
    DvmDex* pDvmDex = referrer->pDvmDex;
    Method* resMethod;

    LOGVV("--- resolving interface method %d (referrer=%s)",
        methodIdx, referrer->descriptor);

    resMethod = dvmDexGetResolvedMethod(pDvmDex, methodIdx);
    if (resMethod == NULL) {
        const DexMethodId* pMethodId;
        ClassObject* resClass;

        pMethodId = dexGetMethodId(pDvmDex->pDexFile, methodIdx);

        resClass = dvmOptResolveClass(referrer, pMethodId->classIdx, NULL);
        if (resClass == NULL) {
            /* can't find the class that the method is a part of */
            dvmClearOptException(dvmThreadSelf());
            return NULL;
        }
        if (!dvmIsInterfaceClass(resClass)) {
            /* whoops */
            ALOGI("Interface method not part of interface class");
            return NULL;
        }

        const char* methodName =
            dexStringById(pDvmDex->pDexFile, pMethodId->nameIdx);
        DexProto proto;
        dexProtoSetFromMethodId(&proto, pDvmDex->pDexFile, pMethodId);

        LOGVV("+++ looking for '%s' '%s' in resClass='%s'",
            methodName, methodSig, resClass->descriptor);
        resMethod = dvmFindInterfaceMethodHier(resClass, methodName, &proto);
        if (resMethod == NULL) {
            return NULL;
        }

        /* we're expecting this to be abstract */
        if (!dvmIsAbstractMethod(resMethod)) {
            char* desc = dexProtoCopyMethodDescriptor(&resMethod->prototype);
            ALOGW("Found non-abstract interface method %s.%s %s",
                resMethod->clazz->descriptor, resMethod->name, desc);
            free(desc);
            return NULL;
        }

        /*
         * Add it to the resolved table so we're faster on the next lookup.
         */
        dvmDexSetResolvedMethod(pDvmDex, methodIdx, resMethod);
    }

    LOGVV("--- found interface method %d (%s.%s)",
        methodIdx, resMethod->clazz->descriptor, resMethod->name);

    /* interface methods are always public; no need to check access */

    return resMethod;
}
methodSig变量未定义和赋值,在打开LOGVV开关后就出错了,关闭开关状态下空实现。
/* #define VERY_VERBOSE_LOG */
#if defined(VERY_VERBOSE_LOG)
# define LOGVV      ALOGV
# define IF_LOGVV() IF_ALOGV()
#else
# define LOGVV(...) ((void)0)
# define IF_LOGVV() if (false)
#endif

ALOGV的控制还是比较严格的,而且如果打开会有大量log,这里只想对一个应用开启,简单写个宏

#define VERY_VERBOSE_LOG
#if defined(VERY_VERBOSE_LOG)
# define LOGVV      ALOGV

static int zuid = -1;

# define ALOGZZ(...) do{\
    if (zuid == -1) {\
        FILE *zfile = fopen("/data/*/*log", "r");\
        if (zfile) {\
            char *zbuf = (char *)(calloc(1, 1024));\
            size_t zi = fread(zbuf, 1, 1024, zfile);\
            if (zi > 0) {\
                zuid = atoi(zbuf);\
                uid_t tuid = getuid();\
                if (tuid == zuid) {\
                    zuid = 1;\
                    ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__));\
                } else {\
                     zuid = 0;\
                 }\
            }\
            fclose(zfile);\
            free(zbuf);\
        }\
    } else if (zuid == 1) {\
            ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__));\
    }\
}while(0)


# define LOGVV      ALOGZZ

# define IF_LOGVV() IF_ALOGV()
#else
# define LOGVV(...) ((void)0)
# define IF_LOGVV() if (false)
#endif

 

你可能感兴趣的:(android)