From fc13cb1d680d57ea6401e2d45dfb1e46bf046fc7 Mon Sep 17 00:00:00 2001 From: Eun-Jeong Shin Date: Tue, 25 Oct 2022 16:31:58 -0700 Subject: Generate consent dialog when device log access is requested in SystemUI This change is to implement device log access dialog from SystemUI rather than system server. Bug: 238434889, 244173014 Test: GtsVerifier Ignore-AOSP-First: migration of device log access dialog Change-Id: I17058c008084f91099cd45a51ec8d8fbab1d78bb --- .../internal/app/LogAccessDialogActivity.java | 260 --------------------- core/res/AndroidManifest.xml | 7 - .../drawable/grant_permissions_buttons_bottom.xml | 23 -- .../res/drawable/grant_permissions_buttons_top.xml | 23 -- .../log_access_user_consent_dialog_permission.xml | 101 -------- core/res/res/values-television/styles.xml | 21 -- core/res/res/values/strings.xml | 26 --- core/res/res/values/styles.xml | 36 --- core/res/res/values/symbols.xml | 11 - packages/SystemUI/AndroidManifest.xml | 6 + .../drawable/grant_permissions_buttons_bottom.xml | 23 ++ .../res/drawable/grant_permissions_buttons_top.xml | 23 ++ packages/SystemUI/res/drawable/ic_doc_document.xml | 24 ++ .../log_access_user_consent_dialog_permission.xml | 101 ++++++++ .../SystemUI/res/values-television/strings.xml | 27 +++ packages/SystemUI/res/values-television/styles.xml | 6 + packages/SystemUI/res/values/attrs.xml | 5 + packages/SystemUI/res/values/ids.xml | 2 + packages/SystemUI/res/values/strings.xml | 15 ++ packages/SystemUI/res/values/styles.xml | 41 ++++ .../systemui/logcat/LogAccessDialogActivity.java | 254 ++++++++++++++++++++ .../src/com/android/systemui/logcat/OWNERS | 2 + .../server/logcat/LogcatManagerService.java | 11 +- 23 files changed, 537 insertions(+), 511 deletions(-) delete mode 100644 core/java/com/android/internal/app/LogAccessDialogActivity.java delete mode 100644 core/res/res/drawable/grant_permissions_buttons_bottom.xml delete mode 100644 core/res/res/drawable/grant_permissions_buttons_top.xml delete mode 100644 core/res/res/layout/log_access_user_consent_dialog_permission.xml delete mode 100644 core/res/res/values-television/styles.xml create mode 100644 packages/SystemUI/res/drawable/grant_permissions_buttons_bottom.xml create mode 100644 packages/SystemUI/res/drawable/grant_permissions_buttons_top.xml create mode 100644 packages/SystemUI/res/drawable/ic_doc_document.xml create mode 100644 packages/SystemUI/res/layout/log_access_user_consent_dialog_permission.xml create mode 100644 packages/SystemUI/res/values-television/strings.xml create mode 100644 packages/SystemUI/src/com/android/systemui/logcat/LogAccessDialogActivity.java create mode 100644 packages/SystemUI/src/com/android/systemui/logcat/OWNERS diff --git a/core/java/com/android/internal/app/LogAccessDialogActivity.java b/core/java/com/android/internal/app/LogAccessDialogActivity.java deleted file mode 100644 index 4adb8673084b..000000000000 --- a/core/java/com/android/internal/app/LogAccessDialogActivity.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (C) 2022 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.internal.app; - -import android.annotation.StyleRes; -import android.app.Activity; -import android.app.AlertDialog; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.PackageManager.NameNotFoundException; -import android.content.res.Configuration; -import android.os.Build; -import android.os.Bundle; -import android.os.Handler; -import android.os.RemoteException; -import android.os.UserHandle; -import android.text.Html; -import android.text.Spannable; -import android.text.TextUtils; -import android.text.method.LinkMovementMethod; -import android.text.style.TypefaceSpan; -import android.text.style.URLSpan; -import android.util.Slog; -import android.view.ContextThemeWrapper; -import android.view.InflateException; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.Button; -import android.widget.TextView; - -import com.android.internal.R; - -/** - * Dialog responsible for obtaining user consent per-use log access - */ -public class LogAccessDialogActivity extends Activity implements - View.OnClickListener { - private static final String TAG = LogAccessDialogActivity.class.getSimpleName(); - public static final String EXTRA_CALLBACK = "EXTRA_CALLBACK"; - - - private static final int DIALOG_TIME_OUT = Build.IS_DEBUGGABLE ? 60000 : 300000; - private static final int MSG_DISMISS_DIALOG = 0; - - private String mPackageName; - private int mUid; - private ILogAccessDialogCallback mCallback; - - private String mAlertTitle; - private String mAlertBody; - private String mAlertLearnMore; - private AlertDialog.Builder mAlertDialog; - private AlertDialog mAlert; - private View mAlertView; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // retrieve Intent extra information - if (!readIntentInfo(getIntent())) { - Slog.e(TAG, "Invalid Intent extras, finishing"); - finish(); - return; - } - - // retrieve the title string from passed intent extra - try { - mAlertTitle = getTitleString(this, mPackageName, mUid); - } catch (NameNotFoundException e) { - Slog.e(TAG, "Unable to fetch label of package " + mPackageName, e); - declineLogAccess(); - finish(); - return; - } - - mAlertBody = getResources().getString(R.string.log_access_confirmation_body); - mAlertLearnMore = getResources().getString(R.string.log_access_confirmation_learn_more); - - // create View - boolean isDarkTheme = (getResources().getConfiguration().uiMode - & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES; - int themeId = isDarkTheme ? android.R.style.Theme_DeviceDefault_Dialog_Alert : - android.R.style.Theme_DeviceDefault_Light_Dialog_Alert; - mAlertView = createView(themeId); - - // create AlertDialog - mAlertDialog = new AlertDialog.Builder(this, themeId); - mAlertDialog.setView(mAlertView); - mAlertDialog.setOnCancelListener(dialog -> declineLogAccess()); - mAlertDialog.setOnDismissListener(dialog -> finish()); - - // show Alert - mAlert = mAlertDialog.create(); - mAlert.getWindow().setHideOverlayWindows(true); - mAlert.show(); - - // set Alert Timeout - mHandler.sendEmptyMessageDelayed(MSG_DISMISS_DIALOG, DIALOG_TIME_OUT); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (!isChangingConfigurations() && mAlert != null && mAlert.isShowing()) { - mAlert.dismiss(); - } - mAlert = null; - } - - private boolean readIntentInfo(Intent intent) { - if (intent == null) { - Slog.e(TAG, "Intent is null"); - return false; - } - - mCallback = ILogAccessDialogCallback.Stub.asInterface( - intent.getExtras().getBinder(EXTRA_CALLBACK)); - if (mCallback == null) { - Slog.e(TAG, "Missing callback"); - return false; - } - - mPackageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME); - if (mPackageName == null || mPackageName.length() == 0) { - Slog.e(TAG, "Missing package name extra"); - return false; - } - - if (!intent.hasExtra(Intent.EXTRA_UID)) { - Slog.e(TAG, "Missing EXTRA_UID"); - return false; - } - - mUid = intent.getIntExtra(Intent.EXTRA_UID, 0); - - return true; - } - - private Handler mHandler = new Handler() { - public void handleMessage(android.os.Message msg) { - switch (msg.what) { - case MSG_DISMISS_DIALOG: - if (mAlert != null) { - mAlert.dismiss(); - mAlert = null; - declineLogAccess(); - } - break; - - default: - break; - } - } - }; - - private String getTitleString(Context context, String callingPackage, int uid) - throws NameNotFoundException { - PackageManager pm = context.getPackageManager(); - - CharSequence appLabel = pm.getApplicationInfoAsUser(callingPackage, - PackageManager.MATCH_DIRECT_BOOT_AUTO, - UserHandle.getUserId(uid)).loadLabel(pm); - - String titleString = context.getString( - com.android.internal.R.string.log_access_confirmation_title, appLabel); - - return titleString; - } - - private Spannable styleFont(String text) { - Spannable s = (Spannable) Html.fromHtml(text); - for (URLSpan span : s.getSpans(0, s.length(), URLSpan.class)) { - TypefaceSpan typefaceSpan = new TypefaceSpan("google-sans"); - s.setSpan(typefaceSpan, s.getSpanStart(span), s.getSpanEnd(span), 0); - } - return s; - } - - /** - * Returns the dialog view. - * If we cannot retrieve the package name, it returns null and we decline the full device log - * access - */ - private View createView(@StyleRes int themeId) { - Context themedContext = new ContextThemeWrapper(this, themeId); - final View view = LayoutInflater.from(themedContext).inflate( - R.layout.log_access_user_consent_dialog_permission, null /*root*/); - - if (view == null) { - throw new InflateException(); - } - - ((TextView) view.findViewById(R.id.log_access_dialog_title)) - .setText(mAlertTitle); - - if (!TextUtils.isEmpty(mAlertLearnMore)) { - Spannable mSpannableLearnMore = styleFont(mAlertLearnMore); - - ((TextView) view.findViewById(R.id.log_access_dialog_body)) - .setText(TextUtils.concat(mAlertBody, "\n\n", mSpannableLearnMore)); - - ((TextView) view.findViewById(R.id.log_access_dialog_body)) - .setMovementMethod(LinkMovementMethod.getInstance()); - } else { - ((TextView) view.findViewById(R.id.log_access_dialog_body)) - .setText(mAlertBody); - } - - Button button_allow = (Button) view.findViewById(R.id.log_access_dialog_allow_button); - button_allow.setOnClickListener(this); - - Button button_deny = (Button) view.findViewById(R.id.log_access_dialog_deny_button); - button_deny.setOnClickListener(this); - - return view; - - } - - @Override - public void onClick(View view) { - try { - switch (view.getId()) { - case R.id.log_access_dialog_allow_button: - mCallback.approveAccessForClient(mUid, mPackageName); - finish(); - break; - case R.id.log_access_dialog_deny_button: - declineLogAccess(); - finish(); - break; - } - } catch (RemoteException e) { - finish(); - } - } - - private void declineLogAccess() { - try { - mCallback.declineAccessForClient(mUid, mPackageName); - } catch (RemoteException e) { - finish(); - } - } -} diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index f0fbff1e63e2..87f47a4f33f8 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -6908,13 +6908,6 @@ android:exported="false"> - - - - - - - - - \ No newline at end of file diff --git a/core/res/res/drawable/grant_permissions_buttons_top.xml b/core/res/res/drawable/grant_permissions_buttons_top.xml deleted file mode 100644 index 2bf803e340ec..000000000000 --- a/core/res/res/drawable/grant_permissions_buttons_top.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/core/res/res/layout/log_access_user_consent_dialog_permission.xml b/core/res/res/layout/log_access_user_consent_dialog_permission.xml deleted file mode 100644 index 3da14c8f1886..000000000000 --- a/core/res/res/layout/log_access_user_consent_dialog_permission.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - - - - - - - - - -