Merge changes I7b5504d0,I10c263dc into oc-dev

* changes:
  Get rid of a lot of binder calls
  Fix recents entry delay
This commit is contained in:
TreeHugger Robot
2017-05-13 12:57:18 +00:00
committed by Android (Google) Code Review
9 changed files with 76 additions and 29 deletions

View File

@@ -23,7 +23,7 @@ import android.view.View;
public interface RecentsComponent { public interface RecentsComponent {
void showRecentApps(boolean triggeredFromAltTab, boolean fromHome); void showRecentApps(boolean triggeredFromAltTab, boolean fromHome);
void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey); void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey);
void toggleRecents(Display display); void toggleRecents();
void preloadRecents(); void preloadRecents();
void showNextAffiliatedTask(); void showNextAffiliatedTask();
void showPrevAffiliatedTask(); void showPrevAffiliatedTask();

View File

@@ -324,14 +324,14 @@ public class Recents extends SystemUI
@Override @Override
public void toggleRecentApps() { public void toggleRecentApps() {
toggleRecents(mContext.getSystemService(WindowManager.class).getDefaultDisplay()); toggleRecents();
} }
/** /**
* Toggles the Recents activity. * Toggles the Recents activity.
*/ */
@Override @Override
public void toggleRecents(Display display) { public void toggleRecents() {
// Ensure the device has been provisioned before allowing the user to interact with // Ensure the device has been provisioned before allowing the user to interact with
// recents // recents
if (!isUserSetup()) { if (!isUserSetup()) {

View File

@@ -222,6 +222,10 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
getApplicationContext()).onActionEnd( getApplicationContext()).onActionEnd(
LatencyTracker.ACTION_TOGGLE_RECENTS)); LatencyTracker.ACTION_TOGGLE_RECENTS));
} }
DejankUtils.postAfterTraversal(() -> {
Recents.getTaskLoader().startLoader(RecentsActivity.this);
Recents.getTaskLoader().getHighResThumbnailLoader().setVisible(true);
});
return true; return true;
} }
}; };
@@ -376,8 +380,6 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
// Notify of the next draw // Notify of the next draw
mRecentsView.getViewTreeObserver().addOnPreDrawListener(mRecentsDrawnEventListener); mRecentsView.getViewTreeObserver().addOnPreDrawListener(mRecentsDrawnEventListener);
Recents.getTaskLoader().getHighResThumbnailLoader().setVisible(true);
} }
@Override @Override

View File

