OSDN Git Service

SslCertificate should provide Date interface
[android-x86/packages-apps-Browser.git] / src / com / android / browser / BrowserActivity.java
index d4a016d..1d57f67 100644 (file)
@@ -73,6 +73,7 @@ import android.text.TextUtils;
 import android.text.format.DateFormat;
 import android.util.AttributeSet;
 import android.util.Log;
+import android.util.Patterns;
 import android.view.ContextMenu;
 import android.view.Gravity;
 import android.view.KeyEvent;
@@ -110,12 +111,9 @@ import android.accounts.AuthenticatorException;
 import android.accounts.OperationCanceledException;
 import android.accounts.AccountManagerCallback;
 
-import com.android.common.Patterns;
 import com.android.common.Search;
 import com.android.common.speech.LoggingEvents;
 
-import com.google.android.gsf.GoogleLoginServiceConstants;
-
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
@@ -157,13 +155,20 @@ public class BrowserActivity extends Activity
     private Account[] mAccountsGoogle;
     private Account[] mAccountsPreferHosted;
 
+    // XXX: These constants should be exposed through some public api. Hardcode
+    // the values for now until some solution for gsf can be worked out.
+    // http://b/issue?id=2425179
+    private static final String ACCOUNT_TYPE = "com.google";
+    private static final String FEATURE_LEGACY_GOOGLE = "legacy_google";
+    private static final String FEATURE_LEGACY_HOSTED_OR_GOOGLE =
+            "legacy_hosted_or_google";
+
     private void startReadOfGoogleAccounts() {
         mAccountsGoogle = null;
         mAccountsPreferHosted = null;
 
         AccountManager.get(this).getAccountsByTypeAndFeatures(
-                GoogleLoginServiceConstants.ACCOUNT_TYPE,
-                new String[]{GoogleLoginServiceConstants.FEATURE_LEGACY_HOSTED_OR_GOOGLE},
+                ACCOUNT_TYPE, new String[]{ FEATURE_LEGACY_HOSTED_OR_GOOGLE },
                 this, null);
     }
 
@@ -174,8 +179,7 @@ public class BrowserActivity extends Activity
                 mAccountsGoogle = accountManagerFuture.getResult();
 
                 AccountManager.get(this).getAccountsByTypeAndFeatures(
-                        GoogleLoginServiceConstants.ACCOUNT_TYPE,
-                        new String[]{GoogleLoginServiceConstants.FEATURE_LEGACY_GOOGLE},
+                        ACCOUNT_TYPE, new String[]{ FEATURE_LEGACY_GOOGLE },
                         this, null);
             } else {
                 mAccountsPreferHosted = accountManagerFuture.getResult();
@@ -2149,7 +2153,7 @@ public class BrowserActivity extends Activity
         resetTitleIconAndProgress();
     }
 
-    private void goBackOnePageOrQuit() {
+    /* package */ void goBackOnePageOrQuit() {
         Tab current = mTabControl.getCurrentTab();
         if (current == null) {
             /*
@@ -3405,14 +3409,14 @@ public class BrowserActivity extends Activity
         }
 
         // issued on:
-        String issuedOn = reformatCertificateDate(
-            certificate.getValidNotBefore());
+        String issuedOn = formatCertificateDate(
+            certificate.getValidNotBeforeDate());
         ((TextView) certificateView.findViewById(R.id.issued_on))
             .setText(issuedOn);
 
         // expires on:
-        String expiresOn = reformatCertificateDate(
-            certificate.getValidNotAfter());
+        String expiresOn = formatCertificateDate(
+            certificate.getValidNotAfterDate());
         ((TextView) certificateView.findViewById(R.id.expires_on))
             .setText(expiresOn);
 
@@ -3420,31 +3424,19 @@ public class BrowserActivity extends Activity
     }
 
     /**
-     * Re-formats the certificate date (Date.toString()) string to
-     * a properly localized date string.
+     * Formats the certificate date to a properly localized date string.
      * @return Properly localized version of the certificate date string and
-     * the original certificate date string if fails to localize.
-     * If the original string is null, returns an empty string "".
+     * the "" if it fails to localize.
      */
-    private String reformatCertificateDate(String certificateDate) {
-      String reformattedDate = null;
-
-      if (certificateDate != null) {
-          Date date = null;
-          try {
-              date = java.text.DateFormat.getInstance().parse(certificateDate);
-          } catch (ParseException e) {
-              date = null;
-          }
-
-          if (date != null) {
-              reformattedDate =
-                  DateFormat.getDateFormat(this).format(date);
-          }
+    private String formatCertificateDate(Date certificateDate) {
+      if (certificateDate == null) {
+          return "";
       }
-
-      return reformattedDate != null ? reformattedDate :
-          (certificateDate != null ? certificateDate : "");
+      String formattedDate = DateFormat.getDateFormat(this).format(certificateDate);
+      if (formattedDate == null) {
+          return "";
+      }
+      return formattedDate;
     }
 
     /**