diff options
| author | 2019-01-14 17:53:17 +0000 | |
|---|---|---|
| committer | 2019-01-14 17:53:17 +0000 | |
| commit | 9114be68cd85d820646d67032dc3f0d27879cb88 (patch) | |
| tree | 4ff7e81b34d9c2d66b6987ea77bb95a35443b2e7 | |
| parent | cf1cf81c332124af3eb39512f791a3da4e702469 (diff) | |
| parent | 880a9510c2346a21c068ca39b70fdc7d706f6554 (diff) | |
Merge "Add @SystemApi to OverlayManager that ThemePicker needs"
| -rw-r--r-- | api/system-current.txt | 20 | ||||
| -rw-r--r-- | core/java/android/app/SystemServiceRegistry.java | 10 | ||||
| -rw-r--r-- | core/java/android/content/om/OverlayInfo.java | 43 | ||||
| -rw-r--r-- | core/java/android/content/om/OverlayManager.java | 98 |
4 files changed, 165 insertions, 6 deletions
diff --git a/api/system-current.txt b/api/system-current.txt index 9d85aab37fb3..f6866041ec13 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -1301,6 +1301,26 @@ package android.content { } +package android.content.om { + + public final class OverlayInfo implements android.os.Parcelable { + method public int describeContents(); + method public boolean isEnabled(); + method public void writeToParcel(android.os.Parcel, int); + field public static final android.os.Parcelable.Creator<android.content.om.OverlayInfo> CREATOR; + field public final java.lang.String category; + field public final java.lang.String packageName; + field public final java.lang.String targetPackageName; + field public final int userId; + } + + public class OverlayManager { + method public java.util.List<android.content.om.OverlayInfo> getOverlayInfosForTarget(java.lang.String, int); + method public boolean setEnabledExclusiveInCategory(java.lang.String, int); + } + +} + package android.content.pm { public class ApplicationInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable { diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index d827f6cb9654..3adafd725a10 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -45,6 +45,8 @@ import android.content.ClipboardManager; import android.content.Context; import android.content.IRestrictionsManager; import android.content.RestrictionsManager; +import android.content.om.IOverlayManager; +import android.content.om.OverlayManager; import android.content.pm.CrossProfileApps; import android.content.pm.ICrossProfileApps; import android.content.pm.IShortcutService; @@ -1053,6 +1055,14 @@ final class SystemServiceRegistry { return new ShortcutManager(ctx, IShortcutService.Stub.asInterface(b)); }}); + registerService(Context.OVERLAY_SERVICE, OverlayManager.class, + new CachedServiceFetcher<OverlayManager>() { + @Override + public OverlayManager createService(ContextImpl ctx) throws ServiceNotFoundException { + IBinder b = ServiceManager.getServiceOrThrow(Context.OVERLAY_SERVICE); + return new OverlayManager(ctx, IOverlayManager.Stub.asInterface(b)); + }}); + registerService(Context.NETWORK_WATCHLIST_SERVICE, NetworkWatchlistManager.class, new CachedServiceFetcher<NetworkWatchlistManager>() { @Override diff --git a/core/java/android/content/om/OverlayInfo.java b/core/java/android/content/om/OverlayInfo.java index dd550032df7c..1989f06ca76b 100644 --- a/core/java/android/content/om/OverlayInfo.java +++ b/core/java/android/content/om/OverlayInfo.java @@ -18,8 +18,7 @@ package android.content.om; import android.annotation.IntDef; import android.annotation.NonNull; -import android.annotation.UnsupportedAppUsage; -import android.os.Build; +import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; @@ -32,8 +31,10 @@ import java.lang.annotation.RetentionPolicy; * * @hide */ +@SystemApi public final class OverlayInfo implements Parcelable { + /** @hide */ @IntDef(prefix = "STATE_", value = { STATE_UNKNOWN, STATE_MISSING_TARGET, @@ -44,6 +45,7 @@ public final class OverlayInfo implements Parcelable { STATE_TARGET_UPGRADING, STATE_OVERLAY_UPGRADING, }) + /** @hide */ @Retention(RetentionPolicy.SOURCE) public @interface State {} @@ -52,17 +54,23 @@ public final class OverlayInfo implements Parcelable { * objects exposed outside the {@link * com.android.server.om.OverlayManagerService} should never have this * state. + * + * @hide */ public static final int STATE_UNKNOWN = -1; /** * The target package of the overlay is not installed. The overlay cannot be enabled. + * + * @hide */ public static final int STATE_MISSING_TARGET = 0; /** * Creation of idmap file failed (e.g. no matching resources). The overlay * cannot be enabled. + * + * @hide */ public static final int STATE_NO_IDMAP = 1; @@ -70,6 +78,7 @@ public final class OverlayInfo implements Parcelable { * The overlay is currently disabled. It can be enabled. * * @see IOverlayManager#setEnabled + * @hide */ public static final int STATE_DISABLED = 2; @@ -77,18 +86,21 @@ public final class OverlayInfo implements Parcelable { * The overlay is currently enabled. It can be disabled. * * @see IOverlayManager#setEnabled + * @hide */ public static final int STATE_ENABLED = 3; /** * The target package is currently being upgraded; the state will change * once the package installation has finished. + * @hide */ public static final int STATE_TARGET_UPGRADING = 4; /** * The overlay package is currently being upgraded; the state will change * once the package installation has finished. + * @hide */ public static final int STATE_OVERLAY_UPGRADING = 5; @@ -96,6 +108,7 @@ public final class OverlayInfo implements Parcelable { * The overlay package is currently enabled because it is marked as * 'static'. It cannot be disabled but will change state if for instance * its target is uninstalled. + * @hide */ public static final int STATE_ENABLED_STATIC = 6; @@ -103,40 +116,52 @@ public final class OverlayInfo implements Parcelable { * Overlay category: theme. * <p> * Change how Android (including the status bar, dialogs, ...) looks. + * + * @hide */ public static final String CATEGORY_THEME = "android.theme"; /** * Package name of the overlay package + * + * @hide */ - @UnsupportedAppUsage + @SystemApi public final String packageName; /** * Package name of the target package + * + * @hide */ - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) + @SystemApi public final String targetPackageName; /** * Category of the overlay package + * + * @hide */ + @SystemApi public final String category; /** * Full path to the base APK for this overlay package + * @hide */ public final String baseCodePath; /** * The state of this OverlayInfo as defined by the STATE_* constants in this class. + * @hide */ - @UnsupportedAppUsage public final @State int state; /** * User handle for which this overlay applies + * @hide */ + @SystemApi public final int userId; /** @@ -161,12 +186,15 @@ public final class OverlayInfo implements Parcelable { * * @param source the source OverlayInfo to base the new instance on * @param state the new state for the source OverlayInfo + * + * @hide */ public OverlayInfo(@NonNull OverlayInfo source, @State int state) { this(source.packageName, source.targetPackageName, source.category, source.baseCodePath, state, source.userId, source.priority, source.isStatic); } + /** @hide */ public OverlayInfo(@NonNull String packageName, @NonNull String targetPackageName, @NonNull String category, @NonNull String baseCodePath, int state, int userId, int priority, boolean isStatic) { @@ -181,6 +209,7 @@ public final class OverlayInfo implements Parcelable { ensureValidState(); } + /** @hide */ public OverlayInfo(Parcel source) { packageName = source.readString(); targetPackageName = source.readString(); @@ -255,8 +284,9 @@ public final class OverlayInfo implements Parcelable { * Disabled overlay packages are installed but are currently not in use. * * @return true if the overlay is enabled, else false. + * @hide */ - @UnsupportedAppUsage + @SystemApi public boolean isEnabled() { switch (state) { case STATE_ENABLED: @@ -272,6 +302,7 @@ public final class OverlayInfo implements Parcelable { * debugging purposes. * * @return a human readable String representing the state. + * @hide */ public static String stateToString(@State int state) { switch (state) { diff --git a/core/java/android/content/om/OverlayManager.java b/core/java/android/content/om/OverlayManager.java new file mode 100644 index 000000000000..7a2220bfddb6 --- /dev/null +++ b/core/java/android/content/om/OverlayManager.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2018 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.om; + +import android.annotation.Nullable; +import android.annotation.SystemApi; +import android.annotation.SystemService; +import android.content.Context; +import android.os.RemoteException; +import android.os.ServiceManager; + +import java.util.List; + +/** + * Updates OverlayManager state; gets information about installed overlay packages. + * @hide + */ +@SystemApi +@SystemService(Context.OVERLAY_SERVICE) +public class OverlayManager { + + private final IOverlayManager mService; + private final Context mContext; + + /** + * Creates a new instance. + * + * @param context The current context in which to operate. + * @param service The backing system service. + * + * @hide + */ + public OverlayManager(Context context, IOverlayManager service) { + mContext = context; + mService = service; + } + + /** @hide */ + public OverlayManager(Context context) { + this(context, IOverlayManager.Stub.asInterface( + ServiceManager.getService(Context.OVERLAY_SERVICE))); + } + /** + * Request that an overlay package is enabled and any other overlay packages with the same + * target package and category are disabled. + * + * @param packageName the name of the overlay package to enable. + * @param userId The user for which to change the overlay. + * @return true if the system successfully registered the request, false otherwise. + * + * @hide + */ + @SystemApi + public boolean setEnabledExclusiveInCategory(@Nullable final String packageName, + int userId) { + try { + return mService.setEnabledExclusiveInCategory(packageName, userId); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Returns information about all overlays for the given target package for + * the specified user. The returned list is ordered according to the + * overlay priority with the highest priority at the end of the list. + * + * @param targetPackageName The name of the target package. + * @param userId The user to get the OverlayInfos for. + * @return A list of OverlayInfo objects; if no overlays exist for the + * requested package, an empty list is returned. + * + * @hide + */ + @SystemApi + public List<OverlayInfo> getOverlayInfosForTarget(@Nullable final String targetPackageName, + int userId) { + try { + return mService.getOverlayInfosForTarget(targetPackageName, userId); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } +} |