• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 
18 package com.android.settings.testutils;
19 
20 import android.content.Context;
21 import android.content.IntentFilter;
22 import android.net.wifi.WifiManager;
23 import android.provider.Settings;
24 
25 import com.android.settings.core.TogglePreferenceController;
26 
27 public class FakeToggleController extends TogglePreferenceController {
28 
29     private String settingKey = "toggle_key";
30 
31     public static final String AVAILABILITY_KEY = "fake_toggle_availability_key";
32 
33     public static final IntentFilter INTENT_FILTER = new IntentFilter(
34             WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
35 
36     private final int ON = 1;
37     private final int OFF = 0;
38 
39     private boolean mIsAsyncUpdate = false;
40 
FakeToggleController(Context context, String preferenceKey)41     public FakeToggleController(Context context, String preferenceKey) {
42         super(context, preferenceKey);
43     }
44 
45     @Override
isChecked()46     public boolean isChecked() {
47         return Settings.System.getInt(mContext.getContentResolver(),
48                 settingKey, OFF) == ON;
49     }
50 
51     @Override
setChecked(boolean isChecked)52     public boolean setChecked(boolean isChecked) {
53         return Settings.System.putInt(mContext.getContentResolver(), settingKey,
54                 isChecked ? ON : OFF);
55     }
56 
57     @Override
getAvailabilityStatus()58     public int getAvailabilityStatus() {
59         return Settings.Global.getInt(mContext.getContentResolver(),
60                 AVAILABILITY_KEY, AVAILABLE);
61     }
62 
63     @Override
getIntentFilter()64     public IntentFilter getIntentFilter() {
65         return INTENT_FILTER;
66     }
67 
68     @Override
isSliceable()69     public boolean isSliceable() {
70         return true;
71     }
72 
73     @Override
hasAsyncUpdate()74     public boolean hasAsyncUpdate() {
75         return mIsAsyncUpdate;
76     }
77 
setAsyncUpdate(boolean isAsyncUpdate)78     public void setAsyncUpdate(boolean isAsyncUpdate) {
79         mIsAsyncUpdate = isAsyncUpdate;
80     }
81 }
82