Better handling unknown uid case in network watchlist service

Bug: 72995507
Test: Hard coded empty digest and it still works
Change-Id: Ieec509aaefc8c8e24b4ab3ecf0c6175a062340db
This commit is contained in:
Ricky Wai
2018-02-06 19:08:51 +00:00
parent 7b2354ece2
commit 292fa6447d

View File

@@ -128,7 +128,7 @@ class WatchlistLoggingHandler extends Handler {
Slog.e(TAG, "Couldn't find package: " + packageNames);
return false;
}
ai = mPm.getApplicationInfo(packageNames[0],0);
ai = mPm.getApplicationInfo(packageNames[0], 0);
} catch (NameNotFoundException e) {
// Should not happen.
return false;
@@ -136,7 +136,7 @@ class WatchlistLoggingHandler extends Handler {
return (ai.flags & ApplicationInfo.FLAG_TEST_ONLY) != 0;
}
/**
/**
* Report network watchlist records if we collected enough data.
*/
public void reportWatchlistIfNecessary() {
@@ -180,6 +180,10 @@ class WatchlistLoggingHandler extends Handler {
return true;
}
final byte[] digest = getDigestFromUid(uid);
if (digest == null) {
Slog.e(TAG, "Cannot get digest from uid: " + uid);
return false;
}
final boolean result = mDbHelper.insertNewRecord(digest, cncHost, timestamp);
tryAggregateRecords();
return result;
@@ -242,6 +246,11 @@ class WatchlistLoggingHandler extends Handler {
final int size = apps.size();
for (int i = 0; i < size; i++) {
byte[] digest = getDigestFromUid(apps.get(i).uid);
if (digest == null) {
Slog.e(TAG, "Cannot get digest from uid: " + apps.get(i).uid
+ ",pkg: " + apps.get(i).packageName);
continue;
}
result.add(HexDump.toHexString(digest));
}
// Step 2: Add all digests from records