Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e82e6627 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "trancoding: lazy-start transcoding service" into sc-dev

parents 875493dc 0621358a
Loading
Loading
Loading
Loading
+14 −1
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.app.ActivityManager;
import android.content.ContentResolver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetFileDescriptor;
@@ -36,6 +37,7 @@ import android.util.Log;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.modules.annotation.MinSdk;
import com.android.modules.annotation.MinSdk;
import com.android.modules.utils.build.SdkLevel;


import java.io.FileNotFoundException;
import java.io.FileNotFoundException;
import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
@@ -119,6 +121,7 @@ public final class MediaTranscodeManager {
    private final String mPackageName;
    private final String mPackageName;
    private final int mPid;
    private final int mPid;
    private final int mUid;
    private final int mUid;
    private final boolean mIsLowRamDevice;
    private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
    private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
    private final HashMap<Integer, TranscodingSession> mPendingTranscodingSessions = new HashMap();
    private final HashMap<Integer, TranscodingSession> mPendingTranscodingSessions = new HashMap();
    private final Object mLock = new Object();
    private final Object mLock = new Object();
@@ -199,7 +202,16 @@ public final class MediaTranscodeManager {
        }
        }
    }
    }


    private static IMediaTranscodingService getService(boolean retry) {
    private IMediaTranscodingService getService(boolean retry) {
        // Do not try to get the service on pre-S. The service is lazy-start and getting the
        // service could block.
        if (!SdkLevel.isAtLeastS()) {
            return null;
        }
        // Do not try to get the service on AndroidGo (low-ram) devices.
        if (mIsLowRamDevice) {
            return null;
        }
        int retryCount = !retry ? 1 :  CONNECT_SERVICE_RETRY_COUNT;
        int retryCount = !retry ? 1 :  CONNECT_SERVICE_RETRY_COUNT;
        Log.i(TAG, "get service with retry " + retryCount);
        Log.i(TAG, "get service with retry " + retryCount);
        for (int count = 1;  count <= retryCount; count++) {
        for (int count = 1;  count <= retryCount; count++) {
@@ -417,6 +429,7 @@ public final class MediaTranscodeManager {
        mPackageName = mContext.getPackageName();
        mPackageName = mContext.getPackageName();
        mUid = Os.getuid();
        mUid = Os.getuid();
        mPid = Os.getpid();
        mPid = Os.getpid();
        mIsLowRamDevice = mContext.getSystemService(ActivityManager.class).isLowRamDevice();
        IMediaTranscodingService service = getService(false /*retry*/);
        IMediaTranscodingService service = getService(false /*retry*/);
        if (service != null) {
        if (service != null) {
            mTranscodingClient = registerClient(service);
            mTranscodingClient = registerClient(service);
+14 −2
Original line number Original line Diff line number Diff line
@@ -45,12 +45,21 @@ public class MediaServiceManager {
     */
     */
    public static final class ServiceRegisterer {
    public static final class ServiceRegisterer {
        private final String mServiceName;
        private final String mServiceName;
        private final boolean mLazyStart;


        /**
        /**
         * @hide
         * @hide
         */
         */
        public ServiceRegisterer(String serviceName) {
        public ServiceRegisterer(String serviceName, boolean lazyStart) {
            mServiceName = serviceName;
            mServiceName = serviceName;
            mLazyStart = lazyStart;
        }

        /**
         * @hide
         */
        public ServiceRegisterer(String serviceName) {
            this(serviceName, false /*lazyStart*/);
        }
        }


        /**
        /**
@@ -61,6 +70,9 @@ public class MediaServiceManager {
         */
         */
        @Nullable
        @Nullable
        public IBinder get() {
        public IBinder get() {
            if (mLazyStart) {
                return ServiceManager.waitForService(mServiceName);
            }
            return ServiceManager.getService(mServiceName);
            return ServiceManager.getService(mServiceName);
        }
        }
    }
    }
@@ -78,7 +90,7 @@ public class MediaServiceManager {
     */
     */
    @NonNull
    @NonNull
    public ServiceRegisterer getMediaTranscodingServiceRegisterer() {
    public ServiceRegisterer getMediaTranscodingServiceRegisterer() {
        return new ServiceRegisterer(MEDIA_TRANSCODING_SERVICE);
        return new ServiceRegisterer(MEDIA_TRANSCODING_SERVICE, true /*lazyStart*/);
    }
    }


    /**
    /**