summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurice Lam <yukl@google.com>2017-04-10 15:42:09 -0700
committerMaurice Lam <yukl@google.com>2017-04-10 15:42:09 -0700
commita3f1dc094f749e873f0c182691dca2d9e928736e (patch)
treececb2861fa690fd479bc363d4e15910d8c776e06
parent24885729e3571ebca96c3fb8041f882d79e0fc0c (diff)
downloadsetupwizard-a3f1dc094f749e873f0c182691dca2d9e928736e.tar.gz
Match direct boot unaware receivers for Partner
In Partner.java, since we don't actually execute code in the package, it is safe to match direct boot unaware receivers as well. Test: ./gradlew connectedAndroidTest test Bug: 36984206 Change-Id: I5ad017458db7d4af2d5a753a3f7663721291402e
-rw-r--r--library/main/src/com/android/setupwizardlib/util/Partner.java24
-rw-r--r--library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java41
2 files changed, 52 insertions, 13 deletions
diff --git a/library/main/src/com/android/setupwizardlib/util/Partner.java b/library/main/src/com/android/setupwizardlib/util/Partner.java
index ada42e0..d6e4919 100644
--- a/library/main/src/com/android/setupwizardlib/util/Partner.java
+++ b/library/main/src/com/android/setupwizardlib/util/Partner.java
@@ -24,9 +24,13 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
+import android.os.Build.VERSION;
+import android.os.Build.VERSION_CODES;
import android.support.annotation.VisibleForTesting;
import android.util.Log;
+import java.util.List;
+
/**
* Utilities to discover and interact with partner customizations. An overlay package is one that
* registers the broadcast receiver for {@code com.android.setupwizard.action.PARTNER_CUSTOMIZATION}
@@ -36,11 +40,12 @@ import android.util.Log;
* <p>Derived from {@code com.android.launcher3/Partner.java}
*/
public class Partner {
+
private static final String TAG = "(SUW) Partner";
/** Marker action used to discover partner */
- private static final String
- ACTION_PARTNER_CUSTOMIZATION = "com.android.setupwizard.action.PARTNER_CUSTOMIZATION";
+ private static final String ACTION_PARTNER_CUSTOMIZATION =
+ "com.android.setupwizard.action.PARTNER_CUSTOMIZATION";
private static boolean sSearched = false;
private static Partner sPartner;
@@ -113,7 +118,20 @@ public class Partner {
if (!sSearched) {
PackageManager pm = context.getPackageManager();
final Intent intent = new Intent(ACTION_PARTNER_CUSTOMIZATION);
- for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
+ List<ResolveInfo> receivers;
+ if (VERSION.SDK_INT >= VERSION_CODES.N) {
+ receivers = pm.queryBroadcastReceivers(
+ intent,
+ PackageManager.MATCH_SYSTEM_ONLY
+ | PackageManager.MATCH_DIRECT_BOOT_AWARE
+ | PackageManager.MATCH_DIRECT_BOOT_UNAWARE);
+ } else {
+ // On versions before N, direct boot doesn't exist. And the MATCH_SYSTEM_ONLY flag
+ // doesn't exist so we filter for system apps in code below.
+ receivers = pm.queryBroadcastReceivers(intent, 0);
+ }
+
+ for (ResolveInfo info : receivers) {
if (info.activityInfo == null) {
continue;
}
diff --git a/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java b/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java
index 8133b6a..f47eef1 100644
--- a/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java
+++ b/library/test/robotest/src/com/android/setupwizardlib/util/PartnerTest.java
@@ -33,6 +33,8 @@ import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
+import android.os.Build.VERSION;
+import android.os.Build.VERSION_CODES;
import com.android.setupwizardlib.BuildConfig;
import com.android.setupwizardlib.R;
@@ -48,9 +50,10 @@ import org.robolectric.res.builder.DefaultPackageManager;
import org.robolectric.shadows.ShadowResources;
import java.util.Arrays;
+import java.util.Collections;
@RunWith(SuwLibRobolectricTestRunner.class)
-@Config(constants = BuildConfig.class)
+@Config(constants = BuildConfig.class, sdk = { Config.OLDEST_SDK, Config.NEWEST_SDK })
public class PartnerTest {
private static final String ACTION_PARTNER_CUSTOMIZATION =
@@ -77,8 +80,8 @@ public class PartnerTest {
mPackageManager.addResolveInfoForIntent(
new Intent(ACTION_PARTNER_CUSTOMIZATION),
Arrays.asList(
- createResolveInfo("foo.bar", false),
- createResolveInfo("test.partner.package", true))
+ createResolveInfo("foo.bar", false, true),
+ createResolveInfo("test.partner.package", true, true))
);
Partner partner = Partner.get(mContext);
@@ -96,8 +99,8 @@ public class PartnerTest {
mPackageManager.addResolveInfoForIntent(
new Intent(ACTION_PARTNER_CUSTOMIZATION),
Arrays.asList(
- createResolveInfo("foo.bar", false),
- createResolveInfo("test.partner.package", false))
+ createResolveInfo("foo.bar", false, true),
+ createResolveInfo("test.partner.package", false, true))
);
Partner partner = Partner.get(mContext);
@@ -113,8 +116,8 @@ public class PartnerTest {
mPackageManager.addResolveInfoForIntent(
new Intent(ACTION_PARTNER_CUSTOMIZATION),
Arrays.asList(
- createResolveInfo("foo.bar", false),
- createResolveInfo("test.partner.package", true))
+ createResolveInfo("foo.bar", false, true),
+ createResolveInfo("test.partner.package", true, true))
);
ResourceEntry entry = Partner.getResourceEntry(mContext, R.integer.suwTransitionDuration);
@@ -128,8 +131,8 @@ public class PartnerTest {
mPackageManager.addResolveInfoForIntent(
new Intent(ACTION_PARTNER_CUSTOMIZATION),
Arrays.asList(
- createResolveInfo("foo.bar", false),
- createResolveInfo("test.partner.package", true))
+ createResolveInfo("foo.bar", false, true),
+ createResolveInfo("test.partner.package", true, true))
);
ResourceEntry entry = Partner.getResourceEntry(mContext, R.color.suw_color_accent_dark);
@@ -138,7 +141,22 @@ public class PartnerTest {
assertFalse("Partner value should come from fallback", entry.isOverlay);
}
- private ResolveInfo createResolveInfo(String packageName, boolean isSystem) {
+ @Test
+ public void testNotDirectBootAware() {
+ mPackageManager.addResolveInfoForIntent(
+ new Intent(ACTION_PARTNER_CUSTOMIZATION),
+ Collections.singletonList(createResolveInfo("test.partner.package", true, false)));
+
+ ResourceEntry entry = Partner.getResourceEntry(mContext, R.color.suw_color_accent_dark);
+ int partnerValue = entry.resources.getColor(entry.id);
+ assertEquals("Partner value should default to 0xff448aff", 0xff448aff, partnerValue);
+ assertFalse("Partner value should come from fallback", entry.isOverlay);
+ }
+
+ private ResolveInfo createResolveInfo(
+ String packageName,
+ boolean isSystem,
+ boolean directBootAware) {
ResolveInfo info = new ResolveInfo();
info.resolvePackageName = packageName;
ActivityInfo activityInfo = new ActivityInfo();
@@ -148,6 +166,9 @@ public class PartnerTest {
activityInfo.applicationInfo = appInfo;
activityInfo.packageName = packageName;
activityInfo.name = packageName;
+ if (VERSION.SDK_INT >= VERSION_CODES.N) {
+ activityInfo.directBootAware = directBootAware;
+ }
info.activityInfo = activityInfo;
return info;
}