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

Commit 374238a9 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker Committed by Justin Dunlap
Browse files

Merge cherrypicks of [19539263, 19967553, 20123964, 20226664, 20029904,...

Merge cherrypicks of [19539263, 19967553, 20123964, 20226664, 20029904, 20250395, 20251403, 20036692, 20306468, 20210471, 20222490, 20181501, 20219552] into security-aosp-tm-release.

Change-Id: Icd609680341d607196d4314f498c37b217d34b6c
parents 0492bf49 16c604aa
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -107,6 +107,34 @@ public class UsbDeviceConnection {
        }
    }

    /**
     * This is meant to be called by UsbRequest's queue() in order to synchronize on
     * UsbDeviceConnection's mLock to prevent the connection being closed while queueing.
     */
    /* package */ boolean queueRequest(UsbRequest request, ByteBuffer buffer, int length) {
        synchronized (mLock) {
            if (!isOpen()) {
                return false;
            }

            return request.queueIfConnectionOpen(buffer, length);
        }
    }

    /**
     * This is meant to be called by UsbRequest's queue() in order to synchronize on
     * UsbDeviceConnection's mLock to prevent the connection being closed while queueing.
     */
    /* package */ boolean queueRequest(UsbRequest request, @Nullable ByteBuffer buffer) {
        synchronized (mLock) {
            if (!isOpen()) {
                return false;
            }

            return request.queueIfConnectionOpen(buffer);
        }
    }

    /**
     * Releases all system resources related to the device.
     * Once the object is closed it cannot be used again.
+58 −10
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ public class UsbRequest {
     * Releases all resources related to this request.
     */
    public void close() {
        synchronized (mLock) {
            if (mNativeContext != 0) {
                mEndpoint = null;
                mConnection = null;
@@ -120,6 +121,7 @@ public class UsbRequest {
                mCloseGuard.close();
            }
        }
    }

    @Override
    protected void finalize() throws Throwable {
@@ -191,10 +193,32 @@ public class UsbRequest {
     */
    @Deprecated
    public boolean queue(ByteBuffer buffer, int length) {
        UsbDeviceConnection connection = mConnection;
        if (connection == null) {
            // The expected exception by CTS Verifier - USB Device test
            throw new NullPointerException("invalid connection");
        }

        // Calling into the underlying UsbDeviceConnection to synchronize on its lock, to prevent
        // the connection being closed while queueing.
        return connection.queueRequest(this, buffer, length);
    }

    /**
     * This is meant to be called from UsbDeviceConnection after synchronizing using the lock over
     * there, to prevent the connection being closed while queueing.
     */
    /* package */ boolean queueIfConnectionOpen(ByteBuffer buffer, int length) {
        UsbDeviceConnection connection = mConnection;
        if (connection == null || !connection.isOpen()) {
            // The expected exception by CTS Verifier - USB Device test
            throw new NullPointerException("invalid connection");
        }

        boolean out = (mEndpoint.getDirection() == UsbConstants.USB_DIR_OUT);
        boolean result;

        if (mConnection.getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.P
        if (connection.getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.P
                && length > MAX_USBFS_BUFFER_SIZE) {
            length = MAX_USBFS_BUFFER_SIZE;
        }
@@ -243,6 +267,28 @@ public class UsbRequest {
     * @return true if the queueing operation succeeded
     */
    public boolean queue(@Nullable ByteBuffer buffer) {
        UsbDeviceConnection connection = mConnection;
        if (connection == null) {
            // The expected exception by CTS Verifier - USB Device test
            throw new IllegalStateException("invalid connection");
        }

        // Calling into the underlying UsbDeviceConnection to synchronize on its lock, to prevent
        // the connection being closed while queueing.
        return connection.queueRequest(this, buffer);
    }

    /**
     * This is meant to be called from UsbDeviceConnection after synchronizing using the lock over
     * there, to prevent the connection being closed while queueing.
     */
    /* package */ boolean queueIfConnectionOpen(@Nullable ByteBuffer buffer) {
        UsbDeviceConnection connection = mConnection;
        if (connection == null || !connection.isOpen()) {
            // The expected exception by CTS Verifier - USB Device test
            throw new IllegalStateException("invalid connection");
        }

        // Request need to be initialized
        Preconditions.checkState(mNativeContext != 0, "request is not initialized");

@@ -260,7 +306,7 @@ public class UsbRequest {
                mIsUsingNewQueue = true;
                wasQueued = native_queue(null, 0, 0);
            } else {
                if (mConnection.getContext().getApplicationInfo().targetSdkVersion
                if (connection.getContext().getApplicationInfo().targetSdkVersion
                        < Build.VERSION_CODES.P) {
                    // Can only send/receive MAX_USBFS_BUFFER_SIZE bytes at once
                    Preconditions.checkArgumentInRange(buffer.remaining(), 0, MAX_USBFS_BUFFER_SIZE,
@@ -363,11 +409,12 @@ public class UsbRequest {
     * @return true if cancelling succeeded
     */
    public boolean cancel() {
        if (mConnection == null) {
        UsbDeviceConnection connection = mConnection;
        if (connection == null) {
            return false;
        }

        return mConnection.cancelRequest(this);
        return connection.cancelRequest(this);
    }

    /**
@@ -382,7 +429,8 @@ public class UsbRequest {
     * @return true if cancelling succeeded.
     */
    /* package */ boolean cancelIfOpen() {
        if (mNativeContext == 0 || (mConnection != null && !mConnection.isOpen())) {
        UsbDeviceConnection connection = mConnection;
        if (mNativeContext == 0 || (connection != null && !connection.isOpen())) {
            Log.w(TAG,
                    "Detected attempt to cancel a request on a connection which isn't open");
            return false;
+20 −3
Original line number Diff line number Diff line
@@ -3344,9 +3344,26 @@ public final class Settings {
                    }
                }
                Bundle b;
                // b/252663068: if we're in system server and the caller did not call
                // clearCallingIdentity, the read would fail due to mismatched AttributionSources.
                // TODO(b/256013480): remove this bypass after fixing the callers in system server.
                if (namespace.equals(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER)
                        && Settings.isInSystemServer()
                        && Binder.getCallingUid() != Process.myUid()) {
                    final long token = Binder.clearCallingIdentity();
                    try {
                        // Fetch all flags for the namespace at once for caching purposes
                        b = cp.call(cr.getAttributionSource(),
                                mProviderHolder.mUri.getAuthority(), mCallListCommand, null, args);
                    } finally {
                        Binder.restoreCallingIdentity(token);
                    }
                } else {
                    // Fetch all flags for the namespace at once for caching purposes
                Bundle b = cp.call(cr.getAttributionSource(),
                    b = cp.call(cr.getAttributionSource(),
                            mProviderHolder.mUri.getAuthority(), mCallListCommand, null, args);
                }
                if (b == null) {
                    // Invalid response, return an empty map
                    return keyValues;
+34 −4
Original line number Diff line number Diff line
@@ -90,6 +90,12 @@ public final class Condition implements Parcelable {
    public final int flags;
    public final int icon;

    /**
     * The maximum string length for any string contained in this condition.
     * @hide
     */
    public static final int MAX_STRING_LENGTH = 1000;

    /**
     * An object representing the current state of a {@link android.app.AutomaticZenRule}.
     * @param id the {@link android.app.AutomaticZenRule#getConditionId()} of the zen rule
@@ -104,16 +110,19 @@ public final class Condition implements Parcelable {
        if (id == null) throw new IllegalArgumentException("id is required");
        if (summary == null) throw new IllegalArgumentException("summary is required");
        if (!isValidState(state)) throw new IllegalArgumentException("state is invalid: " + state);
        this.id = id;
        this.summary = summary;
        this.line1 = line1;
        this.line2 = line2;
        this.id = getTrimmedUri(id);
        this.summary = getTrimmedString(summary);
        this.line1 = getTrimmedString(line1);
        this.line2 = getTrimmedString(line2);
        this.icon = icon;
        this.state = state;
        this.flags = flags;
    }

    public Condition(Parcel source) {
        // This constructor passes all fields directly into the constructor that takes all the
        // fields as arguments; that constructor will trim each of the input strings to
        // max length if necessary.
        this((Uri)source.readParcelable(Condition.class.getClassLoader(), android.net.Uri.class),
                source.readString(),
                source.readString(),
@@ -240,4 +249,25 @@ public final class Condition implements Parcelable {
            return new Condition[size];
        }
    };

    /**
     * Returns a truncated copy of the string if the string is longer than MAX_STRING_LENGTH.
     */
    private static String getTrimmedString(String input) {
        if (input != null && input.length() > MAX_STRING_LENGTH) {
            return input.substring(0, MAX_STRING_LENGTH);
        }
        return input;
    }

    /**
     * Returns a truncated copy of the Uri by trimming the string representation to the maximum
     * string length.
     */
    private static Uri getTrimmedUri(Uri input) {
        if (input != null && input.toString().length() > MAX_STRING_LENGTH) {
            return Uri.parse(getTrimmedString(input.toString()));
        }
        return input;
    }
}
+0 −15
Original line number Diff line number Diff line
@@ -1283,9 +1283,6 @@ public class ResolverActivity extends Activity implements
        }

        if (target != null) {
            if (intent != null && isLaunchingTargetInOtherProfile()) {
                prepareIntentForCrossProfileLaunch(intent);
            }
            safelyStartActivity(target);

            // Rely on the ActivityManager to pop up a dialog regarding app suspension
@@ -1298,15 +1295,6 @@ public class ResolverActivity extends Activity implements
        return true;
    }

    private void prepareIntentForCrossProfileLaunch(Intent intent) {
        intent.fixUris(UserHandle.myUserId());
    }

    private boolean isLaunchingTargetInOtherProfile() {
        return mMultiProfilePagerAdapter.getCurrentUserHandle().getIdentifier()
                != UserHandle.myUserId();
    }

    @VisibleForTesting
    public void safelyStartActivity(TargetInfo cti) {
        // We're dispatching intents that might be coming from legacy apps, so
@@ -1508,9 +1496,6 @@ public class ResolverActivity extends Activity implements

        findViewById(R.id.button_open).setOnClickListener(v -> {
            Intent intent = otherProfileResolveInfo.getResolvedIntent();
            if (intent != null) {
                prepareIntentForCrossProfileLaunch(intent);
            }
            safelyStartActivityAsUser(otherProfileResolveInfo,
                    inactiveAdapter.mResolverListController.getUserHandle());
            finish();
Loading