Merge "Do not report incremental app in network watchlist" into rvc-dev
diff --git a/services/core/java/com/android/server/net/watchlist/WatchlistLoggingHandler.java b/services/core/java/com/android/server/net/watchlist/WatchlistLoggingHandler.java
index 3b3ee58..5599b0c 100644
--- a/services/core/java/com/android/server/net/watchlist/WatchlistLoggingHandler.java
+++ b/services/core/java/com/android/server/net/watchlist/WatchlistLoggingHandler.java
@@ -16,6 +16,8 @@
 
 package com.android.server.net.watchlist;
 
+import static android.os.incremental.IncrementalManager.isIncrementalPath;
+
 import android.annotation.Nullable;
 import android.content.ContentResolver;
 import android.content.Context;
@@ -220,7 +222,7 @@
         }
     }
 
-    private boolean insertRecord(int uid, String cncHost, long timestamp) {
+    private void insertRecord(int uid, String cncHost, long timestamp) {
         if (DEBUG) {
             Slog.i(TAG, "trying to insert record with host: " + cncHost + ", uid: " + uid);
         }
@@ -229,15 +231,15 @@
             if (DEBUG) {
                 Slog.i(TAG, "uid: " + uid + " is not test only package");
             }
-            return true;
+            return;
         }
         final byte[] digest = getDigestFromUid(uid);
         if (digest == null) {
-            Slog.e(TAG, "Cannot get digest from uid: " + uid);
-            return false;
+            return;
         }
-        final boolean result = mDbHelper.insertNewRecord(digest, cncHost, timestamp);
-        return result;
+        if (mDbHelper.insertNewRecord(digest, cncHost, timestamp)) {
+            Slog.w(TAG, "Unable to insert record for uid: " + uid);
+        }
     }
 
     private boolean shouldReportNetworkWatchlist(long lastRecordTime) {
@@ -307,9 +309,6 @@
             byte[] digest = getDigestFromUid(apps.get(i).uid);
             if (digest != null) {
                 result.add(HexDump.toHexString(digest));
-            } else {
-                Slog.e(TAG, "Cannot get digest from uid: " + apps.get(i).uid
-                        + ",pkg: " + apps.get(i).packageName);
             }
         }
         // Step 2: Add all digests from records
@@ -341,9 +340,16 @@
                             Slog.w(TAG, "Cannot find apkPath for " + packageName);
                             continue;
                         }
+                        if (isIncrementalPath(apkPath)) {
+                            // Do not scan incremental fs apk, as the whole APK may not yet
+                            // be available, so we can't compute the hash of it.
+                            Slog.i(TAG, "Skipping incremental path: " + packageName);
+                            continue;
+                        }
                         return DigestUtils.getSha256Hash(new File(apkPath));
                     } catch (NameNotFoundException | NoSuchAlgorithmException | IOException e) {
-                        Slog.e(TAG, "Should not happen", e);
+                        Slog.e(TAG, "Cannot get digest from uid: " + key
+                                + ",pkg: " + packageName, e);
                         return null;
                     }
                 }