Fix a typo in AndroidManifest.xml
And some drive-by clean up.
Change-Id: Ic036f8f5bec8064a5d55e0e032ce45e483323b14
Fixes: 78889604
Test: atest
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e8e45e3..060429e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1114,7 +1114,9 @@
</intent-filter>
</activity>
- <activity android:name=".slice.SliceDeepLinkSpringBoard"
+ <activity
+ android:name=".slices.SliceDeepLinkSpringBoard"
+ android:excludeFromRecents="true"
android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
diff --git a/src/com/android/settings/search/DeviceIndexFeatureProvider.java b/src/com/android/settings/search/DeviceIndexFeatureProvider.java
index 37978df..d529b97 100644
--- a/src/com/android/settings/search/DeviceIndexFeatureProvider.java
+++ b/src/com/android/settings/search/DeviceIndexFeatureProvider.java
@@ -50,7 +50,7 @@
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 @@
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 573dcdf..12a9cf0 100644
--- a/src/com/android/settings/search/DeviceIndexUpdateJobService.java
+++ b/src/com/android/settings/search/DeviceIndexUpdateJobService.java
@@ -17,7 +17,6 @@
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 @@
@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<Uri> slices = manager.getSliceDescendants(baseUri);
- if (DEBUG) Log.d(TAG, "Indexing " + slices.size() + " slices");
+ final Collection<Uri> slices = manager.getSliceDescendants(baseUri);
+ if (DEBUG) {
+ Log.d(TAG, "Indexing " + slices.size() + " slices");
+ }
for (Uri slice : slices) {
if (!mRunningJob) {
@@ -93,16 +96,20 @@
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 0fda33e..0b9961a 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.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 0000000..e7c5d6e
--- /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);
+ }
+}