28
28
import android .os .Looper ;
29
29
import android .os .Process ;
30
30
import android .os .UserHandle ;
31
- import androidx .annotation .Nullable ;
32
31
import android .text .TextUtils ;
33
32
import android .util .Log ;
34
33
import android .util .Pair ;
61
60
import com .android .launcher3 .util .Thunk ;
62
61
import com .android .launcher3 .util .ViewOnDrawExecutor ;
63
62
import com .android .launcher3 .widget .WidgetListRowEntry ;
63
+ import com .android .mxlibrary .util .XLog ;
64
64
65
65
import java .io .FileDescriptor ;
66
66
import java .io .PrintWriter ;
72
72
import java .util .concurrent .CancellationException ;
73
73
import java .util .concurrent .Executor ;
74
74
75
+ import androidx .annotation .Nullable ;
76
+
75
77
import static com .android .launcher3 .LauncherAppState .ACTION_FORCE_ROLOAD ;
76
78
import static com .android .launcher3 .config .FeatureFlags .IS_DOGFOOD_BUILD ;
77
79
@@ -197,12 +199,18 @@ public void bindAppsAdded(ArrayList<Long> newScreens,
197
199
* Runs the specified runnable immediately if called from the worker thread, otherwise it is
198
200
* posted on the worker thread handler.
199
201
*/
200
- private static void runOnWorkerThread (Runnable r ) {
202
+ private static void runOnWorkerThread (Runnable r , boolean isRemoveAfterRun ) {
201
203
if (sWorkerThread .getThreadId () == Process .myTid ()) {
204
+ XLog .e (XLog .getTag (), XLog .TAG_GU );
202
205
r .run ();
203
206
} else {
207
+ XLog .e (XLog .getTag (), XLog .TAG_GU );
204
208
// If we are not on the worker thread, then post to the worker handler
205
209
sWorker .post (r );
210
+ // TODO 存在部分系统会重新调用问题
211
+ if (isRemoveAfterRun ) {
212
+ sWorker .removeCallbacks (r );
213
+ }
206
214
}
207
215
}
208
216
@@ -289,18 +297,19 @@ public void run() {
289
297
}
290
298
}
291
299
};
292
- runOnWorkerThread (r );
300
+ runOnWorkerThread (r , false );
293
301
}
294
302
295
303
/**
296
304
* Update the order of the workspace screens in the database. The array list contains
297
305
* a list of screen ids in the order that they should appear.
298
306
*/
299
307
public static void updateWorkspaceScreenOrder (Context context , final ArrayList <Long > screens ) {
300
- final ArrayList <Long > screensCopy = new ArrayList <Long >(screens );
308
+ XLog .e (XLog .getTag (), XLog .TAG_GU + screens );
309
+ final ArrayList <Long > screensCopy = new ArrayList <>(screens );
301
310
final ContentResolver cr = context .getContentResolver ();
302
311
final Uri uri = LauncherSettings .WorkspaceScreens .CONTENT_URI ;
303
-
312
+ XLog . e ( XLog . getTag (), XLog . TAG_GU );
304
313
// Remove any negative screen ids -- these aren't persisted
305
314
Iterator <Long > iter = screensCopy .iterator ();
306
315
while (iter .hasNext ()) {
@@ -309,13 +318,14 @@ public static void updateWorkspaceScreenOrder(Context context, final ArrayList<L
309
318
iter .remove ();
310
319
}
311
320
}
312
-
321
+ XLog . e ( XLog . getTag (), XLog . TAG_GU );
313
322
Runnable r = new Runnable () {
314
323
@ Override
315
324
public void run () {
316
325
ArrayList <ContentProviderOperation > ops = new ArrayList <ContentProviderOperation >();
317
326
// Clear the table
318
327
ops .add (ContentProviderOperation .newDelete (uri ).build ());
328
+ XLog .e (XLog .getTag (), XLog .TAG_GU + screensCopy );
319
329
int count = screensCopy .size ();
320
330
for (int i = 0 ; i < count ; i ++) {
321
331
ContentValues v = new ContentValues ();
@@ -326,8 +336,10 @@ public void run() {
326
336
}
327
337
328
338
try {
339
+ XLog .e (XLog .getTag (), XLog .TAG_GU + ops );
329
340
cr .applyBatch (LauncherProvider .AUTHORITY , ops );
330
341
} catch (Exception ex ) {
342
+ XLog .e (XLog .getTag (), XLog .TAG_GU + ex .getMessage ());
331
343
throw new RuntimeException (ex );
332
344
}
333
345
@@ -337,7 +349,8 @@ public void run() {
337
349
}
338
350
}
339
351
};
340
- runOnWorkerThread (r );
352
+ XLog .e (XLog .getTag (), XLog .TAG_GU );
353
+ runOnWorkerThread (r , true );
341
354
}
342
355
343
356
/**
@@ -455,6 +468,7 @@ public void onReceive(Context context, Intent intent) {
455
468
* not be called as DB updates are automatically followed by UI update
456
469
*/
457
470
public void forceReload () {
471
+ XLog .e (XLog .getTag (), XLog .TAG_GU );
458
472
synchronized (mLock ) {
459
473
// Stop any existing loaders first, so they don't set mModelLoaded to true later
460
474
stopLoader ();
@@ -479,6 +493,7 @@ public boolean isCurrentCallbacks(Callbacks callbacks) {
479
493
* @return true if the page could be bound synchronously.
480
494
*/
481
495
public boolean startLoader (int synchronousBindPage ) {
496
+ XLog .e (XLog .getTag (), XLog .TAG_GU );
482
497
// Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems
483
498
InstallShortcutReceiver .enableInstallQueue (InstallShortcutReceiver .FLAG_LOADER_RUNNING );
484
499
synchronized (mLock ) {
@@ -527,7 +542,7 @@ public void startLoaderForResults(LoaderResults results) {
527
542
synchronized (mLock ) {
528
543
stopLoader ();
529
544
mLoaderTask = new LoaderTask (mApp , mBgAllAppsList , sBgDataModel , results );
530
- runOnWorkerThread (mLoaderTask );
545
+ runOnWorkerThread (mLoaderTask , false );
531
546
}
532
547
}
533
548
@@ -614,7 +629,7 @@ public void onPackageIconsUpdated(HashSet<String> updatedPackages, UserHandle us
614
629
615
630
public void enqueueModelUpdateTask (ModelUpdateTask task ) {
616
631
task .init (mApp , this , sBgDataModel , mBgAllAppsList , mUiExecutor );
617
- runOnWorkerThread (task );
632
+ runOnWorkerThread (task , false );
618
633
}
619
634
620
635
/**
0 commit comments