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.settings.slices; 18 19 import android.content.ContentResolver; 20 import android.content.ContentValues; 21 import android.content.Context; 22 import android.database.sqlite.SQLiteDatabase; 23 import android.net.Uri; 24 import android.provider.SettingsSlicesContract; 25 26 import com.android.settings.testutils.FakeIndexProvider; 27 import com.android.settings.testutils.FakeToggleController; 28 29 class SliceTestUtils { 30 31 public static final String FAKE_TITLE = "title"; 32 public static final String FAKE_SUMMARY = "summary"; 33 public static final String FAKE_SCREEN_TITLE = "screen_title"; 34 public static final String FAKE_KEYWORDS = "a, b, c"; 35 public static final int FAKE_ICON = 1234; 36 public static final String FAKE_FRAGMENT_NAME = FakeIndexProvider.class.getName(); 37 public static final String FAKE_CONTROLLER_NAME = FakeToggleController.class.getName(); 38 public static final int FAKE_HIGHLIGHT_MENU_RES = FakeToggleController.HIGHLIGHT_MENU_RES; 39 40 insertSliceToDb(Context context, String key)41 public static void insertSliceToDb(Context context, String key) { 42 insertSliceToDb(context, key, true /* isPlatformSlice */); 43 } 44 insertSliceToDb(Context context, String key, boolean isPlatformSlice)45 public static void insertSliceToDb(Context context, String key, boolean isPlatformSlice) { 46 insertSliceToDb(context, key, isPlatformSlice, null /*customizedUnavailableSliceSubtitle*/); 47 } 48 insertSliceToDb(Context context, String key, boolean isPlatformSlice, String customizedUnavailableSliceSubtitle)49 public static void insertSliceToDb(Context context, String key, boolean isPlatformSlice, 50 String customizedUnavailableSliceSubtitle) { 51 insertSliceToDb(context, key, isPlatformSlice, customizedUnavailableSliceSubtitle, false); 52 } 53 insertSliceToDb(Context context, String key, boolean isPlatformSlice, String customizedUnavailableSliceSubtitle, boolean isPublicSlice)54 public static void insertSliceToDb(Context context, String key, boolean isPlatformSlice, 55 String customizedUnavailableSliceSubtitle, boolean isPublicSlice) { 56 final SQLiteDatabase db = SlicesDatabaseHelper.getInstance(context).getWritableDatabase(); 57 ContentValues values = new ContentValues(); 58 values.put(SlicesDatabaseHelper.IndexColumns.KEY, key); 59 values.put(SlicesDatabaseHelper.IndexColumns.SLICE_URI, 60 new Uri.Builder() 61 .scheme(ContentResolver.SCHEME_CONTENT) 62 .authority(isPlatformSlice 63 ? SettingsSlicesContract.AUTHORITY 64 : SettingsSliceProvider.SLICE_AUTHORITY) 65 .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION) 66 .appendPath(key) 67 .build().toString()); 68 values.put(SlicesDatabaseHelper.IndexColumns.TITLE, FAKE_TITLE); 69 values.put(SlicesDatabaseHelper.IndexColumns.SUMMARY, FAKE_SUMMARY); 70 values.put(SlicesDatabaseHelper.IndexColumns.SCREENTITLE, FAKE_SCREEN_TITLE); 71 values.put(SlicesDatabaseHelper.IndexColumns.KEYWORDS, FAKE_KEYWORDS); 72 values.put(SlicesDatabaseHelper.IndexColumns.ICON_RESOURCE, FAKE_ICON); 73 values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, FAKE_FRAGMENT_NAME); 74 values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, FAKE_CONTROLLER_NAME); 75 values.put(SlicesDatabaseHelper.IndexColumns.SLICE_TYPE, SliceData.SliceType.INTENT); 76 values.put(SlicesDatabaseHelper.IndexColumns.UNAVAILABLE_SLICE_SUBTITLE, 77 customizedUnavailableSliceSubtitle); 78 values.put(SlicesDatabaseHelper.IndexColumns.PUBLIC_SLICE, isPublicSlice); 79 values.put(SlicesDatabaseHelper.IndexColumns.HIGHLIGHT_MENU_RESOURCE, 80 FAKE_HIGHLIGHT_MENU_RES); 81 82 db.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values); 83 db.close(); 84 } 85 } 86