Disable content protection settings if no service

Bug: 308613762
Test: Unit tests and manual end-to-end
Change-Id: I0cc1ff1a260a7e14537036497a155135b7e2f0a9
This commit is contained in:
Nino Jagar
2023-10-31 20:34:04 +00:00
parent af9f60f6c2
commit c7628879da
2 changed files with 89 additions and 19 deletions

View File

@@ -17,9 +17,14 @@ package com.android.settings.security;
import static android.view.contentprotection.flags.Flags.settingUiEnabled;
import static com.android.internal.R.string.config_defaultContentProtectionService;
import android.content.ComponentName;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.android.settings.core.BasePreferenceController;
@@ -31,7 +36,24 @@ public class ContentProtectionPreferenceController extends BasePreferenceControl
@Override
public int getAvailabilityStatus() {
// TODO(b/306565942): Add a resource value check.
return settingUiEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
if (!settingUiEnabled() || getContentProtectionServiceComponentName() == null) {
return UNSUPPORTED_ON_DEVICE;
}
return AVAILABLE;
}
@VisibleForTesting
@Nullable
protected String getContentProtectionServiceFlatComponentName() {
return mContext.getString(config_defaultContentProtectionService);
}
@Nullable
private ComponentName getContentProtectionServiceComponentName() {
String flatComponentName = getContentProtectionServiceFlatComponentName();
if (flatComponentName == null) {
return null;
}
return ComponentName.unflattenFromString(flatComponentName);
}
}