blob: 37244bd5bd06d7d3a1da6700166cb26e47680d98 [file] [log] [blame]
Przemyslaw Szczepaniakce73c7e2018-01-22 11:00:41 +00001/*
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 Ogunwale59507092018-10-29 09:00:30 -070017package com.android.server.wm;
Przemyslaw Szczepaniakce73c7e2018-01-22 11:00:41 +000018
Wale Ogunwale59507092018-10-29 09:00:30 -070019import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM;
20import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
Przemyslaw Szczepaniak5e0612c2018-04-23 13:17:13 +010021
Przemyslaw Szczepaniakce73c7e2018-01-22 11:00:41 +000022import android.app.AlertDialog;
23import android.content.Context;
24import android.content.Intent;
25import android.content.pm.ApplicationInfo;
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070026import android.content.pm.PackageItemInfo;
Przemyslaw Szczepaniakce73c7e2018-01-22 11:00:41 +000027import android.content.pm.PackageManager;
Przemyslaw Szczepaniak5e0612c2018-04-23 13:17:13 +010028import android.util.Log;
Przemyslaw Szczepaniakce73c7e2018-01-22 11:00:41 +000029import android.view.Window;
30import android.view.WindowManager;
Przemyslaw Szczepaniakce73c7e2018-01-22 11:00:41 +000031
32import com.android.internal.R;
33import com.android.server.utils.AppInstallerUtil;
34
35public class DeprecatedTargetSdkVersionDialog {
Wale Ogunwale98875612018-10-12 07:53:02 -070036 private static final String TAG = TAG_WITH_CLASS_NAME ? "DeprecatedTargetSdkVersionDialog" : TAG_ATM;
Przemyslaw Szczepaniak5e0612c2018-04-23 13:17:13 +010037
Przemyslaw Szczepaniakce73c7e2018-01-22 11:00:41 +000038 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. Moltmanna6f5c702018-04-23 09:09:16 -070046 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 Szczepaniakce73c7e2018-01-22 11:00:41 +000050 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 Szczepaniak5e0612c2018-04-23 13:17:13 +010084 Log.w(TAG, "Showing SDK deprecation warning for package " + mPackageName);
Przemyslaw Szczepaniakce73c7e2018-01-22 11:00:41 +000085 mDialog.show();
86 }
87
88 public void dismiss() {
89 mDialog.dismiss();
90 }
91}