Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [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; |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 18 | |
| 19 | import android.app.AlertDialog; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.content.pm.ApplicationInfo; |
Philip P. Moltmann | a6f5c70 | 2018-04-23 09:09:16 -0700 | [diff] [blame] | 23 | import android.content.pm.PackageItemInfo; |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 24 | import android.content.pm.PackageManager; |
| 25 | import android.view.Window; |
| 26 | import android.view.WindowManager; |
| 27 | import android.widget.CheckBox; |
| 28 | |
| 29 | import com.android.internal.R; |
| 30 | import com.android.server.utils.AppInstallerUtil; |
| 31 | |
| 32 | public 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. Moltmann | a6f5c70 | 2018-04-23 09:09:16 -0700 | [diff] [blame] | 41 | 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 Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 45 | final CharSequence message = context.getString(R.string.unsupported_compile_sdk_message, |
Alan Viverette | 9fdd44f | 2017-11-28 13:39:16 -0500 | [diff] [blame] | 46 | label); |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 47 | |
| 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 | } |