• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.chooser;
18 
19 import android.app.Activity;
20 import android.app.ActivityTaskManager;
21 import android.content.Intent;
22 import android.os.Bundle;
23 import android.os.IBinder;
24 import android.os.StrictMode;
25 
26 /**
27  * When a target is chosen from the SystemUI Chooser activity, unpack its arguments and
28  * startActivityAsCaller to handle the now-chosen intent.
29  */
30 public class ChooserHelper {
31 
32     private static final String TAG = "ChooserHelper";
33 
onChoose(Activity activity)34     static void onChoose(Activity activity) {
35         final Intent thisIntent = activity.getIntent();
36         final Bundle thisExtras = thisIntent.getExtras();
37         final Intent chosenIntent = thisIntent.getParcelableExtra(Intent.EXTRA_INTENT);
38         final Bundle options = thisIntent.getParcelableExtra(ActivityTaskManager.EXTRA_OPTIONS);
39         final IBinder permissionToken =
40                 thisExtras.getBinder(ActivityTaskManager.EXTRA_PERMISSION_TOKEN);
41         final boolean ignoreTargetSecurity =
42                 thisIntent.getBooleanExtra(ActivityTaskManager.EXTRA_IGNORE_TARGET_SECURITY, false);
43         final int userId = thisIntent.getIntExtra(Intent.EXTRA_USER_ID, -1);
44 
45         // We're dispatching intents that might be coming from legacy apps, so
46         // (as in com.android.internal.app.ResolverActivity) exempt ourselves from death.
47         StrictMode.disableDeathOnFileUriExposure();
48         try {
49             activity.startActivityAsCaller(
50                     chosenIntent, options, permissionToken, ignoreTargetSecurity, userId);
51         } finally {
52             StrictMode.enableDeathOnFileUriExposure();
53         }
54     }
55 }
56