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

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

Merge "Remove DefaultSelectionToolbarRenderService" into main

parents d717bb9a 80f689d9
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -372,13 +372,6 @@ flag {
    bug: "363318732"
}

flag {
    name: "use_system_selection_toolbar_in_sysui"
    namespace: "permissions"
    description: "Uses the SysUi process to host the SelectionToolbarRenderService."
    bug: "363318732"
}

flag {
    name: "note_op_batching_enabled"
    is_fixed_read_only: true
+0 −109
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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 android.service.selectiontoolbar;

import android.util.Slog;
import android.util.SparseArray;
import android.view.selectiontoolbar.ShowInfo;

import java.io.FileDescriptor;
import java.io.PrintWriter;

/**
 * The default implementation of {@link SelectionToolbarRenderService}.
 *
 * <p><b>NOTE:</b> The requests are handled on the service main thread.
 *
 * @hide
 */
// TODO(b/214122495): fix class not found then move to system service folder
public final class DefaultSelectionToolbarRenderService extends SelectionToolbarRenderService {

    private static final String TAG = "DefaultSelectionToolbarRenderService";

    // TODO(b/215497659): handle remove if the client process dies.
    // Only show one toolbar, dismiss the old ones and remove from cache
    // Maps uid -> toolbar instance
    private final SparseArray<RemoteSelectionToolbar> mToolbarCache = new SparseArray<>();

    @Override
    public void onShow(int uid, ShowInfo showInfo,
            SelectionToolbarRenderService.RemoteCallbackWrapper callbackWrapper) {
        RemoteSelectionToolbar existingToolbar = mToolbarCache.get(uid);
        if (existingToolbar != null) {
            // TODO can we remove this check and just update the widget with dismissing?
            Slog.e(TAG, "Do not allow multiple toolbar for the uid : " + uid);
            return;
        }

        RemoteSelectionToolbar toolbar = new RemoteSelectionToolbar(uid, this,
                showInfo, callbackWrapper, this::transferTouch, this::onPasteAction);
        mToolbarCache.put(uid, toolbar);
        toolbar.show(showInfo);
        Slog.v(TAG, "onShow() for uid: " + uid);
    }

    @Override
    public void onHide(int uid) {
        RemoteSelectionToolbar toolbar = mToolbarCache.get(uid);
        if (toolbar != null) {
            Slog.v(TAG, "onHide() for uid: " + uid);
            toolbar.hide(uid);
        }
    }

    @Override
    public void onDismiss(int uid) {
        Slog.v(TAG, "onDismiss() for uid: " + uid);
        removeAndDismissToolbar(uid);
    }

    private void removeAndDismissToolbar(int uid) {
        RemoteSelectionToolbar toolbar = mToolbarCache.removeReturnOld(uid);
        if (toolbar != null) {
            toolbar.dismiss(uid);
        }
    }

    @Override
    public void onUidDied(int uid) {
        Slog.w(TAG, "onUidDied for uid: " + uid);
        removeAndDismissToolbar(uid);
    }

    @Override
    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        int size = mToolbarCache.size();
        pw.print("number selectionToolbar: ");
        pw.println(size);
        String pfx = "  ";
        for (int i = 0; i < size; i++) {
            pw.print("#");
            pw.println(i);
            int uid = mToolbarCache.keyAt(i);
            pw.print(pfx);
            pw.print("uid: ");
            pw.println(uid);
            RemoteSelectionToolbar selectionToolbar = mToolbarCache.get(uid);
            pw.print(pfx);
            pw.print("selectionToolbar: ");
            selectionToolbar.dump(pfx, pw);
            pw.println();
        }
    }
}
+0 −9
Original line number Diff line number Diff line
@@ -9914,15 +9914,6 @@
            </intent-filter>
        </service>
        <service android:name="android.service.selectiontoolbar.DefaultSelectionToolbarRenderService"
                 android:permission="android.permission.BIND_SELECTION_TOOLBAR_RENDER_SERVICE"
                 android:process=":ui"
                 android:exported="false">
            <intent-filter>
                <action android:name="android.service.selectiontoolbar.SelectionToolbarRenderService"/>
            </intent-filter>
        </service>
        <service android:name="com.android.server.art.BackgroundDexoptJobService"
                 android:permission="android.permission.BIND_JOB_SERVICE" >
        </service>
+2 −12
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.server.selectiontoolbar;

import static android.permission.flags.Flags.useSystemSelectionToolbarInSysui;

import android.annotation.NonNull;
import android.content.ComponentName;
import android.content.Context;
@@ -25,7 +23,6 @@ import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.UserHandle;
import android.service.selectiontoolbar.DefaultSelectionToolbarRenderService;
import android.service.selectiontoolbar.ISelectionToolbarRenderService;
import android.service.selectiontoolbar.ISelectionToolbarRenderServiceCallback;
import android.service.selectiontoolbar.SelectionToolbarRenderService;
@@ -55,15 +52,8 @@ public class SelectionToolbarManagerService extends SystemService {
    public SelectionToolbarManagerService(Context context) {
        super(context);

        String serviceName;
        if (useSystemSelectionToolbarInSysui()) {
            serviceName = context.getResources()
        String serviceName = context.getResources()
                .getString(R.string.config_systemUiSelectionToolbarRenderService);
        } else {
            serviceName = new ComponentName(
                    "android", DefaultSelectionToolbarRenderService.class.getName())
                    .flattenToString();
        }
        final ComponentName serviceComponent = ComponentName.unflattenFromString(serviceName);
        mRemoteRenderServiceConnector = new RemoteRenderServiceConnector(context, serviceComponent,
                UserHandle.USER_SYSTEM, new SelectionToolbarRenderServiceRemoteCallback());