Merge "Fix DND crash from SpringboardActivity" into pi-dev am: 3f790b76b0

am: 7fcbaf4ac9

Change-Id: I999288a61ebc780986ed108cd0b255db6ee4d791
This commit is contained in:
Matthew Fritze
2018-05-29 12:52:43 -07:00
committed by android-build-merger
6 changed files with 132 additions and 45 deletions

View File

@@ -102,6 +102,17 @@ public class BluetoothSliceBuilder {
.build(); .build();
} }
public static Intent getIntent(Context context) {
final String screenTitle = context.getText(R.string.bluetooth_settings_title).toString();
final Uri contentUri = new Uri.Builder().appendPath(
SettingsSlicesContract.KEY_BLUETOOTH).build();
return DatabaseIndexingUtils.buildSearchResultPageIntent(context,
BluetoothDashboardFragment.class.getName(), null /* key */, screenTitle,
MetricsProto.MetricsEvent.SETTINGS_CONNECTED_DEVICE_CATEGORY)
.setClassName(context.getPackageName(), SubSettings.class.getName())
.setData(contentUri);
}
/** /**
* Update the current Bluetooth status to the boolean value keyed by * Update the current Bluetooth status to the boolean value keyed by
* {@link android.app.slice.Slice#EXTRA_TOGGLE_STATE} on {@param intent}. * {@link android.app.slice.Slice#EXTRA_TOGGLE_STATE} on {@param intent}.
@@ -123,15 +134,7 @@ public class BluetoothSliceBuilder {
} }
private static PendingIntent getPrimaryAction(Context context) { private static PendingIntent getPrimaryAction(Context context) {
final String screenTitle = context.getText(R.string.bluetooth_settings_title).toString(); final Intent intent = getIntent(context);
final Uri contentUri = new Uri.Builder().appendPath(
SettingsSlicesContract.KEY_BLUETOOTH).build();
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context,
BluetoothDashboardFragment.class.getName(), null /* key */, screenTitle,
MetricsProto.MetricsEvent.SETTINGS_CONNECTED_DEVICE_CATEGORY)
.setClassName(context.getPackageName(), SubSettings.class.getName())
.setData(contentUri);
return PendingIntent.getActivity(context, 0 /* requestCode */, return PendingIntent.getActivity(context, 0 /* requestCode */,
intent, 0 /* flags */); intent, 0 /* flags */);
} }

View File

@@ -78,15 +78,18 @@ public class LocationSliceBuilder {
.build(); .build();
} }
private static PendingIntent getPrimaryAction(Context context) { public static Intent getIntent(Context context) {
final String screenTitle = context.getText(R.string.location_settings_title).toString(); final String screenTitle = context.getText(R.string.location_settings_title).toString();
final Uri contentUri = new Uri.Builder().appendPath(KEY_LOCATION).build(); final Uri contentUri = new Uri.Builder().appendPath(KEY_LOCATION).build();
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context, return DatabaseIndexingUtils.buildSearchResultPageIntent(context,
LocationSettings.class.getName(), KEY_LOCATION, screenTitle, LocationSettings.class.getName(), KEY_LOCATION, screenTitle,
MetricsEvent.LOCATION) MetricsEvent.LOCATION)
.setClassName(context.getPackageName(), SubSettings.class.getName()) .setClassName(context.getPackageName(), SubSettings.class.getName())
.setData(contentUri); .setData(contentUri);
}
private static PendingIntent getPrimaryAction(Context context) {
final Intent intent = getIntent(context);
return PendingIntent.getActivity(context, 0 /* requestCode */, return PendingIntent.getActivity(context, 0 /* requestCode */,
intent, 0 /* flags */); intent, 0 /* flags */);
} }

View File

