Allow system services to be optional

Some Android systems may not have certain system services (particularly the VirtualMachineManager). If this is the case, disable the preference rather than requiring the service and crashing the Settings app.

Bug: 388221800
Test: manual
Flag: NONE bugfix
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:5a594828d7e148ac98b077591e8050e424b54966)
Merged-In: I761054caebe3e846f5c6c76e2818662aad2cb511
Change-Id: I761054caebe3e846f5c6c76e2818662aad2cb511
This commit is contained in:
Alex Stetson
2025-01-23 17:47:12 -08:00
committed by Jaewan Kim
parent 62c017beb5
commit 99f01f7e7a

View File

@@ -34,8 +34,6 @@ import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController; import com.android.settingslib.development.DeveloperOptionsPreferenceController;
import java.util.Objects;
/** Preference controller for Linux terminal option in developers option */ /** Preference controller for Linux terminal option in developers option */
public class LinuxTerminalPreferenceController extends DeveloperOptionsPreferenceController public class LinuxTerminalPreferenceController extends DeveloperOptionsPreferenceController
implements PreferenceControllerMixin { implements PreferenceControllerMixin {
@@ -59,13 +57,15 @@ public class LinuxTerminalPreferenceController extends DeveloperOptionsPreferenc
mTerminalPackageName = mTerminalPackageName =
isPackageInstalled(context.getPackageManager(), packageName) ? packageName : null; isPackageInstalled(context.getPackageManager(), packageName) ? packageName : null;
StorageManager storageManager = StorageManager storageManager = context.getSystemService(StorageManager.class);
Objects.requireNonNull(context.getSystemService(StorageManager.class));
VirtualMachineManager virtualMachineManager = VirtualMachineManager virtualMachineManager =
Objects.requireNonNull(context.getSystemService(VirtualMachineManager.class)); context.getSystemService(VirtualMachineManager.class);
mIsDeviceCapable = mIsDeviceCapable =
getTotalMemory() >= MEMORY_MIN_BYTES getTotalMemory() >= MEMORY_MIN_BYTES
&& storageManager != null
&& storageManager.getPrimaryStorageSize() >= STORAGE_MIN_BYTES && storageManager.getPrimaryStorageSize() >= STORAGE_MIN_BYTES
&& virtualMachineManager != null
&& ((virtualMachineManager.getCapabilities() & CAPABILITY_NON_PROTECTED_VM) && ((virtualMachineManager.getCapabilities() & CAPABILITY_NON_PROTECTED_VM)
!= 0); != 0);
} }