Merge tag 'android-11.0.0_r48' into int/11/fp3

Android 11.0.0 Release 48 (RD2A.211001.002)

* tag 'android-11.0.0_r48':

Change-Id: I23185e7424149da94f36afa973e199caf7fe49c0
diff --git a/src/com/android/mtp/MtpService.java b/src/com/android/mtp/MtpService.java
index 035c0f4..8520b9e 100644
--- a/src/com/android/mtp/MtpService.java
+++ b/src/com/android/mtp/MtpService.java
@@ -45,7 +45,7 @@
 import java.io.File;
 import java.io.FileDescriptor;
 import java.util.HashMap;
-
+import android.util.BoostFramework;
 /**
  * The singleton service backing instances of MtpServer that are started for the foreground user.
  * The service has the responsibility of retrieving user storage information and managing server
@@ -54,7 +54,8 @@
 public class MtpService extends Service {
     private static final String TAG = "MtpService";
     private static final boolean LOGD = false;
-
+    private BoostFramework mPerfBoost = null;
+    private boolean mIsPerfLockAcquired = false;
     // We restrict PTP to these subdirectories
     private static final String[] PTP_DIRECTORIES = new String[] {
         Environment.DIRECTORY_DCIM,
@@ -126,6 +127,10 @@
     @Override
     public void onDestroy() {
         mStorageManager.unregisterListener(mStorageEventListener);
+        if (mIsPerfLockAcquired && mPerfBoost != null) {
+            mPerfBoost.perfLockRelease();
+            mIsPerfLockAcquired = false;
+        }
         synchronized (MtpService.class) {
             if (sServerHolder != null) {
                 sServerHolder.database.setServer(null);
@@ -228,9 +233,21 @@
                 sServerHolder.database.addStorage(volume);
             }
         }
+        if (mPerfBoost == null) {
+            mPerfBoost = new BoostFramework(true);
+        }
+        if (mPerfBoost != null && !mIsPerfLockAcquired) {
+            //Use big enough number here to hold the perflock for entire MTP session
+            mPerfBoost.perfHint(BoostFramework.VENDOR_HINT_MTP_BOOST, null, Integer.MAX_VALUE, -1);
+            mIsPerfLockAcquired = true;
+        }
     }
 
     private void removeStorage(StorageVolume volume) {
+        if (mIsPerfLockAcquired && mPerfBoost != null) {
+            mPerfBoost.perfLockRelease();
+            mIsPerfLockAcquired = false;
+        }
         synchronized (MtpService.class) {
             if (sServerHolder != null) {
                 sServerHolder.database.removeStorage(volume);