Merge "Use PackageManager.FEATURE_CONTROLS to decide availability" into rvc-dev am: 43527ef8f4
am: 5a91550b9d
am: f4678cd408
am: 61fcef26c8
Original change: undetermined Change-Id: I96757fc174b9fdd8b5d21e4a284dfc0ba25fb634
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
@@ -37,7 +38,9 @@ public class DeviceControlsPreferenceController extends GesturePreferenceControl
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
boolean available = mContext.getPackageManager().hasSystemFeature(
|
||||
PackageManager.FEATURE_CONTROLS);
|
||||
return available ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -37,15 +38,15 @@ public class PowerMenuPreferenceController extends BasePreferenceController {
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
boolean controlsEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
CONTROLS_ENABLED_SETTING, 1) == 1;
|
||||
boolean cardsEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
CARDS_ENABLED_SETTING, 0) == 1;
|
||||
boolean cardsVisible = cardsEnabled && Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
CARDS_AVAILABLE_SETTING, 0) == 1;
|
||||
if (controlsEnabled && cardsVisible) {
|
||||
boolean controlsVisible = isControlsAvailable()
|
||||
&& Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
CONTROLS_ENABLED_SETTING, 1) == 1;
|
||||
boolean cardsVisible = isCardsAvailable()
|
||||
&& Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
CARDS_ENABLED_SETTING, 0) == 1;
|
||||
if (controlsVisible && cardsVisible) {
|
||||
return mContext.getText(R.string.power_menu_cards_passes_device_controls);
|
||||
} else if (controlsEnabled) {
|
||||
} else if (controlsVisible) {
|
||||
return mContext.getText(R.string.power_menu_device_controls);
|
||||
} else if (cardsVisible) {
|
||||
return mContext.getText(R.string.power_menu_cards_passes);
|
||||
@@ -56,6 +57,15 @@ public class PowerMenuPreferenceController extends BasePreferenceController {
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
return isCardsAvailable() || isControlsAvailable() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
private boolean isControlsAvailable() {
|
||||
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CONTROLS);
|
||||
}
|
||||
|
||||
private boolean isCardsAvailable() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
CARDS_AVAILABLE_SETTING, 0) == 1;
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.gestures;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
@@ -57,13 +58,20 @@ public class PowerMenuPrivacyPreferenceController extends TogglePreferenceContro
|
||||
public CharSequence getSummary() {
|
||||
boolean cardsAvailable = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
CARDS_AVAILABLE_KEY, 0) != 0;
|
||||
boolean controlsAvailable = isControlsAvailable();
|
||||
final int res;
|
||||
if (!isSecure()) {
|
||||
res = R.string.power_menu_privacy_not_secure;
|
||||
} else if (cardsAvailable) {
|
||||
} else if (cardsAvailable && controlsAvailable) {
|
||||
res = R.string.power_menu_privacy_show;
|
||||
} else {
|
||||
} else if (!cardsAvailable && controlsAvailable) {
|
||||
res = R.string.power_menu_privacy_show_controls;
|
||||
} else if (cardsAvailable) {
|
||||
res = R.string.power_menu_privacy_show_cards;
|
||||
} else {
|
||||
// In this case, neither cards nor controls are available. This preference should not
|
||||
// be accessible as the power menu setting is not accessible
|
||||
return "";
|
||||
}
|
||||
return mContext.getText(res);
|
||||
}
|
||||
@@ -87,7 +95,7 @@ public class PowerMenuPrivacyPreferenceController extends TogglePreferenceContro
|
||||
boolean cardsAvailable = Settings.Secure.getInt(resolver, CARDS_AVAILABLE_KEY, 0) != 0;
|
||||
boolean cardsEnabled = Settings.Secure.getInt(resolver, CARDS_ENABLED_KEY, 0) != 0;
|
||||
boolean controlsEnabled = Settings.Secure.getInt(resolver, CONTROLS_ENABLED_KEY, 1) != 0;
|
||||
return (cardsAvailable && cardsEnabled) || controlsEnabled;
|
||||
return (cardsAvailable && cardsEnabled) || (isControlsAvailable() && controlsEnabled);
|
||||
}
|
||||
|
||||
private boolean isSecure() {
|
||||
@@ -97,4 +105,8 @@ public class PowerMenuPrivacyPreferenceController extends TogglePreferenceContro
|
||||
int userId = UserHandle.myUserId();
|
||||
return utils.isSecure(userId);
|
||||
}
|
||||
|
||||
private boolean isControlsAvailable() {
|
||||
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CONTROLS);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user