• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.app.appfunctions;
18 
19 import static android.app.appfunctions.flags.Flags.FLAG_ENABLE_APP_FUNCTION_MANAGER;
20 
21 import android.annotation.FlaggedApi;
22 import android.annotation.NonNull;
23 import android.app.appsearch.util.DocumentIdUtil;
24 
25 import java.util.Objects;
26 
27 /**
28  * Contains constants and helper related to static metadata represented with {@code
29  * com.android.server.appsearch.appsindexer.appsearchtypes.AppFunctionStaticMetadata}.
30  *
31  * <p>The constants listed here **must not change** and be kept consistent with the canonical static
32  * metadata class.
33  *
34  * @hide
35  */
36 @FlaggedApi(FLAG_ENABLE_APP_FUNCTION_MANAGER)
37 public class AppFunctionStaticMetadataHelper {
38     public static final String STATIC_SCHEMA_TYPE = "AppFunctionStaticMetadata";
39     public static final String STATIC_PROPERTY_ENABLED_BY_DEFAULT = "enabledByDefault";
40     public static final String STATIC_PROPERTY_RESTRICT_CALLERS_WITH_EXECUTE_APP_FUNCTIONS =
41             "restrictCallersWithExecuteAppFunctions";
42 
43     public static final String APP_FUNCTION_STATIC_NAMESPACE = "app_functions";
44     public static final String PROPERTY_FUNCTION_ID = "functionId";
45     public static final String PROPERTY_PACKAGE_NAME = "packageName";
46 
47     // These are constants that has to be kept the same with {@code
48     // com.android.server.appsearch.appsindexer.appsearchtypes.AppSearchHelper}.
49     public static final String APP_FUNCTION_STATIC_METADATA_DB = "apps-db";
50     public static final String APP_FUNCTION_INDEXER_PACKAGE = "android";
51 
52     /** Returns a per-app static metadata schema name, to store all functions for that package. */
getStaticSchemaNameForPackage(@onNull String pkg)53     public static String getStaticSchemaNameForPackage(@NonNull String pkg) {
54         return STATIC_SCHEMA_TYPE + "-" + Objects.requireNonNull(pkg);
55     }
56 
57     /** Returns the document id for an app function's static metadata. */
getDocumentIdForAppFunction( @onNull String pkg, @NonNull String functionId)58     public static String getDocumentIdForAppFunction(
59             @NonNull String pkg, @NonNull String functionId) {
60         return pkg + "/" + functionId;
61     }
62 
63     /**
64      * Returns the fully qualified Id used in AppSearch for the given package and function id app
65      * function static metadata.
66      */
getStaticMetadataQualifiedId(String packageName, String functionId)67     public static String getStaticMetadataQualifiedId(String packageName, String functionId) {
68         return DocumentIdUtil.createQualifiedId(
69                 APP_FUNCTION_INDEXER_PACKAGE,
70                 APP_FUNCTION_STATIC_METADATA_DB,
71                 APP_FUNCTION_STATIC_NAMESPACE,
72                 getDocumentIdForAppFunction(packageName, functionId));
73     }
74 }
75