Skip to content

Commit aee6cbd

Browse files
mikejurkaAndroid Git Automerger
authored andcommitted
am 80343f6: Fix recents animations for secondary users
* commit '80343f646f9686528212f82163a77ef48e30f4c3': Fix recents animations for secondary users
2 parents 01e99ad + 80343f6 commit aee6cbd

File tree

9 files changed

+237
-145
lines changed

9 files changed

+237
-145
lines changed

packages/SystemUI/AndroidManifest.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
<uses-permission android:name="android.permission.WRITE_DREAM_STATE" />
6464

6565
<application
66-
android:name="com.android.systemui.SystemUIApplication"
6766
android:persistent="true"
6867
android:allowClearUserData="false"
6968
android:allowBackup="false"
@@ -118,6 +117,15 @@
118117
</intent-filter>
119118
</activity>
120119

120+
<receiver
121+
android:name=".recent.RecentsPreloadReceiver"
122+
android:exported="false">
123+
<intent-filter>
124+
<action android:name="com.android.systemui.recent.action.PRELOAD" />
125+
<action android:name="com.android.systemui.recent.action.CANCEL_PRELOAD" />
126+
</intent-filter>
127+
</receiver>
128+
121129
<!-- started from UsbDeviceSettingsManager -->
122130
<activity android:name=".usb.UsbConfirmActivity"
123131
android:exported="true"

packages/SystemUI/src/com/android/systemui/SystemUIApplication.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

packages/SystemUI/src/com/android/systemui/recent/RecentTasksLoader.java

