+ * Note: Must be called on the UI thread. + * + * @param ar record for the activity that triggered the warning + */ + @UiThread + private void showDeprecatedAbiDialogUiThread(ActivityRecord ar) { + if (mDeprecatedAbiDialog != null) { + mDeprecatedAbiDialog.dismiss(); + mDeprecatedAbiDialog = null; + } + if (ar != null && !hasPackageFlag( + ar.packageName, FLAG_HIDE_DEPRECATED_ABI)) { + mDeprecatedAbiDialog = new DeprecatedAbiDialog( + AppWarnings.this, mUiContext, ar.info.applicationInfo); + mDeprecatedAbiDialog.show(); + } + } + /** * Dismisses all warnings for the given package. *
@@ -328,6 +379,13 @@ class AppWarnings { mDeprecatedTargetSdkVersionDialog.dismiss(); mDeprecatedTargetSdkVersionDialog = null; } + + // Hides the "deprecated abi" dialog if necessary. + if (mDeprecatedAbiDialog != null && (name == null || name.equals( + mDeprecatedAbiDialog.mPackageName))) { + mDeprecatedAbiDialog.dismiss(); + mDeprecatedAbiDialog = null; + } } /** @@ -381,6 +439,7 @@ class AppWarnings { private static final int MSG_SHOW_UNSUPPORTED_COMPILE_SDK_DIALOG = 3; private static final int MSG_HIDE_DIALOGS_FOR_PACKAGE = 4; private static final int MSG_SHOW_DEPRECATED_TARGET_SDK_DIALOG = 5; + private static final int MSG_SHOW_DEPRECATED_ABI_DIALOG = 6; public UiHandler(Looper looper) { super(looper, null, true); @@ -408,6 +467,10 @@ class AppWarnings { final ActivityRecord ar = (ActivityRecord) msg.obj; showDeprecatedTargetSdkDialogUiThread(ar); } break; + case MSG_SHOW_DEPRECATED_ABI_DIALOG: { + final ActivityRecord ar = (ActivityRecord) msg.obj; + showDeprecatedAbiDialogUiThread(ar); + } break; } } @@ -431,6 +494,11 @@ class AppWarnings { obtainMessage(MSG_SHOW_DEPRECATED_TARGET_SDK_DIALOG, r).sendToTarget(); } + public void showDeprecatedAbiDialog(ActivityRecord r) { + removeMessages(MSG_SHOW_DEPRECATED_ABI_DIALOG); + obtainMessage(MSG_SHOW_DEPRECATED_ABI_DIALOG, r).sendToTarget(); + } + public void hideDialogsForPackage(String name) { obtainMessage(MSG_HIDE_DIALOGS_FOR_PACKAGE, name).sendToTarget(); } diff --git a/services/core/java/com/android/server/wm/DeprecatedAbiDialog.java b/services/core/java/com/android/server/wm/DeprecatedAbiDialog.java new file mode 100644 index 0000000000000..e96208d3d0b3e --- /dev/null +++ b/services/core/java/com/android/server/wm/DeprecatedAbiDialog.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wm; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageItemInfo; +import android.content.pm.PackageManager; +import android.view.Window; +import android.view.WindowManager; + +import com.android.internal.R; + +class DeprecatedAbiDialog extends AppWarnings.BaseDialog { + DeprecatedAbiDialog(final AppWarnings manager, Context context, + ApplicationInfo appInfo) { + super(manager, appInfo.packageName); + + final PackageManager pm = context.getPackageManager(); + final CharSequence label = appInfo.loadSafeLabel(pm, + PackageItemInfo.DEFAULT_MAX_LABEL_SIZE_PX, + PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE + | PackageItemInfo.SAFE_LABEL_FLAG_TRIM); + final CharSequence message = context.getString(R.string.deprecated_abi_message); + + final AlertDialog.Builder builder = new AlertDialog.Builder(context) + .setPositiveButton(R.string.ok, (dialog, which) -> + manager.setPackageFlag( + mPackageName, AppWarnings.FLAG_HIDE_DEPRECATED_ABI, true)) + .setMessage(message) + .setTitle(label); + + // Ensure the content view is prepared. + mDialog = builder.create(); + mDialog.create(); + + final Window window = mDialog.getWindow(); + window.setType(WindowManager.LayoutParams.TYPE_PHONE); + + // DO NOT MODIFY. Used by CTS to verify the dialog is displayed. + window.getAttributes().setTitle("DeprecatedAbiDialog"); + } +}