blob: 853e8189ea8a7694674356400e17dc572edc5eb2 [file] [log] [blame]
Hyunyoung Song880a9512018-12-20 11:24:48 -08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content.om;
18
Zoran Jovanovicd507e2f2019-02-17 22:35:21 +010019import android.annotation.NonNull;
Hyunyoung Song880a9512018-12-20 11:24:48 -080020import android.annotation.Nullable;
Hyunyoung Song8a78caf2019-03-18 22:50:27 -070021import android.annotation.RequiresPermission;
Hyunyoung Song880a9512018-12-20 11:24:48 -080022import android.annotation.SystemApi;
23import android.annotation.SystemService;
Ryan Mitchell4043ca72019-06-03 16:11:24 -070024import android.annotation.TestApi;
Hyunyoung Song880a9512018-12-20 11:24:48 -080025import android.content.Context;
26import android.os.RemoteException;
27import android.os.ServiceManager;
Zoran Jovanovicd507e2f2019-02-17 22:35:21 +010028import android.os.UserHandle;
Hyunyoung Song880a9512018-12-20 11:24:48 -080029
30import java.util.List;
31
32/**
33 * Updates OverlayManager state; gets information about installed overlay packages.
34 * @hide
35 */
36@SystemApi
37@SystemService(Context.OVERLAY_SERVICE)
38public class OverlayManager {
39
40 private final IOverlayManager mService;
41 private final Context mContext;
42
43 /**
44 * Creates a new instance.
45 *
46 * @param context The current context in which to operate.
47 * @param service The backing system service.
48 *
49 * @hide
50 */
51 public OverlayManager(Context context, IOverlayManager service) {
52 mContext = context;
53 mService = service;
54 }
55
56 /** @hide */
57 public OverlayManager(Context context) {
58 this(context, IOverlayManager.Stub.asInterface(
59 ServiceManager.getService(Context.OVERLAY_SERVICE)));
60 }
Hyunyoung Song4b95d692019-01-22 10:21:23 -080061
Hyunyoung Song880a9512018-12-20 11:24:48 -080062 /**
63 * Request that an overlay package is enabled and any other overlay packages with the same
64 * target package and category are disabled.
65 *
Hyunyoung Song8a78caf2019-03-18 22:50:27 -070066 * If a set of overlay packages share the same category, single call to this method is
67 * equivalent to multiple calls to {@link #setEnabled(String, boolean, UserHandle)}.
68 *
Hyunyoung Song880a9512018-12-20 11:24:48 -080069 * @param packageName the name of the overlay package to enable.
Hyunyoung Song8a78caf2019-03-18 22:50:27 -070070 * @param user The user for which to change the overlay.
Hyunyoung Song880a9512018-12-20 11:24:48 -080071 *
72 * @hide
73 */
74 @SystemApi
Hyunyoung Song8a78caf2019-03-18 22:50:27 -070075 @RequiresPermission(anyOf = {
76 "android.permission.INTERACT_ACROSS_USERS",
77 "android.permission.INTERACT_ACROSS_USERS_FULL"
78 })
79 public void setEnabledExclusiveInCategory(@NonNull final String packageName,
80 @NonNull UserHandle user) {
Hyunyoung Song880a9512018-12-20 11:24:48 -080081 try {
Hyunyoung Song8a78caf2019-03-18 22:50:27 -070082 if (!mService.setEnabledExclusiveInCategory(packageName, user.getIdentifier())) {
83 throw new IllegalStateException("setEnabledExclusiveInCategory failed");
84 }
Hyunyoung Song880a9512018-12-20 11:24:48 -080085 } catch (RemoteException e) {
86 throw e.rethrowFromSystemServer();
87 }
88 }
89
90 /**
Hyunyoung Song8a78caf2019-03-18 22:50:27 -070091 * Request that an overlay package is enabled or disabled.
92 *
93 * While {@link #setEnabledExclusiveInCategory(String, UserHandle)} doesn't support disabling
94 * every overlay in a category, this method allows you to disable everything.
Hyunyoung Song4b95d692019-01-22 10:21:23 -080095 *
96 * @param packageName the name of the overlay package to enable.
97 * @param enable {@code false} if the overlay should be turned off.
Hyunyoung Song8a78caf2019-03-18 22:50:27 -070098 * @param user The user for which to change the overlay.
Hyunyoung Song4b95d692019-01-22 10:21:23 -080099 *
100 * @hide
101 */
102 @SystemApi
Hyunyoung Song8a78caf2019-03-18 22:50:27 -0700103 @RequiresPermission(anyOf = {
104 "android.permission.INTERACT_ACROSS_USERS",
105 "android.permission.INTERACT_ACROSS_USERS_FULL"
106 })
107 public void setEnabled(@NonNull final String packageName, final boolean enable,
108 @NonNull UserHandle user) {
Hyunyoung Song4b95d692019-01-22 10:21:23 -0800109 try {
Hyunyoung Song8a78caf2019-03-18 22:50:27 -0700110 if (!mService.setEnabled(packageName, enable, user.getIdentifier())) {
111 throw new IllegalStateException("setEnabled failed");
112 }
Hyunyoung Song4b95d692019-01-22 10:21:23 -0800113 } catch (RemoteException e) {
114 throw e.rethrowFromSystemServer();
115 }
Hyunyoung Song8a78caf2019-03-18 22:50:27 -0700116 return;
Hyunyoung Song4b95d692019-01-22 10:21:23 -0800117 }
118
119 /**
Zoran Jovanovicd507e2f2019-02-17 22:35:21 +0100120 * Returns information about the overlay with the given package name for
121 * the specified user.
122 *
123 * @param packageName The name of the package.
124 * @param userHandle The user to get the OverlayInfos for.
125 * @return An OverlayInfo object; if no overlays exist with the
126 * requested package name, null is returned.
127 *
128 * @hide
129 */
130 @SystemApi
131 @Nullable
132 public OverlayInfo getOverlayInfo(@NonNull final String packageName,
133 @NonNull final UserHandle userHandle) {
134 try {
Hyunyoung Song8a78caf2019-03-18 22:50:27 -0700135 return mService.getOverlayInfo(packageName, userHandle.getIdentifier());
Zoran Jovanovicd507e2f2019-02-17 22:35:21 +0100136 } catch (RemoteException e) {
137 throw e.rethrowFromSystemServer();
138 }
139 }
140
141 /**
Hyunyoung Song880a9512018-12-20 11:24:48 -0800142 * Returns information about all overlays for the given target package for
143 * the specified user. The returned list is ordered according to the
144 * overlay priority with the highest priority at the end of the list.
145 *
146 * @param targetPackageName The name of the target package.
Hyunyoung Song8a78caf2019-03-18 22:50:27 -0700147 * @param user The user to get the OverlayInfos for.
Hyunyoung Song880a9512018-12-20 11:24:48 -0800148 * @return A list of OverlayInfo objects; if no overlays exist for the
149 * requested package, an empty list is returned.
150 *
151 * @hide
152 */
153 @SystemApi
Hyunyoung Song8a78caf2019-03-18 22:50:27 -0700154 @RequiresPermission(anyOf = {
155 "android.permission.INTERACT_ACROSS_USERS",
156 "android.permission.INTERACT_ACROSS_USERS_FULL"
157 })
158 @NonNull
159 public List<OverlayInfo> getOverlayInfosForTarget(@NonNull final String targetPackageName,
160 @NonNull UserHandle user) {
Hyunyoung Song880a9512018-12-20 11:24:48 -0800161 try {
Hyunyoung Song8a78caf2019-03-18 22:50:27 -0700162 return mService.getOverlayInfosForTarget(targetPackageName, user.getIdentifier());
Hyunyoung Song880a9512018-12-20 11:24:48 -0800163 } catch (RemoteException e) {
164 throw e.rethrowFromSystemServer();
165 }
166 }
Ryan Mitchell4043ca72019-06-03 16:11:24 -0700167
168 /**
169 * Returns information about all overlays for the given target package for
170 * the specified user. The returned list is ordered according to the
171 * overlay priority with the highest priority at the end of the list.
172 *
173 * @param targetPackageName The name of the target package.
174 * @param user The user to get the OverlayInfos for.
175 *
176 * @hide
177 */
178 @TestApi
179 @RequiresPermission(anyOf = {
180 "android.permission.INTERACT_ACROSS_USERS",
181 })
182 @NonNull
183 public void invalidateCachesForOverlay(@NonNull final String targetPackageName,
184 @NonNull UserHandle user) {
185 try {
186 mService.invalidateCachesForOverlay(targetPackageName, user.getIdentifier());
187 } catch (RemoteException e) {
188 throw e.rethrowFromSystemServer();
189 }
190 }
Hyunyoung Song880a9512018-12-20 11:24:48 -0800191}