Lines changed: 104 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import android.os.AsyncTask;
3131
import android.os.Handler;
3232
import android.os.Process;
33+
import android.os.UserHandle;
3334
import android.util.Log;
3435
import android.view.MotionEvent;
3536
import android.view.View;
@@ -52,6 +53,8 @@ public class RecentTasksLoader implements View.OnTouchListener {
5253

5354
private Context mContext;
5455
private RecentsPanelView mRecentsPanel;
56+
57+
private Object mFirstTaskLock = new Object();
5558
private TaskDescription mFirstTask;
5659
private boolean mFirstTaskLoaded;
5760

@@ -70,23 +73,16 @@ public class RecentTasksLoader implements View.OnTouchListener {
7073
private enum State { LOADING, LOADED, CANCELLED };
7174
private State mState = State.CANCELLED;
7275

73-
public TaskDescription getFirstTask() {
74-
while (!mFirstTaskLoaded) {
75-
if (mState == State.CANCELLED) {
76-
loadTasksInBackground();
77-
}
78-
try {
79-
if (mState == State.LOADED) {
80-
break;
81-
}
82-
Thread.sleep(5);
83-
} catch (InterruptedException e) {
84-
}
76+
77+
private static RecentTasksLoader sInstance;
78+
public static RecentTasksLoader getInstance(Context context) {
79+
if (sInstance == null) {
80+
sInstance = new RecentTasksLoader(context);
8581
}
86-
return mFirstTask;
82+
return sInstance;
8783
}
8884

89-
public RecentTasksLoader(Context context) {
85+
private RecentTasksLoader(Context context) {
9086
mContext = context;
9187
mHandler = new Handler();
9288

@@ -295,15 +291,107 @@ private void cancelLoadingThumbnailsAndIcons() {
295291
mThumbnailLoader = null;
296292
}
297293
mLoadedTasks = null;
298-
mFirstTask = null;
299-
mFirstTaskLoaded = false;
300294
if (mRecentsPanel != null) {
301295
mRecentsPanel.onTaskLoadingCancelled();
302296
}
303297
mFirstScreenful = false;
304298
mState = State.CANCELLED;
305299
}
306300

301+
private void clearFirstTask() {
302+
synchronized (mFirstTaskLock) {
303+
mFirstTask = null;
304+
mFirstTaskLoaded = false;
305+
}
306+
}
307+
308+
public void preloadFirstTask() {
309+
Thread bgLoad = new Thread() {
310+
public void run() {
311+
TaskDescription first = loadFirstTask();
312+
synchronized(mFirstTaskLock) {
313+
if (mCancelPreloadingFirstTask) {
314+
clearFirstTask();
315+
} else {
316+
mFirstTask = first;
317+
mFirstTaskLoaded = true;
318+
}
319+
mPreloadingFirstTask = false;
320+
}
321+
}
322+
};
323+
synchronized(mFirstTaskLock) {
324+
if (!mPreloadingFirstTask) {
325+
clearFirstTask();
326+
mPreloadingFirstTask = true;
327+
bgLoad.start();
328+
}
329+
}
330+
}
331+
332+
public void cancelPreloadingFirstTask() {
333+
synchronized(mFirstTaskLock) {
334+
if (mPreloadingFirstTask) {
335+
mCancelPreloadingFirstTask = true;
336+
} else {
337+
clearFirstTask();
338+
}
339+
}
340+
}
341+
342+
boolean mPreloadingFirstTask;
343+
boolean mCancelPreloadingFirstTask;
344+
public TaskDescription getFirstTask() {
345+
while(true) {
346+
synchronized(mFirstTaskLock) {
347+
if (mFirstTaskLoaded) {
348+
return mFirstTask;
349+
} else if (!mFirstTaskLoaded && !mPreloadingFirstTask) {
350+
mFirstTask = loadFirstTask();
351+
mFirstTaskLoaded = true;
352+
return mFirstTask;
353+
}
354+
}
355+
try {
356+
Thread.sleep(3);
357+
} catch (InterruptedException e) {
358+
}
359+
}
360+
}
361+
362+
public TaskDescription loadFirstTask() {
363+
final ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
364+
365+
final List<ActivityManager.RecentTaskInfo> recentTasks = am.getRecentTasksForUser(
366+
1, ActivityManager.RECENT_IGNORE_UNAVAILABLE, UserHandle.CURRENT.getIdentifier());
367+
TaskDescription item = null;
368+
if (recentTasks.size() > 0) {
369+
ActivityManager.RecentTaskInfo recentInfo = recentTasks.get(0);
370+
371+
Intent intent = new Intent(recentInfo.baseIntent);
372+
if (recentInfo.origActivity != null) {
373+
intent.setComponent(recentInfo.origActivity);
374+
}
375+
376+
// Don't load the current home activity.
377+
if (isCurrentHomeActivity(intent.getComponent(), null)) {
378+
return null;
379+
}
380+
381+
// Don't load ourselves
382+
if (intent.getComponent().getPackageName().equals(mContext.getPackageName())) {
383+
return null;
384+
}
385+
386+
item = createTaskDescription(recentInfo.id,
387+
recentInfo.persistentId, recentInfo.baseIntent,
388+
recentInfo.origActivity, recentInfo.description);
389+
loadThumbnailAndIcon(item);
390+
return item;
391+
}
392+
return null;
393+
}
394+
307395
public void loadTasksInBackground() {
308396
loadTasksInBackground(false);
309397
}
@@ -367,9 +455,6 @@ protected Void doInBackground(Void... params) {
367455

368456
// Don't load the current home activity.
369457
if (isCurrentHomeActivity(intent.getComponent(), homeInfo)) {
370-
if (index == 0) {
371-
mFirstTaskLoaded = true;
372-
}
373458
continue;
374459
}
375460

@@ -466,19 +551,13 @@ protected Void doInBackground(Void... params) {
466551
}
467552
loadThumbnailAndIcon(td);
468553

469-
if (!mFirstTaskLoaded) {
470-
mFirstTask = td;
471-
mFirstTaskLoaded = true;
472-
}
473554
publishProgress(td);
474555
}
475556

476557
Process.setThreadPriority(origPri);
477558
return null;
478559
}
479560
};
480-
mFirstTask = null;
481-
mFirstTaskLoaded = false;
482561
mThumbnailLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
483562
}
484563
}

packages/SystemUI/src/com/android/systemui/recent/RecentsActivity.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@
3030
import android.view.WindowManager;
3131

3232
import com.android.systemui.R;
33-
import com.android.systemui.SystemUIApplication;
3433
import com.android.systemui.statusbar.tablet.StatusBarPanel;
3534

3635
import java.util.List;
3736

3837
public class RecentsActivity extends Activity {
39-
public static final String TOGGLE_RECENTS_INTENT = "com.android.systemui.TOGGLE_RECENTS";
40-
public static final String CLOSE_RECENTS_INTENT = "com.android.systemui.CLOSE_RECENTS";
38+
public static final String TOGGLE_RECENTS_INTENT = "com.android.systemui.recent.action.TOGGLE_RECENTS";
39+
public static final String PRELOAD_INTENT = "com.android.systemui.recent.action.PRELOAD";
40+
public static final String CANCEL_PRELOAD_INTENT = "com.android.systemui.recent.CANCEL_PRELOAD";
41+
public static final String CLOSE_RECENTS_INTENT = "com.android.systemui.recent.action.CLOSE";
42+
public static final String WINDOW_ANIMATION_START_INTENT = "com.android.systemui.recent.action.WINDOW_ANIMATION_START";
43+
public static final String PRELOAD_PERMISSION = "com.android.systemui.recent.permission.PRELOAD";
44+
public static final String WAITING_FOR_WINDOW_ANIMATION_PARAM = "com.android.systemui.recent.WAITING_FOR_WINDOW_ANIMATION";
4145
private static final String WAS_SHOWING = "was_showing";
4246

4347
private RecentsPanelView mRecentsPanel;
@@ -48,19 +52,21 @@ public class RecentsActivity extends Activity {
4852
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
4953
@Override
5054
public void onReceive(Context context, Intent intent) {
51-
if (mRecentsPanel != null && mRecentsPanel.isShowing()) {
52-
if (mShowing && !mForeground) {
53-
// Captures the case right before we transition to another activity
54-
mRecentsPanel.show(false);
55+
if (CLOSE_RECENTS_INTENT.equals(intent.getAction())) {
56+
if (mRecentsPanel != null && mRecentsPanel.isShowing()) {
57+
if (mShowing && !mForeground) {
58+
// Captures the case right before we transition to another activity
59+
mRecentsPanel.show(false);
60+
}
61+
}
62+
} else if (WINDOW_ANIMATION_START_INTENT.equals(intent.getAction())) {
63+
if (mRecentsPanel != null) {
64+
mRecentsPanel.onWindowAnimationStart();
5565
}
5666
}
5767
}
5868
};
5969

60-
public static interface WindowAnimationStartListener {
61-
void onWindowAnimationStart();
62-
}
63-
6470
public class TouchOutsideListener implements View.OnTouchListener {
6571
private StatusBarPanel mPanel;
6672

@@ -164,25 +170,23 @@ public void dismissAndGoBack() {
164170

165171
@Override
166172
protected void onCreate(Bundle savedInstanceState) {
167-
final SystemUIApplication app = (SystemUIApplication) getApplication();
168-
final RecentTasksLoader recentTasksLoader = app.getRecentTasksLoader();
169-
170173
setContentView(R.layout.status_bar_recent_panel);
171174
mRecentsPanel = (RecentsPanelView) findViewById(R.id.recents_root);
172175
mRecentsPanel.setOnTouchListener(new TouchOutsideListener(mRecentsPanel));
173-
mRecentsPanel.setRecentTasksLoader(recentTasksLoader);
176+
177+
final RecentTasksLoader recentTasksLoader = RecentTasksLoader.getInstance(this);
174178
recentTasksLoader.setRecentsPanel(mRecentsPanel, mRecentsPanel);
175179
mRecentsPanel.setMinSwipeAlpha(
176180
getResources().getInteger(R.integer.config_recent_item_min_alpha) / 100f);
177181

178182
if (savedInstanceState == null ||
179183
savedInstanceState.getBoolean(WAS_SHOWING)) {
180-
handleIntent(getIntent());
184+
handleIntent(getIntent(), (savedInstanceState == null));
181185
}
182186
mIntentFilter = new IntentFilter();
183187
mIntentFilter.addAction(CLOSE_RECENTS_INTENT);
188+
mIntentFilter.addAction(WINDOW_ANIMATION_START_INTENT);
184189
registerReceiver(mIntentReceiver, mIntentFilter);
185-
app.setWindowAnimationStartListener(mRecentsPanel);
186190
super.onCreate(savedInstanceState);
187191
}
188192

@@ -193,31 +197,29 @@ protected void onSaveInstanceState(Bundle outState) {
193197

194198
@Override
195199
protected void onDestroy() {
196-
final SystemUIApplication app = (SystemUIApplication) getApplication();
197-
final RecentTasksLoader recentTasksLoader = app.getRecentTasksLoader();
198-
recentTasksLoader.setRecentsPanel(null, mRecentsPanel);
200+
RecentTasksLoader.getInstance(this).setRecentsPanel(null, mRecentsPanel);
199201
unregisterReceiver(mIntentReceiver);
200-
app.setWindowAnimationStartListener(null);
201202
super.onDestroy();
202203
}
203204

204205
@Override
205206
protected void onNewIntent(Intent intent) {
206-
handleIntent(intent);
207+
handleIntent(intent, true);
207208
}
208209

209-
private void handleIntent(Intent intent) {
210+
private void handleIntent(Intent intent, boolean checkWaitingForAnimationParam) {
210211
super.onNewIntent(intent);
211212

212213
if (TOGGLE_RECENTS_INTENT.equals(intent.getAction())) {
213214
if (mRecentsPanel != null) {
214215
if (mRecentsPanel.isShowing()) {
215216
dismissAndGoBack();
216217
} else {
217-
final SystemUIApplication app = (SystemUIApplication) getApplication();
218-
final RecentTasksLoader recentTasksLoader = app.getRecentTasksLoader();
218+
final RecentTasksLoader recentTasksLoader = RecentTasksLoader.getInstance(this);
219+
boolean waitingForWindowAnimation = checkWaitingForAnimationParam &&
220+
intent.getBooleanExtra(WAITING_FOR_WINDOW_ANIMATION_PARAM, false);
219221
mRecentsPanel.show(true, recentTasksLoader.getLoadedTasks(),
220-
recentTasksLoader.isFirstScreenful());
222+
recentTasksLoader.isFirstScreenful(), waitingForWindowAnimation);
221223
}
222224
}
223225
}

0 commit comments

Comments
 (0)