OSDN Git Service

Tying LauncherAppState lifecycle with LauncherProvider
authorSunny Goyal <sunnygoyal@google.com>
Tue, 24 Nov 2015 19:40:40 +0000 (11:40 -0800)
committerSunny Goyal <sunnygoyal@google.com>
Tue, 24 Nov 2015 20:06:42 +0000 (12:06 -0800)
The content provider is the first component started with the main process,
which makes it ideal for initiating LauncherAppState

Change-Id: I03db82a8949ad1376af53a0033592f421dbf0b15

src/com/android/launcher3/InstallShortcutReceiver.java
src/com/android/launcher3/Launcher.java
src/com/android/launcher3/LauncherProvider.java
src/com/android/launcher3/WallpaperChangedReceiver.java
src/com/android/launcher3/compat/PackageInstallerCompatVL.java

index 9a75193..571d99a 100644 (file)
@@ -171,7 +171,6 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
 
     private static void queuePendingShortcutInfo(PendingInstallShortcutInfo info, Context context) {
         // Queue the item up for adding if launcher has not loaded properly yet
-        LauncherAppState.setApplicationContext(context.getApplicationContext());
         LauncherAppState app = LauncherAppState.getInstance();
         boolean launcherNotLoaded = app.getModel().getCallback() == null;
 
index 97a4eed..7b335d1 100644 (file)
@@ -417,7 +417,6 @@ public class Launcher extends Activity
 
         super.onCreate(savedInstanceState);
 
-        LauncherAppState.setApplicationContext(getApplicationContext());
         LauncherAppState app = LauncherAppState.getInstance();
 
         // Load configuration-specific DeviceProfile
index ef79cf8..f095a05 100644 (file)
@@ -84,6 +84,10 @@ public class LauncherProvider extends ContentProvider {
     @Override
     public boolean onCreate() {
         final Context context = getContext();
+        // The content provider exists for the entire duration of the launcher main process and
+        // is the first component to get created. Initializing application context here ensures
+        // that LauncherAppState always exists in the main process.
+        LauncherAppState.setApplicationContext(context.getApplicationContext());
         StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
         mOpenHelper = new DatabaseHelper(context);
         StrictMode.setThreadPolicy(oldPolicy);
index 2d5612f..c24fbff 100644 (file)
@@ -22,8 +22,6 @@ import android.content.Intent;
 
 public class WallpaperChangedReceiver extends BroadcastReceiver {
     public void onReceive(Context context, Intent data) {
-        LauncherAppState.setApplicationContext(context.getApplicationContext());
-        LauncherAppState appState = LauncherAppState.getInstance();
-        appState.onWallpaperChanged();
+        LauncherAppState.getInstance().onWallpaperChanged();
     }
 }
index 6424e03..4aa667e 100644 (file)
@@ -43,7 +43,6 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
 
     PackageInstallerCompatVL(Context context) {
         mInstaller = context.getPackageManager().getPackageInstaller();
-        LauncherAppState.setApplicationContext(context.getApplicationContext());
         mCache = LauncherAppState.getInstance().getIconCache();
         mWorker = new Handler(LauncherModel.getWorkerLooper());