| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.app; |
| 18 |
|
| 19 |
import android.content.Intent; |
| 20 |
import android.content.pm.ApplicationInfo; |
| 21 |
import android.content.pm.PackageManager; |
| 22 |
import android.os.Bundle; |
| 23 |
import android.text.TextUtils; |
| 24 |
import android.util.Slog; |
| 25 |
|
| 26 |
import com.android.internal.R; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class BlockedAppActivity extends AlertActivity { |
| 34 |
|
| 35 |
private static final String TAG = "BlockedAppActivity"; |
| 36 |
private static final String PACKAGE_NAME = "com.android.internal.app"; |
| 37 |
private static final String EXTRA_BLOCKED_PACKAGE = PACKAGE_NAME + ".extra.BLOCKED_PACKAGE"; |
| 38 |
|
| 39 |
@Override |
| 40 |
protected void onCreate(Bundle savedInstanceState) { |
| 41 |
super.onCreate(savedInstanceState); |
| 42 |
|
| 43 |
Intent intent = getIntent(); |
| 44 |
int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, -1); |
| 45 |
if (userId < 0) { |
| 46 |
Slog.wtf(TAG, "Invalid user: " + userId); |
| 47 |
finish(); |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
String packageName = intent.getStringExtra(EXTRA_BLOCKED_PACKAGE); |
| 52 |
if (TextUtils.isEmpty(packageName)) { |
| 53 |
Slog.wtf(TAG, "Invalid package: " + packageName); |
| 54 |
finish(); |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
CharSequence appLabel = getAppLabel(userId, packageName); |
| 59 |
|
| 60 |
mAlertParams.mTitle = getString(R.string.app_blocked_title); |
| 61 |
mAlertParams.mMessage = getString(R.string.app_blocked_message, appLabel); |
| 62 |
mAlertParams.mPositiveButtonText = getString(android.R.string.ok); |
| 63 |
setupAlert(); |
| 64 |
} |
| 65 |
|
| 66 |
private CharSequence getAppLabel(int userId, String packageName) { |
| 67 |
PackageManager pm = getPackageManager(); |
| 68 |
try { |
| 69 |
ApplicationInfo aInfo = |
| 70 |
pm.getApplicationInfoAsUser(packageName, 0, userId); |
| 71 |
return aInfo.loadLabel(pm); |
| 72 |
} catch (PackageManager.NameNotFoundException ne) { |
| 73 |
Slog.e(TAG, "Package " + packageName + " not found", ne); |
| 74 |
} |
| 75 |
return packageName; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public static Intent createIntent(int userId, String packageName) { |
| 81 |
return new Intent() |
| 82 |
.setClassName("android", BlockedAppActivity.class.getName()) |
| 83 |
.putExtra(Intent.EXTRA_USER_ID, userId) |
| 84 |
.putExtra(EXTRA_BLOCKED_PACKAGE, packageName); |
| 85 |
} |
| 86 |
} |