Add "Up arrow" to Browser Preferences page

Update the Browser Preferences action bar with an "up button" for
navigating browser preferences fragments.

Bug: 3259616
Change-Id: Ice22db6f49b8cec2a2e43a77ccf254c413bf39ba
diff --git a/src/com/android/browser/BrowserPreferencesPage.java b/src/com/android/browser/BrowserPreferencesPage.java
index c47675d..2b42951 100644
--- a/src/com/android/browser/BrowserPreferencesPage.java
+++ b/src/com/android/browser/BrowserPreferencesPage.java
@@ -18,8 +18,11 @@
 
 import com.android.browser.preferences.DebugPreferencesFragment;
 
+import android.app.ActionBar;
+import android.os.Bundle;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceManager;
+import android.view.MenuItem;
 
 import java.util.List;
 
@@ -27,6 +30,17 @@
 
     public static final String CURRENT_PAGE = "currentPage";
 
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+
+        ActionBar actionBar = getActionBar();
+        if (actionBar != null) {
+            actionBar.setDisplayOptions(
+                    ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
+        }
+    }
+
     /**
      * Populate the activity with the top-level headers.
      */
@@ -51,4 +65,19 @@
                 getApplicationContext(),
                 PreferenceManager.getDefaultSharedPreferences(this));
     }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        switch (item.getItemId()) {
+            case android.R.id.home:
+                if (getFragmentManager().countBackStackEntries() > 0) {
+                    getFragmentManager().popBackStack();
+                } else {
+                    finish();
+                }
+                return true;
+        }
+
+        return false;
+    }
 }