add a provider for voice ai.
authorTrillGates <williamtrillgates@gmail.com>
Fri, 23 Apr 2021 07:01:09 +0000 (15:01 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Fri, 23 Apr 2021 07:01:09 +0000 (15:01 +0800)
app/src/main/AndroidManifest.xml
app/src/main/java/com/enqualcomm/support/provider/AiInfoDatabaseHelper.java [new file with mode: 0644]
app/src/main/java/com/enqualcomm/support/provider/AiInfoProvider.java [new file with mode: 0644]

index 50528cc..227a675 100644 (file)
             android:authorities="com.ic.fzd.settings"
             android:exported="true" />
 
+        <provider
+            android:name=".provider.AiInfoProvider"
+            android:authorities="com.ic.ai.info"
+            android:exported="true" />
+
     </application>
 
 </manifest>
\ No newline at end of file
diff --git a/app/src/main/java/com/enqualcomm/support/provider/AiInfoDatabaseHelper.java b/app/src/main/java/com/enqualcomm/support/provider/AiInfoDatabaseHelper.java
new file mode 100644 (file)
index 0000000..2cee563
--- /dev/null
@@ -0,0 +1,56 @@
+package com.enqualcomm.support.provider;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.support.annotation.Nullable;
+import android.util.Log;
+
+/**
+ * 这个helper创建的数据库是给语助用的
+ * 有Launcher的应用列表
+ * 以后可能有其他的内容
+ */
+public class AiInfoDatabaseHelper extends SQLiteOpenHelper {
+
+    public static final String name = "AiInfo";
+    public static final int version = 1;
+    private static final String TAG = "AiInfoDatabaseHelper";
+
+    public AiInfoDatabaseHelper(@Nullable Context context) {
+        super(context, name, null, version);
+    }
+
+    public static final String aTableName = "app_list";
+    public static final String aId = "_id";
+    public static final String aPackageName = "package_name";
+    public static final String aAppName = "app_name";
+    public static final String aBrandName = "brand_name";
+    public static final String aCreateTime = "create_time";
+    public static final String aUpdateTime = "update_time";
+
+    @Override
+    public void onCreate(SQLiteDatabase db) {
+        String appSql = "create table " +
+                aTableName + "(" + aId
+                + " Integer primary key autoincrement "
+                + aPackageName
+                + " text "
+                + aAppName
+                + " text "
+                + aBrandName
+                + " text "
+                + aCreateTime
+                + " date "
+                + aUpdateTime
+                + " date "
+                + ")";
+        Log.d(TAG, "sql == > " + appSql);
+        db.execSQL(appSql);
+    }
+
+    @Override
+    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+
+    }
+}
diff --git a/app/src/main/java/com/enqualcomm/support/provider/AiInfoProvider.java b/app/src/main/java/com/enqualcomm/support/provider/AiInfoProvider.java
new file mode 100644 (file)
index 0000000..f5a26bb
--- /dev/null
@@ -0,0 +1,96 @@
+package com.enqualcomm.support.provider;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.content.UriMatcher;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.net.Uri;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+
+/**
+ * AI智能助手的数据提供者
+ * - 目前只作了一个表,就是应用列表,用于给语音查询的应用列表
+ */
+public class AiInfoProvider extends ContentProvider {
+
+    //添加规则
+    public static final String AUTHORITY = "com.ic.ai.info";
+    public static final String PATH = "apps";
+    public static final String APPS = AUTHORITY + "/" + PATH;
+
+
+    private static UriMatcher uriMatcher;
+    public static final int MATCH_CODE = 0x1;
+
+    static {
+        uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
+        uriMatcher.addURI(AUTHORITY, PATH, MATCH_CODE);
+    }
+
+    private AiInfoDatabaseHelper aiInfoDatabaseHelper;
+
+    @Override
+    public boolean onCreate() {
+        aiInfoDatabaseHelper = new AiInfoDatabaseHelper(getContext());
+        return false;
+    }
+
+    @Nullable
+    @Override
+    public Cursor query(@NonNull Uri uri, @Nullable String[] projection,
+                        @Nullable String selection,
+                        @Nullable String[] selectionArgs,
+                        @Nullable String sortOrder) {
+        int match = uriMatcher.match(uri);
+        if (match == MATCH_CODE) {
+            SQLiteDatabase readableDatabase = aiInfoDatabaseHelper.getReadableDatabase();
+            return readableDatabase.query(AiInfoDatabaseHelper.aTableName,
+                    projection, selection, selectionArgs, null, null, sortOrder);
+
+        }
+        //查询内容
+        return null;
+    }
+
+    @Nullable
+    @Override
+    public String getType(@NonNull Uri uri) {
+        return null;
+    }
+
+    @Nullable
+    @Override
+    public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
+        int match = uriMatcher.match(uri);
+        if (match == MATCH_CODE) {
+            SQLiteDatabase readableDatabase = aiInfoDatabaseHelper.getReadableDatabase();
+            readableDatabase.insert(AiInfoDatabaseHelper.aTableName, null, values);
+        }
+        return null;
+    }
+
+    @Override
+    public int delete(@NonNull Uri uri, @Nullable String selection,
+                      @Nullable String[] selectionArgs) {
+        int match = uriMatcher.match(uri);
+        if (match == MATCH_CODE) {
+            SQLiteDatabase readableDatabase = aiInfoDatabaseHelper.getReadableDatabase();
+            return readableDatabase.delete(AiInfoDatabaseHelper.aTableName, selection, selectionArgs);
+        }
+        return 0;
+    }
+
+    @Override
+    public int update(@NonNull Uri uri, @Nullable ContentValues values,
+                      @Nullable String selection, @Nullable String[] selectionArgs) {
+        int match = uriMatcher.match(uri);
+        if (match == MATCH_CODE) {
+            SQLiteDatabase readableDatabase = aiInfoDatabaseHelper.getReadableDatabase();
+            return readableDatabase.update(AiInfoDatabaseHelper.aTableName,
+                    values, selection, selectionArgs);
+        }
+        return 0;
+    }
+}