Fix some crashes and caching issues

This commit is contained in:
Cameron Gutman
2015-01-31 17:01:46 -05:00
parent baa5199b83
commit 56f438fe47
2 changed files with 16 additions and 4 deletions
+7 -3
View File
@@ -92,9 +92,6 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
// Get the computer object // Get the computer object
computer = managerBinder.getComputer(UUID.fromString(uuidString)); computer = managerBinder.getComputer(UUID.fromString(uuidString));
// Start updates
startComputerUpdates();
try { try {
appGridAdapter = new AppGridAdapter(AppView.this, appGridAdapter = new AppGridAdapter(AppView.this,
PreferenceConfiguration.readPreferences(AppView.this).listMode, PreferenceConfiguration.readPreferences(AppView.this).listMode,
@@ -106,6 +103,9 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
return; return;
} }
// Start updates
startComputerUpdates();
// Load the app grid with cached data (if possible) // Load the app grid with cached data (if possible)
populateAppGridWithCache(); populateAppGridWithCache();
@@ -226,6 +226,10 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
updateUiWithAppList(applist); updateUiWithAppList(applist);
LimeLog.info("Loaded applist from cache"); LimeLog.info("Loaded applist from cache");
} catch (Exception e) { } catch (Exception e) {
if (lastRawApplist != null) {
LimeLog.warning("Saved applist corrupted: "+lastRawApplist);
e.printStackTrace();
}
LimeLog.info("Loading applist from the network"); LimeLog.info("Loading applist from the network");
// We'll need to load from the network // We'll need to load from the network
loadAppsBlocking(); loadAppsBlocking();
@@ -3,8 +3,10 @@ package com.limelight.computers;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@@ -12,6 +14,7 @@ import com.limelight.LimeLog;
import com.limelight.binding.PlatformBinding; import com.limelight.binding.PlatformBinding;
import com.limelight.discovery.DiscoveryService; import com.limelight.discovery.DiscoveryService;
import com.limelight.nvstream.http.ComputerDetails; import com.limelight.nvstream.http.ComputerDetails;
import com.limelight.nvstream.http.NvApp;
import com.limelight.nvstream.http.NvHTTP; import com.limelight.nvstream.http.NvHTTP;
import com.limelight.nvstream.mdns.MdnsComputer; import com.limelight.nvstream.mdns.MdnsComputer;
import com.limelight.nvstream.mdns.MdnsDiscoveryListener; import com.limelight.nvstream.mdns.MdnsDiscoveryListener;
@@ -24,6 +27,8 @@ import android.content.ServiceConnection;
import android.os.Binder; import android.os.Binder;
import android.os.IBinder; import android.os.IBinder;
import org.xmlpull.v1.XmlPullParserException;
public class ComputerManagerService extends Service { public class ComputerManagerService extends Service {
private static final int POLLING_PERIOD_MS = 3000; private static final int POLLING_PERIOD_MS = 3000;
private static final int MDNS_QUERY_PERIOD_MS = 1000; private static final int MDNS_QUERY_PERIOD_MS = 1000;
@@ -544,7 +549,8 @@ public class ComputerManagerService extends Service {
try { try {
// Query the app list from the server // Query the app list from the server
String appList = http.getAppListRaw(); String appList = http.getAppListRaw();
if (appList != null && !appList.isEmpty()) { List<NvApp> list = NvHTTP.getAppListByReader(new StringReader(appList));
if (appList != null && !appList.isEmpty() && !list.isEmpty()) {
// Open the cache file // Open the cache file
FileOutputStream cacheOut = CacheHelper.openCacheFileForOutput(getCacheDir(), "applist", computer.uuid.toString()); FileOutputStream cacheOut = CacheHelper.openCacheFileForOutput(getCacheDir(), "applist", computer.uuid.toString());
CacheHelper.writeStringToOutputStream(cacheOut, appList); CacheHelper.writeStringToOutputStream(cacheOut, appList);
@@ -564,6 +570,8 @@ public class ComputerManagerService extends Service {
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} }
} while (waitPollingDelay()); } while (waitPollingDelay());
} }