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

Commit 3a0ce014 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Merge cherrypicks of ['googleplex-android-review.googlesource.com/23563580',...

Merge cherrypicks of ['googleplex-android-review.googlesource.com/23563580', 'googleplex-android-review.googlesource.com/23728493', 'googleplex-android-review.googlesource.com/23545068'] into security-aosp-tm-release.

Change-Id: I45da8cc8ba14f6d2d9bcfb42adbbb18659bc0c54
parents 185bd5b8 846180c1
Loading
Loading
Loading
Loading
+68 −61
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import android.text.TextUtils.TruncateAt;
import android.util.EventLog;
import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -156,9 +157,9 @@ public class DeviceAdminAdd extends CollapsingToolbarBaseActivity {

        mHandler = new Handler(getMainLooper());

        mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
        mAppOps = (AppOpsManager)getSystemService(Context.APP_OPS_SERVICE);
        mLayoutInflaternflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mDPM = getSystemService(DevicePolicyManager.class);
        mAppOps = getSystemService(AppOpsManager.class);
        mLayoutInflaternflater = getSystemService(LayoutInflater.class);
        PackageManager packageManager = getPackageManager();

        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
@@ -421,8 +422,8 @@ public class DeviceAdminAdd extends CollapsingToolbarBaseActivity {

        final View restrictedAction = findViewById(R.id.restricted_action);
        restrictedAction.setFilterTouchesWhenObscured(true);
        restrictedAction.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

        final View.OnClickListener restrictedActionClickListener = v -> {
            if (!mActionButton.isEnabled()) {
                showPolicyTransparencyDialogIfRequired();
                return;
@@ -465,14 +466,20 @@ public class DeviceAdminAdd extends CollapsingToolbarBaseActivity {
                            }
                        }, mHandler));
                // Don't want to wait too long.
                    getWindow().getDecorView().getHandler().postDelayed(new Runnable() {
                        @Override public void run() {
                            continueRemoveAction(null);
                        }
                    }, 2*1000);
                }
                getWindow().getDecorView().getHandler().postDelayed(
                        () -> continueRemoveAction(null), 2 * 1000);
            }
        };
        restrictedAction.setOnKeyListener((view, keyCode, keyEvent) -> {
            if ((keyEvent.getFlags() & KeyEvent.FLAG_FROM_SYSTEM) == 0) {
                Log.e(TAG, "Can not activate device-admin with KeyEvent from non-system app.");
                // Consume event to suppress click.
                return true;
            }
            // Fallback to view click handler.
            return false;
        });
        restrictedAction.setOnClickListener(restrictedActionClickListener);
    }

    /**
+4 −1
Original line number Diff line number Diff line
@@ -81,6 +81,8 @@ public class ApprovalPreferenceController extends BasePreferenceController {
        final RestrictedSwitchPreference preference =
                (RestrictedSwitchPreference) pref;
        final CharSequence label = mPkgInfo.applicationInfo.loadLabel(mPm);
        final boolean isAllowedCn = mCn.flattenToShortString().length()
                <= NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH;
        final boolean isEnabled = isServiceEnabled(mCn);
        preference.setChecked(isEnabled);
        preference.setOnPreferenceChangeListener((p, newValue) -> {
@@ -105,7 +107,8 @@ public class ApprovalPreferenceController extends BasePreferenceController {
                return false;
            }
        });
        preference.updateState(mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isEnabled);
        preference.updateState(
                mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isAllowedCn, isEnabled);
    }

    public void disable(final ComponentName cn) {
+3 −1
Original line number Diff line number Diff line
@@ -67,7 +67,9 @@ public class NotificationAccessConfirmationActivity extends Activity
        mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL);
        CharSequence mAppLabel;

        if (mComponentName == null || mComponentName.getPackageName() == null) {
        if (mComponentName == null || mComponentName.getPackageName() == null
                || mComponentName.flattenToString().length()
                > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) {
            finish();
            return;
        }
+14 −13
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.widget.Toast;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.applications.AppInfoBase;
@@ -63,9 +64,8 @@ import java.util.List;
@SearchIndexable
public class NotificationAccessSettings extends EmptyTextSettings {
    private static final String TAG = "NotifAccessSettings";
    private static final String ALLOWED_KEY = "allowed";
    private static final String NOT_ALLOWED_KEY = "not_allowed";
    private static final int MAX_CN_LENGTH = 500;
    static final String ALLOWED_KEY = "allowed";
    static final String NOT_ALLOWED_KEY = "not_allowed";

    private static final ManagedServiceSettings.Config CONFIG =
            new ManagedServiceSettings.Config.Builder()
@@ -80,9 +80,9 @@ public class NotificationAccessSettings extends EmptyTextSettings {
                    .setEmptyText(R.string.no_notification_listeners)
                    .build();

    private NotificationManager mNm;
    @VisibleForTesting NotificationManager mNm;
    protected Context mContext;
    private PackageManager mPm;
    @VisibleForTesting PackageManager mPm;
    private DevicePolicyManager mDpm;
    private ServiceListing mServiceListing;
    private IconDrawableFactory mIconDrawableFactory;
@@ -102,12 +102,6 @@ public class NotificationAccessSettings extends EmptyTextSettings {
                .setNoun(CONFIG.noun)
                .setSetting(CONFIG.setting)
                .setTag(CONFIG.tag)
                .setValidator(info -> {
                    if (info.getComponentName().flattenToString().length() > MAX_CN_LENGTH) {
                        return false;
                    }
                    return true;
                })
                .build();
        mServiceListing.addCallback(this::updateList);

@@ -140,7 +134,8 @@ public class NotificationAccessSettings extends EmptyTextSettings {
        mServiceListing.setListening(false);
    }

    private void updateList(List<ServiceInfo> services) {
    @VisibleForTesting
    void updateList(List<ServiceInfo> services) {
        final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        final int managedProfileId = Utils.getManagedProfileId(um, UserHandle.myUserId());

@@ -153,6 +148,12 @@ public class NotificationAccessSettings extends EmptyTextSettings {
        services.sort(new PackageItemInfo.DisplayNameComparator(mPm));
        for (ServiceInfo service : services) {
            final ComponentName cn = new ComponentName(service.packageName, service.name);
            boolean isAllowed = mNm.isNotificationListenerAccessGranted(cn);
            if (!isAllowed && cn.flattenToString().length()
                    > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) {
                continue;
            }

            CharSequence title = null;
            try {
                title = mPm.getApplicationInfoAsUser(
@@ -200,7 +201,7 @@ public class NotificationAccessSettings extends EmptyTextSettings {
                        return true;
                    });
            pref.setKey(cn.flattenToString());
            if (mNm.isNotificationListenerAccessGranted(cn)) {
            if (isAllowed) {
                allowedCategory.addPreference(pref);
            } else {
                notAllowedCategory.addPreference(pref);
+3 −0
Original line number Diff line number Diff line
@@ -132,6 +132,9 @@ public class NotificationBackend {

    static public CharSequence getDeviceList(ICompanionDeviceManager cdm, LocalBluetoothManager lbm,
            String pkg, int userId) {
        if (cdm == null) {
            return "";
        }
        boolean multiple = false;
        StringBuilder sb = new StringBuilder();

Loading