blob: c459d35c5772a984e6c8da9e79c796f69c83b37d (
plain)
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
|
package com.android.dialer.settings;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Process;
import android.os.UserManager;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.telecom.TelecomManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Toast;
import com.android.contacts.common.util.PermissionsUtil;
import com.android.dialer.R;
import java.util.List;
public class DialerSettingsActivity extends PreferenceActivity {
protected SharedPreferences mPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
}
@Override
public void onBuildHeaders(List<Header> target) {
Header displayOptionsHeader = new Header();
displayOptionsHeader.titleRes = R.string.display_options_title;
displayOptionsHeader.fragment = DisplayOptionsSettingsFragment.class.getName();
target.add(displayOptionsHeader);
Header soundSettingsHeader = new Header();
soundSettingsHeader.titleRes = R.string.sounds_and_vibration_title;
soundSettingsHeader.fragment = SoundSettingsFragment.class.getName();
soundSettingsHeader.id = R.id.settings_header_sounds_and_vibration;
target.add(soundSettingsHeader);
Header quickResponseSettingsHeader = new Header();
Intent quickResponseSettingsIntent =
new Intent(TelecomManager.ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS);
quickResponseSettingsHeader.titleRes = R.string.respond_via_sms_setting_title;
quickResponseSettingsHeader.intent = quickResponseSettingsIntent;
target.add(quickResponseSettingsHeader);
TelephonyManager telephonyManager =
(TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// Only show call setting menus if the current user is the primary/owner user.
if (isPrimaryUser()) {
// Show "Call Settings" if there is one SIM and "Phone Accounts" if there are more.
if (telephonyManager.getPhoneCount() <= 1) {
Header callSettingsHeader = new Header();
Intent callSettingsIntent = new Intent(TelecomManager.ACTION_SHOW_CALL_SETTINGS);
callSettingsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
callSettingsHeader.titleRes = R.string.call_settings_label;
callSettingsHeader.intent = callSettingsIntent;
target.add(callSettingsHeader);
} else {
Header phoneAccountSettingsHeader = new Header();
Intent phoneAccountSettingsIntent =
new Intent(TelecomManager.ACTION_CHANGE_PHONE_ACCOUNTS);
phoneAccountSettingsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
phoneAccountSettingsHeader.titleRes = R.string.phone_account_settings_label;
phoneAccountSettingsHeader.intent = phoneAccountSettingsIntent;
target.add(phoneAccountSettingsHeader);
}
if (telephonyManager.isTtyModeSupported()
|| telephonyManager.isHearingAidCompatibilitySupported()) {
Header accessibilitySettingsHeader = new Header();
Intent accessibilitySettingsIntent =
new Intent(TelecomManager.ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS);
accessibilitySettingsHeader.titleRes = R.string.accessibility_settings_title;
accessibilitySettingsHeader.intent = accessibilitySettingsIntent;
target.add(accessibilitySettingsHeader);
}
}
}
@Override
public void onHeaderClick(Header header, int position) {
if (header.id == R.id.settings_header_sounds_and_vibration) {
// If we don't have the permission to write to system settings, go to system sound
// settings instead. Otherwise, perform the super implementation (which launches our
// own preference fragment.
if (!Settings.System.canWrite(this)) {
Toast.makeText(
this,
getResources().getString(R.string.toast_cannot_write_system_settings),
Toast.LENGTH_SHORT).show();
startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS));
return;
}
}
super.onHeaderClick(header, position);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
return true;
}
return false;
}
@Override
protected boolean isValidFragment(String fragmentName) {
return true;
}
/**
* @return Whether the current user is the primary user.
*/
private boolean isPrimaryUser() {
final UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
return userManager.isSystemUser();
}
}
|