Debian Codegraph @

tests/PlatformCompatGating/src/com/android/compat/testing/DummyApi.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2016 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.compat.testing;
18
19 import android.compat.Compatibility;
20 import android.content.Context;
21 import android.os.RemoteException;
22 import android.os.ServiceManager;
23
24 import com.android.internal.compat.IPlatformCompat;
25
26 /**
27 * This is a dummy API to test gating
28 *
29 * @hide
30 */
31 public class DummyApi {
32
33 public static final long CHANGE_ID = 666013;
34 public static final long CHANGE_ID_1 = 666014;
35 public static final long CHANGE_ID_2 = 666015;
36 public static final long CHANGE_SYSTEM_SERVER = 666016;
37
38 /**
39 * Dummy method
40 * @return "A" if change is enabled, "B" otherwise.
41 */
42 public static String dummyFunc() {
43 if (Compatibility.isChangeEnabled(CHANGE_ID)) {
44 return "A";
45 }
46 return "B";
47 }
48
49 /**
50 * Dummy combined method
51 * @return "0" if {@link CHANGE_ID_1} is disabled and {@link CHANGE_ID_2} is disabled,
52 "1" if {@link CHANGE_ID_1} is disabled and {@link CHANGE_ID_2} is enabled,
53 "2" if {@link CHANGE_ID_1} is enabled and {@link CHANGE_ID_2} is disabled,
54 "3" if {@link CHANGE_ID_1} is enabled and {@link CHANGE_ID_2} is enabled.
55 */
56 public static String dummyCombinedFunc() {
57 if (!Compatibility.isChangeEnabled(CHANGE_ID_1)
58 && !Compatibility.isChangeEnabled(CHANGE_ID_2)) {
59 return "0";
60 } else if (!Compatibility.isChangeEnabled(CHANGE_ID_1)
61 && Compatibility.isChangeEnabled(CHANGE_ID_2)) {
62 return "1";
63 } else if (Compatibility.isChangeEnabled(CHANGE_ID_1)
64 && !Compatibility.isChangeEnabled(CHANGE_ID_2)) {
65 return "2";
66 }
67 return "3";
68 }
69
70 /**
71 * Dummy api using system server API.
72 */
73 public static boolean dummySystemServer(Context context) {
74 IPlatformCompat platformCompat = IPlatformCompat.Stub
75 .asInterface(ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE));
76 if (platformCompat == null) {
77 throw new RuntimeException("Could not obtain IPlatformCompat instance!");
78 }
79 String packageName = context.getPackageName();
80 try {
81 return platformCompat.isChangeEnabledByPackageName(CHANGE_SYSTEM_SERVER, packageName,
82 context.getUserId());
83 } catch (RemoteException e) {
84 throw new RuntimeException("Could not get change value!", e);
85 }
86 }
87 }