OSDN Git Service

Fix crashes in Settings + SUW
authorJason Monk <jmonk@google.com>
Thu, 3 Dec 2015 15:51:58 +0000 (10:51 -0500)
committerJason Monk <jmonk@google.com>
Thu, 3 Dec 2015 15:51:58 +0000 (10:51 -0500)
Bug: 25981625
Bug: 25989520
Bug: 25987331
Change-Id: Ib53c99edf45bb4550bfb9761ed09ca3677068591

packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java
packages/SettingsLib/src/com/android/settingslib/drawer/SettingsDrawerActivity.java

index c9a5f8f..e6fe447 100644 (file)
@@ -116,7 +116,7 @@ public class ApplicationsState {
 
     final HandlerThread mThread;
     final BackgroundHandler mBackgroundHandler;
-    final MainHandler mMainHandler = new MainHandler();
+    final MainHandler mMainHandler = new MainHandler(Looper.getMainLooper());
 
     private ApplicationsState(Application app) {
         mContext = app;
@@ -687,6 +687,10 @@ public class ApplicationsState {
         static final int MSG_LAUNCHER_INFO_CHANGED = 7;
         static final int MSG_LOAD_ENTRIES_COMPLETE = 8;
 
+        public MainHandler(Looper looper) {
+            super(looper);
+        }
+
         @Override
         public void handleMessage(Message msg) {
             rebuildActiveSessions();
index 581c810..102e47a 100644 (file)
@@ -77,10 +77,7 @@ public class SettingsDrawerActivity extends Activity {
             mDrawerLayout = null;
             return;
         }
-        if (sDashboardCategories == null) {
-            sTileCache = new HashMap<>();
-            sDashboardCategories = TileUtils.getCategories(this, sTileCache);
-        }
+        getDashboardCategories();
         setActionBar(toolbar);
         mDrawerAdapter = new SettingsDrawerAdapter(this);
         ListView listView = (ListView) findViewById(R.id.left_drawer);
@@ -109,19 +106,23 @@ public class SettingsDrawerActivity extends Activity {
     protected void onResume() {
         super.onResume();
 
-        final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
-        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
-        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
-        filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
-        filter.addDataScheme("package");
-        registerReceiver(mPackageReceiver, filter);
+        if (mDrawerLayout != null) {
+            final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
+            filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+            filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
+            filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
+            filter.addDataScheme("package");
+            registerReceiver(mPackageReceiver, filter);
 
-        new CategoriesUpdater().execute();
+            new CategoriesUpdater().execute();
+        }
     }
 
     @Override
     protected void onPause() {
-        unregisterReceiver(mPackageReceiver);
+        if (mDrawerLayout != null) {
+            unregisterReceiver(mPackageReceiver);
+        }
 
         super.onPause();
     }
@@ -178,6 +179,10 @@ public class SettingsDrawerActivity extends Activity {
     }
 
     public List<DashboardCategory> getDashboardCategories() {
+        if (sDashboardCategories == null) {
+            sTileCache = new HashMap<>();
+            sDashboardCategories = TileUtils.getCategories(this, sTileCache);
+        }
         return sDashboardCategories;
     }