Block Install Intent for Wear devices

- We did not support this feature on Android Wear before
- The impact is unknown. For example, the Setting for UNKNOWN_SOURCES is
not implemented in Android Wear Settings App.

Bug: 24336381

Change-Id: I0fb4006d4769291c872e8f21407383a7c4a77b93
diff --git a/res/values-watch/styles.xml b/res/values-watch/styles.xml
index dc2be04..01ab90e 100644
--- a/res/values-watch/styles.xml
+++ b/res/values-watch/styles.xml
@@ -15,6 +15,8 @@
 -->
 
 <resources>
+    <style name="Theme.DialogWhenLarge" parent="@android:style/Theme.DeviceDefault.NoActionBar"/>
+
     <!-- START: Ported values -->
     <style name="TextAppearance.Wearable.Small" parent="android:TextAppearance.Medium">
         <item name="android:textSize">16sp</item>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d79ba63..0f1a73f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -274,4 +274,9 @@
          before permissions can be changed. [CHAR LIMIT=NONE] -->
     <string name="screen_overlay_button">Open settings</string>
 
+    <!-- Title of dialog telling users that Install/Uninstall action is not supported on Android Wear. -->
+    <string name="wear_not_allowed_dlg_title">Android Wear</string>
+    <!-- Title of dialog telling users that Install/Uninstall action is not supported on Android Wear. -->
+    <string name="wear_not_allowed_dlg_text">Instal/Uninstall actions not supported on Wear.</string>
+
 </resources>
diff --git a/src/com/android/packageinstaller/InstallFlowAnalytics.java b/src/com/android/packageinstaller/InstallFlowAnalytics.java
index 2fc6db3..4591f31 100644
--- a/src/com/android/packageinstaller/InstallFlowAnalytics.java
+++ b/src/com/android/packageinstaller/InstallFlowAnalytics.java
@@ -85,6 +85,11 @@
      */
     static final byte RESULT_PACKAGE_MANAGER_INSTALL_FAILED = 6;
 
+    /**
+     * Installation blocked since this feature is not allowed on Android Wear devices yet.
+     */
+    static final byte RESULT_NOT_ALLOWED_ON_WEAR = 7;
+
     private static final int FLAG_INSTALLS_FROM_UNKNOWN_SOURCES_PERMITTED = 1 << 0;
     private static final int FLAG_INSTALL_REQUEST_FROM_UNKNOWN_SOURCE = 1 << 1;
     private static final int FLAG_VERIFY_APPS_ENABLED = 1 << 2;
@@ -600,4 +605,4 @@
         }
         return digest.digest();
     }
-}
\ No newline at end of file
+}
diff --git a/src/com/android/packageinstaller/PackageInstallerActivity.java b/src/com/android/packageinstaller/PackageInstallerActivity.java
index 6bcd80e..868872a 100644
--- a/src/com/android/packageinstaller/PackageInstallerActivity.java
+++ b/src/com/android/packageinstaller/PackageInstallerActivity.java
@@ -110,6 +110,7 @@
     private static final int DLG_INSTALL_ERROR = DLG_BASE + 4;
     private static final int DLG_ALLOW_SOURCE = DLG_BASE + 5;
     private static final int DLG_ADMIN_RESTRICTS_UNKNOWN_SOURCES = DLG_BASE + 6;
+    private static final int DLG_NOT_SUPPORTED_ON_WEAR = DLG_BASE + 7;
 
     private void startInstallConfirm() {
         TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
@@ -293,7 +294,7 @@
                             Log.i(TAG, "Canceling installation");
                             finish();
                         }
-                  })
+                })
                   .setOnCancelListener(this)
                   .create();
         case DLG_INSTALL_ERROR :
@@ -333,6 +334,18 @@
                     })
                     .setOnCancelListener(this)
                     .create();
+        case DLG_NOT_SUPPORTED_ON_WEAR:
+            return new AlertDialog.Builder(this)
+                    .setTitle(R.string.wear_not_allowed_dlg_title)
+                    .setMessage(R.string.wear_not_allowed_dlg_text)
+                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
+                        public void onClick(DialogInterface dialog, int which) {
+                            setResult(RESULT_OK);
+                            finish();
+                        }
+                    })
+                    .setOnCancelListener(this)
+                    .create();
        }
        return null;
    }
@@ -478,6 +491,13 @@
         mInstallFlowAnalytics.setAppVerifierInstalled(isAppVerifierInstalled());
         mInstallFlowAnalytics.setPackageUri(mPackageURI.toString());
 
+        if (DeviceUtils.isWear(this)) {
+            showDialogInner(DLG_NOT_SUPPORTED_ON_WEAR);
+            mInstallFlowAnalytics.setFlowFinished(
+                    InstallFlowAnalytics.RESULT_NOT_ALLOWED_ON_WEAR);
+            return;
+        }
+
         final String scheme = mPackageURI.getScheme();
         if (scheme != null && !"file".equals(scheme) && !"package".equals(scheme)) {
             Log.w(TAG, "Unsupported scheme " + scheme);