Debian Codegraph @

core/java/com/android/internal/app/BlockedAppStreamingActivity.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2022 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.internal.app;
18
19 import android.content.Intent;
20 import android.content.pm.ActivityInfo;
21 import android.os.Bundle;
22 import android.text.TextUtils;
23 import android.util.Slog;
24
25 import com.android.internal.R;
26
27 /**
28 * A dialog shown to the user when they try to launch an app that is not allowed on a virtual
29 * device. The intent to start this activity must be created with the static factory method provided
30 * below.
31 */
32 public class BlockedAppStreamingActivity extends AlertActivity {
33
34 private static final String TAG = "BlockedAppStreamingActivity";
35 private static final String PACKAGE_NAME = "com.android.internal.app";
36 private static final String EXTRA_BLOCKED_ACTIVITY_INFO =
37 PACKAGE_NAME + ".extra.BLOCKED_ACTIVITY_INFO";
38 private static final String EXTRA_STREAMED_DEVICE = PACKAGE_NAME + ".extra.STREAMED_DEVICE";
39 private static final String BLOCKED_COMPONENT_PLAYSTORE = "com.android.vending";
40 private static final String BLOCKED_COMPONENT_SETTINGS = "com.android.settings";
41
42 @Override
43 protected void onCreate(Bundle savedInstanceState) {
44 super.onCreate(savedInstanceState);
45
46 Intent intent = getIntent();
47 CharSequence appLabel = null;
48 ActivityInfo activityInfo = intent.getParcelableExtra(EXTRA_BLOCKED_ACTIVITY_INFO);
49 if (activityInfo != null) {
50 appLabel = activityInfo.loadLabel(getPackageManager());
51 }
52
53 if (TextUtils.isEmpty(appLabel)) {
54 Slog.wtf(TAG, "Invalid activity info: " + activityInfo);
55 finish();
56 return;
57 }
58
59 CharSequence streamedDeviceName = intent.getCharSequenceExtra(EXTRA_STREAMED_DEVICE);
60 if (!TextUtils.isEmpty(streamedDeviceName)) {
61 if (TextUtils.equals(activityInfo.packageName,
62 getPackageManager().getPermissionControllerPackageName())) {
63 mAlertParams.mTitle =
64 getString(R.string.app_streaming_blocked_title_for_permission_dialog);
65 mAlertParams.mMessage =
66 getString(R.string.app_streaming_blocked_message, streamedDeviceName);
67 } else if (TextUtils.equals(activityInfo.packageName, BLOCKED_COMPONENT_PLAYSTORE)) {
68 mAlertParams.mTitle =
69 getString(R.string.app_streaming_blocked_title_for_playstore_dialog);
70 mAlertParams.mMessage =
71 getString(R.string.app_streaming_blocked_message, streamedDeviceName);
72 } else if (TextUtils.equals(activityInfo.packageName, BLOCKED_COMPONENT_SETTINGS)) {
73 mAlertParams.mTitle =
74 getString(R.string.app_streaming_blocked_title_for_settings_dialog);
75 mAlertParams.mMessage =
76 getString(R.string.app_streaming_blocked_message_for_settings_dialog,
77 streamedDeviceName);
78 } else {
79 // No title required
80 mAlertParams.mMessage =
81 getString(R.string.app_streaming_blocked_message, streamedDeviceName);
82 }
83 } else {
84 // No title required
85 mAlertParams.mMessage = getString(R.string.app_blocked_message, appLabel);
86 }
87 mAlertParams.mPositiveButtonText = getString(android.R.string.ok);
88 setupAlert();
89 }
90
91 /**
92 * Creates an intent that launches {@link BlockedAppStreamingActivity} when app streaming is
93 * blocked.
94 */
95 public static Intent createIntent(ActivityInfo activityInfo, CharSequence streamedDeviceName) {
96 return new Intent()
97 .setClassName("android", BlockedAppStreamingActivity.class.getName())
98 .putExtra(EXTRA_BLOCKED_ACTIVITY_INFO, activityInfo)
99 .putExtra(EXTRA_STREAMED_DEVICE, streamedDeviceName);
100 }
101 }