blob: d98b7b87d3d90b0449871f861dcf071306f96272 [file] [log] [blame]
Keun-young Park4727da32016-05-31 10:00:51 -07001/*
2 * Copyright (C) 2016 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 */
16package com.android.car.pm;
17
18import android.app.Activity;
Keun-young Park4727da32016-05-31 10:00:51 -070019import android.content.ComponentName;
Yao, Yuxing66644122018-04-02 10:08:33 -070020import android.content.pm.ApplicationInfo;
Keun-young Park4727da32016-05-31 10:00:51 -070021import android.content.pm.PackageManager;
Keun-young Park4727da32016-05-31 10:00:51 -070022import android.os.Bundle;
Yao, Yuxing66644122018-04-02 10:08:33 -070023import android.widget.TextView;
Keun-young Park4727da32016-05-31 10:00:51 -070024
Keun-young Park4727da32016-05-31 10:00:51 -070025import com.android.car.R;
26
27/**
28 * Default activity that will be launched when the current foreground activity is not allowed.
29 * Additional information on blocked Activity will be passed as extra in Intent
Yao, Yuxing66644122018-04-02 10:08:33 -070030 * via {@link #INTENT_KEY_BLOCKED_ACTIVITY} key.
Keun-young Park4727da32016-05-31 10:00:51 -070031 */
32public class ActivityBlockingActivity extends Activity {
Keun-young Park4727da32016-05-31 10:00:51 -070033 public static final String INTENT_KEY_BLOCKED_ACTIVITY = "blocked_activity";
Yao, Yuxing66644122018-04-02 10:08:33 -070034
Keun-young Park4727da32016-05-31 10:00:51 -070035 @Override
36 protected void onCreate(Bundle savedInstanceState) {
37 super.onCreate(savedInstanceState);
38 setContentView(R.layout.activity_blocking);
Keun-young Park4727da32016-05-31 10:00:51 -070039
Yao, Yuxing66644122018-04-02 10:08:33 -070040 String blockedActivity = getIntent().getStringExtra(INTENT_KEY_BLOCKED_ACTIVITY);
Yao, Yuxing13ae2902018-04-12 16:20:34 -070041
42 TextView blockedTitle = findViewById(R.id.activity_blocked_title);
43 blockedTitle.setText(getString(R.string.activity_blocked_string,
44 findBlockedApplicationLabel(blockedActivity)));
45 }
46
47 /**
48 * Returns the application label of blockedActivity. If that fails, the original activity will
49 * be returned.
50 */
51 private String findBlockedApplicationLabel(String blockedActivity) {
52 String label = blockedActivity;
Yao, Yuxing66644122018-04-02 10:08:33 -070053 // Attempt to update blockedActivity name to application label.
54 try {
55 ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo(
56 ComponentName.unflattenFromString(blockedActivity).getPackageName(), 0);
57 CharSequence appLabel = getPackageManager().getApplicationLabel(applicationInfo);
58 if (appLabel != null) {
Yao, Yuxing13ae2902018-04-12 16:20:34 -070059 label = appLabel.toString();
Yao, Yuxing66644122018-04-02 10:08:33 -070060 }
61 } catch (PackageManager.NameNotFoundException e) {
62 e.printStackTrace();
63 }
Yao, Yuxing13ae2902018-04-12 16:20:34 -070064 return label;
Keun-young Park4727da32016-05-31 10:00:51 -070065 }
66}