From a737118adea9827c1a422379e3bcf1745cbe75db Mon Sep 17 00:00:00 2001 From: hkuang Date: Thu, 1 Apr 2021 21:41:35 -0700 Subject: [PATCH] transcoding: Connect the new addClientUid with service. Bug: 171398942 Test: atest CtsMediaTranscodingTestCases:MediaTranscodeManagerTest Change-Id: Ibec9821a49e2f5f894717fb6e05fca8aa2470054 --- apex/media/framework/api/system-current.txt | 2 +- .../android/media/MediaTranscodeManager.java | 49 ++++++++++++++----- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/apex/media/framework/api/system-current.txt b/apex/media/framework/api/system-current.txt index 8d83309f5be08..61702db90011e 100644 --- a/apex/media/framework/api/system-current.txt +++ b/apex/media/framework/api/system-current.txt @@ -25,7 +25,7 @@ package android.media { } public static final class MediaTranscodeManager.TranscodingSession { - method public void addClientUid(int); + method public boolean addClientUid(int); method public void cancel(); method @NonNull public java.util.List getClientUids(); method public int getErrorCode(); diff --git a/apex/media/framework/java/android/media/MediaTranscodeManager.java b/apex/media/framework/java/android/media/MediaTranscodeManager.java index 775b0e54b24c5..1e9b9b9442e7e 100644 --- a/apex/media/framework/java/android/media/MediaTranscodeManager.java +++ b/apex/media/framework/java/android/media/MediaTranscodeManager.java @@ -1361,8 +1361,6 @@ public final class MediaTranscodeManager { private @TranscodingSessionErrorCode int mErrorCode = ERROR_NONE; @GuardedBy("mLock") private boolean mHasRetried = false; - @GuardedBy("mLock") - private @NonNull List mClientUidList = new ArrayList<>(); // The original request that associated with this session. private final TranscodingRequest mRequest; @@ -1381,7 +1379,6 @@ public final class MediaTranscodeManager { mListenerExecutor = executor; mListener = listener; mRequest = request; - mClientUidList.add(request.getClientUid()); } /** @@ -1532,17 +1529,31 @@ public final class MediaTranscodeManager { * Only privilege caller with android.permission.WRITE_MEDIA_STORAGE could add the * uid. Note that the permission check happens on the service side upon starting the * transcoding. If the client does not have the permission, the transcoding will fail. + * @param uid the additional client uid to be added. + * @return true if successfully added, false otherwise. */ - public void addClientUid(int uid) { + public boolean addClientUid(int uid) { if (uid < 0) { throw new IllegalArgumentException("Invalid Uid"); } - synchronized (mLock) { - if (!mClientUidList.contains(uid)) { - // see ag/14023202 for implementation - mClientUidList.add(uid); - } + + // Get the client interface. + ITranscodingClient client = mManager.getTranscodingClient(); + if (client == null) { + Log.e(TAG, "Service is dead..."); + return false; } + + try { + if (!client.addClientUid(mSessionId, uid)) { + Log.e(TAG, "Failed to add client uid"); + return false; + } + } catch (Exception ex) { + Log.e(TAG, "Failed to get client uids due to " + ex); + return false; + } + return true; } /** @@ -1551,9 +1562,25 @@ public final class MediaTranscodeManager { */ @NonNull public List getClientUids() { - synchronized (mLock) { - return mClientUidList; + List uidList = new ArrayList(); + + // Get the client interface. + ITranscodingClient client = mManager.getTranscodingClient(); + if (client == null) { + Log.e(TAG, "Service is dead..."); + return uidList; } + + try { + int[] clientUids = client.getClientUids(mSessionId); + for (int i : clientUids) { + uidList.add(i); + } + } catch (Exception ex) { + Log.e(TAG, "Failed to get client uids due to " + ex); + } + + return uidList; } /**