Merge "Nemo CTS: Call the right class for SSL" into cw-e-dev
am: b0876d3cb4

* commit 'b0876d3cb4e90c21acc23941a80648d45451e7fd':
  Nemo CTS: Call the right class for SSL
diff --git a/src/com/android/certinstaller/CertInstaller.java b/src/com/android/certinstaller/CertInstaller.java
index 907646e..0a6049e 100644
--- a/src/com/android/certinstaller/CertInstaller.java
+++ b/src/com/android/certinstaller/CertInstaller.java
@@ -21,6 +21,7 @@
 import android.app.Dialog;
 import android.app.ProgressDialog;
 import android.content.ActivityNotFoundException;
+import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.os.AsyncTask;
@@ -394,6 +395,7 @@
         }
         nameInput.setText(getDefaultName());
         nameInput.selectAll();
+        final Context appContext = getApplicationContext();
         Dialog d = new AlertDialog.Builder(this)
                 .setView(view)
                 .setTitle(R.string.name_credential_dialog_title)
@@ -411,7 +413,7 @@
                             // install everything to system keystore
                             try {
                                 startActivityForResult(
-                                        mCredentials.createSystemInstallIntent(),
+                                        mCredentials.createSystemInstallIntent(appContext),
                                         REQUEST_SYSTEM_INSTALL_CODE);
                             } catch (ActivityNotFoundException e) {
                                 Log.w(TAG, "systemInstall(): " + e);
diff --git a/src/com/android/certinstaller/CredentialHelper.java b/src/com/android/certinstaller/CredentialHelper.java
index c131268..a3e2e27 100644
--- a/src/com/android/certinstaller/CredentialHelper.java
+++ b/src/com/android/certinstaller/CredentialHelper.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.PackageManager;
 import android.os.Bundle;
 import android.os.RemoteException;
 import android.security.Credentials;
@@ -256,11 +257,16 @@
         return mUid != -1;
     }
 
-    Intent createSystemInstallIntent() {
+    Intent createSystemInstallIntent(final Context context) {
         Intent intent = new Intent("com.android.credentials.INSTALL");
         // To prevent the private key from being sniffed, we explicitly spell
         // out the intent receiver class.
-        intent.setClassName("com.android.settings", "com.android.settings.CredentialStorage");
+        if (!isWear(context)) {
+            intent.setClassName("com.android.settings", "com.android.settings.CredentialStorage");
+        } else {
+            intent.setClassName("com.google.android.apps.wearable.settings",
+                    "com.google.android.clockwork.settings.CredentialStorage");
+        }
         intent.putExtra(Credentials.EXTRA_INSTALL_AS_UID, mUid);
         try {
             if (mUserKey != null) {
@@ -365,4 +371,8 @@
 
         return true;
     }
+
+    private static boolean isWear(final Context context) {
+        return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);
+    }
 }