@@ -121,6 +121,16 @@ public class ZenModeSliceBuilder {
// handle it. // handle it.
} }
public static Intent getIntent(Context context) {
final Uri contentUri = new Uri.Builder().appendPath(ZEN_MODE_KEY).build();
final String screenTitle = context.getText(R.string.zen_mode_settings_title).toString();
return DatabaseIndexingUtils.buildSearchResultPageIntent(context,
ZenModeSettings.class.getName(), ZEN_MODE_KEY, screenTitle,
MetricsEvent.NOTIFICATION_ZEN_MODE)
.setClassName(context.getPackageName(), SubSettings.class.getName())
.setData(contentUri);
}
private static boolean isZenModeEnabled(Context context) { private static boolean isZenModeEnabled(Context context) {
final NotificationManager manager = context.getSystemService(NotificationManager.class); final NotificationManager manager = context.getSystemService(NotificationManager.class);
final int zenMode = manager.getZenMode(); final int zenMode = manager.getZenMode();
@@ -137,16 +147,8 @@ public class ZenModeSliceBuilder {
} }
private static PendingIntent getPrimaryAction(Context context) { private static PendingIntent getPrimaryAction(Context context) {
final String screenTitle = context.getText(R.string.zen_mode_settings_title).toString(); final Intent intent = getIntent(context);
final Uri contentUri = new Uri.Builder().appendPath(ZEN_MODE_KEY).build(); return PendingIntent.getActivity(context, 0 /* requestCode */, intent, 0 /* flags */);
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context,
ZenModeSettings.class.getName(), ZEN_MODE_KEY, screenTitle,
MetricsEvent.NOTIFICATION_ZEN_MODE)
.setClassName(context.getPackageName(), SubSettings.class.getName())
.setData(contentUri);
return PendingIntent.getActivity(context, 0 /* requestCode */,
intent, 0 /* flags */);
} }
private static PendingIntent getBroadcastIntent(Context context) { private static PendingIntent getBroadcastIntent(Context context) {

View File

@@ -18,8 +18,16 @@ import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings;
import android.util.Log; import android.util.Log;
import com.android.settings.bluetooth.BluetoothSliceBuilder;
import com.android.settings.location.LocationSliceBuilder;
import com.android.settings.notification.ZenModeSliceBuilder;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.wifi.WifiSliceBuilder;
import com.android.settings.wifi.calling.WifiCallingSliceHelper;
import java.net.URISyntaxException; import java.net.URISyntaxException;
public class SliceDeepLinkSpringBoard extends Activity { public class SliceDeepLinkSpringBoard extends Activity {
@@ -44,11 +52,26 @@ public class SliceDeepLinkSpringBoard extends Activity {
if (ACTION_VIEW_SLICE.equals(intent.getAction())) { if (ACTION_VIEW_SLICE.equals(intent.getAction())) {
// This shouldn't matter since the slice is shown instead of the device // This shouldn't matter since the slice is shown instead of the device
// index caring about the launch uri. // index caring about the launch uri.
Uri slice = Uri.parse(intent.getStringExtra(EXTRA_SLICE)); final Uri slice = Uri.parse(intent.getStringExtra(EXTRA_SLICE));
SlicesDatabaseAccessor slicesDatabaseAccessor = new SlicesDatabaseAccessor(this); final Intent launchIntent;
// Sadly have to block here because we don't know where to go.
final SliceData sliceData = slicesDatabaseAccessor.getSliceDataFromUri(slice); // TODO (b/80263568) Avoid duplicating this list of Slice Uris.
Intent launchIntent = SliceBuilderUtils.getContentIntent(this, sliceData); if (WifiSliceBuilder.WIFI_URI.equals(slice)) {
launchIntent = WifiSliceBuilder.getIntent(this /* context */);
} else if (ZenModeSliceBuilder.ZEN_MODE_URI.equals(slice)) {
launchIntent = ZenModeSliceBuilder.getIntent(this /* context */);
} else if (BluetoothSliceBuilder.BLUETOOTH_URI.equals(slice)) {
launchIntent = BluetoothSliceBuilder.getIntent(this /* context */);
} else if (LocationSliceBuilder.LOCATION_URI.equals(slice)) {
launchIntent = LocationSliceBuilder.getIntent(this /* context */);
} else {
final SlicesDatabaseAccessor slicesDatabaseAccessor =
new SlicesDatabaseAccessor(this /* context */);
// Sadly have to block here because we don't know where to go.
final SliceData sliceData = slicesDatabaseAccessor.getSliceDataFromUri(slice);
launchIntent = SliceBuilderUtils.getContentIntent(this, sliceData);
}
startActivity(launchIntent); startActivity(launchIntent);
} else { } else {
startActivity(intent); startActivity(intent);
@@ -57,6 +80,10 @@ public class SliceDeepLinkSpringBoard extends Activity {
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
Log.e(TAG, "Error decoding uri", e); Log.e(TAG, "Error decoding uri", e);
finish(); finish();
} catch (IllegalStateException e) {
Log.w(TAG, "Couldn't launch Slice intent", e);
startActivity(new Intent(Settings.ACTION_SETTINGS));
finish();
} }
} }

View File

@@ -120,6 +120,18 @@ public class WifiSliceBuilder {
// handle it. // handle it.
} }
public static Intent getIntent(Context context) {
final String screenTitle = context.getText(R.string.wifi_settings).toString();
final Uri contentUri = new Uri.Builder().appendPath(KEY_WIFI).build();
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context,
WifiSettings.class.getName(), KEY_WIFI, screenTitle,
MetricsEvent.DIALOG_WIFI_AP_EDIT)
.setClassName(context.getPackageName(), SubSettings.class.getName())
.setData(contentUri);
return intent;
}
private static boolean isWifiEnabled(Context context) { private static boolean isWifiEnabled(Context context) {
final WifiManager wifiManager = context.getSystemService(WifiManager.class); final WifiManager wifiManager = context.getSystemService(WifiManager.class);
@@ -158,14 +170,7 @@ public class WifiSliceBuilder {
} }
private static PendingIntent getPrimaryAction(Context context) { private static PendingIntent getPrimaryAction(Context context) {
final String screenTitle = context.getText(R.string.wifi_settings).toString(); final Intent intent = getIntent(context);
final Uri contentUri = new Uri.Builder().appendPath(KEY_WIFI).build();
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context,
WifiSettings.class.getName(), KEY_WIFI, screenTitle,
MetricsEvent.DIALOG_WIFI_AP_EDIT);
intent.setClassName(context.getPackageName(), SubSettings.class.getName());
intent.setData(contentUri);
return PendingIntent.getActivity(context, 0 /* requestCode */, return PendingIntent.getActivity(context, 0 /* requestCode */,
intent, 0 /* flags */); intent, 0 /* flags */);
} }

View File

@@ -21,14 +21,22 @@ import static com.android.settings.search.DeviceIndexFeatureProvider.createDeepL
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.platform.test.annotations.Presubmit;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4; 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.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@MediumTest
public class SliceDeepLinkSpringBoardTest { public class SliceDeepLinkSpringBoardTest {
private Context mContext; private Context mContext;
@@ -38,18 +46,57 @@ public class SliceDeepLinkSpringBoardTest {
} }
@Test @Test
public void launcheDeepLinkIntent_shouldNotCrash() { @Presubmit
final Uri springBoardIntentUri = createDeepLink( public void launchesDeepLinkIntent_shouldNotCrash() {
new Intent(SliceDeepLinkSpringBoard.ACTION_VIEW_SLICE) final Intent deepLinkIntent = getSpringboardIntent(
.setPackage(mContext.getPackageName()) "content://com.android.settings.slices/action/test_slice");
.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); 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);
}
} }