diff --git a/AndroidManifest.xml b/AndroidManifest.xml index e8e45e3e881..060429e9007 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1114,7 +1114,9 @@ - diff --git a/src/com/android/settings/search/DeviceIndexFeatureProvider.java b/src/com/android/settings/search/DeviceIndexFeatureProvider.java index 37978df1699..d529b978d94 100644 --- a/src/com/android/settings/search/DeviceIndexFeatureProvider.java +++ b/src/com/android/settings/search/DeviceIndexFeatureProvider.java @@ -50,7 +50,7 @@ public interface DeviceIndexFeatureProvider { if (!isIndexingEnabled()) return; if (!force && Objects.equals( - Settings.Secure.getString(context.getContentResolver(), INDEX_VERSION), VERSION)) { + Settings.Secure.getString(context.getContentResolver(), INDEX_VERSION), VERSION)) { // No need to update. return; } @@ -70,11 +70,10 @@ public interface DeviceIndexFeatureProvider { Settings.Secure.putString(context.getContentResolver(), INDEX_VERSION, VERSION); } - static String createDeepLink(String s) { + static Uri createDeepLink(String s) { return new Uri.Builder().scheme(SETTINGS) .authority(SettingsSliceProvider.SLICE_AUTHORITY) .appendQueryParameter(INTENT, s) - .build() - .toString(); + .build(); } } diff --git a/src/com/android/settings/search/DeviceIndexUpdateJobService.java b/src/com/android/settings/search/DeviceIndexUpdateJobService.java index 573dcdf5c8b..12a9cf00fcb 100644 --- a/src/com/android/settings/search/DeviceIndexUpdateJobService.java +++ b/src/com/android/settings/search/DeviceIndexUpdateJobService.java @@ -17,7 +17,6 @@ package com.android.settings.search; import static android.app.slice.Slice.HINT_LARGE; import static android.app.slice.Slice.HINT_TITLE; import static android.app.slice.SliceItem.FORMAT_TEXT; - import static com.android.settings.search.DeviceIndexFeatureProvider.createDeepLink; import android.app.job.JobParameters; @@ -73,16 +72,20 @@ public class DeviceIndexUpdateJobService extends JobService { @VisibleForTesting protected void updateIndex(JobParameters params) { - if (DEBUG) Log.d(TAG, "Starting index"); - DeviceIndexFeatureProvider indexProvider = FeatureFactory.getFactory( - this).getDeviceIndexFeatureProvider(); - SliceManager manager = getSliceManager(); - Uri baseUri = new Builder() + if (DEBUG) { + Log.d(TAG, "Starting index"); + } + final DeviceIndexFeatureProvider indexProvider = FeatureFactory.getFactory(this) + .getDeviceIndexFeatureProvider(); + final SliceManager manager = getSliceManager(); + final Uri baseUri = new Builder() .scheme(ContentResolver.SCHEME_CONTENT) .authority(SettingsSliceProvider.SLICE_AUTHORITY) .build(); - Collection slices = manager.getSliceDescendants(baseUri); - if (DEBUG) Log.d(TAG, "Indexing " + slices.size() + " slices"); + final Collection slices = manager.getSliceDescendants(baseUri); + if (DEBUG) { + Log.d(TAG, "Indexing " + slices.size() + " slices"); + } for (Uri slice : slices) { if (!mRunningJob) { @@ -93,16 +96,20 @@ public class DeviceIndexUpdateJobService extends JobService { SliceMetadata metaData = getMetadata(loadedSlice); CharSequence title = findTitle(loadedSlice, metaData); if (title != null) { - if (DEBUG) Log.d(TAG, "Indexing: " + slice + " " + title + " " + loadedSlice); - indexProvider.index(this, title, slice, Uri.parse(createDeepLink( + if (DEBUG) { + Log.d(TAG, "Indexing: " + slice + " " + title + " " + loadedSlice); + } + indexProvider.index(this, title, slice, createDeepLink( new Intent(SliceDeepLinkSpringBoard.ACTION_VIEW_SLICE) .setPackage(getPackageName()) .putExtra(SliceDeepLinkSpringBoard.EXTRA_SLICE, slice.toString()) - .toUri(Intent.URI_ANDROID_APP_SCHEME))), + .toUri(Intent.URI_ANDROID_APP_SCHEME)), metaData.getSliceKeywords()); } } - if (DEBUG) Log.d(TAG, "Done indexing"); + if (DEBUG) { + Log.d(TAG, "Done indexing"); + } jobFinished(params, false); } diff --git a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java index 0fda33e07f2..0b9961a6a1f 100644 --- a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java +++ b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java @@ -18,16 +18,12 @@ package com.android.settings.slices; import static android.content.ContentResolver.SCHEME_CONTENT; - import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.app.slice.SliceManager; -import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.sqlite.SQLiteDatabase; @@ -44,13 +40,13 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RuntimeEnvironment; -import androidx.slice.Slice; - import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import androidx.slice.Slice; + /** * TODO Investigate using ShadowContentResolver.registerProviderInternal(String, ContentProvider) */ diff --git a/tests/unit/src/com/android/settings/slices/SliceDeepLinkSpringBoardTest.java b/tests/unit/src/com/android/settings/slices/SliceDeepLinkSpringBoardTest.java new file mode 100644 index 00000000000..e7c5d6e30fe --- /dev/null +++ b/tests/unit/src/com/android/settings/slices/SliceDeepLinkSpringBoardTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.slices; + +import static com.android.settings.search.DeviceIndexFeatureProvider.createDeepLink; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class SliceDeepLinkSpringBoardTest { + private Context mContext; + + @Before + public void setUp() { + mContext = InstrumentationRegistry.getTargetContext(); + } + + @Test + public void launcheDeepLinkIntent_shouldNotCrash() { + final Uri springBoardIntentUri = createDeepLink( + new Intent(SliceDeepLinkSpringBoard.ACTION_VIEW_SLICE) + .setPackage(mContext.getPackageName()) + .putExtra(SliceDeepLinkSpringBoard.EXTRA_SLICE, + "content://com.android.settings.slices/action/test_slice") + .toUri(Intent.URI_ANDROID_APP_SCHEME)); + + final Intent deepLinkIntent = new Intent(Intent.ACTION_VIEW) + .setData(springBoardIntentUri) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + mContext.startActivity(deepLinkIntent); + } +}