Don't show afw default app pref if there is no candidate.
Change-Id: I25f077662264406a8a4d819db7b4713be753a33b Fix: 22564285 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -125,6 +125,10 @@ public final class SmsDefaultDialog extends AlertActivity implements
|
|||||||
p.mOnClickListener = this;
|
p.mOnClickListener = this;
|
||||||
p.mNegativeButtonText = getString(R.string.cancel);
|
p.mNegativeButtonText = getString(R.string.cancel);
|
||||||
p.mNegativeButtonListener = this;
|
p.mNegativeButtonListener = this;
|
||||||
|
if (p.mAdapter.isEmpty()) {
|
||||||
|
// If there is nothing to choose from, don't build the dialog.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setupAlert();
|
setupAlert();
|
||||||
|
|
||||||
|
@@ -39,7 +39,8 @@ public class DefaultBrowserPreferenceController extends DefaultAppPreferenceCont
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return true;
|
final List<ResolveInfo> candidates = getCandidates();
|
||||||
|
return candidates != null && !candidates.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -61,16 +62,6 @@ public class DefaultBrowserPreferenceController extends DefaultAppPreferenceCont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getOnlyAppLabel() {
|
|
||||||
// Resolve that intent and check that the handleAllWebDataURI boolean is set
|
|
||||||
final List<ResolveInfo> list = mPackageManager.queryIntentActivitiesAsUser(BROWSE_PROBE,
|
|
||||||
PackageManager.MATCH_ALL, mUserId);
|
|
||||||
if (list != null && list.size() == 1) {
|
|
||||||
return list.get(0).loadLabel(mPackageManager.getPackageManager()).toString();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DefaultAppInfo getDefaultAppInfo() {
|
protected DefaultAppInfo getDefaultAppInfo() {
|
||||||
try {
|
try {
|
||||||
@@ -81,6 +72,20 @@ public class DefaultBrowserPreferenceController extends DefaultAppPreferenceCont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<ResolveInfo> getCandidates() {
|
||||||
|
return mPackageManager.queryIntentActivitiesAsUser(BROWSE_PROBE, PackageManager.MATCH_ALL,
|
||||||
|
mUserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getOnlyAppLabel() {
|
||||||
|
// Resolve that intent and check that the handleAllWebDataURI boolean is set
|
||||||
|
final List<ResolveInfo> list = getCandidates();
|
||||||
|
if (list != null && list.size() == 1) {
|
||||||
|
return list.get(0).loadLabel(mPackageManager.getPackageManager()).toString();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the pkg contains browser capability
|
* Whether or not the pkg contains browser capability
|
||||||
*/
|
*/
|
||||||
|
@@ -42,7 +42,11 @@ public class DefaultPhonePreferenceController extends DefaultAppPreferenceContro
|
|||||||
final boolean hasUserRestriction =
|
final boolean hasUserRestriction =
|
||||||
um.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS);
|
um.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS);
|
||||||
|
|
||||||
return !hasUserRestriction;
|
if (hasUserRestriction) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final List<String> candidates = getCandidates();
|
||||||
|
return candidates != null && !candidates.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -60,6 +64,10 @@ public class DefaultPhonePreferenceController extends DefaultAppPreferenceContro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> getCandidates() {
|
||||||
|
return DefaultDialerManager.getInstalledDialerApplications(mContext, mUserId);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean hasPhonePreference(String pkg, Context context) {
|
public static boolean hasPhonePreference(String pkg, Context context) {
|
||||||
List<String> dialerPackages =
|
List<String> dialerPackages =
|
||||||
DefaultDialerManager.getInstalledDialerApplications(context, UserHandle.myUserId());
|
DefaultDialerManager.getInstalledDialerApplications(context, UserHandle.myUserId());
|
||||||
|
@@ -23,21 +23,26 @@ import com.android.settings.Utils;
|
|||||||
|
|
||||||
public class DefaultWorkBrowserPreferenceController extends DefaultBrowserPreferenceController {
|
public class DefaultWorkBrowserPreferenceController extends DefaultBrowserPreferenceController {
|
||||||
|
|
||||||
|
private final UserHandle mUserHandle;
|
||||||
|
|
||||||
public DefaultWorkBrowserPreferenceController(Context context) {
|
public DefaultWorkBrowserPreferenceController(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
final UserHandle managedProfile = Utils.getManagedProfile(mUserManager);
|
mUserHandle = Utils.getManagedProfile(mUserManager);
|
||||||
if (managedProfile != null) {
|
if (mUserHandle != null) {
|
||||||
mUserId = managedProfile.getIdentifier();
|
mUserId = mUserHandle.getIdentifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAvailable() {
|
|
||||||
return Utils.getManagedProfile(mUserManager) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return "work_default_browser";
|
return "work_default_browser";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
if (mUserHandle == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return super.isAvailable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,11 +17,28 @@
|
|||||||
package com.android.settings.applications.defaultapps;
|
package com.android.settings.applications.defaultapps;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
|
||||||
|
import com.android.settings.Utils;
|
||||||
|
|
||||||
public class DefaultWorkPhonePreferenceController extends DefaultPhonePreferenceController {
|
public class DefaultWorkPhonePreferenceController extends DefaultPhonePreferenceController {
|
||||||
|
|
||||||
|
private final UserHandle mUserHandle;
|
||||||
|
|
||||||
public DefaultWorkPhonePreferenceController(Context context) {
|
public DefaultWorkPhonePreferenceController(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
mUserHandle = Utils.getManagedProfile(mUserManager);
|
||||||
|
if (mUserHandle != null) {
|
||||||
|
mUserId = mUserHandle.getIdentifier();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
if (mUserHandle == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return super.isAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -36,7 +36,9 @@ import org.mockito.MockitoAnnotations;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
@@ -68,7 +70,18 @@ public class DefaultBrowserPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAlwaysAvailable() {
|
public void isAvailable_noBrowser_shouldReturnFalse() {
|
||||||
|
when(mPackageManager.queryIntentActivitiesAsUser(any(Intent.class), anyInt(), anyInt()))
|
||||||
|
.thenReturn(null);
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_hasBrowser_shouldReturnTrue() {
|
||||||
|
final List<ResolveInfo> candidates = new ArrayList<>();
|
||||||
|
candidates.add(new ResolveInfo());
|
||||||
|
when(mPackageManager.queryIntentActivitiesAsUser(any(Intent.class), anyInt(), anyInt()))
|
||||||
|
.thenReturn(candidates);
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user