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

Commit 1c6ac92e authored by Matt Gilbride's avatar Matt Gilbride
Browse files

Make IDropBoxManagerService compatible with aidl_interface

IDropBoxManagerService referenced hand-crafted parcelable
DropBoxManager.Entry, making it incompatible with aidl_interface.
This change makes the AIDL files compatible by wrapping the internal
implementation:

- Removes `DropBoxManager.aidl`, which referenced a C header to include
  the manually implemented Parcelable `DropBoxManager.Entry`.
- Moves `Entry` to an AIDL parcelable within
  `IDropbBoxManagerService.aidl`
- Modifies `IDropBoxManagerService.java` to return
  `IDropBoxManagerService.Entry` instead of `DropBoxManager.Entry`, in
  accordance with the new AIDL surface.
- `DropBoxManager.h` implemented `DropBoxManager.Entry`, but it wasn't
  used anywhere in native code. Removes the `Entry` implementation
  there.
- `DropBoxManager.java` implements `DropBoxManager.Entry` as part of its
  public API surface. Thus, we can't remove this manually implemented
  Parcelable. Modifies `DropBoxManager.java` to wrap the new
  `IDropBoxManagerService.Entry` returned by the service and return
  a `DropBoxManager.Entry` constructed from
  `IDropBoxManagerService.Entry` where necessary. This keeps the API
  surface the same.
- Adds `DropBoxManagerTestCpp` as a sanity check to ensure the native
  API still works.

Bug: 420949170
Bug: 368152571
Test: atest DropBoxManagerTestCpp
Test: atest CtsDropBoxManagerTestCases
Flag: EXEMPT pure refactor, no API or behavioral changes
Change-Id: Iddadeb5a175e395982ea632194f433536936aa26
parent e5d353a3
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -104,14 +104,15 @@ release_package_messagequeue_implementation_srcs {
    out: ["android/os/MessageQueue.java"],
}

