• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "OverrideLog.h"
2 #include "spdhelper.h"
3 #include "config.h"
4 
setPatchAsBad()5 void SpdHelper::setPatchAsBad()
6 {
7     getInstance().setPatchAsBadImpl();
8 }
9 
incErrorCount()10 void SpdHelper::incErrorCount()
11 {
12     getInstance().incErrorCountImpl();
13 }
14 
isPatchBad(UINT8 * prm,UINT32 len)15 bool SpdHelper::isPatchBad(UINT8* prm, UINT32 len)
16 {
17     return getInstance().isPatchBadImpl(prm, len);
18 }
19 
isSpdDebug()20 bool SpdHelper::isSpdDebug()
21 {
22     bool b = getInstance().isSpdDebugImpl();
23     ALOGD("%s SpdDebug is %s", __func__, (b ? "TRUE" : "FALSE"));
24     return b;
25 }
26 
incErrorCountImpl()27 void SpdHelper::incErrorCountImpl()
28 {
29     if (++mErrorCount >= mMaxErrorCount)
30     {
31         setPatchAsBadImpl();
32     }
33 }
34 
setPatchAsBadImpl()35 void SpdHelper::setPatchAsBadImpl()
36 {
37     mIsPatchBad = true;
38 }
39 
toHex(UINT8 b)40 inline const char * toHex(UINT8 b)
41 {
42     static char hex[] = "0123456789ABCDEF";
43     static char c[3];
44     c[0] = hex[((b >> 4) & 0x0F)];
45     c[1] = hex[((b >> 0) & 0x0F)];
46     c[2] = '\0';
47     return &c[0];
48 }
49 
isPatchBadImpl(UINT8 * prm,UINT32 len)50 bool SpdHelper::isPatchBadImpl(UINT8* prm, UINT32 len)
51 {
52     string strNew;
53 
54     // Get the patch ID from the prm data.
55     for (int i = 0; i < 8 && i < len; ++i)
56         strNew.append(toHex(*prm++));
57 
58     // If it is not the same patch as before, then reset things.
59     if ( strNew != mPatchId )
60     {
61         mPatchId = strNew;
62         mErrorCount = 0;
63         mIsPatchBad = false;
64     }
65 
66     // Otherwise the 'mIsPatchBad' will tell if its bad or not.
67     ALOGD("%s '%s' (%d) is %sa known bad patch file", __func__, mPatchId.c_str(), mErrorCount, (mIsPatchBad ? "" : "not "));
68 
69     return mIsPatchBad;
70 }
71 
getInstance()72 SpdHelper& SpdHelper::getInstance()
73 {
74     static SpdHelper* theInstance = NULL;
75     if (theInstance == NULL)
76         theInstance= new SpdHelper;
77     return *theInstance;
78 }
79 
SpdHelper()80 SpdHelper::SpdHelper()
81 {
82     mErrorCount = 0;
83     mPatchId.erase();
84     if(!GetNumValue((char*)NAME_SPD_MAXRETRYCOUNT, &mMaxErrorCount, sizeof(mMaxErrorCount)))
85         mMaxErrorCount = DEFAULT_SPD_MAXRETRYCOUNT;
86     if (!GetNumValue((char*)NAME_SPD_DEBUG, &mSpdDebug, sizeof(mSpdDebug)))
87         mSpdDebug = false;
88 }
89