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