Camera: Look up client name for NDK earlier

Before, the client package name, which can be empty for NDK clients,
wasn't looked up until BasicClient. Move lookup to connectHelper,
to ensure there's a name to pass to other system services such as
window manager.

Note that for shared UID processes, we may select the wrong name,
but this is not expected to cause problems for the situations where
the name is used, beyond just confusing logs.

Also fix up PID reporting for the initial camera connect logging.

Test: atest CtsCameraTestCases on oriole, plus manual testing
  with an NDK-using app to verify that the frame rate override reaches
  window manager correctly.
Bug: 239452794
Change-Id: I006a73e0c9eec99c827085a722d0edfa879bdd23
diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
index c645c28..f2d15ef 100644
--- a/services/camera/libcameraservice/CameraService.h
+++ b/services/camera/libcameraservice/CameraService.h
@@ -828,10 +828,19 @@
     // sorted in alpha-numeric order.
     void filterAPI1SystemCameraLocked(const std::vector<std::string> &normalDeviceIds);
 
+    // In some cases the calling code has no access to the package it runs under.
+    // For example, NDK camera API.
+    // In this case we will get the packages for the calling UID and pick the first one
+    // for attributing the app op. This will work correctly for runtime permissions
+    // as for legacy apps we will toggle the app op for all packages in the UID.
+    // The caveat is that the operation may be attributed to the wrong package and
+    // stats based on app ops may be slightly off.
+    String16 getPackageNameFromUid(int clientUid);
+
     // Single implementation shared between the various connect calls
     template<class CALLBACK, class CLIENT>
     binder::Status connectHelper(const sp<CALLBACK>& cameraCb, const String8& cameraId,
-            int api1CameraId, const String16& clientPackageName, bool systemNativeClient,
+            int api1CameraId, const String16& clientPackageNameMaybe, bool systemNativeClient,
             const std::optional<String16>& clientFeatureId, int clientUid, int clientPid,
             apiLevel effectiveApiLevel, bool shimUpdateOnly, int scoreOffset, int targetSdkVersion,
             /*out*/sp<CLIENT>& device);