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

Commit c87a9d24 authored by Robert Horvath's avatar Robert Horvath Committed by Automerger Merge Worker
Browse files

Merge changes I6a3f56bd,Ib5f39eb1 into tm-dev am: 1999fa10 am: 7d58f856 am: 4d3c2b3b

parents c67ef4fa 4d3c2b3b
Loading
Loading
Loading
Loading
+0 −27
Original line number Diff line number Diff line
@@ -42,31 +42,4 @@ oneway interface ILogcatManagerService {
     * @param fd  The FD (Socket) of client who makes the request.
     */
    void finishThread(in int uid, in int gid, in int pid, in int fd);


    /**
     * The function is called by UX component to notify
     * LogcatManagerService that the user approved
     * the privileged log data access.
     *
     * @param uid The UID of client who makes the request.
     * @param gid The GID of client who makes the request.
     * @param pid The PID of client who makes the request.
     * @param fd  The FD (Socket) of client who makes the request.
     */
    void approve(in int uid, in int gid, in int pid, in int fd);


    /**
     * The function is called by UX component to notify
     * LogcatManagerService that the user declined
     * the privileged log data access.
     *
     * @param uid The UID of client who makes the request.
     * @param gid The GID of client who makes the request.
     * @param pid The PID of client who makes the request.
     * @param fd  The FD (Socket) of client who makes the request.
     */
    void decline(in int uid, in int gid, in int pid, in int fd);
}
+1 −2
Original line number Diff line number Diff line
@@ -6776,9 +6776,8 @@
        </activity>

        <activity android:name="com.android.server.logcat.LogAccessDialogActivity"
                  android:theme="@style/Theme.DeviceDefault.Dialog.Alert.DayNight"
                  android:theme="@style/Theme.Translucent.NoTitleBar"
                  android:excludeFromRecents="true"
                  android:label="@string/log_access_confirmation_title"
                  android:exported="false">
        </activity>

+69 −80
Original line number Diff line number Diff line
@@ -16,26 +16,28 @@

package com.android.server.logcat;

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.ServiceManager;
import android.os.UserHandle;
import android.os.logcat.ILogcatManagerService;
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;
import com.android.server.LocalServices;

