Merge "Add dispatcher activity to forward privileged euicc intents." am: 0cad33a5bc
am: 6c1f9973df

Change-Id: I1e0b704a9415ec9dca3e5c1a4f862c33c422a0ad
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f68b72e..de1f0f3 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -458,6 +458,24 @@
             </intent-filter>
         </activity>
 
+        <!--
+            Handler for EuiccManager's privileged action intents. These are locked down so that only
+            privileged processes can start them.
+        -->
+        <activity android:name=".euicc.EuiccPrivilegedActionUiDispatcherActivity"
+                  android:permission="android.permission.CALL_PRIVILEGED">
+            <!-- Max out priority to ensure nobody else will handle these intents. -->
+            <intent-filter android:priority="1000">
+                <action android:name=
+                            "android.telephony.euicc.action.TOGGLE_SUBSCRIPTION_PRIVILEGED" />
+                <action android:name=
+                            "android.telephony.euicc.action.DELETE_SUBSCRIPTION_PRIVILEGED" />
+                <action android:name=
+                            "android.telephony.euicc.action.RENAME_SUBSCRIPTION_PRIVILEGED" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </activity>
+
         <activity android:name="EmergencyCallbackModeExitDialog"
             android:excludeFromRecents="true"
             android:label="@string/ecm_exit_dialog"
diff --git a/src/com/android/phone/euicc/EuiccPrivilegedActionUiDispatcherActivity.java b/src/com/android/phone/euicc/EuiccPrivilegedActionUiDispatcherActivity.java
new file mode 100644
index 0000000..389795b
--- /dev/null
+++ b/src/com/android/phone/euicc/EuiccPrivilegedActionUiDispatcherActivity.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.phone.euicc;
+
+import android.annotation.Nullable;
+import android.content.Intent;
+import android.service.euicc.EuiccService;
+import android.telephony.euicc.EuiccManager;
+import android.util.Log;
+
+/**
+ * Trampoline activity to forward privileged eUICC intents from the system to the active UI
+ * implementation.
+ *
+ * <p>Unlike {@link EuiccUiDispatcherActivity}, this activity requires a locked-down permission to
+ * start.
+ */
+public class EuiccPrivilegedActionUiDispatcherActivity extends EuiccUiDispatcherActivity {
+    private static final String TAG = "EuiccPrivUiDispatcher";
+
+    @Override
+    @Nullable
+    protected Intent getEuiccUiIntent() {
+        String action = getIntent().getAction();
+
+        Intent intent = new Intent();
+        // Propagate the extras from the original Intent.
+        intent.putExtras(getIntent());
+        switch (action) {
+            case EuiccManager.ACTION_TOGGLE_SUBSCRIPTION_PRIVILEGED:
+                intent.setAction(EuiccService.ACTION_TOGGLE_SUBSCRIPTION_PRIVILEGED);
+                break;
+            case EuiccManager.ACTION_DELETE_SUBSCRIPTION_PRIVILEGED:
+                intent.setAction(EuiccService.ACTION_DELETE_SUBSCRIPTION_PRIVILEGED);
+                break;
+            case EuiccManager.ACTION_RENAME_SUBSCRIPTION_PRIVILEGED:
+                intent.setAction(EuiccService.ACTION_RENAME_SUBSCRIPTION_PRIVILEGED);
+                break;
+            default:
+                Log.w(TAG, "Unsupported action: " + action);
+                return null;
+        }
+
+        return intent;
+    }
+}