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 /**
20  * Platform native private API for talking with the PlatformCompat service.
21  *
22  * <p> Should be used for gating and logging from non-app processes running cpp code.
23  * For app processes please use android.compat.Compatibility API.
24  *
25  * {@hide}
26  */
27 interface IPlatformCompatNative
28 {
29     /**
30      * Reports that a compatibility change is affecting an app process now.
31      *
32      * <p>Note: for changes that are gated using {@link #isChangeEnabled(long, String)},
33      * you do not need to call this API directly. The change will be reported for you.
34      *
35      * @param changeId    The ID of the compatibility change taking effect.
36      * @param userId      The ID of the user that the operation is done for.
37      * @param packageName The package name of the app in question.
38      */
reportChangeByPackageName(long changeId, @utf8InCpp String packageName, int userId)39      void reportChangeByPackageName(long changeId, @utf8InCpp String packageName, int userId);
40 
41     /**
42      * Reports that a compatibility change is affecting an app process now.
43      *
44      * <p>Note: for changes that are gated using {@link #isChangeEnabled(long, int)},
45      * you do not need to call this API directly. The change will be reported for you.
46      *
47      * @param changeId The ID of the compatibility change taking effect.
48      * @param uid      The UID of the app in question.
49      */
reportChangeByUid(long changeId, int uid)50     void reportChangeByUid(long changeId, int uid);
51 
52     /**
53      * Query if a given compatibility change is enabled for an app process. This method should
54      * be called when implementing functionality on behalf of the affected app.
55      *
56      * <p>Returns {@code true} if there is no installed package by the provided package name.
57      *
58      * <p>If this method returns {@code true}, the calling code should implement the compatibility
59      * change, resulting in differing behaviour compared to earlier releases. If this method
60      * returns
61      * {@code false}, the calling code should behave as it did in earlier releases.
62      *
63      * <p>It will also report the change as {@link #reportChange(long, String)} would, so there is
64      * no need to call that method directly.
65      *
66      * @param changeId    The ID of the compatibility change in question.
67      * @param packageName The package name of the app in question.
68      * @param userId      The ID of the user that the operation is done for.
69      * @return {@code true} if the change is enabled for the current app.
70      */
isChangeEnabledByPackageName(long changeId, @utf8InCpp String packageName, int userId)71     boolean isChangeEnabledByPackageName(long changeId, @utf8InCpp String packageName, int userId);
72 
73     /**
74      * Query if a given compatibility change is enabled for an app process. This method should
75      * be called when implementing functionality on behalf of the affected app.
76      *
77      * <p> Returns {@code true} if there are no installed packages for the required UID, or if the
78      * change is enabled for ALL of the installed packages associated with the provided UID. Please
79      * use a more specific API if you want a different behaviour for multi-package UIDs.
80      *
81      * <p>If this method returns {@code true}, the calling code should implement the compatibility
82      * change, resulting in differing behaviour compared to earlier releases. If this method
83      * returns {@code false}, the calling code should behave as it did in earlier releases.
84      *
85      * <p>It will also report the change as {@link #reportChange(long, int)} would, so there is
86      * no need to call that method directly.
87      *
88      * @param changeId The ID of the compatibility change in question.
89      * @param uid      The UID of the app in question.
90      * @return {@code true} if the change is enabled for the current app.
91      */
isChangeEnabledByUid(long changeId, int uid)92     boolean isChangeEnabledByUid(long changeId, int uid);
93 }