blob: 6a878b983543f7a972bfff4658509b08bf93ffbe [file] [log] [blame]
Alan Viveretteb6a25732017-11-21 14:49:24 -05001/*
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;
Alan Viveretteb6a25732017-11-21 14:49:24 -050018
19import android.app.AlertDialog;
20import android.content.Context;
21import android.content.Intent;
22import android.content.pm.ApplicationInfo;
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070023import android.content.pm.PackageItemInfo;
Alan Viveretteb6a25732017-11-21 14:49:24 -050024import android.content.pm.PackageManager;
25import android.view.Window;
26import android.view.WindowManager;
27import android.widget.CheckBox;
28
29import com.android.internal.R;
30import com.android.server.utils.AppInstallerUtil;
31
32public class UnsupportedCompileSdkDialog {
33 private final AlertDialog mDialog;
34 private final String mPackageName;
35
36 public UnsupportedCompileSdkDialog(final AppWarnings manager, Context context,
37 ApplicationInfo appInfo) {
38 mPackageName = appInfo.packageName;
39
40 final PackageManager pm = context.getPackageManager();
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070041 final CharSequence label = appInfo.loadSafeLabel(pm,
42 PackageItemInfo.DEFAULT_MAX_LABEL_SIZE_PX,
43 PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE
44 | PackageItemInfo.SAFE_LABEL_FLAG_TRIM);
Alan Viveretteb6a25732017-11-21 14:49:24 -050045 final CharSequence message = context.getString(R.string.unsupported_compile_sdk_message,
Alan Viverette9fdd44f2017-11-28 13:39:16 -050046 label);
Alan Viveretteb6a25732017-11-21 14:49:24 -050047
48 final AlertDialog.Builder builder = new AlertDialog.Builder(context)
49 .setPositiveButton(R.string.ok, null)
50 .setMessage(message)
51 .setView(R.layout.unsupported_compile_sdk_dialog_content);
52
53 // If we might be able to update the app, show a button.
54 final Intent installerIntent = AppInstallerUtil.createIntent(context, appInfo.packageName);
55 if (installerIntent != null) {
56 builder.setNeutralButton(R.string.unsupported_compile_sdk_check_update,
57 (dialog, which) -> context.startActivity(installerIntent));
58 }
59
60 // Ensure the content view is prepared.
61 mDialog = builder.create();
62 mDialog.create();
63
64 final Window window = mDialog.getWindow();
65 window.setType(WindowManager.LayoutParams.TYPE_PHONE);
66
67 // DO NOT MODIFY. Used by CTS to verify the dialog is displayed.
68 window.getAttributes().setTitle("UnsupportedCompileSdkDialog");
69
70 final CheckBox alwaysShow = mDialog.findViewById(R.id.ask_checkbox);
71 alwaysShow.setChecked(true);
72 alwaysShow.setOnCheckedChangeListener((buttonView, isChecked) -> manager.setPackageFlag(
73 mPackageName, AppWarnings.FLAG_HIDE_COMPILE_SDK, !isChecked));
74 }
75
76 public String getPackageName() {
77 return mPackageName;
78 }
79
80 public void show() {
81 mDialog.show();
82 }
83
84 public void dismiss() {
85 mDialog.dismiss();
86 }
87}