1 /* 2 * Copyright 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.development.linuxterminal; 18 19 import static android.content.Intent.EXTRA_USER_ID; 20 21 import android.app.settings.SettingsEnums; 22 import android.content.Context; 23 import android.os.UserHandle; 24 25 import androidx.annotation.NonNull; 26 27 import com.android.settings.R; 28 import com.android.settings.dashboard.DashboardFragment; 29 import com.android.settings.search.BaseSearchIndexProvider; 30 import com.android.settingslib.core.AbstractPreferenceController; 31 import com.android.settingslib.development.DevelopmentSettingsEnabler; 32 import com.android.settingslib.search.SearchIndexable; 33 34 import java.util.ArrayList; 35 import java.util.List; 36 37 /** Fragment shown for 'Linux terminal development' preference in developer option. */ 38 @SearchIndexable 39 public class LinuxTerminalDashboardFragment extends DashboardFragment { 40 private static final String TAG = "LinuxTerminalFrag"; 41 42 private Context mUserAwareContext; 43 44 private int mUserId; 45 46 @Override getMetricsCategory()47 public int getMetricsCategory() { 48 return SettingsEnums.LINUX_TERMINAL_DASHBOARD; 49 } 50 51 @NonNull 52 @Override getLogTag()53 public String getLogTag() { 54 return TAG; 55 } 56 57 @Override getPreferenceScreenResId()58 public int getPreferenceScreenResId() { 59 return R.xml.linux_terminal_settings; 60 } 61 62 @Override onAttach(@onNull Context context)63 public void onAttach(@NonNull Context context) { 64 // Initialize mUserId and mUserAwareContext before super.onAttach(), 65 // so createPreferenceControllers() can be called with proper values from super.onAttach(). 66 int currentUserId = UserHandle.myUserId(); 67 mUserId = getArguments().getInt(EXTRA_USER_ID, currentUserId); 68 mUserAwareContext = 69 (currentUserId == mUserId) 70 ? context 71 : context.createContextAsUser(UserHandle.of(mUserId), /* flags= */ 0); 72 73 // Note: This calls createPreferenceControllers() inside. 74 super.onAttach(context); 75 } 76 77 @Override 78 @NonNull createPreferenceControllers( @onNull Context context)79 public List<AbstractPreferenceController> createPreferenceControllers( 80 @NonNull Context context) { 81 List<AbstractPreferenceController> list = new ArrayList<>(); 82 list.add(new EnableLinuxTerminalPreferenceController(context, mUserAwareContext, mUserId)); 83 return list; 84 } 85 86 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 87 new BaseSearchIndexProvider(R.xml.linux_terminal_settings) { 88 89 @Override 90 protected boolean isPageSearchEnabled(Context context) { 91 return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(context); 92 } 93 }; 94 } 95