1 /*
2  * Copyright (C) 2011 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.database.sqlite;
18 
19 import android.compat.annotation.UnsupportedAppUsage;
20 import android.os.Build;
21 
22 /**
23  * Describes a custom SQL function.
24  *
25  * @hide
26  */
27 public final class SQLiteCustomFunction {
28     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
29     public final String name;
30     @UnsupportedAppUsage
31     public final int numArgs;
32     public final SQLiteDatabase.CustomFunction callback;
33 
34     /**
35      * Create custom function.
36      *
37      * @param name The name of the sqlite3 function.
38      * @param numArgs The number of arguments for the function, or -1 to
39      * support any number of arguments.
40      * @param callback The callback to invoke when the function is executed.
41      */
SQLiteCustomFunction(String name, int numArgs, SQLiteDatabase.CustomFunction callback)42     public SQLiteCustomFunction(String name, int numArgs,
43             SQLiteDatabase.CustomFunction callback) {
44         if (name == null) {
45             throw new IllegalArgumentException("name must not be null.");
46         }
47 
48         this.name = name;
49         this.numArgs = numArgs;
50         this.callback = callback;
51     }
52 
53     // Called from native.
54     @SuppressWarnings("unused")
55     @UnsupportedAppUsage
dispatchCallback(String[] args)56     private void dispatchCallback(String[] args) {
57         callback.callback(args);
58     }
59 }
60