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

Commit 66daa23b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Implment get/query APIs for properties"

parents 46aed909 569435e0
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -12105,6 +12105,8 @@ package android.content.pm {
    method public abstract android.content.pm.PermissionInfo getPermissionInfo(@NonNull String, int) throws android.content.pm.PackageManager.NameNotFoundException;
    method @Deprecated public abstract int getPreferredActivities(@NonNull java.util.List<android.content.IntentFilter>, @NonNull java.util.List<android.content.ComponentName>, @Nullable String);
    method @Deprecated @NonNull public abstract java.util.List<android.content.pm.PackageInfo> getPreferredPackages(int);
    method @NonNull public android.content.pm.PackageManager.Property getProperty(@NonNull String, @NonNull String) throws android.content.pm.PackageManager.NameNotFoundException;
    method @NonNull public android.content.pm.PackageManager.Property getProperty(@NonNull String, @NonNull android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
    method @NonNull public abstract android.content.pm.ProviderInfo getProviderInfo(@NonNull android.content.ComponentName, int) throws android.content.pm.PackageManager.NameNotFoundException;
    method @NonNull public abstract android.content.pm.ActivityInfo getReceiverInfo(@NonNull android.content.ComponentName, int) throws android.content.pm.PackageManager.NameNotFoundException;
    method @NonNull public abstract android.content.res.Resources getResourcesForActivity(@NonNull android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
@@ -12137,6 +12139,8 @@ package android.content.pm {
    method public boolean isPackageSuspended();
    method @CheckResult public abstract boolean isPermissionRevokedByPolicy(@NonNull String, @NonNull String);
    method public abstract boolean isSafeMode();
    method @NonNull public java.util.List<android.content.pm.PackageManager.Property> queryActivityProperty(@NonNull String);
    method @NonNull public java.util.List<android.content.pm.PackageManager.Property> queryApplicationProperty(@NonNull String);
    method @NonNull public abstract java.util.List<android.content.pm.ResolveInfo> queryBroadcastReceivers(@NonNull android.content.Intent, int);
    method @NonNull public abstract java.util.List<android.content.pm.ProviderInfo> queryContentProviders(@Nullable String, int, int);
    method @NonNull public abstract java.util.List<android.content.pm.InstrumentationInfo> queryInstrumentation(@NonNull String, int);
@@ -12145,6 +12149,9 @@ package android.content.pm {
    method @NonNull public abstract java.util.List<android.content.pm.ResolveInfo> queryIntentContentProviders(@NonNull android.content.Intent, int);
    method @NonNull public abstract java.util.List<android.content.pm.ResolveInfo> queryIntentServices(@NonNull android.content.Intent, int);
    method @NonNull public abstract java.util.List<android.content.pm.PermissionInfo> queryPermissionsByGroup(@NonNull String, int) throws android.content.pm.PackageManager.NameNotFoundException;
    method @NonNull public java.util.List<android.content.pm.PackageManager.Property> queryProviderProperty(@NonNull String);
    method @NonNull public java.util.List<android.content.pm.PackageManager.Property> queryReceiverProperty(@NonNull String);
    method @NonNull public java.util.List<android.content.pm.PackageManager.Property> queryServiceProperty(@NonNull String);
    method @Deprecated public abstract void removePackageFromPreferred(@NonNull String);
    method public abstract void removePermission(@NonNull String);
    method @RequiresPermission(value="android.permission.WHITELIST_RESTRICTED_PERMISSIONS", conditional=true) public boolean removeWhitelistedRestrictedPermission(@NonNull String, @NonNull String, int);
+110 −0
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManager.Property;
import android.content.pm.ParceledListSlice;
import android.content.pm.PermissionGroupInfo;
import android.content.pm.PermissionInfo;
@@ -3551,4 +3553,112 @@ public class ApplicationPackageManager extends PackageManager {
            throw e.rethrowAsRuntimeException();
        }
    }

    @Override
    public Property getProperty(String propertyName, String packageName)
            throws NameNotFoundException {
        Objects.requireNonNull(packageName);
        Objects.requireNonNull(propertyName);
        try {
            final Property property = mPM.getProperty(propertyName, packageName, null);
            if (property == null) {
                throw new NameNotFoundException();
            }
            return property;
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }

    @Override
    public Property getProperty(String propertyName, ComponentName component)
            throws NameNotFoundException {
        Objects.requireNonNull(component);
        Objects.requireNonNull(propertyName);
        try {
            final Property property = mPM.getProperty(
                    propertyName, component.getPackageName(), component.getClassName());
            if (property == null) {
                throw new NameNotFoundException();
            }
            return property;
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }

    @Override
    public List<Property> queryApplicationProperty(String propertyName) {
        Objects.requireNonNull(propertyName);
        try {
            final ParceledListSlice<Property> parceledList =
                    mPM.queryProperty(propertyName, TYPE_APPLICATION);
            if (parceledList == null) {
                return Collections.emptyList();
            }
            return parceledList.getList();
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }

    @Override
    public List<Property> queryActivityProperty(String propertyName) {
        Objects.requireNonNull(propertyName);
        try {
            final ParceledListSlice<Property> parceledList =
                    mPM.queryProperty(propertyName, TYPE_ACTIVITY);
            if (parceledList == null) {
                return Collections.emptyList();
            }
            return parceledList.getList();
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }

    @Override
    public List<Property> queryProviderProperty(String propertyName) {
        Objects.requireNonNull(propertyName);
        try {
            final ParceledListSlice<Property> parceledList =
                    mPM.queryProperty(propertyName, TYPE_PROVIDER);
            if (parceledList == null) {
                return Collections.emptyList();
            }
            return parceledList.getList();
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }

    @Override
    public List<Property> queryReceiverProperty(String propertyName) {
        Objects.requireNonNull(propertyName);
        try {
            final ParceledListSlice<Property> parceledList =
                    mPM.queryProperty(propertyName, TYPE_RECEIVER);
            if (parceledList == null) {
                return Collections.emptyList();
            }
            return parceledList.getList();
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }

    @Override
    public List<Property> queryServiceProperty(String propertyName) {
        Objects.requireNonNull(propertyName);
        try {
            final ParceledListSlice<Property> parceledList =
                    mPM.queryProperty(propertyName, TYPE_SERVICE);
            if (parceledList == null) {
                return Collections.emptyList();
            }
            return parceledList.getList();
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.content.pm.InstrumentationInfo;
import android.content.pm.KeySet;
import android.content.pm.ModuleInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.content.pm.ProviderInfo;
import android.content.pm.PermissionGroupInfo;
@@ -797,4 +798,7 @@ interface IPackageManager {
    IBinder getHoldLockToken();

    void holdLock(in IBinder token, in int durationMs);

    PackageManager.Property getProperty(String propertyName, String packageName, String className);
    ParceledListSlice queryProperty(String propertyName, int componentType);
}
+20 −0
Original line number Diff line number Diff line
/*
**
** Copyright 2020, 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.content.pm;

parcelable PackageManager.Property;
+119 −2
Original line number Diff line number Diff line
@@ -311,6 +311,8 @@ public abstract class PackageManager {
        public void writeToParcel(@NonNull Parcel dest, int flags) {
            dest.writeString(mName);
            dest.writeInt(mType);
            dest.writeString(mPackageName);
            dest.writeString(mClassName);
            if (mType == TYPE_BOOLEAN) {
                dest.writeBoolean(mBooleanValue);
            } else if (mType == TYPE_FLOAT) {
@@ -322,8 +324,6 @@ public abstract class PackageManager {
            } else if (mType == TYPE_STRING) {
                dest.writeString(mStringValue);
            }
            dest.writeString(mPackageName);
            dest.writeString(mClassName);
        }

        @NonNull
@@ -370,6 +370,41 @@ public abstract class PackageManager {
        public void onPermissionsChanged(int uid);
    }

    /** @hide */
    public static final int TYPE_UNKNOWN = 0;
    /** @hide */
    public static final int TYPE_ACTIVITY = 1;
    /** @hide */
    public static final int TYPE_RECEIVER = 2;
    /** @hide */
    public static final int TYPE_SERVICE = 3;
    /** @hide */
    public static final int TYPE_PROVIDER = 4;
    /** @hide */
    public static final int TYPE_APPLICATION = 5;
    /** @hide */
    @IntDef(prefix = { "TYPE_" }, value = {
            TYPE_UNKNOWN,
            TYPE_ACTIVITY,
            TYPE_RECEIVER,
            TYPE_SERVICE,
            TYPE_PROVIDER,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ComponentType {}

    /** @hide */
    @IntDef(prefix = { "TYPE_" }, value = {
            TYPE_UNKNOWN,
            TYPE_ACTIVITY,
            TYPE_RECEIVER,
            TYPE_SERVICE,
            TYPE_PROVIDER,
            TYPE_APPLICATION,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface PropertyLocation {}

    /**
     * As a guiding principle:
     * <p>
@@ -8601,6 +8636,88 @@ public abstract class PackageManager {
        throw new UnsupportedOperationException(
                "getMimeGroup not implemented in subclass");
    }

    /**
     * Returns the property defined in the given package's &lt;appliction&gt; tag.
     *
     * @throws NameNotFoundException if either the given package is not installed or if the
     * given property is not defined within the &lt;application&gt; tag.
     */
    @NonNull
    public Property getProperty(@NonNull String propertyName, @NonNull String packageName)
            throws NameNotFoundException {
        throw new UnsupportedOperationException(
                "getProperty not implemented in subclass");
    }

    /**
     * Returns the property defined in the given component declaration.
     *
     * @throws NameNotFoundException if either the given component does not exist or if the
     * given property is not defined within the component declaration.
     */
    @NonNull
    public Property getProperty(@NonNull String propertyName, @NonNull ComponentName component)
            throws NameNotFoundException {
        throw new UnsupportedOperationException(
                "getProperty not implemented in subclass");
    }

    /**
     * Returns the property definition for all &lt;application&gt; tags.
     * <p>If the property is not defined with any &lt;application&gt; tag,
     * returns and empty list.
     */
    @NonNull
    public List<Property> queryApplicationProperty(@NonNull String propertyName) {
        throw new UnsupportedOperationException(
                "qeuryApplicationProperty not implemented in subclass");
    }

    /**
     * Returns the property definition for all &lt;activity&gt; and &lt;activity-alias&gt; tags.
     * <p>If the property is not defined with any &lt;activity&gt; and &lt;activity-alias&gt; tag,
     * returns and empty list.
     */
    @NonNull
    public List<Property> queryActivityProperty(@NonNull String propertyName) {
        throw new UnsupportedOperationException(
                "qeuryActivityProperty not implemented in subclass");
    }

    /**
     * Returns the property definition for all &lt;provider&gt; tags.
     * <p>If the property is not defined with any &lt;provider&gt; tag,
     * returns and empty list.
     */
    @NonNull
    public List<Property> queryProviderProperty(@NonNull String propertyName) {
        throw new UnsupportedOperationException(
                "qeuryProviderProperty not implemented in subclass");
    }

    /**
     * Returns the property definition for all &lt;receiver&gt; tags.
     * <p>If the property is not defined with any &lt;receiver&gt; tag,
     * returns and empty list.
     */
    @NonNull
    public List<Property> queryReceiverProperty(@NonNull String propertyName) {
        throw new UnsupportedOperationException(
                "qeuryReceiverProperty not implemented in subclass");
    }

    /**
     * Returns the property definition for all &lt;service&gt; tags.
     * <p>If the property is not defined with any &lt;service&gt; tag,
     * returns and empty list.
     */
    @NonNull
    public List<Property> queryServiceProperty(@NonNull String propertyName) {
        throw new UnsupportedOperationException(
                "qeuryServiceProperty not implemented in subclass");
    }

    /**
     * Grants implicit visibility of the package that provides an authority to a querying UID.
     *
Loading