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

Commit 10088ca2 authored by Martijn Coenen's avatar Martijn Coenen
Browse files

Support Notification bitmap offloading.

Introduce a BitmapOffloadService in system_server that can take a Bitmap
and serve it as a Uri through a ContentProvider. This allows the Bitmap
to be written to disk, and to be loaded back into memory when needed.

The ContentProvider will only allow system_server to insert, modify and
delete entries. Users of the offloader must provide a PermissionChecker
interface to determine which callers are allowed to retrieve the
Bitmap associated with each entry.

The offloader does not persist the Bitmaps; they are wiped on every
system_server start. It will also only allow offloading Bitmaps if the
device has enough free storage space.

Modify NotificationManagerService to offload BigPicture Bitmaps, if
the corresponding flag is enabled.

Bug: 398153219
Flag: android.service.notification.notification_bitmap_offloading
Test: atest CtsNotificationTestCases
Change-Id: I531d3e81c8733f913ec7638f3877d11bb1229e88
parent 421044be
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -73,3 +73,10 @@ flag {
  description: "This flag controls regrouping after notification classification"
  bug: "372775153"
}

flag {
  name: "notification_bitmap_offloading"
  namespace: "systemui"
  description: "Enables offloading Bitmaps to disk"
  bug: "398153219"
}
+8 −0
Original line number Diff line number Diff line
@@ -9660,6 +9660,14 @@
            android:exported="true">
        </provider>

        <provider
            android:name="com.android.server.bitmapoffload.BitmapOffloadProvider"
            android:authorities="com.android.bitmapoffload"
            android:singleUser="true"
            android:enabled="true"
            android:exported="true">
        </provider>

        <meta-data
            android:name="com.android.server.patch.25239169"
            android:value="true" />
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.bitmapoffload;

import android.annotation.IntDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public final class BitmapOffload {
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = "BITMAP_SOURCE_", value = {
        BITMAP_SOURCE_NOTIFICATIONS,
    })
    public @interface BitmapSource {}
    public static final int BITMAP_SOURCE_NOTIFICATIONS = 0;
}
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.bitmapoffload;

import android.annotation.IntDef;
import android.net.Uri;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public final class BitmapOffloadContract {
    public static final String AUTHORITY = "com.android.bitmapoffload";

    public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/bitmaps");

    public static final String COLUMN_ID = "_id";
    public static final String COLUMN_SOURCE = "source";
    public static final String COLUMN_FILE_NAME = "filename";
    public static final String COLUMN_FILE_SIZE = "filesize";
    public static final String COLUMN_WIDTH = "width";
    public static final String COLUMN_HEIGHT = "height";
    public static final String COLUMN_OWNER_UID = "owner_uid";
    public static final String COLUMN_STATUS = "status";

    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = "OFFLOAD_STATUS_", value = {
            OFFLOAD_STATUS_PENDING,
            OFFLOAD_STATUS_COMPLETED,
            OFFLOAD_STATUS_FAILED
    })
    public @interface OffloadStatus {}
    public static final int OFFLOAD_STATUS_PENDING = 0;
    public static final int OFFLOAD_STATUS_COMPLETED = 1;
    public static final int OFFLOAD_STATUS_FAILED = 2;
}
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.bitmapoffload;

import android.graphics.Bitmap;
import android.net.Uri;

public abstract class BitmapOffloadInternal {
    public interface PermissionHandler {
        boolean isAllowedToOpen(Uri uri, int callingUid, int owningUid);
    }

    public abstract Uri offloadBitmap(@BitmapOffload.BitmapSource int source, Bitmap bitmap);
    public abstract void registerPermissionHandler(@BitmapOffload.BitmapSource int source,
            PermissionHandler handler);
    public abstract boolean checkPermission(@BitmapOffload.BitmapSource int source, Uri uri,
            int callingUid, int owningUid);
}
Loading