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

Commit aa357456 authored by Winson Chung's avatar Winson Chung
Browse files

Move more calls to the lib.

- Move the task stack listener wrapper into the shared lib, along with some
  other AM calls.

Bug: 67510855
Test: Launch recents

Change-Id: Icb5ea78ec42d4b76a1c531ce336dd9a3f07a9629
parent a6ea1833
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -232,7 +232,7 @@ interface IActivityManager {
            boolean requireFull, in String name, in String callerPackage);
    void addPackageDependency(in String packageName);
    void killApplication(in String pkg, int appId, int userId, in String reason);
    void closeSystemDialogs(in String reason);
    oneway void closeSystemDialogs(in String reason);
    Debug.MemoryInfo[] getProcessMemoryInfo(in int[] pids);
    void killApplicationProcess(in String processName, int uid);
    int startActivityIntentSender(in IApplicationThread caller,
@@ -450,9 +450,8 @@ interface IActivityManager {
    int checkPermissionWithToken(in String permission, int pid, int uid,
            in IBinder callerToken);
    void registerTaskStackListener(in ITaskStackListener listener);
    void unregisterTaskStackListener(in ITaskStackListener listener);


    // Start of M transactions
    void notifyCleartextNetwork(int uid, in byte[] firstPacket);
    int createStackOnDisplay(int displayId);
    void setTaskResizeable(int taskId, int resizeableMode);
@@ -618,7 +617,6 @@ interface IActivityManager {
     * @return Returns true if the configuration was updated.
     */
    boolean updateDisplayOverrideConfiguration(in Configuration values, int displayId);
    void unregisterTaskStackListener(ITaskStackListener listener);
    void moveStackToDisplay(int stackId, int displayId);
    boolean requestAutofillData(in IAssistDataReceiver receiver, in Bundle receiverExtras,
                                in IBinder activityToken, int flags);
+50 −0
Original line number Diff line number Diff line
@@ -50,11 +50,13 @@ public class ActivityManagerWrapper {

    private final PackageManager mPackageManager;
    private final IconDrawableFactory mDrawableFactory;
    private final BackgroundExecutor mBackgroundExecutor;

    private ActivityManagerWrapper() {
        final Context context = AppGlobals.getInitialApplication();
        mPackageManager = context.getPackageManager();
        mDrawableFactory = IconDrawableFactory.newInstance(context);
        mBackgroundExecutor = BackgroundExecutor.get();
    }

    public static ActivityManagerWrapper getInstance() {
@@ -198,4 +200,52 @@ public class ActivityManagerWrapper {
        }
        return label;
    }

    /**
     * Requests that the system close any open system windows (including other SystemUI).
     */
    public void closeSystemWindows(String reason) {
        mBackgroundExecutor.submit(() -> {
            try {
                ActivityManager.getService().closeSystemDialogs(reason);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed to close system windows", e);
            }
        });
    }

    /**
     * Removes a task by id.
     */
    public void removeTask(int taskId) {
        mBackgroundExecutor.submit(() -> {
            try {
                ActivityManager.getService().removeTask(taskId);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed to remove task=" + taskId, e);
            }
        });
    }

    /**
     * Cancels the current window transtion to/from Recents for the given task id.
     */
    public void cancelWindowTransition(int taskId) {
        try {
            ActivityManager.getService().cancelTaskWindowTransition(taskId);
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to cancel window transition for task=" + taskId, e);
        }
    }

    /**
     * Cancels the current thumbnail transtion to/from Recents for the given task id.
     */
    public void cancelThumbnailTransition(int taskId) {
        try {
            ActivityManager.getService().cancelTaskThumbnailTransition(taskId);
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to cancel window transition for task=" + taskId, e);
        }
    }
}
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.systemui.shared.system;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * Offloads work from other threads by running it in a background thread.
 */
public class BackgroundExecutor {

    private static final BackgroundExecutor sInstance = new BackgroundExecutor();

    private final ExecutorService mExecutorService = Executors.newFixedThreadPool(2);

    /**
     * @return the static instance of the background executor.
     */
    public static BackgroundExecutor get() {
        return sInstance;
    }

    /**
     * Runs the given {@param runnable} on one of the background executor threads.
     */
    public Future<?> submit(Runnable runnable) {
        return mExecutorService.submit(runnable);
    }
}
+11 −14
Original line number Diff line number Diff line
@@ -14,24 +14,22 @@
 * limitations under the License.
 */

package com.android.systemui.recents.misc;
package com.android.systemui.shared.system;

import android.app.ActivityManager.TaskSnapshot;
import android.content.Context;
import android.os.UserHandle;
import android.util.Log;

/**
 * An abstract class to track task stack changes.
 * Classes should implement this instead of {@link android.app.ITaskStackListener}
 * to reduce IPC calls from system services. These callbacks will be called on the main thread.
 * An interface to track task stack changes. Classes should implement this instead of
 * {@link android.app.ITaskStackListener} to reduce IPC calls from system services.
 */
public abstract class TaskStackChangeListener {

    /**
     * NOTE: This call is made of the thread that the binder call comes in on.
     */
    // Binder thread callbacks
    public void onTaskStackChangedBackground() { }

    // Main thread callbacks
    public void onTaskStackChanged() { }
    public void onTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) { }
    public void onActivityPinned(String packageName, int userId, int taskId, int stackId) { }
@@ -45,17 +43,16 @@ public abstract class TaskStackChangeListener {
    public void onTaskProfileLocked(int taskId, int userId) { }

    /**
     * Checks that the current user matches the user's SystemUI process. Since
     * Checks that the current user matches the process. Since
     * {@link android.app.ITaskStackListener} is not multi-user aware, handlers of
     * TaskStackChangeListener should make this call to verify that we don't act on events from other
     * user's processes.
     * {@link TaskStackChangeListener} should make this call to verify that we don't act on events
     * originating from another user's interactions.
     */
    protected final boolean checkCurrentUserId(Context context, boolean debug) {
    protected final boolean checkCurrentUserId(int currentUserId, boolean debug) {
        int processUserId = UserHandle.myUserId();
        int currentUserId = SystemServicesProxy.getInstance(context).getCurrentUser();
        if (processUserId != currentUserId) {
            if (debug) {
                Log.d(SystemServicesProxy.TAG, "UID mismatch. SystemUI is running uid=" + processUserId
                Log.d("TaskStackChangeListener", "UID mismatch. Process is uid=" + processUserId
                        + " and the current user is uid=" + currentUserId);
            }
            return false;
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.systemui.recents.misc;
package com.android.systemui.shared.system;

import android.app.ActivityManager.TaskSnapshot;
import android.app.IActivityManager;
Loading