diff options
Diffstat (limited to 'src/com/android/browser')
-rw-r--r-- | src/com/android/browser/BrowserActivity.java | 164 | ||||
-rw-r--r-- | src/com/android/browser/TabControl.java | 9 |
2 files changed, 71 insertions, 102 deletions
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index 66832ed..c20c5a3 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -20,7 +20,6 @@ import com.google.android.googleapps.IGoogleLoginService; import com.google.android.googlelogin.GoogleLoginServiceConstants; import android.app.Activity; -import android.app.ActivityManager; import android.app.AlertDialog; import android.app.ProgressDialog; import android.app.SearchManager; @@ -721,6 +720,69 @@ public class BrowserActivity extends Activity PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Browser"); + /* enables registration for changes in network status from + http stack */ + mNetworkStateChangedFilter = new IntentFilter(); + mNetworkStateChangedFilter.addAction( + ConnectivityManager.CONNECTIVITY_ACTION); + mNetworkStateIntentReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals( + ConnectivityManager.CONNECTIVITY_ACTION)) { + boolean down = intent.getBooleanExtra( + ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); + onNetworkToggle(!down); + } + } + }; + + IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); + filter.addAction(Intent.ACTION_PACKAGE_REMOVED); + filter.addDataScheme("package"); + mPackageInstallationReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + final String action = intent.getAction(); + final String packageName = intent.getData() + .getSchemeSpecificPart(); + final boolean replacing = intent.getBooleanExtra( + Intent.EXTRA_REPLACING, false); + if (Intent.ACTION_PACKAGE_REMOVED.equals(action) && replacing) { + // if it is replacing, refreshPlugins() when adding + return; + } + PackageManager pm = BrowserActivity.this.getPackageManager(); + PackageInfo pkgInfo = null; + try { + pkgInfo = pm.getPackageInfo(packageName, + PackageManager.GET_PERMISSIONS); + } catch (PackageManager.NameNotFoundException e) { + return; + } + if (pkgInfo != null) { + String permissions[] = pkgInfo.requestedPermissions; + if (permissions == null) { + return; + } + boolean permissionOk = false; + for (String permit : permissions) { + if (PluginManager.PLUGIN_PERMISSION.equals(permit)) { + permissionOk = true; + break; + } + } + if (permissionOk) { + PluginManager.getInstance(BrowserActivity.this) + .refreshPlugins( + Intent.ACTION_PACKAGE_ADDED + .equals(action)); + } + } + } + }; + registerReceiver(mPackageInstallationReceiver, filter); + // If this was a web search request, pass it on to the default web search provider. if (handleWebSearchIntent(getIntent())) { moveTaskToBack(true); @@ -787,74 +849,12 @@ public class BrowserActivity extends Activity // are not animating from the tab picker. attachTabToContentView(mTabControl.getCurrentTab()); } + // Read JavaScript flags if it exists. String jsFlags = mSettings.getJsFlags(); if (jsFlags.trim().length() != 0) { mTabControl.getCurrentWebView().setJsFlags(jsFlags); } - - /* enables registration for changes in network status from - http stack */ - mNetworkStateChangedFilter = new IntentFilter(); - mNetworkStateChangedFilter.addAction( - ConnectivityManager.CONNECTIVITY_ACTION); - mNetworkStateIntentReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals( - ConnectivityManager.CONNECTIVITY_ACTION)) { - boolean down = intent.getBooleanExtra( - ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); - onNetworkToggle(!down); - } - } - }; - - IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); - filter.addAction(Intent.ACTION_PACKAGE_REMOVED); - filter.addDataScheme("package"); - mPackageInstallationReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - final String action = intent.getAction(); - final String packageName = intent.getData() - .getSchemeSpecificPart(); - final boolean replacing = intent.getBooleanExtra( - Intent.EXTRA_REPLACING, false); - if (Intent.ACTION_PACKAGE_REMOVED.equals(action) && replacing) { - // if it is replacing, refreshPlugins() when adding - return; - } - PackageManager pm = BrowserActivity.this.getPackageManager(); - PackageInfo pkgInfo = null; - try { - pkgInfo = pm.getPackageInfo(packageName, - PackageManager.GET_PERMISSIONS); - } catch (PackageManager.NameNotFoundException e) { - return; - } - if (pkgInfo != null) { - String permissions[] = pkgInfo.requestedPermissions; - if (permissions == null) { - return; - } - boolean permissionOk = false; - for (String permit : permissions) { - if (PluginManager.PLUGIN_PERMISSION.equals(permit)) { - permissionOk = true; - break; - } - } - if (permissionOk) { - PluginManager.getInstance(BrowserActivity.this) - .refreshPlugins( - Intent.ACTION_PACKAGE_ADDED - .equals(action)); - } - } - } - }; - registerReceiver(mPackageInstallationReceiver, filter); } @Override @@ -2830,8 +2830,7 @@ public class BrowserActivity extends Activity private static final int ANIMATE_FROM_OVERVIEW = 104; private static final int ANIMATE_TO_OVERVIEW = 105; private static final int OPEN_TAB_AND_SHOW = 106; - private static final int CHECK_MEMORY = 107; - private static final int RELEASE_WAKELOCK = 108; + private static final int RELEASE_WAKELOCK = 107; // Private handler for handling javascript and saving passwords private Handler mHandler = new Handler() { @@ -2912,14 +2911,6 @@ public class BrowserActivity extends Activity resumeAfterCredentials(); break; - case CHECK_MEMORY: - // reschedule to check memory condition - mHandler.removeMessages(CHECK_MEMORY); - mHandler.sendMessageDelayed(mHandler.obtainMessage - (CHECK_MEMORY), CHECK_MEMORY_INTERVAL); - checkMemory(); - break; - case RELEASE_WAKELOCK: if (mWakeLock.isHeld()) { mWakeLock.release(); @@ -3087,10 +3078,6 @@ public class BrowserActivity extends Activity view.setNetworkAvailable(false); } } - - // schedule to check memory condition - mHandler.sendMessageDelayed(mHandler.obtainMessage(CHECK_MEMORY), - CHECK_MEMORY_INTERVAL); } @Override @@ -3198,9 +3185,6 @@ public class BrowserActivity extends Activity } } } - - mHandler.removeMessages(CHECK_MEMORY); - checkMemory(); } // return true if want to hijack the url to let another app to handle it @@ -4864,21 +4848,6 @@ public class BrowserActivity extends Activity } } - private void checkMemory() { - ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); - ((ActivityManager) getSystemService(ACTIVITY_SERVICE)) - .getMemoryInfo(mi); - // FIXME: mi.lowMemory is too aggressive, use (mi.availMem < - // mi.threshold) for now - // if (mi.lowMemory) { - if (mi.availMem < mi.threshold) { - Log.w(LOGTAG, "Browser is freeing memory now because: available=" - + (mi.availMem / 1024) + "K threshold=" - + (mi.threshold / 1024) + "K"); - mTabControl.freeMemory(); - } - } - private String smartUrlFilter(Uri inUri) { if (inUri != null) { return smartUrlFilter(inUri.toString()); @@ -5167,9 +5136,6 @@ public class BrowserActivity extends Activity final static int DOWNLOAD_PAGE = 2; final static int PREFERENCES_PAGE = 3; - // the frenquency of checking whether system memory is low - final static int CHECK_MEMORY_INTERVAL = 30000; // 30 seconds - /** * A UrlData class to abstract how the content will be set to WebView. * This base class uses loadUrl to show the content. diff --git a/src/com/android/browser/TabControl.java b/src/com/android/browser/TabControl.java index c7c3e3f..c5085b3 100644 --- a/src/com/android/browser/TabControl.java +++ b/src/com/android/browser/TabControl.java @@ -698,8 +698,10 @@ class TabControl { * WebView cache; */ void freeMemory() { + if (getTabCount() == 0) return; + // free the least frequently used background tab - Tab t = getLeastUsedTab(); + Tab t = getLeastUsedTab(getCurrentTab().getParentTab()); if (t != null) { Log.w(LOGTAG, "Free a tab in the browser"); freeTab(t); @@ -718,7 +720,7 @@ class TabControl { System.gc(); } - private Tab getLeastUsedTab() { + private Tab getLeastUsedTab(Tab currentParent) { // Don't do anything if we only have 1 tab. if (getTabCount() == 1) { return null; @@ -734,7 +736,8 @@ class TabControl { } do { t = mTabQueue.get(i++); - } while (i < queueSize && t != null && t.mMainView == null); + } while (i < queueSize + && ((t != null && t.mMainView == null) || t == currentParent)); // Don't do anything if the last remaining tab is the current one or if // the last tab has been freed already. |