Fix DND crash from SpringboardActivity

Special case Uris need to explicitly add their intents.
This unfortunately duplicates a list of special-cased Slices,
but I have attached a bug with a plan to address this duplicity in Q.

Change-Id: I346915c32543713d33716422018d7c950cce323d
Fixes: 80065409
Test: atest SliceDeepLinkSpringBoardTest
This commit is contained in:
Matthew Fritze
2018-05-24 16:09:05 -07:00
parent 2e0709b3b8
commit a559103b1b
6 changed files with 132 additions and 45 deletions

View File

@@ -21,14 +21,22 @@ import static com.android.settings.search.DeviceIndexFeatureProvider.createDeepL
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.platform.test.annotations.Presubmit;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4;
import com.android.settings.bluetooth.BluetoothSliceBuilder;
import com.android.settings.location.LocationSliceBuilder;
import com.android.settings.notification.ZenModeSliceBuilder;
import com.android.settings.wifi.WifiSliceBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class SliceDeepLinkSpringBoardTest {
private Context mContext;
@@ -38,18 +46,57 @@ public class SliceDeepLinkSpringBoardTest {
}
@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);
@Presubmit
public void launchesDeepLinkIntent_shouldNotCrash() {
final Intent deepLinkIntent = getSpringboardIntent(
"content://com.android.settings.slices/action/test_slice");
mContext.startActivity(deepLinkIntent);
}
@Test
@Presubmit
public void launchesDeepLinkIntent_wifiSlice_shouldNotCrash() {
final Intent deepLinkIntent = getSpringboardIntent(WifiSliceBuilder.WIFI_URI.toString());
mContext.startActivity(deepLinkIntent);
}
@Test
@Presubmit
public void launchesDeepLinkIntent_bluetoothSlice_shouldNotCrash() {
final Intent deepLinkIntent = getSpringboardIntent(
BluetoothSliceBuilder.BLUETOOTH_URI.toString());
mContext.startActivity(deepLinkIntent);
}
@Test
@Presubmit
public void launchesDeepLinkIntent_dndSlice_shouldNotCrash() {
final Intent deepLinkIntent = getSpringboardIntent(
ZenModeSliceBuilder.ZEN_MODE_URI.toString());
mContext.startActivity(deepLinkIntent);
}
@Test
@Presubmit
public void launchesDeepLinkIntent_locationSlice_shouldNotCrash() {
final Intent deepLinkIntent = getSpringboardIntent(
LocationSliceBuilder.LOCATION_URI.toString());
mContext.startActivity(deepLinkIntent);
}
private Intent getSpringboardIntent(String uriString) {
final Uri uri = createDeepLink(new Intent(SliceDeepLinkSpringBoard.ACTION_VIEW_SLICE)
.setPackage(mContext.getPackageName())
.putExtra(SliceDeepLinkSpringBoard.EXTRA_SLICE, uriString)
.toUri(Intent.URI_ANDROID_APP_SCHEME));
return new Intent(Intent.ACTION_VIEW)
.setData(uri)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
}