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

Commit 0cb49d54 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 12851542 from 6eb3950f to 25Q2-release

Change-Id: I1f00ffb095695c92500d03482f3c780c0899633b
parents 8a8fe9ce 6eb3950f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -4136,6 +4136,7 @@ package android.view.inputmethod {
    method @RequiresPermission(android.Manifest.permission.TEST_INPUT_METHOD) public boolean isInputMethodPickerShown();
    method @NonNull @RequiresPermission(value=android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional=true) public boolean isStylusHandwritingAvailableAsUser(@NonNull android.os.UserHandle);
    method @RequiresPermission(android.Manifest.permission.TEST_INPUT_METHOD) public void setStylusWindowIdleTimeoutForTest(long);
    method @RequiresPermission(android.Manifest.permission.TEST_INPUT_METHOD) public boolean shouldShowImeSwitcherButtonForTest();
    field public static final long CLEAR_SHOW_FORCED_FLAG_WHEN_LEAVING = 214016041L; // 0xcc1a029L
  }

+151 −19
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.app;

import static android.Manifest.permission.POST_NOTIFICATIONS;
import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.service.notification.Flags.notificationClassification;

@@ -50,6 +51,7 @@ import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.IpcDataCache;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
@@ -71,6 +73,8 @@ import android.util.LruCache;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;