/**
 * Dialog responsible for obtaining user consent per-use log access
@@ -43,45 +45,54 @@ import com.android.internal.R;
public class LogAccessDialogActivity extends Activity implements
        View.OnClickListener {
    private static final String TAG = LogAccessDialogActivity.class.getSimpleName();
    private Context mContext;

    private final ILogcatManagerService mLogcatManagerService =
            ILogcatManagerService.Stub.asInterface(ServiceManager.getService("logcat"));
    private static final int DIALOG_TIME_OUT = Build.IS_DEBUGGABLE ? 60000 : 300000;
    private static final int MSG_DISMISS_DIALOG = 0;

    private String mPackageName;
    private final LogcatManagerService.LogcatManagerServiceInternal mLogcatManagerInternal =
            LocalServices.getService(LogcatManagerService.LogcatManagerServiceInternal.class);

    private String mPackageName;
    private int mUid;
    private int mGid;
    private int mPid;
    private int mFd;

    private String mAlertTitle;
    private AlertDialog.Builder mAlertDialog;
    private AlertDialog mAlert;
    private View mAlertView;

    private static final int DIALOG_TIME_OUT = Build.IS_DEBUGGABLE ? 60000 : 300000;
    private static final int MSG_DISMISS_DIALOG = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        try {
            mContext = this;

        // retrieve Intent extra information
            Intent intent = getIntent();
            getIntentInfo(intent);
        if (!readIntentInfo(getIntent())) {
            Slog.e(TAG, "Invalid Intent extras, finishing");
            finish();
            return;
        }

        // retrieve the title string from passed intent extra
            mAlertTitle = getTitleString(mContext, mPackageName, mUid);
        try {
            mAlertTitle = getTitleString(this, mPackageName, mUid);
        } catch (NameNotFoundException e) {
            Slog.e(TAG, "Unable to fetch label of package " + mPackageName, e);
            declineLogAccess();
            finish();
            return;
        }

            // creaet View
            mAlertView = createView();
        // 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);
        mAlertDialog = new AlertDialog.Builder(this, themeId);
        mAlertDialog.setView(mAlertView);
        mAlertDialog.setOnCancelListener(dialog -> declineLogAccess());
        mAlertDialog.setOnDismissListener(dialog -> finish());

        // show Alert
        mAlert = mAlertDialog.create();
@@ -89,15 +100,6 @@ public class LogAccessDialogActivity extends Activity implements

        // set Alert Timeout
        mHandler.sendEmptyMessageDelayed(MSG_DISMISS_DIALOG, DIALOG_TIME_OUT);

        } catch (Exception e) {
            try {
                Slog.e(TAG, "onCreate failed, declining the logd access", e);
                mLogcatManagerService.decline(mUid, mGid, mPid, mFd);
            } catch (RemoteException ex) {
                Slog.e(TAG, "Fails to call remote functions", ex);
            }
        }
    }

    @Override
@@ -109,21 +111,26 @@ public class LogAccessDialogActivity extends Activity implements
        mAlert = null;
    }

    private void getIntentInfo(Intent intent) throws Exception {

    private boolean readIntentInfo(Intent intent) {
        if (intent == null) {
            throw new NullPointerException("Intent is null");
            Slog.e(TAG, "Intent is null");
            return false;
        }

        mPackageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME);
        if (mPackageName == null || mPackageName.length() == 0) {
            throw new NullPointerException("Package Name is null");
            Slog.e(TAG, "Missing package name extra");
            return false;
        }

        mUid = intent.getIntExtra("com.android.server.logcat.uid", 0);
        mGid = intent.getIntExtra("com.android.server.logcat.gid", 0);
        mPid = intent.getIntExtra("com.android.server.logcat.pid", 0);
        mFd = intent.getIntExtra("com.android.server.logcat.fd", 0);
        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() {
@@ -133,11 +140,7 @@ public class LogAccessDialogActivity extends Activity implements
                    if (mAlert != null) {
                        mAlert.dismiss();
                        mAlert = null;
                        try {
                            mLogcatManagerService.decline(mUid, mGid, mPid, mFd);
                        } catch (RemoteException e) {
                            Slog.e(TAG, "Fails to call remote functions", e);
                        }
                        declineLogAccess();
                    }
                    break;

@@ -148,25 +151,15 @@ public class LogAccessDialogActivity extends Activity implements
    };

    private String getTitleString(Context context, String callingPackage, int uid)
            throws Exception {

            throws NameNotFoundException {
        PackageManager pm = context.getPackageManager();
        if (pm == null) {
            throw new NullPointerException("PackageManager is null");
        }

        CharSequence appLabel = pm.getApplicationInfoAsUser(callingPackage,
                PackageManager.MATCH_DIRECT_BOOT_AUTO,
                UserHandle.getUserId(uid)).loadLabel(pm);
        if (appLabel == null || appLabel.length() == 0) {
            throw new NameNotFoundException("Application Label is null");
        }

        String titleString = context.getString(
                com.android.internal.R.string.log_access_confirmation_title, appLabel);
        if (titleString == null || titleString.length() == 0) {
            throw new NullPointerException("Title is null");
        }

        return titleString;
    }
@@ -176,9 +169,9 @@ public class LogAccessDialogActivity extends Activity implements
     * If we cannot retrieve the package name, it returns null and we decline the full device log
     * access
     */
    private View createView() throws Exception {

        final View view = getLayoutInflater().inflate(
    private View createView(@StyleRes int themeId) {
        Context themedContext = new ContextThemeWrapper(getApplicationContext(), themeId);
        final View view = LayoutInflater.from(themedContext).inflate(
                R.layout.log_access_user_consent_dialog_permission, null /*root*/);

        if (view == null) {
@@ -202,21 +195,17 @@ public class LogAccessDialogActivity extends Activity implements
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.log_access_dialog_allow_button:
                try {
                    mLogcatManagerService.approve(mUid, mGid, mPid, mFd);
                } catch (RemoteException e) {
                    Slog.e(TAG, "Fails to call remote functions", e);
                }
                mLogcatManagerInternal.approveAccessForClient(mUid, mPackageName);
                finish();
                break;
            case R.id.log_access_dialog_deny_button:
                try {
                    mLogcatManagerService.decline(mUid, mGid, mPid, mFd);
                } catch (RemoteException e) {
                    Slog.e(TAG, "Fails to call remote functions", e);
                }
                declineLogAccess();
                finish();
                break;
        }
    }

    private void declineLogAccess() {
        mLogcatManagerInternal.declineAccessForClient(mUid, mPackageName);
    }
}