Fixing issue with toasts not showing for guest users.
Bug: 30001278
Change-Id: I43269da8a6c41f4fec5923aafe5a624ec75ba651
diff --git a/packages/SystemUI/src/com/android/systemui/recents/IRecentsNonSystemUserCallbacks.aidl b/packages/SystemUI/src/com/android/systemui/recents/IRecentsNonSystemUserCallbacks.aidl
index 9403664..9214eef 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/IRecentsNonSystemUserCallbacks.aidl
+++ b/packages/SystemUI/src/com/android/systemui/recents/IRecentsNonSystemUserCallbacks.aidl
@@ -35,4 +35,5 @@
in Rect initialBounds);
void onDraggingInRecents(float distanceFromTop);
void onDraggingInRecentsEnded(float velocity);
+ void showCurrentUserToast(int msgResId, int msgLength);
}
diff --git a/packages/SystemUI/src/com/android/systemui/recents/Recents.java b/packages/SystemUI/src/com/android/systemui/recents/Recents.java
index e117bfe..5b25f052 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/Recents.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/Recents.java
@@ -53,6 +53,7 @@
import com.android.systemui.recents.events.activity.RecentsActivityStartingEvent;
import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent;
import com.android.systemui.recents.events.component.ScreenPinningRequestEvent;
+import com.android.systemui.recents.events.component.ShowUserToastEvent;
import com.android.systemui.recents.events.ui.RecentsDrawnEvent;
import com.android.systemui.recents.misc.SystemServicesProxy;
import com.android.systemui.recents.model.RecentsTaskLoader;
@@ -455,8 +456,8 @@
mDraggingInRecentsCurrentUser = currentUser;
return true;
} else {
- Toast.makeText(mContext, R.string.recents_incompatible_app_message,
- Toast.LENGTH_SHORT).show();
+ EventBus.getDefault().send(new ShowUserToastEvent(
+ R.string.recents_incompatible_app_message, Toast.LENGTH_SHORT));
return false;
}
} else {
@@ -674,6 +675,27 @@
mImpl.onConfigurationChanged();
}
+ public final void onBusEvent(ShowUserToastEvent event) {
+ int currentUser = sSystemServicesProxy.getCurrentUser();
+ if (sSystemServicesProxy.isSystemUser(currentUser)) {
+ mImpl.onShowCurrentUserToast(event.msgResId, event.msgLength);
+ } else {
+ if (mSystemToUserCallbacks != null) {
+ IRecentsNonSystemUserCallbacks callbacks =
+ mSystemToUserCallbacks.getNonSystemUserRecentsForUser(currentUser);
+ if (callbacks != null) {
+ try {
+ callbacks.showCurrentUserToast(event.msgResId, event.msgLength);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Callback failed", e);
+ }
+ } else {
+ Log.e(TAG, "No SystemUI callbacks found for user: " + currentUser);
+ }
+ }
+ }
+ }
+
/**
* Attempts to register with the system user.
*/
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java
index 2757fc4..5519b92 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java
@@ -40,6 +40,7 @@
import android.view.ViewConfiguration;
import android.view.WindowManager;
+import android.widget.Toast;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.policy.DockedDividerUtils;
import com.android.systemui.R;
@@ -392,6 +393,10 @@
EventBus.getDefault().sendOntoMainThread(new DraggingInRecentsEndedEvent(velocity));
}
+ public void onShowCurrentUserToast(int msgResId, int msgLength) {
+ Toast.makeText(mContext, msgResId, msgLength).show();
+ }
+
/**
* Transitions to the next recent task in the stack.
*/
diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsImplProxy.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsImplProxy.java
index 60bf760..ff9e89e9 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/RecentsImplProxy.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsImplProxy.java
@@ -38,6 +38,7 @@
private static final int MSG_DOCK_TOP_TASK = 7;
private static final int MSG_ON_DRAGGING_IN_RECENTS = 8;
private static final int MSG_ON_DRAGGING_IN_RECENTS_ENDED = 9;
+ private static final int MSG_SHOW_USER_TOAST = 10;
private RecentsImpl mImpl;
@@ -109,6 +110,11 @@
mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_DRAGGING_IN_RECENTS_ENDED, velocity));
}
+ @Override
+ public void showCurrentUserToast(int msgResId, int msgLength) {
+ mHandler.sendMessage(mHandler.obtainMessage(MSG_SHOW_USER_TOAST, msgResId, msgLength));
+ }
+
private final Handler mHandler = new Handler() {
@Override
@@ -147,6 +153,9 @@
case MSG_ON_DRAGGING_IN_RECENTS_ENDED:
mImpl.onDraggingInRecentsEnded((Float) msg.obj);
break;
+ case MSG_SHOW_USER_TOAST:
+ mImpl.onShowCurrentUserToast(msg.arg1, msg.arg2);
+ break;
default:
super.handleMessage(msg);
}
diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/component/ShowUserToastEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/component/ShowUserToastEvent.java
new file mode 100644
index 0000000..e2b39c3
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/recents/events/component/ShowUserToastEvent.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2016 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.recents.events.component;
+
+import com.android.systemui.recents.events.EventBus;
+
+/**
+ * This is sent when we want to show a toast for the current user.
+ */
+public class ShowUserToastEvent extends EventBus.Event {
+
+ public final int msgResId;
+ public final int msgLength;
+
+ public ShowUserToastEvent(int msgResId, int msgLength) {
+ this.msgResId = msgResId;
+ this.msgLength = msgLength;
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java
index 702b076d..fce7f9d 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java
@@ -1258,7 +1258,7 @@
String innerPrefix = prefix + " ";
writer.print(prefix); writer.print(TAG);
- writer.write(" numStackTasks="); writer.write(mNumStackTasks);
+ writer.write(" numStackTasks="); writer.print(mNumStackTasks);
writer.println();
writer.print(innerPrefix);
diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/ForcedResizableInfoActivityController.java b/packages/SystemUI/src/com/android/systemui/stackdivider/ForcedResizableInfoActivityController.java
index 5f083d5..5920f46 100644
--- a/packages/SystemUI/src/com/android/systemui/stackdivider/ForcedResizableInfoActivityController.java
+++ b/packages/SystemUI/src/com/android/systemui/stackdivider/ForcedResizableInfoActivityController.java
@@ -20,12 +20,14 @@
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
+import android.os.UserHandle;
import android.util.ArraySet;
import android.widget.Toast;
import com.android.systemui.R;
import com.android.systemui.recents.events.EventBus;
import com.android.systemui.recents.events.activity.AppTransitionFinishedEvent;
+import com.android.systemui.recents.events.component.ShowUserToastEvent;
import com.android.systemui.recents.misc.SystemServicesProxy;
import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener;
import com.android.systemui.stackdivider.events.StartedDragingEvent;
@@ -100,9 +102,8 @@
}
private void activityDismissingDockedStack() {
- Toast toast = Toast.makeText(mContext, R.string.dock_non_resizeble_failed_to_dock_text,
- Toast.LENGTH_SHORT);
- toast.show();
+ EventBus.getDefault().send(new ShowUserToastEvent(
+ R.string.dock_non_resizeble_failed_to_dock_text, Toast.LENGTH_SHORT));
}
private void showPending() {
@@ -112,7 +113,7 @@
ActivityOptions options = ActivityOptions.makeBasic();
options.setLaunchTaskId(mPendingTaskIds.valueAt(i));
options.setTaskOverlay(true);
- mContext.startActivity(intent, options.toBundle());
+ mContext.startActivityAsUser(intent, options.toBundle(), UserHandle.CURRENT);
}
mPendingTaskIds.clear();
}