Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package com.android.car.pm; |
| 17 | |
| 18 | import android.app.Activity; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 19 | import android.content.ComponentName; |
Yao, Yuxing | 6664412 | 2018-04-02 10:08:33 -0700 | [diff] [blame] | 20 | import android.content.pm.ApplicationInfo; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 21 | import android.content.pm.PackageManager; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 22 | import android.os.Bundle; |
Yao, Yuxing | 6664412 | 2018-04-02 10:08:33 -0700 | [diff] [blame] | 23 | import android.widget.TextView; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 24 | |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 25 | import 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, Yuxing | 6664412 | 2018-04-02 10:08:33 -0700 | [diff] [blame] | 30 | * via {@link #INTENT_KEY_BLOCKED_ACTIVITY} key. |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 31 | */ |
| 32 | public class ActivityBlockingActivity extends Activity { |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 33 | public static final String INTENT_KEY_BLOCKED_ACTIVITY = "blocked_activity"; |
Yao, Yuxing | 6664412 | 2018-04-02 10:08:33 -0700 | [diff] [blame] | 34 | |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 35 | @Override |
| 36 | protected void onCreate(Bundle savedInstanceState) { |
| 37 | super.onCreate(savedInstanceState); |
| 38 | setContentView(R.layout.activity_blocking); |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 39 | |
Yao, Yuxing | 6664412 | 2018-04-02 10:08:33 -0700 | [diff] [blame] | 40 | String blockedActivity = getIntent().getStringExtra(INTENT_KEY_BLOCKED_ACTIVITY); |
Yao, Yuxing | 13ae290 | 2018-04-12 16:20:34 -0700 | [diff] [blame^] | 41 | |
| 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, Yuxing | 6664412 | 2018-04-02 10:08:33 -0700 | [diff] [blame] | 53 | // 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, Yuxing | 13ae290 | 2018-04-12 16:20:34 -0700 | [diff] [blame^] | 59 | label = appLabel.toString(); |
Yao, Yuxing | 6664412 | 2018-04-02 10:08:33 -0700 | [diff] [blame] | 60 | } |
| 61 | } catch (PackageManager.NameNotFoundException e) { |
| 62 | e.printStackTrace(); |
| 63 | } |
Yao, Yuxing | 13ae290 | 2018-04-12 16:20:34 -0700 | [diff] [blame^] | 64 | return label; |
Keun-young Park | 4727da3 | 2016-05-31 10:00:51 -0700 | [diff] [blame] | 65 | } |
| 66 | } |