import com.android.internal.annotations.VisibleForTesting;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.time.InstantSource;
@@ -1202,6 +1206,13 @@ public class NotificationManager {
     * package (see {@link Context#createPackageContext(String, int)}).</p>
     */
    public NotificationChannel getNotificationChannel(String channelId) {
        if (Flags.nmBinderPerfCacheChannels()) {
            return getChannelFromList(channelId,
                    mNotificationChannelListCache.query(new NotificationChannelQuery(
                            mContext.getOpPackageName(),
                            mContext.getPackageName(),
                            mContext.getUserId())));
        } else {
            INotificationManager service = service();
            try {
                return service.getNotificationChannel(mContext.getOpPackageName(),
@@ -1210,6 +1221,7 @@ public class NotificationManager {
                throw e.rethrowFromSystemServer();
            }
        }
    }

    /**
     * Returns the notification channel settings for a given channel and
@@ -1222,6 +1234,13 @@ public class NotificationManager {
     */
    public @Nullable NotificationChannel getNotificationChannel(@NonNull String channelId,
            @NonNull String conversationId) {
        if (Flags.nmBinderPerfCacheChannels()) {
            return getConversationChannelFromList(channelId, conversationId,
                    mNotificationChannelListCache.query(new NotificationChannelQuery(
                            mContext.getOpPackageName(),
                            mContext.getPackageName(),
                            mContext.getUserId())));
        } else {
            INotificationManager service = service();
            try {
                return service.getConversationNotificationChannel(mContext.getOpPackageName(),
@@ -1231,6 +1250,7 @@ public class NotificationManager {
                throw e.rethrowFromSystemServer();
            }
        }
    }

    /**
     * Returns all notification channels belonging to the calling package.
@@ -1241,6 +1261,12 @@ public class NotificationManager {
     * {@link Context#createPackageContext(String, int)}).</p>
     */
    public List<NotificationChannel> getNotificationChannels() {
        if (Flags.nmBinderPerfCacheChannels()) {
            return mNotificationChannelListCache.query(new NotificationChannelQuery(
               mContext.getOpPackageName(),
               mContext.getPackageName(),
               mContext.getUserId()));
        } else {
            INotificationManager service = service();
            try {
                return service.getNotificationChannels(mContext.getOpPackageName(),
@@ -1249,6 +1275,47 @@ public class NotificationManager {
                throw e.rethrowFromSystemServer();
            }
        }
    }

    // channel list assumed to be associated with the appropriate package & user id already.
    private static NotificationChannel getChannelFromList(String channelId,
            List<NotificationChannel> channels) {
        if (channels == null) {
            return null;
        }
        if (channelId == null) {
            channelId = DEFAULT_CHANNEL_ID;
        }
        for (NotificationChannel channel : channels) {
            if (channelId.equals(channel.getId())) {
                return channel;
            }
        }
        return null;
    }

    private static NotificationChannel getConversationChannelFromList(String channelId,
            String conversationId, List<NotificationChannel> channels) {
        if (channels == null) {
            return null;
        }
        if (channelId == null) {
            channelId = DEFAULT_CHANNEL_ID;
        }
        if (conversationId == null) {
            return getChannelFromList(channelId, channels);
        }
        NotificationChannel parent = null;
        for (NotificationChannel channel : channels) {
            if (conversationId.equals(channel.getConversationId())
                    && channelId.equals(channel.getParentChannelId())) {
                return channel;
            } else if (channelId.equals(channel.getId())) {
                parent = channel;
            }
        }
        return parent;
    }

    /**
     * Deletes the given notification channel.
@@ -1328,6 +1395,71 @@ public class NotificationManager {
        }
    }

    private static final String NOTIFICATION_CHANNEL_CACHE_API = "getNotificationChannel";
    private static final String NOTIFICATION_CHANNEL_LIST_CACHE_NAME = "getNotificationChannels";
    private static final int NOTIFICATION_CHANNEL_CACHE_SIZE = 10;

    private final IpcDataCache.QueryHandler<NotificationChannelQuery, List<NotificationChannel>>
            mNotificationChannelListQueryHandler = new IpcDataCache.QueryHandler<>() {
                @Override
                public List<NotificationChannel> apply(NotificationChannelQuery query) {
                    INotificationManager service = service();
                    try {
                        return service.getNotificationChannels(query.callingPkg,
                                query.targetPkg, query.userId).getList();
                    } catch (RemoteException e) {
                        throw e.rethrowFromSystemServer();
                    }
                }

                @Override
                public boolean shouldBypassCache(@NonNull NotificationChannelQuery query) {
                    // Other locations should also not be querying the cache in the first place if
                    // the flag is not enabled, but this is an extra precaution.
                    if (!Flags.nmBinderPerfCacheChannels()) {
                        Log.wtf(TAG,
                                "shouldBypassCache called when nm_binder_perf_cache_channels off");
                        return true;
                    }
                    return false;
                }
            };

    private final IpcDataCache<NotificationChannelQuery, List<NotificationChannel>>
            mNotificationChannelListCache =
            new IpcDataCache<>(NOTIFICATION_CHANNEL_CACHE_SIZE, IpcDataCache.MODULE_SYSTEM,
                    NOTIFICATION_CHANNEL_CACHE_API, NOTIFICATION_CHANNEL_LIST_CACHE_NAME,
                    mNotificationChannelListQueryHandler);

    private record NotificationChannelQuery(
            String callingPkg,
            String targetPkg,
            int userId) {}

    /**
     * @hide
     */
    public static void invalidateNotificationChannelCache() {
        if (Flags.nmBinderPerfCacheChannels()) {
            IpcDataCache.invalidateCache(IpcDataCache.MODULE_SYSTEM,
                    NOTIFICATION_CHANNEL_CACHE_API);
        } else {
            // if we are here, we have failed to flag something
            Log.wtf(TAG, "invalidateNotificationChannelCache called without flag");
        }
    }

    /**
     * For testing only: running tests with a cache requires marking the cache's property for
     * testing, as test APIs otherwise cannot invalidate the cache. This must be called after
     * calling PropertyInvalidatedCache.setTestMode(true).
     * @hide
     */
    @VisibleForTesting
    public void setChannelCacheToTestMode() {
        mNotificationChannelListCache.testPropertyName();
    }

    /**
     * @hide
     */
+14 −0
Original line number Diff line number Diff line
@@ -489,6 +489,20 @@ final class IInputMethodManagerGlobalInvoker {
        }
    }

    @AnyThread
    @RequiresPermission(Manifest.permission.TEST_INPUT_METHOD)
    static boolean shouldShowImeSwitcherButtonForTest() {
        final IInputMethodManager service = getService();
        if (service == null) {
            return false;
        }
        try {
            return service.shouldShowImeSwitcherButtonForTest();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    @AnyThread
    @Nullable
    @RequiresPermission(value = Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)
+13 −0
Original line number Diff line number Diff line
@@ -4535,6 +4535,19 @@ public final class InputMethodManager {
        IInputMethodManagerGlobalInvoker.onImeSwitchButtonClickFromSystem(displayId);
    }

    /**
     * A test API for CTS to check whether the IME Switcher button should be shown when the IME
     * is shown.
     *
     * @hide
     */
    @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
    @TestApi
    @RequiresPermission(Manifest.permission.TEST_INPUT_METHOD)
    public boolean shouldShowImeSwitcherButtonForTest() {
        return IInputMethodManagerGlobalInvoker.shouldShowImeSwitcherButtonForTest();
    }

    /**
     * A test API for CTS to check whether there are any pending IME visibility requests.
     *
+9 −0
Original line number Diff line number Diff line
@@ -149,6 +149,15 @@ interface IInputMethodManager {
    + "permission.WRITE_SECURE_SETTINGS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL})")
    oneway void onImeSwitchButtonClickFromSystem(int displayId);

    /**
     * A test API for CTS to check whether the IME Switcher button should be shown when the IME
     * is shown.
     */
    @EnforcePermission("TEST_INPUT_METHOD")
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
            + "android.Manifest.permission.TEST_INPUT_METHOD)")
    boolean shouldShowImeSwitcherButtonForTest();

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
            + "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)")
    @nullable InputMethodSubtype getCurrentInputMethodSubtype(int userId);
Loading