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

Commit b66f4f4b authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Jeff Sharkey
Browse files

Aggresive performance optimizations.

Now that we have LocalCallingIdentity, we can start caching it in
very narrow cases.  We must be careful to not cache too long, since
any changes to granted permissions for the UID mean we need to
re-evaluate any cached answers.

The best middle-ground for this in the Q release is to use an active
camera session as a proxy for when we should create a cache object
and then later invalidate it.  (It's very unlikely that a user
changes permissions while actively using the camera, and this is
a strong signal that the caller is sensitive to performance.)

Many other sprinkled optimizations to avoid extra binder calls into
the OS, such as aggressively caching VolumeInfo related details.

Track IDs that are owned by each LocalCallingIdentity, to speed up
all future security checks.

Dispatch all change notifications asynchronously, and delay them by
several seconds while the camera is being actively used, to give
more important foreground work a fighting chance.  Invalidate
thumbnails asynchronously.

Optimizations to ModernMediaScanner where it's safe to skip the
"reconcile" and "clean" steps when we're focused on a single file
that we successfully scanned.

Local tests show this CL improves performance of a test app that
takes 100 rapid shots by 45%.  (All the collective optimizations
done so far this week add up to a 70% improvement.)

Bug: 130758409
Test: atest --test-mapping packages/providers/MediaProvider
Exempt-From-Owner-Approval: trivial manifest change
Change-Id: I38cc826af47d41219ef44eae6fbd293caa0c01d5
parent 1add7b84
Loading
Loading
Loading
Loading
+16 −9
Original line number Original line Diff line number Diff line
@@ -3304,6 +3304,14 @@ public final class MediaStore {
    @TestApi
    @TestApi
    public static @NonNull File getVolumePath(@NonNull String volumeName)
    public static @NonNull File getVolumePath(@NonNull String volumeName)
            throws FileNotFoundException {
            throws FileNotFoundException {
        final StorageManager sm = AppGlobals.getInitialApplication()
                .getSystemService(StorageManager.class);
        return getVolumePath(sm.getVolumes(), volumeName);
    }

    /** {@hide} */
    public static @NonNull File getVolumePath(@NonNull List<VolumeInfo> volumes,
            @NonNull String volumeName) throws FileNotFoundException {
        if (TextUtils.isEmpty(volumeName)) {
        if (TextUtils.isEmpty(volumeName)) {
            throw new IllegalArgumentException();
            throw new IllegalArgumentException();
        }
        }
@@ -3312,19 +3320,18 @@ public final class MediaStore {
            case VOLUME_INTERNAL:
            case VOLUME_INTERNAL:
            case VOLUME_EXTERNAL:
            case VOLUME_EXTERNAL:
                throw new FileNotFoundException(volumeName + " has no associated path");
                throw new FileNotFoundException(volumeName + " has no associated path");
            case VOLUME_EXTERNAL_PRIMARY:
                return Environment.getExternalStorageDirectory();
        }
        }


        final StorageManager sm = AppGlobals.getInitialApplication()
        final boolean wantPrimary = VOLUME_EXTERNAL_PRIMARY.equals(volumeName);
                .getSystemService(StorageManager.class);
        for (VolumeInfo volume : volumes) {
        for (VolumeInfo vi : sm.getVolumes()) {
            final boolean matchPrimary = wantPrimary
            if (Objects.equals(vi.getNormalizedFsUuid(), volumeName)) {
                    && volume.isPrimary();
                final File path = vi.getPathForUser(UserHandle.myUserId());
            final boolean matchSecondary = !wantPrimary
                    && Objects.equals(volume.getNormalizedFsUuid(), volumeName);
            if (matchPrimary || matchSecondary) {
                final File path = volume.getPathForUser(UserHandle.myUserId());
                if (path != null) {
                if (path != null) {
                    return path;
                    return path;
                } else {
                    throw new FileNotFoundException("Failed to find path for " + vi);
                }
                }
            }
            }
        }
        }
+1 −1
Original line number Original line Diff line number Diff line
@@ -4434,7 +4434,7 @@
    <!-- Allows an application to watch changes and/or active state of app ops.
    <!-- Allows an application to watch changes and/or active state of app ops.
         @hide <p>Not for use by third-party applications. -->
         @hide <p>Not for use by third-party applications. -->
    <permission android:name="android.permission.WATCH_APPOPS"
    <permission android:name="android.permission.WATCH_APPOPS"
        android:protectionLevel="signature" />
        android:protectionLevel="signature|privileged" />


    <!-- Allows an application to directly open the "Open by default" page inside a package's
    <!-- Allows an application to directly open the "Open by default" page inside a package's
         Details screen.
         Details screen.
+1 −0
Original line number Original line Diff line number Diff line
@@ -195,6 +195,7 @@ applications that come with the platform
        <permission name="android.permission.MANAGE_USERS"/>
        <permission name="android.permission.MANAGE_USERS"/>
        <permission name="android.permission.USE_RESERVED_DISK"/>
        <permission name="android.permission.USE_RESERVED_DISK"/>
        <permission name="android.permission.WRITE_MEDIA_STORAGE"/>
        <permission name="android.permission.WRITE_MEDIA_STORAGE"/>
        <permission name="android.permission.WATCH_APPOPS"/>
    </privapp-permissions>
    </privapp-permissions>


    <privapp-permissions package="com.android.providers.telephony">
    <privapp-permissions package="com.android.providers.telephony">
+0 −1
Original line number Original line Diff line number Diff line
@@ -170,7 +170,6 @@
    <!-- Permission needed to enable/disable Bluetooth/Wifi -->
    <!-- Permission needed to enable/disable Bluetooth/Wifi -->
    <uses-permission android:name="android.permission.MANAGE_BLUETOOTH_WHEN_WIRELESS_CONSENT_REQUIRED" />
    <uses-permission android:name="android.permission.MANAGE_BLUETOOTH_WHEN_WIRELESS_CONSENT_REQUIRED" />
    <uses-permission android:name="android.permission.MANAGE_WIFI_WHEN_WIRELESS_CONSENT_REQUIRED" />
    <uses-permission android:name="android.permission.MANAGE_WIFI_WHEN_WIRELESS_CONSENT_REQUIRED" />
    <uses-permission android:name="android.permission.WATCH_APPOPS" />
    <!-- Permission needed to invoke DynamicSystem (AOT) -->
    <!-- Permission needed to invoke DynamicSystem (AOT) -->
    <uses-permission android:name="android.permission.INSTALL_DYNAMIC_SYSTEM" />
    <uses-permission android:name="android.permission.INSTALL_DYNAMIC_SYSTEM" />


+0 −3
Original line number Original line Diff line number Diff line
@@ -222,9 +222,6 @@
    <!-- to change themes - light or dark -->
    <!-- to change themes - light or dark -->
    <uses-permission android:name="android.permission.CHANGE_OVERLAY_PACKAGES" />
    <uses-permission android:name="android.permission.CHANGE_OVERLAY_PACKAGES" />


    <!-- Listen app op changes -->
    <uses-permission android:name="android.permission.WATCH_APPOPS" />

    <!-- to read and change hvac values in a car -->
    <!-- to read and change hvac values in a car -->
    <uses-permission android:name="android.car.permission.CONTROL_CAR_CLIMATE" />
    <uses-permission android:name="android.car.permission.CONTROL_CAR_CLIMATE" />