Add option for settings to push to a device index

The index implementation is optional and left up to the OEM.

Test: Open settings, see content in index
Test: robo tests
Bug: 68378569
Bug: 76102600
Change-Id: Idb8bb1e0cabbbe92e7a852e2eadbdcd8c2ab7d56
This commit is contained in:
Jason Monk
2017-11-22 10:04:38 -05:00
parent 2c1de66c58
commit f6edc7c80a
10 changed files with 316 additions and 5 deletions

View File

@@ -17,27 +17,26 @@
package com.android.settings.slices;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.app.slice.SliceManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.provider.SettingsSlicesContract;
import android.support.annotation.VisibleForTesting;
import android.util.Log;
import com.android.settings.R;
import com.android.settingslib.utils.ThreadUtils;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.WeakHashMap;
import androidx.slice.Slice;
import androidx.slice.SliceProvider;
import androidx.slice.builders.SliceAction;
import androidx.slice.builders.ListBuilder;
import androidx.slice.builders.SliceAction;
/**
* A {@link SliceProvider} for Settings to enabled inline results in system apps.
@@ -106,6 +105,17 @@ public class SettingsSliceProvider extends SliceProvider {
return true;
}
@Override
public Uri onMapIntentToUri(Intent intent) {
try {
return getContext().getSystemService(SliceManager.class).mapIntentToUri(
SliceDeepLinkSpringBoard.parse(
intent.getData(), getContext().getPackageName()));
} catch (URISyntaxException e) {
return null;
}
}
@Override
public Slice onBindSlice(Uri sliceUri) {
String path = sliceUri.getPath();

View File

@@ -0,0 +1,64 @@
/*
* 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 android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import java.net.URISyntaxException;
public class SliceDeepLinkSpringBoard extends Activity {
private static final String TAG = "DeeplinkSpringboard";
public static final String INTENT = "intent";
public static final String SETTINGS = "settings";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Uri uri = getIntent().getData();
if (uri == null) {
Log.e(TAG, "No data found");
finish();
return;
}
try {
Intent intent = parse(uri, getPackageName());
startActivity(intent);
finish();
} catch (URISyntaxException e) {
Log.e(TAG, "Error decoding uri", e);
finish();
}
}
public static Intent parse(Uri uri, String pkg) throws URISyntaxException {
Intent intent = Intent.parseUri(uri.getQueryParameter(INTENT),
Intent.URI_ANDROID_APP_SCHEME);
// Start with some really strict constraints and loosen them if we need to.
// Don't allow components.
intent.setComponent(null);
// Clear out the extras.
if (intent.getExtras() != null) {
intent.getExtras().clear();
}
// Make sure this points at Settings.
intent.setPackage(pkg);
return intent;
}
}