Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ce1f5634 authored by Eun-Jeong Shin's avatar Eun-Jeong Shin Committed by Android (Google) Code Review
Browse files

Merge "Add hyperlink to "Learn more" in device log access dialog" into tm-qpr-dev

parents 5926e155 db1ed6fa
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
/*
 * 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;

/**
 * IPC interface for an application to receive callbacks from the log access dialog callback.
 */
oneway interface ILogAccessDialogCallback {
    void approveAccessForClient(int uid, String packageName);
    void declineAccessForClient(int uid, String packageName);
}
 No newline at end of file
+64 −16
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.server.logcat;
package com.android.internal.app;

import android.annotation.StyleRes;
import android.app.Activity;
@@ -27,7 +27,14 @@ 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;
@@ -37,7 +44,6 @@ import android.widget.Button;
import android.widget.TextView;

import com.android.internal.R;
import com.android.server.LocalServices;

/**
 * Dialog responsible for obtaining user consent per-use log access
@@ -45,17 +51,19 @@ import com.android.server.LocalServices;
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 final LogcatManagerService.LogcatManagerServiceInternal mLogcatManagerInternal =
            LocalServices.getService(LogcatManagerService.LogcatManagerServiceInternal.class);

    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;
@@ -81,6 +89,9 @@ public class LogAccessDialogActivity extends Activity implements
            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;
@@ -118,6 +129,13 @@ public class LogAccessDialogActivity extends Activity implements
            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");
@@ -165,13 +183,22 @@ public class LogAccessDialogActivity extends Activity implements
        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(getApplicationContext(), themeId);
        Context themedContext = new ContextThemeWrapper(this, themeId);
        final View view = LayoutInflater.from(themedContext).inflate(
                R.layout.log_access_user_consent_dialog_permission, null /*root*/);

@@ -182,6 +209,19 @@ public class LogAccessDialogActivity extends Activity implements
        ((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);

@@ -194,9 +234,10 @@ public class LogAccessDialogActivity extends Activity implements

    @Override
    public void onClick(View view) {
        try {
            switch (view.getId()) {
                case R.id.log_access_dialog_allow_button:
                mLogcatManagerInternal.approveAccessForClient(mUid, mPackageName);
                    mCallback.approveAccessForClient(mUid, mPackageName);
                    finish();
                    break;
                case R.id.log_access_dialog_deny_button:
@@ -204,9 +245,16 @@ public class LogAccessDialogActivity extends Activity implements
                    finish();
                    break;
            }
        } catch (RemoteException e) {
            finish();
        }
    }

    private void declineLogAccess() {
        mLogcatManagerInternal.declineAccessForClient(mUid, mPackageName);
        try {
            mCallback.declineAccessForClient(mUid, mPackageName);
        } catch (RemoteException e) {
            finish();
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -6783,8 +6783,9 @@
                  android:exported="false">
        </activity>

        <activity android:name="com.android.server.logcat.LogAccessDialogActivity"
        <activity android:name="com.android.internal.app.LogAccessDialogActivity"
                  android:theme="@style/Theme.Translucent.NoTitleBar"
                  android:process=":ui"
                  android:excludeFromRecents="true"
                  android:exported="false">
        </activity>
+12 −1
Original line number Diff line number Diff line
@@ -5755,10 +5755,21 @@
    <string name="log_access_confirmation_deny">Don\u2019t allow</string>

    <!-- Content for the log access confirmation dialog. [CHAR LIMIT=NONE]-->
    <string name="log_access_confirmation_body">Device logs record what happens on your device. Apps can use these logs to find and fix issues.\n\nSome logs may contain sensitive info, so only allow apps you trust to access all device logs.
    <string name="log_access_confirmation_body" product="default">Device logs record what happens on your device. Apps can use these logs to find and fix issues.\n\nSome logs may contain sensitive info, so only allow apps you trust to access all device logs.
        \n\nIf you don’t allow this app to access all device logs, it can still access its own logs. Your device manufacturer may still be able to access some logs or info on your device.
    </string>

    <!-- Content for the log access confirmation dialog. [CHAR LIMIT=NONE]-->
    <string name="log_access_confirmation_body" product="tv">Device logs record what happens on your device. Apps can use these logs to find and fix issues.\n\nSome logs may contain sensitive info, so only allow apps you trust to access all device logs.
        \n\nIf you don’t allow this app to access all device logs, it can still access its own logs. Your device manufacturer may still be able to access some logs or info on your device.\n\nLearn more at g.co/android/devicelogs.
    </string>

    <!-- Learn more URL for the log access confirmation dialog. [DO NOT TRANSLATE]-->
    <string name="log_access_confirmation_learn_more" product="default" translatable="false">&lt;a href="https://support.google.com/android?p=system_logs#topic=7313011"&gt;Learn more&lt;/a&gt;</string>

    <!-- Learn more URL for the log access confirmation dialog. [DO NOT TRANSLATE]-->
    <string name="log_access_confirmation_learn_more" product="tv" translatable="false"></string>

    <!-- Privacy notice do not show [CHAR LIMIT=20] -->
    <string name="log_access_do_not_show_again">Don\u2019t show again</string>

+2 −0
Original line number Diff line number Diff line
@@ -3925,8 +3925,10 @@
  <java-symbol type="string" name="log_access_confirmation_deny" />
  <java-symbol type="string" name="log_access_confirmation_title" />
  <java-symbol type="string" name="log_access_confirmation_body" />
  <java-symbol type="string" name="log_access_confirmation_learn_more" />
  <java-symbol type="layout" name="log_access_user_consent_dialog_permission" />
  <java-symbol type="id" name="log_access_dialog_title" />
  <java-symbol type="id" name="log_access_dialog_body" />
  <java-symbol type="id" name="log_access_dialog_allow_button" />
  <java-symbol type="id" name="log_access_dialog_deny_button" />

Loading