1 /* 2 * Copyright (C) 2019 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; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.os.SystemProperties; 22 23 import androidx.preference.Preference; 24 25 import com.android.settings.R; 26 import com.android.settings.core.PreferenceControllerMixin; 27 import com.android.settingslib.development.DeveloperOptionsPreferenceController; 28 29 class SelectDSUPreferenceController extends DeveloperOptionsPreferenceController implements 30 PreferenceControllerMixin { 31 32 private static final String DSU_LOADER_KEY = "dsu_loader"; 33 SelectDSUPreferenceController(Context context)34 SelectDSUPreferenceController(Context context) { 35 super(context); 36 } 37 38 @Override getPreferenceKey()39 public String getPreferenceKey() { 40 return DSU_LOADER_KEY; 41 } 42 isDSURunning()43 private boolean isDSURunning() { 44 return SystemProperties.getBoolean("ro.gsid.image_running", false); 45 } 46 47 @Override handlePreferenceTreeClick(Preference preference)48 public boolean handlePreferenceTreeClick(Preference preference) { 49 if (DSU_LOADER_KEY.equals(preference.getKey())) { 50 if (isDSURunning()) { 51 return true; 52 } 53 final Intent intent = new Intent(mContext, DSULoader.class); 54 mContext.startActivity(intent); 55 return true; 56 } 57 return false; 58 } 59 60 @Override updateState(Preference preference)61 public void updateState(Preference preference) { 62 int key = isDSURunning() ? R.string.dsu_is_running : R.string.dsu_loader_description; 63 preference.setSummary(mContext.getResources().getString(key)); 64 } 65 } 66