Hyunyoung Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.content.om; |
| 18 | |
Zoran Jovanovic | d507e2f | 2019-02-17 22:35:21 +0100 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Hyunyoung Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Hyunyoung Song | 8a78caf | 2019-03-18 22:50:27 -0700 | [diff] [blame] | 21 | import android.annotation.RequiresPermission; |
Hyunyoung Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 22 | import android.annotation.SystemApi; |
| 23 | import android.annotation.SystemService; |
Ryan Mitchell | 4043ca7 | 2019-06-03 16:11:24 -0700 | [diff] [blame^] | 24 | import android.annotation.TestApi; |
Hyunyoung Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.os.RemoteException; |
| 27 | import android.os.ServiceManager; |
Zoran Jovanovic | d507e2f | 2019-02-17 22:35:21 +0100 | [diff] [blame] | 28 | import android.os.UserHandle; |
Hyunyoung Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 29 | |
| 30 | import 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) |
| 38 | public 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 Song | 4b95d69 | 2019-01-22 10:21:23 -0800 | [diff] [blame] | 61 | |
Hyunyoung Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 62 | /** |
| 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 Song | 8a78caf | 2019-03-18 22:50:27 -0700 | [diff] [blame] | 66 | * 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 Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 69 | * @param packageName the name of the overlay package to enable. |
Hyunyoung Song | 8a78caf | 2019-03-18 22:50:27 -0700 | [diff] [blame] | 70 | * @param user The user for which to change the overlay. |
Hyunyoung Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 71 | * |
| 72 | * @hide |
| 73 | */ |
| 74 | @SystemApi |
Hyunyoung Song | 8a78caf | 2019-03-18 22:50:27 -0700 | [diff] [blame] | 75 | @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 Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 81 | try { |
Hyunyoung Song | 8a78caf | 2019-03-18 22:50:27 -0700 | [diff] [blame] | 82 | if (!mService.setEnabledExclusiveInCategory(packageName, user.getIdentifier())) { |
| 83 | throw new IllegalStateException("setEnabledExclusiveInCategory failed"); |
| 84 | } |
Hyunyoung Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 85 | } catch (RemoteException e) { |
| 86 | throw e.rethrowFromSystemServer(); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /** |
Hyunyoung Song | 8a78caf | 2019-03-18 22:50:27 -0700 | [diff] [blame] | 91 | * 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 Song | 4b95d69 | 2019-01-22 10:21:23 -0800 | [diff] [blame] | 95 | * |
| 96 | * @param packageName the name of the overlay package to enable. |
| 97 | * @param enable {@code false} if the overlay should be turned off. |
Hyunyoung Song | 8a78caf | 2019-03-18 22:50:27 -0700 | [diff] [blame] | 98 | * @param user The user for which to change the overlay. |
Hyunyoung Song | 4b95d69 | 2019-01-22 10:21:23 -0800 | [diff] [blame] | 99 | * |
| 100 | * @hide |
| 101 | */ |
| 102 | @SystemApi |
Hyunyoung Song | 8a78caf | 2019-03-18 22:50:27 -0700 | [diff] [blame] | 103 | @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 Song | 4b95d69 | 2019-01-22 10:21:23 -0800 | [diff] [blame] | 109 | try { |
Hyunyoung Song | 8a78caf | 2019-03-18 22:50:27 -0700 | [diff] [blame] | 110 | if (!mService.setEnabled(packageName, enable, user.getIdentifier())) { |
| 111 | throw new IllegalStateException("setEnabled failed"); |
| 112 | } |
Hyunyoung Song | 4b95d69 | 2019-01-22 10:21:23 -0800 | [diff] [blame] | 113 | } catch (RemoteException e) { |
| 114 | throw e.rethrowFromSystemServer(); |
| 115 | } |
Hyunyoung Song | 8a78caf | 2019-03-18 22:50:27 -0700 | [diff] [blame] | 116 | return; |
Hyunyoung Song | 4b95d69 | 2019-01-22 10:21:23 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /** |
Zoran Jovanovic | d507e2f | 2019-02-17 22:35:21 +0100 | [diff] [blame] | 120 | * 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 Song | 8a78caf | 2019-03-18 22:50:27 -0700 | [diff] [blame] | 135 | return mService.getOverlayInfo(packageName, userHandle.getIdentifier()); |
Zoran Jovanovic | d507e2f | 2019-02-17 22:35:21 +0100 | [diff] [blame] | 136 | } catch (RemoteException e) { |
| 137 | throw e.rethrowFromSystemServer(); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /** |
Hyunyoung Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 142 | * 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 Song | 8a78caf | 2019-03-18 22:50:27 -0700 | [diff] [blame] | 147 | * @param user The user to get the OverlayInfos for. |
Hyunyoung Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 148 | * @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 Song | 8a78caf | 2019-03-18 22:50:27 -0700 | [diff] [blame] | 154 | @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 Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 161 | try { |
Hyunyoung Song | 8a78caf | 2019-03-18 22:50:27 -0700 | [diff] [blame] | 162 | return mService.getOverlayInfosForTarget(targetPackageName, user.getIdentifier()); |
Hyunyoung Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 163 | } catch (RemoteException e) { |
| 164 | throw e.rethrowFromSystemServer(); |
| 165 | } |
| 166 | } |
Ryan Mitchell | 4043ca7 | 2019-06-03 16:11:24 -0700 | [diff] [blame^] | 167 | |
| 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 Song | 880a951 | 2018-12-20 11:24:48 -0800 | [diff] [blame] | 191 | } |