1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.tuner;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.ContentObserver;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import android.provider.Settings;
import com.android.systemui.DemoMode;
import com.android.systemui.R;
public class DemoModeFragment extends PreferenceFragment implements OnPreferenceChangeListener {
private static final String DEMO_MODE_ALLOWED = "sysui_demo_allowed";
private static final String DEMO_MODE_ON = "sysui_tuner_demo_on";
private static final String[] STATUS_ICONS = {
"volume",
"bluetooth",
"location",
"alarm",
"zen",
"sync",
"tty",
"eri",
"mute",
"speakerphone",
"managed_profile",
};
private SwitchPreference mEnabledSwitch;
private SwitchPreference mOnSwitch;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context context = getContext();
mEnabledSwitch = new SwitchPreference(context);
mEnabledSwitch.setTitle(R.string.enable_demo_mode);
mEnabledSwitch.setOnPreferenceChangeListener(this);
mOnSwitch = new SwitchPreference(context);
mOnSwitch.setTitle(R.string.show_demo_mode);
mOnSwitch.setEnabled(false);
mOnSwitch.setOnPreferenceChangeListener(this);
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context);
screen.addPreference(mEnabledSwitch);
screen.addPreference(mOnSwitch);
setPreferenceScreen(screen);
updateDemoModeEnabled();
updateDemoModeOn();
ContentResolver contentResolver = getContext().getContentResolver();
contentResolver.registerContentObserver(Settings.Global.getUriFor(DEMO_MODE_ALLOWED), false,
mDemoModeObserver);
contentResolver.registerContentObserver(Settings.Global.getUriFor(DEMO_MODE_ON), false,
mDemoModeObserver);
}
@Override
public void onDestroy() {
getContext().getContentResolver().unregisterContentObserver(mDemoModeObserver);
super.onDestroy();
}
private void updateDemoModeEnabled() {
boolean enabled = Settings.Global.getInt(getContext().getContentResolver(),
DEMO_MODE_ALLOWED, 0) != 0;
mEnabledSwitch.setChecked(enabled);
mOnSwitch.setEnabled(enabled);
}
private void updateDemoModeOn() {
boolean enabled = Settings.Global.getInt(getContext().getContentResolver(),
DEMO_MODE_ON, 0) != 0;
mOnSwitch.setChecked(enabled);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mEnabledSwitch) {
setGlobal(DEMO_MODE_ALLOWED, newValue == Boolean.TRUE ? 1 : 0);
} else if (preference == mOnSwitch) {
if (newValue == Boolean.TRUE) {
startDemoMode();
} else {
stopDemoMode();
}
} else {
return false;
}
return true;
}
private void startDemoMode() {
Intent intent = new Intent(DemoMode.ACTION_DEMO);
intent.putExtra(DemoMode.EXTRA_COMMAND, DemoMode.COMMAND_ENTER);
getContext().sendBroadcast(intent);
intent.putExtra(DemoMode.EXTRA_COMMAND, DemoMode.COMMAND_CLOCK);
intent.putExtra("hhmm", "0520");
getContext().sendBroadcast(intent);
intent.putExtra(DemoMode.EXTRA_COMMAND, DemoMode.COMMAND_NETWORK);
intent.putExtra("wifi", "show");
intent.putExtra("mobile", "show");
intent.putExtra("sims", "1");
intent.putExtra("nosim", "false");
intent.putExtra("level", "4");
intent.putExtra("datatypel", "");
getContext().sendBroadcast(intent);
// Need to send this after so that the sim controller already exists.
intent.putExtra("fully", "true");
getContext().sendBroadcast(intent);
intent.putExtra(DemoMode.EXTRA_COMMAND, DemoMode.COMMAND_BATTERY);
intent.putExtra("level", "100");
intent.putExtra("plugged", "false");
getContext().sendBroadcast(intent);
intent.putExtra(DemoMode.EXTRA_COMMAND, DemoMode.COMMAND_STATUS);
for (String icon : STATUS_ICONS) {
intent.putExtra(icon, "hide");
}
getContext().sendBroadcast(intent);
intent.putExtra(DemoMode.EXTRA_COMMAND, DemoMode.COMMAND_NOTIFICATIONS);
intent.putExtra("visible", "false");
getContext().sendBroadcast(intent);
setGlobal(DEMO_MODE_ON, 1);
}
private void stopDemoMode() {
Intent intent = new Intent(DemoMode.ACTION_DEMO);
intent.putExtra(DemoMode.EXTRA_COMMAND, DemoMode.COMMAND_EXIT);
getContext().sendBroadcast(intent);
setGlobal(DEMO_MODE_ON, 0);
}
private void setGlobal(String key, int value) {
Settings.Global.putInt(getContext().getContentResolver(), key, value);
}
private final ContentObserver mDemoModeObserver =
new ContentObserver(new Handler(Looper.getMainLooper())) {
public void onChange(boolean selfChange) {
updateDemoModeEnabled();
updateDemoModeOn();
};
};
}
|