diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2010-05-03 17:23:01 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2010-05-03 17:23:01 -0700 |
commit | fbbd2aced9ace1d063ad166d96a605446a9d2f7e (patch) | |
tree | 3e81e7b3183415ea4746ea11201d0bcce3d44dc6 | |
parent | 1ff2c0df2ec8db9aa558ef1f3948ac5f3bd9d6cd (diff) | |
parent | 2ceb570ad3b37fca2169ea9f453984cebf8c372c (diff) | |
download | packages_apps_Browser-fbbd2aced9ace1d063ad166d96a605446a9d2f7e.zip packages_apps_Browser-fbbd2aced9ace1d063ad166d96a605446a9d2f7e.tar.gz packages_apps_Browser-fbbd2aced9ace1d063ad166d96a605446a9d2f7e.tar.bz2 |
merge from open-source master
Change-Id: I5dbf9446b7d4409ec843ee800c82ec06bda7c8db
-rw-r--r-- | src/com/android/browser/BrowserBackupAgent.java | 57 | ||||
-rw-r--r-- | src/com/android/browser/ErrorConsoleView.java | 2 | ||||
-rw-r--r-- | src/com/android/browser/WebsiteSettingsActivity.java | 105 |
3 files changed, 94 insertions, 70 deletions
diff --git a/src/com/android/browser/BrowserBackupAgent.java b/src/com/android/browser/BrowserBackupAgent.java index 6f6e829..c968ce5 100644 --- a/src/com/android/browser/BrowserBackupAgent.java +++ b/src/com/android/browser/BrowserBackupAgent.java @@ -84,6 +84,10 @@ public class BrowserBackupAgent extends BackupAgent { savedVersion = in.readInt(); } catch (EOFException e) { // It means we had no previous state; that's fine + } finally { + if (in != null) { + in.close(); + } } // Build a flattened representation of the bookmarks table @@ -174,6 +178,10 @@ public class BrowserBackupAgent extends BackupAgent { } catch (IOException ioe) { Log.w(TAG, "Bad backup data; not restoring"); crc = -1; + } finally { + if (in != null) { + in.close(); + } } } @@ -187,7 +195,7 @@ public class BrowserBackupAgent extends BackupAgent { } } - class Bookmark { + static class Bookmark { public String url; public int visits; public long date; @@ -258,13 +266,18 @@ public class BrowserBackupAgent extends BackupAgent { data.writeEntityHeader(key, toCopy); FileInputStream in = new FileInputStream(file); - int nRead; - while (toCopy > 0) { - nRead = in.read(buf, 0, CHUNK); - data.writeEntityData(buf, nRead); - toCopy -= nRead; + try { + int nRead; + while (toCopy > 0) { + nRead = in.read(buf, 0, CHUNK); + data.writeEntityData(buf, nRead); + toCopy -= nRead; + } + } finally { + if (in != null) { + in.close(); + } } - in.close(); } // Read the given file from backup to a file, calculating a CRC32 along the way @@ -275,14 +288,18 @@ public class BrowserBackupAgent extends BackupAgent { CRC32 crc = new CRC32(); FileOutputStream out = new FileOutputStream(file); - while (toRead > 0) { - int numRead = data.readEntityData(buf, 0, CHUNK); - crc.update(buf, 0, numRead); - out.write(buf, 0, numRead); - toRead -= numRead; + try { + while (toRead > 0) { + int numRead = data.readEntityData(buf, 0, CHUNK); + crc.update(buf, 0, numRead); + out.write(buf, 0, numRead); + toRead -= numRead; + } + } finally { + if (out != null) { + out.close(); + } } - - out.close(); return crc.getValue(); } @@ -291,8 +308,14 @@ public class BrowserBackupAgent extends BackupAgent { throws IOException { DataOutputStream out = new DataOutputStream( new FileOutputStream(stateFile.getFileDescriptor())); - out.writeLong(fileSize); - out.writeLong(crc); - out.writeInt(BACKUP_AGENT_VERSION); + try { + out.writeLong(fileSize); + out.writeLong(crc); + out.writeInt(BACKUP_AGENT_VERSION); + } finally { + if (out != null) { + out.close(); + } + } } } diff --git a/src/com/android/browser/ErrorConsoleView.java b/src/com/android/browser/ErrorConsoleView.java index 0f87cb5..ca5fed4 100644 --- a/src/com/android/browser/ErrorConsoleView.java +++ b/src/com/android/browser/ErrorConsoleView.java @@ -230,7 +230,7 @@ import java.util.Vector; * This class is an adapter for ErrorConsoleListView that contains the error console * message data. */ - private class ErrorConsoleMessageList extends android.widget.BaseAdapter + private static class ErrorConsoleMessageList extends android.widget.BaseAdapter implements android.widget.ListAdapter { private Vector<ConsoleMessage> mMessages; diff --git a/src/com/android/browser/WebsiteSettingsActivity.java b/src/com/android/browser/WebsiteSettingsActivity.java index 430286f..1e27092 100644 --- a/src/com/android/browser/WebsiteSettingsActivity.java +++ b/src/com/android/browser/WebsiteSettingsActivity.java @@ -62,7 +62,7 @@ public class WebsiteSettingsActivity extends ListActivity { private static String sMBStored = null; private SiteAdapter mAdapter = null; - class Site { + static class Site { private String mOrigin; private String mTitle; private Bitmap mIcon; @@ -190,7 +190,7 @@ public class WebsiteSettingsActivity extends ListActivity { * Adds the specified feature to the site corresponding to supplied * origin in the map. Creates the site if it does not already exist. */ - private void addFeatureToSite(Map sites, String origin, int feature) { + private void addFeatureToSite(Map<String, Site> sites, String origin, int feature) { Site site = null; if (sites.containsKey(origin)) { site = (Site) sites.get(origin); @@ -213,7 +213,7 @@ public class WebsiteSettingsActivity extends ListActivity { WebStorage.getInstance().getOrigins(new ValueCallback<Map>() { public void onReceiveValue(Map origins) { - Map sites = new HashMap<String, Site>(); + Map<String, Site> sites = new HashMap<String, Site>(); if (origins != null) { Iterator<String> iter = origins.keySet().iterator(); while (iter.hasNext()) { @@ -225,7 +225,7 @@ public class WebsiteSettingsActivity extends ListActivity { }); } - public void askForGeolocation(final Map sites) { + public void askForGeolocation(final Map<String, Site> sites) { GeolocationPermissions.getInstance().getOrigins(new ValueCallback<Set<String> >() { public void onReceiveValue(Set<String> origins) { if (origins != null) { @@ -240,19 +240,19 @@ public class WebsiteSettingsActivity extends ListActivity { }); } - public void populateIcons(Map sites) { + public void populateIcons(Map<String, Site> sites) { // Create a map from host to origin. This is used to add metadata // (title, icon) for this origin from the bookmarks DB. - HashMap hosts = new HashMap<String, Set<Site> >(); - Set keys = sites.keySet(); - Iterator<String> originIter = keys.iterator(); + HashMap<String, Set<Site>> hosts = new HashMap<String, Set<Site>>(); + Set<Map.Entry<String, Site>> elements = sites.entrySet(); + Iterator<Map.Entry<String, Site>> originIter = elements.iterator(); while (originIter.hasNext()) { - String origin = originIter.next(); - Site site = (Site) sites.get(origin); - String host = Uri.parse(origin).getHost(); - Set hostSites = null; + Map.Entry<String, Site> entry = originIter.next(); + Site site = entry.getValue(); + String host = Uri.parse(entry.getKey()).getHost(); + Set<Site> hostSites = null; if (hosts.containsKey(host)) { - hostSites = (Set) hosts.get(host); + hostSites = (Set<Site>)hosts.get(host); } else { hostSites = new HashSet<Site>(); hosts.put(host, hostSites); @@ -266,55 +266,56 @@ public class WebsiteSettingsActivity extends ListActivity { new String[] { Browser.BookmarkColumns.URL, Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.FAVICON }, "bookmark = 1", null, null); - if ((c != null) && c.moveToFirst()) { - int urlIndex = c.getColumnIndex(Browser.BookmarkColumns.URL); - int titleIndex = c.getColumnIndex(Browser.BookmarkColumns.TITLE); - int faviconIndex = c.getColumnIndex(Browser.BookmarkColumns.FAVICON); - do { - String url = c.getString(urlIndex); - String host = Uri.parse(url).getHost(); - if (hosts.containsKey(host)) { - String title = c.getString(titleIndex); - Bitmap bmp = null; - byte[] data = c.getBlob(faviconIndex); - if (data != null) { - bmp = BitmapFactory.decodeByteArray(data, 0, data.length); - } - Set matchingSites = (Set) hosts.get(host); - Iterator<Site> sitesIter = matchingSites.iterator(); - while (sitesIter.hasNext()) { - Site site = sitesIter.next(); - // We should only set the title if the bookmark is for the root - // (i.e. www.google.com), as website settings act on the origin - // as a whole rather than a single page under that origin. If the - // user has bookmarked a page under the root but *not* the root, - // then we risk displaying the title of that page which may or - // may not have any relevance to the origin. - if (url.equals(site.getOrigin()) || - (new String(site.getOrigin()+"/")).equals(url)) { - site.setTitle(title); + if (c != null) { + if (c.moveToFirst()) { + int urlIndex = c.getColumnIndex(Browser.BookmarkColumns.URL); + int titleIndex = c.getColumnIndex(Browser.BookmarkColumns.TITLE); + int faviconIndex = c.getColumnIndex(Browser.BookmarkColumns.FAVICON); + do { + String url = c.getString(urlIndex); + String host = Uri.parse(url).getHost(); + if (hosts.containsKey(host)) { + String title = c.getString(titleIndex); + Bitmap bmp = null; + byte[] data = c.getBlob(faviconIndex); + if (data != null) { + bmp = BitmapFactory.decodeByteArray(data, 0, data.length); } - if (bmp != null) { - site.setIcon(bmp); + Set matchingSites = (Set) hosts.get(host); + Iterator<Site> sitesIter = matchingSites.iterator(); + while (sitesIter.hasNext()) { + Site site = sitesIter.next(); + // We should only set the title if the bookmark is for the root + // (i.e. www.google.com), as website settings act on the origin + // as a whole rather than a single page under that origin. If the + // user has bookmarked a page under the root but *not* the root, + // then we risk displaying the title of that page which may or + // may not have any relevance to the origin. + if (url.equals(site.getOrigin()) || + (new String(site.getOrigin()+"/")).equals(url)) { + site.setTitle(title); + } + if (bmp != null) { + site.setIcon(bmp); + } } } - } - } while (c.moveToNext()); + } while (c.moveToNext()); + } + c.close(); } - - c.close(); } - public void populateOrigins(Map sites) { + public void populateOrigins(Map<String, Site> sites) { clear(); // We can now simply populate our array with Site instances - Set keys = sites.keySet(); - Iterator<String> originIter = keys.iterator(); - while (originIter.hasNext()) { - String origin = originIter.next(); - Site site = (Site) sites.get(origin); + Set<Map.Entry<String, Site>> elements = sites.entrySet(); + Iterator<Map.Entry<String, Site>> entryIterator = elements.iterator(); + while (entryIterator.hasNext()) { + Map.Entry<String, Site> entry = entryIterator.next(); + Site site = entry.getValue(); add(site); } |