1 /* 2 * Copyright (C) 2019 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 com.android.internal.compat; 18 19 import android.content.pm.ApplicationInfo; 20 import com.android.internal.compat.IOverrideValidator; 21 import java.util.Map; 22 23 parcelable CompatibilityChangeConfig; 24 parcelable CompatibilityChangeInfo; 25 26 /** 27 * Platform private API for talking with the PlatformCompat service. 28 * 29 * <p> Should be used for gating and logging from non-app processes. 30 * For app processes please use android.compat.Compatibility API. 31 * 32 * {@hide} 33 */ 34 interface IPlatformCompat 35 { 36 37 /** 38 * Reports that a compatibility change is affecting an app process now. 39 * 40 * <p>Note: for changes that are gated using {@link #isChangeEnabled(long, ApplicationInfo)}, 41 * you do not need to call this API directly. The change will be reported for you. 42 * 43 * @param changeId The ID of the compatibility change taking effect. 44 * @param appInfo Representing the affected app. 45 */ reportChange(long changeId, in ApplicationInfo appInfo)46 void reportChange(long changeId, in ApplicationInfo appInfo); 47 48 /** 49 * Reports that a compatibility change is affecting an app process now. 50 * 51 * <p>Note: for changes that are gated using {@link #isChangeEnabled(long, String)}, 52 * you do not need to call this API directly. The change will be reported for you. 53 * 54 * @param changeId The ID of the compatibility change taking effect. 55 * @param userId The ID of the user that the operation is done for. 56 * @param packageName The package name of the app in question. 57 */ reportChangeByPackageName(long changeId, in String packageName, int userId)58 void reportChangeByPackageName(long changeId, in String packageName, int userId); 59 60 /** 61 * Reports that a compatibility change is affecting an app process now. 62 * 63 * <p>Note: for changes that are gated using {@link #isChangeEnabled(long, int)}, 64 * you do not need to call this API directly. The change will be reported for you. 65 * 66 * @param changeId The ID of the compatibility change taking effect. 67 * @param uid The UID of the app in question. 68 */ reportChangeByUid(long changeId, int uid)69 void reportChangeByUid(long changeId, int uid); 70 71 /** 72 * Query if a given compatibility change is enabled for an app process. This method should 73 * be called when implementing functionality on behalf of the affected app. 74 * 75 * <p>If this method returns {@code true}, the calling code should implement the compatibility 76 * change, resulting in differing behaviour compared to earlier releases. If this method returns 77 * {@code false}, the calling code should behave as it did in earlier releases. 78 * 79 * <p>It will also report the change as {@link #reportChange(long, ApplicationInfo)} would, so 80 * there is no need to call that method directly. 81 * 82 * @param changeId The ID of the compatibility change in question. 83 * @param appInfo Representing the app in question. 84 * @return {@code true} if the change is enabled for the current app. 85 */ isChangeEnabled(long changeId, in ApplicationInfo appInfo)86 boolean isChangeEnabled(long changeId, in ApplicationInfo appInfo); 87 88 /** 89 * Query if a given compatibility change is enabled for an app process. This method should 90 * be called when implementing functionality on behalf of the affected app. 91 * 92 * <p>Same as {@link #isChangeEnabled(long, ApplicationInfo)}, except it receives a package name 93 * and userId instead of an {@link ApplicationInfo} 94 * object, and finds an app info object based on the package name. Returns {@code true} if 95 * there is no installed package by that name. 96 * 97 * <p>If this method returns {@code true}, the calling code should implement the compatibility 98 * change, resulting in differing behaviour compared to earlier releases. If this method 99 * returns 100 * {@code false}, the calling code should behave as it did in earlier releases. 101 * 102 * <p>It will also report the change as {@link #reportChange(long, String)} would, so there is 103 * no need to call that method directly. 104 * 105 * @param changeId The ID of the compatibility change in question. 106 * @param packageName The package name of the app in question. 107 * @param userId The ID of the user that the operation is done for. 108 * @return {@code true} if the change is enabled for the current app. 109 */ isChangeEnabledByPackageName(long changeId, in String packageName, int userId)110 boolean isChangeEnabledByPackageName(long changeId, in String packageName, int userId); 111 112 /** 113 * Query if a given compatibility change is enabled for an app process. This method should 114 * be called when implementing functionality on behalf of the affected app. 115 * 116 * <p>Same as {@link #isChangeEnabled(long, ApplicationInfo)}, except it receives a uid 117 * instead of an {@link ApplicationInfo} object, and finds an app info object based on the 118 * uid (or objects if there's more than one package associated with the UID). 119 * Returns {@code true} if there are no installed packages for the required UID, or if the 120 * change is enabled for ALL of the installed packages associated with the provided UID. Please 121 * use a more specific API if you want a different behaviour for multi-package UIDs. 122 * 123 * <p>If this method returns {@code true}, the calling code should implement the compatibility 124 * change, resulting in differing behaviour compared to earlier releases. If this method 125 * returns {@code false}, the calling code should behave as it did in earlier releases. 126 * 127 * <p>It will also report the change as {@link #reportChange(long, int)} would, so there is 128 * no need to call that method directly. 129 * 130 * @param changeId The ID of the compatibility change in question. 131 * @param uid The UID of the app in question. 132 * @return {@code true} if the change is enabled for the current app. 133 */ isChangeEnabledByUid(long changeId, int uid)134 boolean isChangeEnabledByUid(long changeId, int uid); 135 136 /** 137 * Add overrides to compatibility changes. Kills the app to allow the changes to take effect. 138 * 139 * @param overrides Parcelable containing the compat change overrides to be applied. 140 * @param packageName The package name of the app whose changes will be overridden. 141 * 142 */ setOverrides(in CompatibilityChangeConfig overrides, in String packageName)143 void setOverrides(in CompatibilityChangeConfig overrides, in String packageName); 144 145 /** 146 * Add overrides to compatibility changes. Doesn't kill the app, to be only used in tests. 147 * 148 * @param overrides Parcelable containing the compat change overrides to be applied. 149 * @param packageName The package name of the app whose changes will be overridden. 150 * 151 */ setOverridesForTest(in CompatibilityChangeConfig overrides, in String packageName)152 void setOverridesForTest(in CompatibilityChangeConfig overrides, in String packageName); 153 154 /** 155 * Removes an override previously added via {@link #setOverrides(CompatibilityChangeConfig, 156 * String)}. This restores the default behaviour for the given change and app, once any app 157 * processes have been restarted. 158 * Kills the app to allow the changes to take effect. 159 * 160 * @param changeId The ID of the change that was overridden. 161 * @param packageName The app package name that was overridden. 162 * @return {@code true} if an override existed; 163 */ clearOverride(long changeId, String packageName)164 boolean clearOverride(long changeId, String packageName); 165 166 /** 167 * Enable all compatibility changes which have enabledAfterTargetSdk == 168 * {@param targetSdkVersion} for an app, subject to the policy. Kills the app to allow the 169 * changes to take effect. 170 * 171 * @param packageName The package name of the app whose compatibility changes will be enabled. 172 * @param targetSdkVersion The targetSdkVersion for filtering the changes to be enabled. 173 * 174 * @return The number of changes that were enabled. 175 */ enableTargetSdkChanges(in String packageName, int targetSdkVersion)176 int enableTargetSdkChanges(in String packageName, int targetSdkVersion); 177 178 /** 179 * Disable all compatibility changes which have enabledAfterTargetSdk == 180 * {@param targetSdkVersion} for an app, subject to the policy. Kills the app to allow the 181 * changes to take effect. 182 * 183 * @param packageName The package name of the app whose compatibility changes will be disabled. 184 * @param targetSdkVersion The targetSdkVersion for filtering the changes to be disabled. 185 * 186 * @return The number of changes that were disabled. 187 */ disableTargetSdkChanges(in String packageName, int targetSdkVersion)188 int disableTargetSdkChanges(in String packageName, int targetSdkVersion); 189 190 /** 191 * Revert overrides to compatibility changes. Kills the app to allow the changes to take effect. 192 * 193 * @param packageName The package name of the app whose overrides will be cleared. 194 * 195 */ clearOverrides(in String packageName)196 void clearOverrides(in String packageName); 197 198 /** 199 * Revert overrides to compatibility changes. Doesn't kill the app, to be only used in tests. 200 * 201 * @param packageName The package name of the app whose overrides will be cleared. 202 * 203 */ clearOverridesForTest(in String packageName)204 void clearOverridesForTest(in String packageName); 205 206 207 /** 208 * Get configs for an application. 209 * 210 * @param appInfo The application whose config will be returned. 211 * 212 * @return A {@link CompatibilityChangeConfig}, representing whether a change is enabled for 213 * the given app or not. 214 */ getAppConfig(in ApplicationInfo appInfo)215 CompatibilityChangeConfig getAppConfig(in ApplicationInfo appInfo); 216 217 /** 218 * List all compatibility changes. 219 * 220 * @return An array of {@link CompatChangeInfo} known to the service. 221 */ listAllChanges()222 CompatibilityChangeInfo[] listAllChanges(); 223 224 /** 225 * List the compatibility changes that should be present in the UI. 226 * Filters out certain changes like e.g. logging only. 227 * 228 * @return An array of {@link CompatChangeInfo}. 229 */ listUIChanges()230 CompatibilityChangeInfo[] listUIChanges(); 231 232 /** 233 * Get an instance that can determine whether a changeid can be overridden for a package name. 234 */ getOverrideValidator()235 IOverrideValidator getOverrideValidator(); 236 } 237