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

Commit 365f625e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make PackageNameUserHandlePair Parcelable" into main

parents 36542874 95fae49f
Loading
Loading
Loading
Loading
+18 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2025 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 android.media;

parcelable AppId;
+94 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2025 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 android.media;

import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserHandle;

import java.util.Objects;

/**
 * A pair of {@link UserHandle} and package name to uniquely identify apps.
 *
 * @hide
 */
public final class AppId implements Parcelable {

    public static final Creator<AppId> CREATOR =
            new Creator<>() {
                @Override
                public AppId createFromParcel(Parcel in) {
                    return new AppId(
                            in.readString(),
                            in.readParcelable(UserHandle.class.getClassLoader(), UserHandle.class));
                }

                @Override
                public AppId[] newArray(int size) {
                    return new AppId[size];
                }
            };

    public final String mPackageName;
    public final UserHandle mUserHandle;

    /** Constructor. */
    public AppId(String mPackageName, UserHandle mUserHandle) {
        this.mPackageName = mPackageName;
        this.mUserHandle = mUserHandle;
    }

    // Parcelable implementation.

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mPackageName);
        dest.writeParcelable(mUserHandle, flags);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    // Object implementation.

    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (obj == null || obj.getClass() != this.getClass()) return false;
        var that = (AppId) obj;
        return Objects.equals(this.mPackageName, that.mPackageName)
                && Objects.equals(this.mUserHandle, that.mUserHandle);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mPackageName, mUserHandle);
    }

    @Override
    public String toString() {
        return "AppId["
                + "mPackageName='"
                + mPackageName
                + "', "
                + "mUserHandle="
                + mUserHandle
                + ']';
    }
}
+3 −7
Original line number Original line Diff line number Diff line
@@ -140,13 +140,10 @@ public final class MediaRouter2 {
    // The manager request ID representing that no manager is involved.
    // The manager request ID representing that no manager is involved.
    private static final long MANAGER_REQUEST_ID_NONE = MediaRoute2ProviderService.REQUEST_ID_NONE;
    private static final long MANAGER_REQUEST_ID_NONE = MediaRoute2ProviderService.REQUEST_ID_NONE;


    private record PackageNameUserHandlePair(String packageName, UserHandle user) {}

    private record InstanceInvalidatedCallbackRecord(Executor executor, Runnable runnable) {}
    private record InstanceInvalidatedCallbackRecord(Executor executor, Runnable runnable) {}


    @GuardedBy("sSystemRouterLock")
    @GuardedBy("sSystemRouterLock")
    private static final Map<PackageNameUserHandlePair, MediaRouter2> sAppToProxyRouterMap =
    private static final Map<AppId, MediaRouter2> sAppToProxyRouterMap = new ArrayMap<>();
            new ArrayMap<>();


    @GuardedBy("sRouterLock")
    @GuardedBy("sRouterLock")
    private static MediaRouter2 sInstance;
    private static MediaRouter2 sInstance;
@@ -438,7 +435,7 @@ public final class MediaRouter2 {
            }
            }
        }
        }


        PackageNameUserHandlePair key = new PackageNameUserHandlePair(clientPackageName, user);
        AppId key = new AppId(clientPackageName, user);


        synchronized (sSystemRouterLock) {
        synchronized (sSystemRouterLock) {
            MediaRouter2 instance = sAppToProxyRouterMap.get(key);
            MediaRouter2 instance = sAppToProxyRouterMap.get(key);
@@ -3720,8 +3717,7 @@ public final class MediaRouter2 {
            // After this block, all following getInstance() calls should throw a SecurityException,
            // After this block, all following getInstance() calls should throw a SecurityException,
            // so no new onInstanceInvalidatedListeners can be registered to this instance.
            // so no new onInstanceInvalidatedListeners can be registered to this instance.
            synchronized (sSystemRouterLock) {
            synchronized (sSystemRouterLock) {
                PackageNameUserHandlePair key =
                AppId key = new AppId(mClientPackageName, mClientUser);
                        new PackageNameUserHandlePair(mClientPackageName, mClientUser);
                sAppToProxyRouterMap.remove(key);
                sAppToProxyRouterMap.remove(key);
            }
            }