diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-11-21 19:38:01 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-11-21 19:38:01 +0000 |
| commit | 66daa23b1b2eeefce39d2a9914f2c19c0b9b00af (patch) | |
| tree | 0dad2a34ebe3d63d4efe60bd483d78c5d011d226 /core/java/android | |
| parent | 46aed909cbba6fc92020be2f6f4468993971d3ca (diff) | |
| parent | 569435e0eb42bcd9ae31efb22244ed186ed82d45 (diff) | |
Merge "Implment get/query APIs for properties"
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/ApplicationPackageManager.java | 110 | ||||
| -rw-r--r-- | core/java/android/content/pm/IPackageManager.aidl | 4 | ||||
| -rw-r--r-- | core/java/android/content/pm/PackageManager.aidl | 20 | ||||
| -rw-r--r-- | core/java/android/content/pm/PackageManager.java | 121 |
4 files changed, 253 insertions, 2 deletions
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java index 7cef93fe7547..34437afb614a 100644 --- a/core/java/android/app/ApplicationPackageManager.java +++ b/core/java/android/app/ApplicationPackageManager.java @@ -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(); + } + } } diff --git a/core/java/android/content/pm/IPackageManager.aidl b/core/java/android/content/pm/IPackageManager.aidl index d66a42a6232a..f634b8a54a0f 100644 --- a/core/java/android/content/pm/IPackageManager.aidl +++ b/core/java/android/content/pm/IPackageManager.aidl @@ -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); } diff --git a/core/java/android/content/pm/PackageManager.aidl b/core/java/android/content/pm/PackageManager.aidl new file mode 100644 index 000000000000..31365a19f286 --- /dev/null +++ b/core/java/android/content/pm/PackageManager.aidl @@ -0,0 +1,20 @@ +/* +** +** 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; diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index 53dfcbf3a3b4..044b3b2e8284 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -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 <appliction> tag. + * + * @throws NameNotFoundException if either the given package is not installed or if the + * given property is not defined within the <application> 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 <application> tags. + * <p>If the property is not defined with any <application> 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 <activity> and <activity-alias> tags. + * <p>If the property is not defined with any <activity> and <activity-alias> 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 <provider> tags. + * <p>If the property is not defined with any <provider> 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 <receiver> tags. + * <p>If the property is not defined with any <receiver> 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 <service> tags. + * <p>If the property is not defined with any <service> 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. * |
