• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.settingslib.development.DeveloperOptionsPreferenceController;
27 
28 class SelectDSUPreferenceController extends DeveloperOptionsPreferenceController {
29 
30     private static final String DSU_LOADER_KEY = "dsu_loader";
31 
SelectDSUPreferenceController(Context context)32     SelectDSUPreferenceController(Context context) {
33         super(context);
34     }
35 
36     @Override
getPreferenceKey()37     public String getPreferenceKey() {
38         return DSU_LOADER_KEY;
39     }
40 
isDSURunning()41     private boolean isDSURunning() {
42         return SystemProperties.getBoolean("ro.gsid.image_running", false);
43     }
44 
45     @Override
handlePreferenceTreeClick(Preference preference)46     public boolean handlePreferenceTreeClick(Preference preference) {
47         if (DSU_LOADER_KEY.equals(preference.getKey())) {
48             if (isDSURunning()) {
49                 return true;
50             }
51             final Intent intent = new Intent(mContext, DSULoader.class);
52             mContext.startActivity(intent);
53             return true;
54         }
55         return false;
56     }
57 
58     @Override
updateState(Preference preference)59     public void updateState(Preference preference) {
60         int key = isDSURunning() ? R.string.dsu_is_running : R.string.dsu_loader_description;
61         preference.setSummary(mContext.getResources().getString(key));
62     }
63 }
64