aidl_library {
    name: "IDropBoxManagerService_aidl",
    srcs: [
        "com/android/internal/os/IDropBoxManagerService.aidl",
    ],
    hdrs: [
        "android/os/DropBoxManager.aidl",
    ],
aidl_interface {
    name: "dropboxmanager_aidl",
    srcs: ["com/android/internal/os/IDropBoxManagerService.aidl"],
    unstable: true,
    backend: {
        java: {
            enabled: false, // TODO(b/424186512) switch frameworks/base to using this as well, it uses core build **/*.aidl glob now
        },
    },
}

filegroup {
+0 −19
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 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.os;

parcelable DropBoxManager.Entry cpp_header "android/os/DropBoxManager.h";
+27 −20
Original line number Diff line number Diff line
@@ -202,6 +202,16 @@ public class DropBoxManager {
            mFlags = flags;
        }

        private Entry(@NonNull IDropBoxManagerService.Entry internalEntry) {
            if (internalEntry == null) throw new NullPointerException("internalEntry == null");

            mTag = internalEntry.tag;
            mTimeMillis = internalEntry.timestamp;
            mData = internalEntry.data;
            mFileDescriptor = internalEntry.fd;
            mFlags = internalEntry.flags;
        }

        /** Close the input stream associated with this entry. */
        public void close() {
            try { if (mFileDescriptor != null) mFileDescriptor.close(); } catch (IOException e) { }
@@ -266,15 +276,9 @@ public class DropBoxManager {
        public static final @android.annotation.NonNull Parcelable.Creator<Entry> CREATOR = new Parcelable.Creator() {
            public Entry[] newArray(int size) { return new Entry[size]; }
            public Entry createFromParcel(Parcel in) {
                String tag = in.readString();
                long millis = in.readLong();
                int flags = in.readInt();
                if ((flags & HAS_BYTE_ARRAY) != 0) {
                    return new Entry(tag, millis, in.createByteArray(), flags & ~HAS_BYTE_ARRAY);
                } else {
                    ParcelFileDescriptor pfd = ParcelFileDescriptor.CREATOR.createFromParcel(in);
                    return new Entry(tag, millis, pfd, flags);
                }
                IDropBoxManagerService.Entry internalEntry =
                        IDropBoxManagerService.Entry.CREATOR.createFromParcel(in);
                return internalEntry == null ? null : new Entry(internalEntry);
            }
        };

@@ -283,15 +287,17 @@ public class DropBoxManager {
        }

        public void writeToParcel(Parcel out, int flags) {
            out.writeString(mTag);
            out.writeLong(mTimeMillis);
            if (mFileDescriptor != null) {
                out.writeInt(mFlags & ~HAS_BYTE_ARRAY);  // Clear bit just to be safe
                mFileDescriptor.writeToParcel(out, flags);
            } else {
                out.writeInt(mFlags | HAS_BYTE_ARRAY);
                out.writeByteArray(mData);
            toInternalEntry().writeToParcel(out, flags);
        }

        private IDropBoxManagerService.Entry toInternalEntry() {
            IDropBoxManagerService.Entry internalEntry = new IDropBoxManagerService.Entry();
            internalEntry.tag = mTag;
            internalEntry.timestamp = mTimeMillis;
            internalEntry.fd = mFileDescriptor;
            internalEntry.flags = mFlags;
            internalEntry.data = mData;
            return internalEntry;
        }
    }

@@ -393,8 +399,9 @@ public class DropBoxManager {
    @RequiresPermission(allOf = { READ_DROPBOX_DATA, PACKAGE_USAGE_STATS })
    public @Nullable Entry getNextEntry(String tag, long msec) {
        try {
            return mService.getNextEntryWithAttribution(tag, msec, mContext.getOpPackageName(),
                    mContext.getAttributionTag());
            IDropBoxManagerService.Entry entry = mService.getNextEntryWithAttribution(
                    tag, msec, mContext.getOpPackageName(), mContext.getAttributionTag());
            return entry == null ? null : new Entry(entry);
        } catch (SecurityException e) {
            if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.P) {
                throw e;
+15 −3
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.internal.os;

import android.os.DropBoxManager;
import android.os.ParcelFileDescriptor;

/**
@@ -36,8 +35,21 @@ interface IDropBoxManagerService {
    /** @see DropBoxManager#getNextEntry */
    @UnsupportedAppUsage(maxTargetSdk=30,
            publicAlternatives="Use {@link android.os.DropBoxManager#getNextEntry} instead")
    DropBoxManager.Entry getNextEntry(String tag, long millis, String packageName);
    Entry getNextEntry(String tag, long millis, String packageName);

    DropBoxManager.Entry getNextEntryWithAttribution(String tag, long millis, String packageName,
    Entry getNextEntryWithAttribution(String tag, long millis, String packageName,
            String attributionTag);

    /**
     * An entry maintained by drop box, including contents and metadata.
     * @hide
     */
    parcelable Entry {
        String tag;
        long timestamp;
        ParcelFileDescriptor fd;
        int flags;
        byte[] data;
    }

}
+15 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ cc_library_shared {
        "libcutils",
        "liblog",
        "libutils",
        "dropboxmanager_aidl-cpp",
    ],
    header_libs: [
        "libbase_headers",
@@ -42,7 +43,6 @@ cc_library_shared {
    aidl: {
        libs: [
            "ILogcatManagerService_aidl",
            "IDropBoxManagerService_aidl",
        ],
    },

@@ -56,3 +56,17 @@ cc_library_shared {
        "-Wunreachable-code",
    ],
}

cc_test {
    name: "DropBoxManagerTestCpp",
    team: "trendy_team_foundations",
    srcs: [
        "test/DropBoxManagerTest.cpp",
    ],
    shared_libs: [
        "libbase",
        "libservices",
        "libutils",
    ],
    require_root: true,
}
Loading