blob: 84dca7fe1c8a94b85c53ce0e02f8140c3790d6d5 [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
17package com.android.server.am;
18
19import android.app.AlertDialog;
20import android.content.Context;
21import android.content.Intent;
22import android.content.pm.ApplicationInfo;
23import android.content.pm.PackageManager;
24import android.os.Build;
25import android.os.SystemPropertiesProto;
26import android.view.Window;
27import android.view.WindowManager;
28import android.widget.CheckBox;
29
30import com.android.internal.R;
31import com.android.server.utils.AppInstallerUtil;
32
33public class DeprecatedTargetSdkVersionDialog {
34 private final AlertDialog mDialog;
35 private final String mPackageName;
36
37 public DeprecatedTargetSdkVersionDialog(final AppWarnings manager, Context context,
38 ApplicationInfo appInfo) {
39 mPackageName = appInfo.packageName;
40
41 final PackageManager pm = context.getPackageManager();
42 final CharSequence label = appInfo.loadSafeLabel(pm);
43 final CharSequence message = context.getString(R.string.deprecated_target_sdk_message);
44
45 final AlertDialog.Builder builder = new AlertDialog.Builder(context)
46 .setPositiveButton(R.string.ok, (dialog, which) ->
47 manager.setPackageFlag(
48 mPackageName, AppWarnings.FLAG_HIDE_DEPRECATED_SDK, true))
49 .setMessage(message)
50 .setTitle(label);
51
52 // If we might be able to update the app, show a button.
53 final Intent installerIntent = AppInstallerUtil.createIntent(context, appInfo.packageName);
54 if (installerIntent != null) {
55 builder.setNeutralButton(R.string.deprecated_target_sdk_app_store,
56 (dialog, which) -> {
57 context.startActivity(installerIntent);
58 });
59 }
60
61 // Ensure the content view is prepared.
62 mDialog = builder.create();
63 mDialog.create();
64
65 final Window window = mDialog.getWindow();
66 window.setType(WindowManager.LayoutParams.TYPE_PHONE);
67
68 // DO NOT MODIFY. Used by CTS to verify the dialog is displayed.
69 window.getAttributes().setTitle("DeprecatedTargetSdkVersionDialog");
70 }
71
72 public String getPackageName() {
73 return mPackageName;
74 }
75
76 public void show() {
77 mDialog.show();
78 }
79
80 public void dismiss() {
81 mDialog.dismiss();
82 }
83}