Przemyslaw Szczepaniak | ce73c7e | 2018-01-22 11:00:41 +0000 | [diff] [blame] | 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 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Przemyslaw Szczepaniak | ce73c7e | 2018-01-22 11:00:41 +0000 | [diff] [blame] | 18 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 19 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 20 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Przemyslaw Szczepaniak | 5e0612c | 2018-04-23 13:17:13 +0100 | [diff] [blame] | 21 | |
Przemyslaw Szczepaniak | ce73c7e | 2018-01-22 11:00:41 +0000 | [diff] [blame] | 22 | import android.app.AlertDialog; |
| 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
| 25 | import android.content.pm.ApplicationInfo; |
Philip P. Moltmann | a6f5c70 | 2018-04-23 09:09:16 -0700 | [diff] [blame] | 26 | import android.content.pm.PackageItemInfo; |
Przemyslaw Szczepaniak | ce73c7e | 2018-01-22 11:00:41 +0000 | [diff] [blame] | 27 | import android.content.pm.PackageManager; |
Przemyslaw Szczepaniak | 5e0612c | 2018-04-23 13:17:13 +0100 | [diff] [blame] | 28 | import android.util.Log; |
Przemyslaw Szczepaniak | ce73c7e | 2018-01-22 11:00:41 +0000 | [diff] [blame] | 29 | import android.view.Window; |
| 30 | import android.view.WindowManager; |
Przemyslaw Szczepaniak | ce73c7e | 2018-01-22 11:00:41 +0000 | [diff] [blame] | 31 | |
| 32 | import com.android.internal.R; |
| 33 | import com.android.server.utils.AppInstallerUtil; |
| 34 | |
| 35 | public class DeprecatedTargetSdkVersionDialog { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 36 | private static final String TAG = TAG_WITH_CLASS_NAME ? "DeprecatedTargetSdkVersionDialog" : TAG_ATM; |
Przemyslaw Szczepaniak | 5e0612c | 2018-04-23 13:17:13 +0100 | [diff] [blame] | 37 | |
Przemyslaw Szczepaniak | ce73c7e | 2018-01-22 11:00:41 +0000 | [diff] [blame] | 38 | private final AlertDialog mDialog; |
| 39 | private final String mPackageName; |
| 40 | |
| 41 | public DeprecatedTargetSdkVersionDialog(final AppWarnings manager, Context context, |
| 42 | ApplicationInfo appInfo) { |
| 43 | mPackageName = appInfo.packageName; |
| 44 | |
| 45 | final PackageManager pm = context.getPackageManager(); |
Philip P. Moltmann | a6f5c70 | 2018-04-23 09:09:16 -0700 | [diff] [blame] | 46 | final CharSequence label = appInfo.loadSafeLabel(pm, |
| 47 | PackageItemInfo.DEFAULT_MAX_LABEL_SIZE_PX, |
| 48 | PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE |
| 49 | | PackageItemInfo.SAFE_LABEL_FLAG_TRIM); |
Przemyslaw Szczepaniak | ce73c7e | 2018-01-22 11:00:41 +0000 | [diff] [blame] | 50 | final CharSequence message = context.getString(R.string.deprecated_target_sdk_message); |
| 51 | |
| 52 | final AlertDialog.Builder builder = new AlertDialog.Builder(context) |
| 53 | .setPositiveButton(R.string.ok, (dialog, which) -> |
| 54 | manager.setPackageFlag( |
| 55 | mPackageName, AppWarnings.FLAG_HIDE_DEPRECATED_SDK, true)) |
| 56 | .setMessage(message) |
| 57 | .setTitle(label); |
| 58 | |
| 59 | // If we might be able to update the app, show a button. |
| 60 | final Intent installerIntent = AppInstallerUtil.createIntent(context, appInfo.packageName); |
| 61 | if (installerIntent != null) { |
| 62 | builder.setNeutralButton(R.string.deprecated_target_sdk_app_store, |
| 63 | (dialog, which) -> { |
| 64 | context.startActivity(installerIntent); |
| 65 | }); |
| 66 | } |
| 67 | |
| 68 | // Ensure the content view is prepared. |
| 69 | mDialog = builder.create(); |
| 70 | mDialog.create(); |
| 71 | |
| 72 | final Window window = mDialog.getWindow(); |
| 73 | window.setType(WindowManager.LayoutParams.TYPE_PHONE); |
| 74 | |
| 75 | // DO NOT MODIFY. Used by CTS to verify the dialog is displayed. |
| 76 | window.getAttributes().setTitle("DeprecatedTargetSdkVersionDialog"); |
| 77 | } |
| 78 | |
| 79 | public String getPackageName() { |
| 80 | return mPackageName; |
| 81 | } |
| 82 | |
| 83 | public void show() { |
Przemyslaw Szczepaniak | 5e0612c | 2018-04-23 13:17:13 +0100 | [diff] [blame] | 84 | Log.w(TAG, "Showing SDK deprecation warning for package " + mPackageName); |
Przemyslaw Szczepaniak | ce73c7e | 2018-01-22 11:00:41 +0000 | [diff] [blame] | 85 | mDialog.show(); |
| 86 | } |
| 87 | |
| 88 | public void dismiss() { |
| 89 | mDialog.dismiss(); |
| 90 | } |
| 91 | } |