blob: 8653dc9a78376f4ae855cb77e9cee4b79ca32320 (
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
|
package com.android.dialer.settings;
import com.google.common.collect.Lists;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.PreferenceActivity.Header;
import android.telecom.TelecomManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.MenuItem;
import com.android.dialer.DialtactsActivity;
import com.android.dialer.R;
import java.util.List;
public class DialerSettingsActivity extends PreferenceActivity {
protected SharedPreferences mPreferences;
private static final int OWNER_HANDLE_ID = 0;
@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();
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 boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
return true;
}
return false;
}
@Override
protected boolean isValidFragment(String fragmentName) {
return true;
}
/**
* Whether a user handle associated with the current user is that of the primary owner. That is,
* whether there is a user handle which has an id which matches the owner's handle.
* @return Whether the current user is the primary user.
*/
private boolean isPrimaryUser() {
UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
List<UserHandle> userHandles = userManager.getUserProfiles();
for (int i = 0; i < userHandles.size(); i++){
if (userHandles.get(i).myUserId() == OWNER_HANDLE_ID) {
return true;
}
}
return false;
}
}
|