@@ -27,6 +27,7 @@ import static android.provider.Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDO
import android.annotation.NonNull; import android.annotation.NonNull;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.ActivityManager.StackInfo;
import android.app.ActivityManager.TaskSnapshot; import android.app.ActivityManager.TaskSnapshot;
import android.app.ActivityOptions; import android.app.ActivityOptions;
import android.app.AppGlobals; import android.app.AppGlobals;
@@ -95,6 +96,8 @@ import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/** /**
* Acts as a shim around the real system services that we need to access data from, and provides * Acts as a shim around the real system services that we need to access data from, and provides
@@ -143,6 +146,7 @@ public class SystemServicesProxy {
Canvas mBgProtectionCanvas; Canvas mBgProtectionCanvas;
private final Handler mHandler = new H(); private final Handler mHandler = new H();
private final ExecutorService mOnewayExecutor = Executors.newSingleThreadExecutor();
/** /**
* An abstract class to track task stack changes. * An abstract class to track task stack changes.
@@ -466,13 +470,20 @@ public class SystemServicesProxy {
if (mIam == null) return false; if (mIam == null) return false;
try { try {
ActivityManager.StackInfo homeStackInfo = mIam.getStackInfo( List<StackInfo> stackInfos = mIam.getAllStackInfos();
ActivityManager.StackId.HOME_STACK_ID); ActivityManager.StackInfo homeStackInfo = null;
ActivityManager.StackInfo fullscreenStackInfo = mIam.getStackInfo( ActivityManager.StackInfo fullscreenStackInfo = null;
ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID); ActivityManager.StackInfo recentsStackInfo = null;
ActivityManager.StackInfo recentsStackInfo = mIam.getStackInfo( for (int i = 0; i < stackInfos.size(); i++) {
ActivityManager.StackId.RECENTS_STACK_ID); StackInfo stackInfo = stackInfos.get(i);
if (stackInfo.stackId == HOME_STACK_ID) {
homeStackInfo = stackInfo;
} else if (stackInfo.stackId == FULLSCREEN_WORKSPACE_STACK_ID) {
fullscreenStackInfo = stackInfo;
} else if (stackInfo.stackId == RECENTS_STACK_ID) {
recentsStackInfo = stackInfo;
}
}
boolean homeStackVisibleNotOccluded = isStackNotOccluded(homeStackInfo, boolean homeStackVisibleNotOccluded = isStackNotOccluded(homeStackInfo,
fullscreenStackInfo); fullscreenStackInfo);
boolean recentsStackVisibleNotOccluded = isStackNotOccluded(recentsStackInfo, boolean recentsStackVisibleNotOccluded = isStackNotOccluded(recentsStackInfo,
@@ -755,10 +766,12 @@ public class SystemServicesProxy {
* Sends a message to close other system windows. * Sends a message to close other system windows.
*/ */
public void sendCloseSystemWindows(String reason) { public void sendCloseSystemWindows(String reason) {
try { mOnewayExecutor.submit(() -> {
mIam.closeSystemDialogs(reason); try {
} catch (RemoteException e) { mIam.closeSystemDialogs(reason);
} } catch (RemoteException e) {
}
});
} }
/** /**
@@ -998,9 +1011,7 @@ public class SystemServicesProxy {
* Returns the current user id. * Returns the current user id.
*/ */
public int getCurrentUser() { public int getCurrentUser() {
if (mAm == null) return 0; return KeyguardUpdateMonitor.getCurrentUser();
return mAm.getCurrentUser();
} }
/** /**

View File

@@ -50,6 +50,7 @@ public class HighResThumbnailLoader implements TaskCallbacks {
private boolean mLoading; private boolean mLoading;
private boolean mVisible; private boolean mVisible;
private boolean mFlingingFast; private boolean mFlingingFast;
private boolean mTaskLoadQueueIdle;
public HighResThumbnailLoader(SystemServicesProxy ssp, Looper looper) { public HighResThumbnailLoader(SystemServicesProxy ssp, Looper looper) {
mMainThreadHandler = new Handler(looper); mMainThreadHandler = new Handler(looper);
@@ -71,13 +72,22 @@ public class HighResThumbnailLoader implements TaskCallbacks {
updateLoading(); updateLoading();
} }
/**
* Sets whether the other task load queue is idling. Avoid double-loading bitmaps by not
* starting this queue until the other queue is idling.
*/
public void setTaskLoadQueueIdle(boolean idle) {
mTaskLoadQueueIdle = idle;
updateLoading();
}
@VisibleForTesting @VisibleForTesting
boolean isLoading() { boolean isLoading() {
return mLoading; return mLoading;
} }
private void updateLoading() { private void updateLoading() {
setLoading(mVisible && !mFlingingFast); setLoading(mVisible && !mFlingingFast && mTaskLoadQueueIdle);
} }
private void setLoading(boolean loading) { private void setLoading(boolean loading) {

View File

@@ -33,6 +33,7 @@ import android.util.SparseArray;
import android.util.SparseBooleanArray; import android.util.SparseBooleanArray;
import android.util.SparseIntArray; import android.util.SparseIntArray;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.Prefs; import com.android.systemui.Prefs;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.recents.Recents; import com.android.systemui.recents.Recents;
@@ -86,7 +87,7 @@ public class RecentsTaskLoadPlan {
mCurrentQuietProfiles.clear(); mCurrentQuietProfiles.clear();
if (currentUserId == UserHandle.USER_CURRENT) { if (currentUserId == UserHandle.USER_CURRENT) {
currentUserId = ActivityManager.getCurrentUser(); currentUserId = KeyguardUpdateMonitor.getCurrentUser();
} }
UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
List<UserInfo> profiles = userManager.getProfiles(currentUserId); List<UserInfo> profiles = userManager.getProfiles(currentUserId);

View File

@@ -48,6 +48,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
* A Task load queue * A Task load queue
*/ */
class TaskResourceLoadQueue { class TaskResourceLoadQueue {
ConcurrentLinkedQueue<Task> mQueue = new ConcurrentLinkedQueue<Task>(); ConcurrentLinkedQueue<Task> mQueue = new ConcurrentLinkedQueue<Task>();
/** Adds a new task to the load queue */ /** Adds a new task to the load queue */
@@ -104,15 +105,18 @@ class BackgroundTaskLoader implements Runnable {
boolean mCancelled; boolean mCancelled;
boolean mWaitingOnLoadQueue; boolean mWaitingOnLoadQueue;
private final OnIdleChangedListener mOnIdleChangedListener;
/** Constructor, creates a new loading thread that loads task resources in the background */ /** Constructor, creates a new loading thread that loads task resources in the background */
public BackgroundTaskLoader(TaskResourceLoadQueue loadQueue, public BackgroundTaskLoader(TaskResourceLoadQueue loadQueue,
TaskKeyLruCache<Drawable> iconCache, Bitmap defaultThumbnail, TaskKeyLruCache<Drawable> iconCache, Bitmap defaultThumbnail,
BitmapDrawable defaultIcon) { BitmapDrawable defaultIcon, OnIdleChangedListener onIdleChangedListener) {
mLoadQueue = loadQueue; mLoadQueue = loadQueue;
mIconCache = iconCache; mIconCache = iconCache;
mDefaultThumbnail = defaultThumbnail; mDefaultThumbnail = defaultThumbnail;
mDefaultIcon = defaultIcon; mDefaultIcon = defaultIcon;
mMainThreadHandler = new Handler(); mMainThreadHandler = new Handler();
mOnIdleChangedListener = onIdleChangedListener;
mLoadThread = new HandlerThread("Recents-TaskResourceLoader", mLoadThread = new HandlerThread("Recents-TaskResourceLoader",
android.os.Process.THREAD_PRIORITY_BACKGROUND); android.os.Process.THREAD_PRIORITY_BACKGROUND);
mLoadThread.start(); mLoadThread.start();
@@ -169,7 +173,11 @@ class BackgroundTaskLoader implements Runnable {
synchronized(mLoadQueue) { synchronized(mLoadQueue) {
try { try {
mWaitingOnLoadQueue = true; mWaitingOnLoadQueue = true;
mMainThreadHandler.post(
() -> mOnIdleChangedListener.onIdleChanged(true));
mLoadQueue.wait(); mLoadQueue.wait();
mMainThreadHandler.post(
() -> mOnIdleChangedListener.onIdleChanged(false));
mWaitingOnLoadQueue = false; mWaitingOnLoadQueue = false;
} catch (InterruptedException ie) { } catch (InterruptedException ie) {
ie.printStackTrace(); ie.printStackTrace();
@@ -230,6 +238,10 @@ class BackgroundTaskLoader implements Runnable {
} }
} }
} }
interface OnIdleChangedListener {
void onIdleChanged(boolean idle);
}
} }
/** /**
@@ -298,15 +310,16 @@ public class RecentsTaskLoader {
// Initialize the proxy, cache and loaders // Initialize the proxy, cache and loaders
int numRecentTasks = ActivityManager.getMaxRecentTasksStatic(); int numRecentTasks = ActivityManager.getMaxRecentTasksStatic();
mHighResThumbnailLoader = new HighResThumbnailLoader(Recents.getSystemServices(),
Looper.getMainLooper());
mLoadQueue = new TaskResourceLoadQueue(); mLoadQueue = new TaskResourceLoadQueue();
mIconCache = new TaskKeyLruCache<>(iconCacheSize, mClearActivityInfoOnEviction); mIconCache = new TaskKeyLruCache<>(iconCacheSize, mClearActivityInfoOnEviction);
mActivityLabelCache = new TaskKeyLruCache<>(numRecentTasks, mClearActivityInfoOnEviction); mActivityLabelCache = new TaskKeyLruCache<>(numRecentTasks, mClearActivityInfoOnEviction);
mContentDescriptionCache = new TaskKeyLruCache<>(numRecentTasks, mContentDescriptionCache = new TaskKeyLruCache<>(numRecentTasks,
mClearActivityInfoOnEviction); mClearActivityInfoOnEviction);
mActivityInfoCache = new LruCache(numRecentTasks); mActivityInfoCache = new LruCache(numRecentTasks);
mLoader = new BackgroundTaskLoader(mLoadQueue, mIconCache, mDefaultThumbnail, mDefaultIcon); mLoader = new BackgroundTaskLoader(mLoadQueue, mIconCache, mDefaultThumbnail, mDefaultIcon,
mHighResThumbnailLoader = new HighResThumbnailLoader(Recents.getSystemServices(), mHighResThumbnailLoader::setTaskLoadQueueIdle);
Looper.getMainLooper());
} }
/** Returns the size of the app icon cache. */ /** Returns the size of the app icon cache. */
@@ -360,9 +373,6 @@ public class RecentsTaskLoader {
mTempCache.evictAll(); mTempCache.evictAll();
if (!opts.onlyLoadForCache) { if (!opts.onlyLoadForCache) {
mNumVisibleTasksLoaded = opts.numVisibleTasks; mNumVisibleTasksLoaded = opts.numVisibleTasks;
// Start the loader
mLoader.start(context);
} }
} }
@@ -607,6 +617,13 @@ public class RecentsTaskLoader {
return activityInfo; return activityInfo;
} }
/**
* Starts loading tasks.
*/
public void startLoader(Context ctx) {
mLoader.start(ctx);
}
/** /**
* Stops the task loader and clears all queued, pending task loads. * Stops the task loader and clears all queued, pending task loads.
*/ */

View File

@@ -1159,7 +1159,7 @@ public class DividerView extends FrameLayout implements OnTouchListener,
*/ */
public int growsRecents() { public int growsRecents() {
boolean result = mGrowRecents boolean result = mGrowRecents
&& mWindowManagerProxy.getDockSide() == WindowManager.DOCKED_TOP && mDockSide == WindowManager.DOCKED_TOP
&& getCurrentPosition() == getSnapAlgorithm().getLastSplitTarget().position; && getCurrentPosition() == getSnapAlgorithm().getLastSplitTarget().position;
if (result) { if (result) {
return getSnapAlgorithm().getMiddleTarget().position; return getSnapAlgorithm().getMiddleTarget().position;

View File

@@ -62,6 +62,7 @@ public class HighResThumbnailLoaderTest extends SysuiTestCase {
when(mMockSystemServicesProxy.getTaskThumbnail(anyInt(), anyBoolean())) when(mMockSystemServicesProxy.getTaskThumbnail(anyInt(), anyBoolean()))
.thenReturn(mThumbnailData); .thenReturn(mThumbnailData);
mLoader.setVisible(true); mLoader.setVisible(true);
mLoader.setTaskLoadQueueIdle(true);
} }
@Test @Test
@@ -75,6 +76,11 @@ public class HighResThumbnailLoaderTest extends SysuiTestCase {
assertFalse(mLoader.isLoading()); assertFalse(mLoader.isLoading());
mLoader.setFlingingFast(false); mLoader.setFlingingFast(false);
assertTrue(mLoader.isLoading()); assertTrue(mLoader.isLoading());
mLoader.setFlingingFast(false);
mLoader.setTaskLoadQueueIdle(false);
assertFalse(mLoader.isLoading());
mLoader.setTaskLoadQueueIdle(true);
assertTrue(mLoader.isLoading());
} }
@Test @Test