Add start-encryption intent filter to settings

* Add intent-filter for "android.app.action.START_ENCRYPTION"
* Add pseudo-activity to host intent-filter
* Add code to settings page that exits quickly when encryption
  is not available or is already started.

This can be tested using ApiDemos -> App -> Device Admin

Bug: 3346770
Change-Id: Ie97459cf9e2a7b09b690bf085e64ef905466e77a
diff --git a/src/com/android/settings/CryptKeeperSettings.java b/src/com/android/settings/CryptKeeperSettings.java
index 26483ec..d26e5ff 100644
--- a/src/com/android/settings/CryptKeeperSettings.java
+++ b/src/com/android/settings/CryptKeeperSettings.java
@@ -19,6 +19,7 @@
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.Fragment;
+import android.app.admin.DevicePolicyManager;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
@@ -90,7 +91,6 @@
         }
     };
 
-
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
         mContentView = inflater.inflate(R.layout.crypt_keeper_settings, null);
@@ -118,6 +118,28 @@
     }
 
     /**
+     * If encryption is already started, and this launched via a "start encryption" intent,
+     * then exit immediately - it's already up and running, so there's no point in "starting" it.
+     */
+    @Override
+    public void onActivityCreated(Bundle savedInstanceState) {
+        super.onActivityCreated(savedInstanceState);
+        Activity activity = getActivity();
+        Intent intent = activity.getIntent();
+        if (DevicePolicyManager.ACTION_START_ENCRYPTION.equals(intent.getAction())) {
+            DevicePolicyManager dpm = (DevicePolicyManager)
+                    activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
+            if (dpm != null) {
+                int status = dpm.getStorageEncryptionStatus();
+                if (status != DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE) {
+                    // There is nothing to do here, so simply finish() (which returns to caller)
+                    activity.finish();
+                }
+            }
+        }
+    }
+
+    /**
      * Keyguard validation is run using the standard {@link ConfirmLockPattern}
      * component as a subactivity
      * @param request the request code to be returned once confirmation finishes
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 11d8c57..1e54504 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -332,4 +332,5 @@
     public static class PowerUsageSummaryActivity extends Settings { }
     public static class AccountSyncSettingsActivity extends Settings { }
     public static class AccountSyncSettingsInAddAccountActivity extends Settings { }
+    public static class CryptKeeperSettingsActivity extends Settings { }
 }