Merge "Wire user info and use user context for text toasts" into rvc-dev

This commit is contained in:
Bernardo Rufino
2020-04-06 21:59:20 +00:00
committed by Android (Google) Code Review
13 changed files with 164 additions and 93 deletions

View File

@@ -43,7 +43,7 @@ import android.os.ServiceManager;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.IAccessibilityManager;
import com.android.internal.annotations.GuardedBy;
@@ -610,10 +610,10 @@ public class Toast {
*/
TN(Context context, String packageName, Binder token, List<Callback> callbacks,
@Nullable Looper looper) {
WindowManager windowManager = context.getSystemService(WindowManager.class);
AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(context);
mPresenter = new ToastPresenter(context, windowManager, accessibilityManager,
getService(), packageName);
IAccessibilityManager accessibilityManager = IAccessibilityManager.Stub.asInterface(
ServiceManager.getService(Context.ACCESSIBILITY_SERVICE));
mPresenter = new ToastPresenter(context, accessibilityManager, getService(),
packageName);
mParams = mPresenter.getLayoutParams();
mPackageName = packageName;
mToken = token;

View File

@@ -27,6 +27,7 @@ import android.content.res.Resources;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
@@ -34,8 +35,10 @@ import android.view.View;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.IAccessibilityManager;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
/**
@@ -49,12 +52,14 @@ public class ToastPresenter {
private static final long SHORT_DURATION_TIMEOUT = 4000;
private static final long LONG_DURATION_TIMEOUT = 7000;
@VisibleForTesting
public static final int TEXT_TOAST_LAYOUT = R.layout.transient_notification;
/**
* Returns the default text toast view for message {@code text}.
*/
public static View getTextToastView(Context context, CharSequence text) {
View view = LayoutInflater.from(context).inflate(
R.layout.transient_notification, null);
View view = LayoutInflater.from(context).inflate(TEXT_TOAST_LAYOUT, null);
TextView textView = view.findViewById(com.android.internal.R.id.message);
textView.setText(text);
return view;
@@ -70,15 +75,23 @@ public class ToastPresenter {
@Nullable private View mView;
@Nullable private IBinder mToken;
public ToastPresenter(Context context, WindowManager windowManager,
AccessibilityManager accessibilityManager,
public ToastPresenter(Context context, IAccessibilityManager accessibilityManager,
INotificationManager notificationManager, String packageName) {
mContext = context;
mResources = context.getResources();
mWindowManager = windowManager;
mAccessibilityManager = accessibilityManager;
mWindowManager = context.getSystemService(WindowManager.class);
mNotificationManager = notificationManager;
mPackageName = packageName;
// We obtain AccessibilityManager manually via its constructor instead of using method
// AccessibilityManager.getInstance() for 2 reasons:
// 1. We want to be able to inject IAccessibilityManager in tests to verify behavior.
// 2. getInstance() caches the instance for the process even if we pass a different
// context to it. This is problematic for multi-user because callers can pass a context
// created via Context.createContextAsUser().
mAccessibilityManager = new AccessibilityManager(context, accessibilityManager,
UserHandle.getCallingUserId());
mParams = createLayoutParams();
}

View File

@@ -204,8 +204,8 @@ oneway interface IStatusBar
/**
* Displays a text toast.
*/
void showToast(String packageName, IBinder token, CharSequence text, IBinder windowToken,
int duration, @nullable ITransientNotificationCallback callback);
void showToast(int uid, String packageName, IBinder token, CharSequence text,
IBinder windowToken, int duration, @nullable ITransientNotificationCallback callback);
/**
* Cancels toast with token {@code token} in {@code packageName}.