Merge "Spell checker settings updates" into nyc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 61b62cb..32ec381 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2768,7 +2768,7 @@
</intent-filter>
</activity>
- <activity android:name="Settings$ManageDefaultAppsActivity"
+ <activity android:name="Settings$AdvancedAppsActivity"
android:taskAffinity=""
android:exported="true">
<intent-filter android:priority="1">
@@ -2780,7 +2780,7 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.applications.ManageDefaultApps" />
+ android:value="com.android.settings.applications.AdvancedAppSettings" />
</activity>
<service
diff --git a/res/layout/battery_active_view.xml b/res/layout/battery_active_view.xml
new file mode 100644
index 0000000..b5ada00
--- /dev/null
+++ b/res/layout/battery_active_view.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingEnd="56dp"
+ android:paddingTop="4dp"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@android:id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textColor="?android:attr/textColorSecondary" />
+
+ <com.android.settings.fuelgauge.BatteryActiveView
+ android:id="@+id/battery_active"
+ android:layout_width="match_parent"
+ android:layout_height="6dp" />
+
+</LinearLayout>
diff --git a/res/layout/battery_history_detail.xml b/res/layout/battery_history_detail.xml
new file mode 100644
index 0000000..d1563bf
--- /dev/null
+++ b/res/layout/battery_history_detail.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/charge"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:textSize="36sp"
+ android:textColor="?android:attr/colorAccent" />
+
+ <TextView
+ android:id="@+id/estimation"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingBottom="8dp"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textColor="?android:attr/textColorSecondary" />
+
+ <com.android.settingslib.graph.UsageView
+ android:id="@+id/battery_usage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ settings:sideLabels="@array/battery_labels"
+ android:colorAccent="?android:attr/colorAccent"
+ android:gravity="end"
+ settings:textColor="?android:attr/textColorSecondary" />
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="1dp"
+ android:layout_marginTop="2dp"
+ android:background="?android:attr/listDivider" />
+
+ <ScrollView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <include android:id="@+id/cell_network_group"
+ layout="@layout/battery_active_view" />
+
+ <include android:id="@+id/camera_group"
+ layout="@layout/battery_active_view" />
+
+ <include android:id="@+id/flashlight_group"
+ layout="@layout/battery_active_view" />
+
+ <include android:id="@+id/gps_group"
+ layout="@layout/battery_active_view" />
+
+ <include android:id="@+id/wifi_group"
+ layout="@layout/battery_active_view" />
+
+ <include android:id="@+id/cpu_group"
+ layout="@layout/battery_active_view" />
+
+ <include android:id="@+id/screen_on_group"
+ layout="@layout/battery_active_view" />
+
+ <include android:id="@+id/charging_group"
+ layout="@layout/battery_active_view" />
+
+ </LinearLayout>
+
+ </ScrollView>
+
+</LinearLayout>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index c6dd246..94d7df8 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -126,4 +126,8 @@
<!-- Confirm device credentials screen -->
<attr name="confirmDeviceCredentialsSideMargin" format="dimension" />
<attr name="confirmDeviceCredentialsTopMargin" format="dimension" />
+
+ <declare-styleable name="WorkPreference">
+ <attr name="forWork" format="boolean" />
+ </declare-styleable>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b6ef7b7..5538a11 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6511,7 +6511,10 @@
<string name="fingerprint_not_recognized">Not recognized</string>
<!-- Title for Default Apps settings [CHAR LIMIT=30] -->
- <string name="default_apps_title">Default Apps</string>
+ <string name="default_apps_title">Default</string>
+
+ <!-- Title for Default Apps settings for work [CHAR LIMIT=30] -->
+ <string name="default_for_work">Default for work</string>
<!-- Title for Assist and voice input settings [CHAR LIMIT=30] -->
<string name="assist_and_voice_input_title">Assist & voice input</string>
@@ -7252,4 +7255,8 @@
<string name="notification_log_details_default">default</string>
<!-- Notification log debug tool: the word 'none' -->
<string name="notification_log_details_none">none</string>
+
+ <!-- [CHAR_LIMIT=60] Label for special access screen -->
+ <string name="special_access">Special access</string>
+
</resources>
diff --git a/res/xml/advanced_apps.xml b/res/xml/advanced_apps.xml
index 70b6856..99e81a6 100644
--- a/res/xml/advanced_apps.xml
+++ b/res/xml/advanced_apps.xml
@@ -24,52 +24,80 @@
android:title="@string/app_permissions"
settings:keywords="@string/keywords_app_permissions" />
- <PreferenceScreen
+ <PreferenceCategory
+ android:title="@string/default_apps_title">
+
+ <PreferenceScreen
android:key="domain_urls"
android:title="@string/domain_urls_title"
android:fragment="com.android.settings.applications.ManageApplications">
- <extra
+ <extra
android:name="classname"
android:value="com.android.settings.Settings$DomainsURLsAppListActivity" />
- </PreferenceScreen>
+ </PreferenceScreen>
+
+ <Preference
+ android:key="assist_and_voice_input"
+ android:fragment="com.android.settings.applications.ManageAssist"
+ android:title="@string/assist_and_voice_input_title" />
+
+ <com.android.settings.applications.DefaultHomePreference
+ android:key="default_home"
+ android:title="@string/home_app"
+ android:summary="@string/no_default_home" />
+
+ <com.android.settings.applications.DefaultBrowserPreference
+ android:key="default_browser"
+ android:title="@string/default_browser_title"
+ android:summary="@string/default_browser_title_none" />
+
+ <com.android.settings.applications.DefaultPhonePreference
+ android:key="default_phone_app"
+ android:title="@string/default_phone_title"
+ settings:keywords="@string/keywords_default_phone_app" />
+
+ <com.android.settings.applications.DefaultEmergencyPreference
+ android:key="default_emergency_app"
+ android:title="@string/default_emergency_app"
+ settings:keywords="@string/keywords_emergency_app" />
+
+ <com.android.settings.applications.DefaultSmsPreference
+ android:key="default_sms_app"
+ android:title="@string/sms_application_title"
+ settings:keywords="@string/keywords_more_default_sms_app" />
+
+ <com.android.settings.applications.DefaultNotificationAssistantPreference
+ android:key="default_notification_asst_app"
+ android:title="@string/default_notification_assistant" />
+
+
+ </PreferenceCategory>
+
+ <com.android.settings.WorkOnlyCategory
+ android:key="work_defaults"
+ android:title="@string/default_for_work">
+
+ <com.android.settings.applications.DefaultBrowserPreference
+ android:key="work_default_browser"
+ android:title="@string/default_browser_title"
+ android:summary="@string/default_browser_title_none"
+ settings:forWork="true" />
+
+ <com.android.settings.applications.DefaultPhonePreference
+ android:key="work_default_phone_app"
+ android:title="@string/default_phone_title"
+ settings:keywords="@string/keywords_default_phone_app"
+ settings:forWork="true" />
+
+ </com.android.settings.WorkOnlyCategory>
<PreferenceCategory
- android:title="@string/advanced_apps" />
+ android:title="@string/advanced_apps">
- <PreferenceScreen
- android:key="default_apps"
- android:fragment="com.android.settings.applications.ManageDefaultApps"
- android:title="@string/default_apps_title"
- settings:keywords="@string/keywords_default_apps" />
+ <PreferenceScreen
+ android:key="special_access"
+ android:fragment="com.android.settings.applications.SpecialAccessSettings"
+ android:title="@string/special_access" />
- <PreferenceScreen
- android:key="system_alert_window"
- android:title="@string/system_alert_window_settings"
- android:fragment="com.android.settings.applications.ManageApplications"
- settings:keywords="@string/keywords_system_alert_window">
- <extra
- android:name="classname"
- android:value="com.android.settings.Settings$OverlaySettingsActivity" />
- </PreferenceScreen>
-
- <PreferenceScreen
- android:key="write_settings_apps"
- android:title="@string/write_settings"
- android:fragment="com.android.settings.applications.ManageApplications"
- settings:keywords="@string/keywords_write_settings">
- <extra
- android:name="classname"
- android:value="com.android.settings.Settings$WriteSettingsActivity" />
- </PreferenceScreen>
-
- <PreferenceScreen
- android:key="high_power_apps"
- android:title="@string/high_power_apps"
- android:fragment="com.android.settings.applications.ManageApplications"
- settings:keywords="@string/keywords_ignore_optimizations">
- <extra
- android:name="classname"
- android:value="com.android.settings.Settings$HighPowerApplicationsActivity" />
- </PreferenceScreen>
-
+ </PreferenceCategory>
</PreferenceScreen>
diff --git a/res/xml/default_apps.xml b/res/xml/default_apps.xml
deleted file mode 100644
index 76d0e8c..0000000
--- a/res/xml/default_apps.xml
+++ /dev/null
@@ -1,62 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- 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.
--->
-
-<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
- android:key="default_apps">
-
- <Preference
- android:key="assist_and_voice_input"
- android:fragment="com.android.settings.applications.ManageAssist"
- android:title="@string/assist_and_voice_input_title"
- />
-
- <com.android.settings.applications.DefaultHomePreference
- android:key="default_home"
- android:title="@string/home_app"
- android:summary="@string/no_default_home"
- />
-
- <com.android.settings.applications.DefaultBrowserPreference
- android:key="default_browser"
- android:title="@string/default_browser_title"
- android:summary="@string/default_browser_title_none"
- />
-
- <com.android.settings.applications.DefaultPhonePreference
- android:key="default_phone_app"
- android:title="@string/default_phone_title"
- settings:keywords="@string/keywords_default_phone_app"
- />
-
- <com.android.settings.applications.DefaultEmergencyPreference
- android:key="default_emergency_app"
- android:title="@string/default_emergency_app"
- settings:keywords="@string/keywords_emergency_app"
- />
-
- <com.android.settings.applications.DefaultSmsPreference
- android:key="default_sms_app"
- android:title="@string/sms_application_title"
- settings:keywords="@string/keywords_more_default_sms_app"
- />
-
- <com.android.settings.applications.DefaultNotificationAssistantPreference
- android:key="default_notification_asst_app"
- android:title="@string/default_notification_assistant" />
-
-</PreferenceScreen>
diff --git a/res/xml/special_access.xml b/res/xml/special_access.xml
new file mode 100644
index 0000000..9b404df
--- /dev/null
+++ b/res/xml/special_access.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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.
+-->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
+
+ <PreferenceScreen
+ android:key="high_power_apps"
+ android:title="@string/high_power_apps"
+ android:fragment="com.android.settings.applications.ManageApplications"
+ settings:keywords="@string/keywords_ignore_optimizations">
+ <extra
+ android:name="classname"
+ android:value="com.android.settings.Settings$HighPowerApplicationsActivity" />
+ </PreferenceScreen>
+
+ <PreferenceScreen
+ android:key="device_administrators"
+ android:title="@string/manage_device_admin"
+ android:fragment="com.android.settings.DeviceAdminSettings" />
+
+ <PreferenceScreen
+ android:key="zen_access"
+ android:title="@string/manage_zen_access_title"
+ android:fragment="com.android.settings.notification.ZenAccessSettings" />
+
+ <PreferenceScreen
+ android:key="system_alert_window"
+ android:title="@string/system_alert_window_settings"
+ android:fragment="com.android.settings.applications.ManageApplications"
+ settings:keywords="@string/keywords_system_alert_window">
+ <extra
+ android:name="classname"
+ android:value="com.android.settings.Settings$OverlaySettingsActivity" />
+ </PreferenceScreen>
+
+ <PreferenceScreen
+ android:key="write_settings_apps"
+ android:title="@string/write_settings"
+ android:fragment="com.android.settings.applications.ManageApplications"
+ settings:keywords="@string/keywords_write_settings">
+ <extra
+ android:name="classname"
+ android:value="com.android.settings.Settings$WriteSettingsActivity" />
+ </PreferenceScreen>
+
+ <PreferenceScreen
+ android:key="notification_access"
+ android:title="@string/manage_notification_access_title"
+ android:fragment="com.android.settings.notification.NotificationAccessSettings" />
+
+ <PreferenceScreen
+ android:key="data_saver"
+ android:title="@string/unrestricted_data_saver"
+ android:fragment="com.android.settings.datausage.UnrestrictedDataAccess" />
+
+ <PreferenceScreen
+ android:key="usage_access"
+ android:title="@string/usage_access"
+ android:fragment="com.android.settings.applications.ManageApplications"
+ settings:keywords="@string/keywords_write_settings">
+ <extra
+ android:name="classname"
+ android:value="com.android.settings.Settings$UsageAccessSettingsActivity" />
+ </PreferenceScreen>
+</PreferenceScreen>
diff --git a/src/com/android/settings/AppListPreference.java b/src/com/android/settings/AppListPreference.java
index 1c1ccd7..8dee7b8 100644
--- a/src/com/android/settings/AppListPreference.java
+++ b/src/com/android/settings/AppListPreference.java
@@ -23,9 +23,12 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
+import android.os.UserHandle;
+import android.os.UserManager;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
@@ -47,6 +50,9 @@
public static final String ITEM_NONE_VALUE = "";
+ protected final boolean mForWork;
+ protected final int mUserId;
+
private Drawable[] mEntryDrawables;
private boolean mShowItemNone = false;
private CharSequence[] mSummaries;
@@ -91,13 +97,24 @@
}
}
- public AppListPreference(Context context, AttributeSet attrs,
- int defStyleAttr, int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
+ public AppListPreference(Context context, AttributeSet attrs, int defStyle, int defAttrs) {
+ super(context, attrs, defStyle, defAttrs);
+
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WorkPreference, 0, 0);
+ mForWork = a.getBoolean(R.styleable.WorkPreference_forWork, false);
+ final UserHandle managedProfile = Utils.getManagedProfile(UserManager.get(context));
+ mUserId = mForWork && managedProfile != null ? managedProfile.getIdentifier()
+ : UserHandle.myUserId();
}
public AppListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
+
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WorkPreference, 0, 0);
+ mForWork = a.getBoolean(R.styleable.WorkPreference_forWork, false);
+ final UserHandle managedProfile = Utils.getManagedProfile(UserManager.get(context));
+ mUserId = mForWork && managedProfile != null ? managedProfile.getIdentifier()
+ : UserHandle.myUserId();
}
public void setShowItemNone(boolean showItemNone) {
@@ -114,7 +131,8 @@
int selectedIndex = -1;
for (int i = 0; i < packageNames.length; i++) {
try {
- ApplicationInfo appInfo = pm.getApplicationInfo(packageNames[i].toString(), 0);
+ ApplicationInfo appInfo = pm.getApplicationInfoAsUser(packageNames[i].toString(), 0,
+ mUserId);
applicationNames.add(appInfo.loadLabel(pm));
validatedPackageNames.add(appInfo.packageName);
entryDrawables.add(appInfo.loadIcon(pm));
@@ -162,8 +180,8 @@
int selectedIndex = -1;
for (int i = 0; i < componentNames.length; i++) {
try {
- ApplicationInfo appInfo = pm.getApplicationInfo(
- componentNames[i].getPackageName().toString(), 0);
+ ApplicationInfo appInfo = pm.getApplicationInfoAsUser(
+ componentNames[i].getPackageName().toString(), 0, mUserId);
applicationNames.add(appInfo.loadLabel(pm));
validatedComponentNames.add(componentNames[i].flattenToString());
entryDrawables.add(appInfo.loadIcon(pm));
diff --git a/src/com/android/settings/InstrumentedFragment.java b/src/com/android/settings/InstrumentedFragment.java
index b5f99b5..9c0c9be 100644
--- a/src/com/android/settings/InstrumentedFragment.java
+++ b/src/com/android/settings/InstrumentedFragment.java
@@ -47,6 +47,7 @@
// Used for generic logging of Settings Preference Persistence, should not be used
// outside SharedPreferencesLogger.
public static final int ACTION_GENERIC_PACKAGE = UNDECLARED + 16;
+ public static final int SPECIAL_ACCESS = UNDECLARED + 17;
/**
* Declare the view of this category.
diff --git a/src/com/android/settings/PreferenceAvailabilityProvider.java b/src/com/android/settings/SelfAvailablePreference.java
similarity index 94%
rename from src/com/android/settings/PreferenceAvailabilityProvider.java
rename to src/com/android/settings/SelfAvailablePreference.java
index bb33aee..8e4e56d 100644
--- a/src/com/android/settings/PreferenceAvailabilityProvider.java
+++ b/src/com/android/settings/SelfAvailablePreference.java
@@ -21,7 +21,7 @@
/**
* Interface for classes whose instances can provide the availability of the preference.
*/
-public interface PreferenceAvailabilityProvider {
+public interface SelfAvailablePreference {
/**
* @return the availability of the preference. Please make sure the availability in managed
* profile is taken into account.
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 494fd3b..95aa700 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -124,7 +124,7 @@
public static class WriteSettingsActivity extends SettingsActivity { /* empty */ }
public static class AppDrawOverlaySettingsActivity extends SettingsActivity { /* empty */ }
public static class AppWriteSettingsActivity extends SettingsActivity { /* empty */ }
- public static class ManageDefaultAppsActivity extends SettingsActivity { /* empty */ }
+ public static class AdvancedAppsActivity extends SettingsActivity { /* empty */ }
public static class WifiCallingSuggestionActivity extends SettingsActivity { /* empty */ }
public static class ZenModeAutomationSuggestionActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index b875823..3f69a36 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -56,11 +56,11 @@
import com.android.settings.accessibility.CaptionPropertiesFragment;
import com.android.settings.accounts.AccountSettings;
import com.android.settings.accounts.AccountSyncSettings;
+import com.android.settings.applications.AdvancedAppSettings;
import com.android.settings.applications.DrawOverlayDetails;
import com.android.settings.applications.InstalledAppDetails;
import com.android.settings.applications.ManageApplications;
import com.android.settings.applications.ManageAssist;
-import com.android.settings.applications.ManageDefaultApps;
import com.android.settings.applications.ProcessStatsSummary;
import com.android.settings.applications.ProcessStatsUi;
import com.android.settings.applications.UsageAccessDetails;
@@ -315,7 +315,7 @@
ProcessStatsSummary.class.getName(),
DrawOverlayDetails.class.getName(),
WriteSettingsDetails.class.getName(),
- ManageDefaultApps.class.getName(),
+ AdvancedAppSettings.class.getName(),
WallpaperTypeSettings.class.getName(),
};
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index e871c82..6144f72 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -25,6 +25,7 @@
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.os.Bundle;
+import android.support.annotation.XmlRes;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceGroupAdapter;
@@ -132,6 +133,25 @@
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
}
+ @Override
+ public void addPreferencesFromResource(@XmlRes int preferencesResId) {
+ super.addPreferencesFromResource(preferencesResId);
+ checkAvailablePrefs(getPreferenceScreen());
+ }
+
+ private void checkAvailablePrefs(PreferenceGroup preferenceGroup) {
+ if (preferenceGroup == null) return;
+ for (int i = 0; i < preferenceGroup.getPreferenceCount(); i++) {
+ Preference pref = preferenceGroup.getPreference(i);
+ if (pref instanceof SelfAvailablePreference
+ && !((SelfAvailablePreference) pref).isAvailable(getContext())) {
+ preferenceGroup.removePreference(pref);
+ } else if (pref instanceof PreferenceGroup) {
+ checkAvailablePrefs((PreferenceGroup) pref);
+ }
+ }
+ }
+
public FloatingActionButton getFloatingActionButton() {
return mFloatingActionButton;
}
diff --git a/src/com/android/settings/ShowAdminSupportDetailsDialog.java b/src/com/android/settings/ShowAdminSupportDetailsDialog.java
index f44c4b8..2f2379a 100644
--- a/src/com/android/settings/ShowAdminSupportDetailsDialog.java
+++ b/src/com/android/settings/ShowAdminSupportDetailsDialog.java
@@ -60,7 +60,7 @@
mDialogView = LayoutInflater.from(this).inflate(
R.layout.admin_support_details_dialog, null);
- setAdminSupportDetails(this, mDialogView, mEnforcedAdmin, true);
+ initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId);
new AlertDialog.Builder(this)
.setView(mDialogView)
@@ -75,7 +75,7 @@
EnforcedAdmin admin = getAdminDetailsFromIntent(intent);
if (!mEnforcedAdmin.equals(admin)) {
mEnforcedAdmin = admin;
- setAdminSupportDetails(this, mDialogView, mEnforcedAdmin, true);
+ initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId);
}
}
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index b54c414..c6af8fb 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -64,6 +64,8 @@
import android.service.persistentdata.PersistentDataBlockManager;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
+import android.support.v7.preference.PreferenceManager;
+import android.support.v7.preference.PreferenceScreen;
import android.telephony.TelephonyManager;
import android.text.Spannable;
import android.text.SpannableString;
@@ -83,7 +85,6 @@
import android.widget.ListView;
import android.widget.TabWidget;
import com.android.internal.util.UserIcons;
-import com.android.settings.datausage.DataUsageList;
import java.io.IOException;
import java.io.InputStream;
@@ -1025,5 +1026,41 @@
.toString();
}
}
+
+ public static List<String> getNonIndexable(int xml, Context context) {
+ List<String> ret = new ArrayList<>();
+ PreferenceManager manager = new PreferenceManager(context);
+ PreferenceScreen screen = manager.inflateFromResource(context, xml, null);
+ checkPrefs(screen, ret);
+
+ return ret;
+ }
+
+ private static void checkPrefs(PreferenceGroup group, List<String> ret) {
+ if (group == null) return;
+ for (int i = 0; i < group.getPreferenceCount(); i++) {
+ Preference pref = group.getPreference(i);
+ if (pref instanceof SelfAvailablePreference
+ && !((SelfAvailablePreference) pref).isAvailable(group.getContext())) {
+ ret.add(pref.getKey());
+ if (pref instanceof PreferenceGroup) {
+ addAll((PreferenceGroup) pref, ret);
+ }
+ } else if (pref instanceof PreferenceGroup) {
+ checkPrefs((PreferenceGroup) pref, ret);
+ }
+ }
+ }
+
+ private static void addAll(PreferenceGroup group, List<String> ret) {
+ if (group == null) return;
+ for (int i = 0; i < group.getPreferenceCount(); i++) {
+ Preference pref = group.getPreference(i);
+ ret.add(pref.getKey());
+ if (pref instanceof PreferenceGroup) {
+ addAll((PreferenceGroup) pref, ret);
+ }
+ }
+ }
}
diff --git a/src/com/android/settings/WorkOnlyCategory.java b/src/com/android/settings/WorkOnlyCategory.java
new file mode 100644
index 0000000..ca4c82d
--- /dev/null
+++ b/src/com/android/settings/WorkOnlyCategory.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2016 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.settings;
+
+import android.content.Context;
+import android.os.UserManager;
+import android.support.v7.preference.PreferenceCategory;
+import android.util.AttributeSet;
+
+/**
+ * A PreferenceCategory that is only visible when the device has a work profile.
+ */
+public class WorkOnlyCategory extends PreferenceCategory implements SelfAvailablePreference {
+
+ public WorkOnlyCategory(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ public boolean isAvailable(Context context) {
+ return Utils.getManagedProfile(UserManager.get(context)) != null;
+ }
+}
diff --git a/src/com/android/settings/applications/AdvancedAppSettings.java b/src/com/android/settings/applications/AdvancedAppSettings.java
index 50f9a5b..6edbf60 100644
--- a/src/com/android/settings/applications/AdvancedAppSettings.java
+++ b/src/com/android/settings/applications/AdvancedAppSettings.java
@@ -16,23 +16,29 @@
package com.android.settings.applications;
import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.provider.SearchIndexableResource;
import android.support.v7.preference.Preference;
-
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
import com.android.settings.applications.PermissionsSummaryHelper.PermissionsResultCallback;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
import com.android.settingslib.applications.ApplicationsState.Session;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
public class AdvancedAppSettings extends SettingsPreferenceFragment implements
- ApplicationsState.Callbacks {
+ ApplicationsState.Callbacks, Indexable {
static final String TAG = "AdvancedAppSettings";
@@ -176,4 +182,20 @@
}
}
}
+
+ public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider() {
+ @Override
+ public List<SearchIndexableResource> getXmlResourcesToIndex(
+ Context context, boolean enabled) {
+ SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.advanced_apps;
+ return Arrays.asList(sir);
+ }
+
+ @Override
+ public List<String> getNonIndexableKeys(Context context) {
+ return Utils.getNonIndexable(R.xml.advanced_apps, context);
+ }
+ };
}
diff --git a/src/com/android/settings/applications/AppInfoBase.java b/src/com/android/settings/applications/AppInfoBase.java
index 76729ab..8a99e03 100644
--- a/src/com/android/settings/applications/AppInfoBase.java
+++ b/src/com/android/settings/applications/AppInfoBase.java
@@ -136,7 +136,8 @@
mPackageInfo = mPm.getPackageInfo(mAppEntry.info.packageName,
PackageManager.GET_DISABLED_COMPONENTS |
PackageManager.GET_UNINSTALLED_PACKAGES |
- PackageManager.GET_SIGNATURES);
+ PackageManager.GET_SIGNATURES |
+ PackageManager.GET_PERMISSIONS);
} catch (NameNotFoundException e) {
Log.e(TAG, "Exception when retrieving package:" + mAppEntry.info.packageName, e);
}
diff --git a/src/com/android/settings/applications/AppStateBaseBridge.java b/src/com/android/settings/applications/AppStateBaseBridge.java
index 1e04e13..d0b8431 100644
--- a/src/com/android/settings/applications/AppStateBaseBridge.java
+++ b/src/com/android/settings/applications/AppStateBaseBridge.java
@@ -43,7 +43,8 @@
// Running on the same background thread as the ApplicationsState lets
// us run in the background and make sure they aren't doing updates at
// the same time as us as well.
- mHandler = new BackgroundHandler(mAppState.getBackgroundLooper());
+ mHandler = new BackgroundHandler(mAppState != null ? mAppState.getBackgroundLooper()
+ : Looper.getMainLooper());
mMainHandler = new MainHandler();
}
diff --git a/src/com/android/settings/applications/DefaultBrowserPreference.java b/src/com/android/settings/applications/DefaultBrowserPreference.java
index a9a4e2a..d25e224 100644
--- a/src/com/android/settings/applications/DefaultBrowserPreference.java
+++ b/src/com/android/settings/applications/DefaultBrowserPreference.java
@@ -21,17 +21,26 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
+import android.os.Handler;
import android.os.UserHandle;
+import android.text.TextUtils;
import android.util.AttributeSet;
-
+import android.util.Log;
+import com.android.internal.content.PackageMonitor;
import com.android.settings.AppListPreference;
-import com.android.settings.PreferenceAvailabilityProvider;
+import com.android.settings.R;
import java.util.ArrayList;
import java.util.List;
public class DefaultBrowserPreference extends AppListPreference {
+ private static final String TAG = "DefaultBrowserPref";
+
+ private static final long DELAY_UPDATE_BROWSER_MILLIS = 500;
+
+ private final Handler mHandler = new Handler();
+
final private PackageManager mPm;
public DefaultBrowserPreference(Context context, AttributeSet attrs) {
@@ -41,12 +50,70 @@
refreshBrowserApps();
}
+ @Override
+ public void onAttached() {
+ super.onAttached();
+ updateDefaultBrowserPreference();
+ mPackageMonitor.register(getContext(), getContext().getMainLooper(), false);
+ }
+
+ @Override
+ public void onDetached() {
+ mPackageMonitor.unregister();
+ super.onDetached();
+ }
+
+ @Override
+ protected boolean persistString(String newValue) {
+
+ if (newValue == null) {
+ return false;
+ }
+ final CharSequence packageName = (CharSequence) newValue;
+ if (TextUtils.isEmpty(packageName)) {
+ return false;
+ }
+ boolean result = mPm.setDefaultBrowserPackageNameAsUser(
+ packageName.toString(), mUserId);
+ if (result) {
+ setSummary("%s");
+ }
+ return result && super.persistString(newValue);
+ }
+
public void refreshBrowserApps() {
List<String> browsers = resolveBrowserApps();
setPackageNames(browsers.toArray(new String[browsers.size()]), null);
}
+ private void updateDefaultBrowserPreference() {
+ refreshBrowserApps();
+
+ final PackageManager pm = getContext().getPackageManager();
+
+ String packageName = pm.getDefaultBrowserPackageNameAsUser(mUserId);
+ if (!TextUtils.isEmpty(packageName)) {
+ // Check if the default Browser package is still there
+ Intent intent = new Intent();
+ intent.setPackage(packageName);
+ intent.setAction(Intent.ACTION_VIEW);
+ intent.addCategory(Intent.CATEGORY_BROWSABLE);
+ intent.setData(Uri.parse("http:"));
+
+ ResolveInfo info = mPm.resolveActivityAsUser(intent, 0, mUserId);
+ if (info != null) {
+ setValue(packageName);
+ setSummary("%s");
+ } else {
+ setSummary(R.string.default_browser_title_none);
+ }
+ } else {
+ setSummary(R.string.default_browser_title_none);
+ Log.d(TAG, "Cannot set empty default Browser value!");
+ }
+ }
+
private List<String> resolveBrowserApps() {
List<String> result = new ArrayList<>();
@@ -58,7 +125,7 @@
// Resolve that intent and check that the handleAllWebDataURI boolean is set
List<ResolveInfo> list = mPm.queryIntentActivitiesAsUser(intent, PackageManager.MATCH_ALL,
- UserHandle.myUserId());
+ mUserId);
final int count = list.size();
for (int i=0; i<count; i++) {
@@ -74,10 +141,53 @@
return result;
}
- public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
+ private final Runnable mUpdateRunnable = new Runnable() {
@Override
- public boolean isAvailable(Context context) {
- return true;
+ public void run() {
+ updateDefaultBrowserPreference();
}
+ };
+
+ private final PackageMonitor mPackageMonitor = new PackageMonitor() {
+ @Override
+ public void onPackageAdded(String packageName, int uid) {
+ sendUpdate();
+ }
+
+ @Override
+ public void onPackageAppeared(String packageName, int reason) {
+ sendUpdate();
+ }
+
+ @Override
+ public void onPackageDisappeared(String packageName, int reason) {
+ sendUpdate();
+ }
+
+ @Override
+ public void onPackageRemoved(String packageName, int uid) {
+ sendUpdate();
+ }
+
+ private void sendUpdate() {
+ mHandler.postDelayed(mUpdateRunnable, DELAY_UPDATE_BROWSER_MILLIS);
+ }
+ };
+
+ public static boolean hasBrowserPreference(String pkg, Context context) {
+ Intent intent = new Intent();
+ intent.setAction(Intent.ACTION_VIEW);
+ intent.addCategory(Intent.CATEGORY_BROWSABLE);
+ intent.setData(Uri.parse("http:"));
+ intent.setPackage(pkg);
+ final List<ResolveInfo> resolveInfos =
+ context.getPackageManager().queryIntentActivities(intent, 0);
+ return resolveInfos != null && resolveInfos.size() != 0;
+ }
+
+ public static boolean isBrowserDefault(String pkg, Context context) {
+ String defaultPackage = context.getPackageManager()
+ .getDefaultBrowserPackageNameAsUser(UserHandle.myUserId());
+ return defaultPackage != null && defaultPackage.equals(pkg);
}
}
diff --git a/src/com/android/settings/applications/DefaultEmergencyPreference.java b/src/com/android/settings/applications/DefaultEmergencyPreference.java
index bb6e84d..2a37633 100644
--- a/src/com/android/settings/applications/DefaultEmergencyPreference.java
+++ b/src/com/android/settings/applications/DefaultEmergencyPreference.java
@@ -16,6 +16,7 @@
package com.android.settings.applications;
+import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -24,16 +25,14 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.AsyncTask;
-import android.os.UserManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.AttributeSet;
-
+import com.android.internal.telephony.SmsApplication;
import com.android.settings.AppListPreference;
-import com.android.settings.PreferenceAvailabilityProvider;
-import com.android.settings.Utils;
+import com.android.settings.SelfAvailablePreference;
import java.util.List;
import java.util.Objects;
@@ -42,7 +41,8 @@
/**
* A preference for choosing the default emergency app
*/
-public class DefaultEmergencyPreference extends AppListPreference {
+public class DefaultEmergencyPreference extends AppListPreference
+ implements SelfAvailablePreference {
private final ContentResolver mContentResolver;
@@ -144,12 +144,22 @@
&& (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
}
- public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
- @Override
- public boolean isAvailable(Context context) {
- return isCapable(context)
- && context.getPackageManager().resolveActivity(QUERY_INTENT, 0) != null
- && !Utils.isManagedProfile(UserManager.get(context));
- }
+ public boolean isAvailable(Context context) {
+ return isCapable(context)
+ && context.getPackageManager().resolveActivity(QUERY_INTENT, 0) != null;
+ }
+
+ public static boolean hasEmergencyPreference(String pkg, Context context) {
+ Intent i = new Intent(QUERY_INTENT);
+ i.setPackage(pkg);
+ final List<ResolveInfo> resolveInfos =
+ context.getPackageManager().queryIntentActivities(i, 0);
+ return resolveInfos != null && resolveInfos.size() != 0;
+ }
+
+ public static boolean isEmergencyDefault(String pkg, Context context) {
+ String defaultPackage = Settings.Secure.getString(context.getContentResolver(),
+ Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION);
+ return defaultPackage != null && defaultPackage.equals(pkg);
}
}
diff --git a/src/com/android/settings/applications/DefaultHomePreference.java b/src/com/android/settings/applications/DefaultHomePreference.java
index 2837a97..9f4a913 100644
--- a/src/com/android/settings/applications/DefaultHomePreference.java
+++ b/src/com/android/settings/applications/DefaultHomePreference.java
@@ -26,11 +26,8 @@
import android.os.Build;
import android.os.UserManager;
import android.util.AttributeSet;
-
import com.android.settings.AppListPreference;
-import com.android.settings.PreferenceAvailabilityProvider;
import com.android.settings.R;
-import com.android.settings.Utils;
import java.util.ArrayList;
import java.util.List;
@@ -118,10 +115,23 @@
return false;
}
- public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
- @Override
- public boolean isAvailable(Context context) {
- return !Utils.isManagedProfile(UserManager.get(context));
+ public static boolean hasHomePreference(String pkg, Context context) {
+ ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
+ PackageManager pm = context.getPackageManager();
+ pm.getHomeActivities(homeActivities);
+ for (int i = 0; i < homeActivities.size(); i++) {
+ if (homeActivities.get(i).activityInfo.packageName.equals(pkg)) {
+ return true;
+ }
}
+ return false;
+ }
+
+ public static boolean isHomeDefault(String pkg, Context context) {
+ ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
+ PackageManager pm = context.getPackageManager();
+ ComponentName def = pm.getHomeActivities(homeActivities);
+
+ return def != null && def.getPackageName().equals(pkg);
}
}
diff --git a/src/com/android/settings/applications/DefaultNotificationAssistantPreference.java b/src/com/android/settings/applications/DefaultNotificationAssistantPreference.java
index ab3a0b2..53fc391 100644
--- a/src/com/android/settings/applications/DefaultNotificationAssistantPreference.java
+++ b/src/com/android/settings/applications/DefaultNotificationAssistantPreference.java
@@ -16,8 +16,6 @@
package com.android.settings.applications;
-import com.android.settings.AppListPreference;
-
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
@@ -25,20 +23,17 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
-import android.os.UserManager;
import android.provider.Settings;
import android.service.notification.NotificationAssistantService;
import android.util.AttributeSet;
import android.util.Slog;
+import com.android.settings.AppListPreference;
+import com.android.settings.R;
+import com.android.settings.notification.ManagedServiceSettings;
import java.util.ArrayList;
import java.util.List;
-import com.android.settings.PreferenceAvailabilityProvider;
-import com.android.settings.R;
-import com.android.settings.Utils;
-import com.android.settings.notification.ManagedServiceSettings;
-
public class DefaultNotificationAssistantPreference extends AppListPreference {
private static final String TAG = "DefaultNotiAssist";
@@ -111,11 +106,4 @@
c.emptyText = R.string.no_notification_listeners;
return c;
}
-
- public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
- @Override
- public boolean isAvailable(Context context) {
- return !Utils.isManagedProfile(UserManager.get(context));
- }
- }
}
diff --git a/src/com/android/settings/applications/DefaultPhonePreference.java b/src/com/android/settings/applications/DefaultPhonePreference.java
index 7ab6325..23f3929 100644
--- a/src/com/android/settings/applications/DefaultPhonePreference.java
+++ b/src/com/android/settings/applications/DefaultPhonePreference.java
@@ -17,21 +17,19 @@
package com.android.settings.applications;
import android.content.Context;
+import android.os.UserHandle;
import android.os.UserManager;
import android.telecom.DefaultDialerManager;
-import android.telecom.TelecomManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.AttributeSet;
-
import com.android.settings.AppListPreference;
-import com.android.settings.PreferenceAvailabilityProvider;
-import com.android.settings.Utils;
+import com.android.settings.SelfAvailablePreference;
import java.util.List;
import java.util.Objects;
-public class DefaultPhonePreference extends AppListPreference {
+public class DefaultPhonePreference extends AppListPreference implements SelfAvailablePreference {
private final Context mContext;
public DefaultPhonePreference(Context context, AttributeSet attrs) {
@@ -44,7 +42,7 @@
@Override
protected boolean persistString(String value) {
if (!TextUtils.isEmpty(value) && !Objects.equals(value, getDefaultPackage())) {
- TelecomManager.from(mContext).setDefaultDialer(value);
+ DefaultDialerManager.setDefaultDialerApplication(getContext(), value, mUserId);
}
setSummary(getEntry());
return true;
@@ -52,7 +50,7 @@
private void loadDialerApps() {
List<String> dialerPackages =
- DefaultDialerManager.getInstalledDialerApplications(getContext());
+ DefaultDialerManager.getInstalledDialerApplications(getContext(), mUserId);
final String[] dialers = new String[dialerPackages.size()];
for (int i = 0; i < dialerPackages.size(); i++) {
@@ -62,22 +60,31 @@
}
private String getDefaultPackage() {
- return DefaultDialerManager.getDefaultDialerApplication(getContext());
+ return DefaultDialerManager.getDefaultDialerApplication(getContext(), mUserId);
}
- public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
- @Override
- public boolean isAvailable(Context context) {
-
- final TelephonyManager tm =
- (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- if (!tm.isVoiceCapable()) {
- return false;
- }
-
- final UserManager um =
- (UserManager) context.getSystemService(Context.USER_SERVICE);
- return !um.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS);
+ @Override
+ public boolean isAvailable(Context context) {
+ final TelephonyManager tm =
+ (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ if (!tm.isVoiceCapable()) {
+ return false;
}
+
+ final UserManager um =
+ (UserManager) context.getSystemService(Context.USER_SERVICE);
+ return !um.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS);
+ }
+
+ public static boolean hasPhonePreference(String pkg, Context context) {
+ List<String> dialerPackages =
+ DefaultDialerManager.getInstalledDialerApplications(context, UserHandle.myUserId());
+ return dialerPackages.contains(pkg);
+ }
+
+ public static boolean isPhoneDefault(String pkg, Context context) {
+ String def = DefaultDialerManager.getDefaultDialerApplication(context,
+ UserHandle.myUserId());
+ return def != null && def.equals(pkg);
}
}
diff --git a/src/com/android/settings/applications/DefaultSmsPreference.java b/src/com/android/settings/applications/DefaultSmsPreference.java
index 73404bb..9315102 100644
--- a/src/com/android/settings/applications/DefaultSmsPreference.java
+++ b/src/com/android/settings/applications/DefaultSmsPreference.java
@@ -22,17 +22,15 @@
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.AttributeSet;
-
import com.android.internal.telephony.SmsApplication;
import com.android.internal.telephony.SmsApplication.SmsApplicationData;
import com.android.settings.AppListPreference;
-import com.android.settings.PreferenceAvailabilityProvider;
-import com.android.settings.Utils;
+import com.android.settings.SelfAvailablePreference;
import java.util.Collection;
import java.util.Objects;
-public class DefaultSmsPreference extends AppListPreference {
+public class DefaultSmsPreference extends AppListPreference implements SelfAvailablePreference {
public DefaultSmsPreference(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -70,18 +68,29 @@
return true;
}
- public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
- @Override
- public boolean isAvailable(Context context) {
- boolean isRestrictedUser =
- UserManager.get(context)
- .getUserInfo(UserHandle.myUserId()).isRestricted();
- TelephonyManager tm =
- (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- return !isRestrictedUser
- && tm.isSmsCapable()
- && !Utils.isManagedProfile(UserManager.get(context));
- }
+ @Override
+ public boolean isAvailable(Context context) {
+ boolean isRestrictedUser =
+ UserManager.get(context)
+ .getUserInfo(UserHandle.myUserId()).isRestricted();
+ TelephonyManager tm =
+ (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ return !isRestrictedUser && tm.isSmsCapable();
}
+ public static boolean hasSmsPreference(String pkg, Context context) {
+ Collection<SmsApplicationData> smsApplications =
+ SmsApplication.getApplicationCollection(context);
+ for (SmsApplicationData data : smsApplications) {
+ if (data.mPackageName.equals(pkg)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static boolean isSmsDefault(String pkg, Context context) {
+ ComponentName appName = SmsApplication.getDefaultSmsApplication(context, true);
+ return appName != null && appName.getPackageName().equals(pkg);
+ }
}
diff --git a/src/com/android/settings/applications/DrawOverlayDetails.java b/src/com/android/settings/applications/DrawOverlayDetails.java
index 92ff480..7e87d8e 100644
--- a/src/com/android/settings/applications/DrawOverlayDetails.java
+++ b/src/com/android/settings/applications/DrawOverlayDetails.java
@@ -156,13 +156,17 @@
}
public static CharSequence getSummary(Context context, AppEntry entry) {
- if (entry.extraInfo != null) {
- return getSummary(context, new OverlayState((PermissionState)entry.extraInfo));
+ OverlayState state;
+ if (entry.extraInfo instanceof OverlayState) {
+ state = (OverlayState) entry.extraInfo;
+ } else if (entry.extraInfo instanceof PermissionState) {
+ state = new OverlayState((PermissionState) entry.extraInfo);
+ } else {
+ state = new AppStateOverlayBridge(context, null, null).getOverlayInfo(
+ entry.info.packageName, entry.info.uid);
}
- // fallback if for whatever reason entry.extrainfo is null - the result
- // may be less accurate
- return getSummary(context, entry.info.packageName);
+ return getSummary(context, state);
}
public static CharSequence getSummary(Context context, OverlayState overlayState) {
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index 7ba6c7f..197da7c 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -16,6 +16,7 @@
package com.android.settings.applications;
+import android.Manifest.permission;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
@@ -51,6 +52,8 @@
import android.os.UserManager;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceClickListener;
+import android.support.v7.preference.PreferenceCategory;
+import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.format.Formatter;
@@ -285,6 +288,7 @@
setHasOptionsMenu(true);
addPreferencesFromResource(R.xml.installed_app_details);
+ addDynamicPrefs();
if (Utils.isBandwidthControlEnabled()) {
INetworkStatsService statsService = INetworkStatsService.Stub.asInterface(
@@ -321,6 +325,7 @@
}
new BatteryUpdater().execute();
new MemoryUpdater().execute();
+ updateDynamicPrefs();
}
@Override
@@ -806,6 +811,119 @@
return true;
}
+ private void addDynamicPrefs() {
+ if (Utils.isManagedProfile(UserManager.get(getContext()))) {
+ return;
+ }
+ final PreferenceScreen screen = getPreferenceScreen();
+ if (DefaultHomePreference.hasHomePreference(mPackageName, getContext())) {
+ screen.addPreference(new ShortcutPreference(getPrefContext(),
+ AdvancedAppSettings.class, "default_home", R.string.home_app,
+ R.string.configure_apps));
+ }
+ if (DefaultBrowserPreference.hasBrowserPreference(mPackageName, getContext())) {
+ screen.addPreference(new ShortcutPreference(getPrefContext(),
+ AdvancedAppSettings.class, "default_browser", R.string.default_browser_title,
+ R.string.configure_apps));
+ }
+ if (DefaultPhonePreference.hasPhonePreference(mPackageName, getContext())) {
+ screen.addPreference(new ShortcutPreference(getPrefContext(),
+ AdvancedAppSettings.class, "default_phone_app", R.string.default_phone_title,
+ R.string.configure_apps));
+ }
+ if (DefaultEmergencyPreference.hasEmergencyPreference(mPackageName, getContext())) {
+ screen.addPreference(new ShortcutPreference(getPrefContext(),
+ AdvancedAppSettings.class, "default_emergency_app",
+ R.string.default_emergency_app, R.string.configure_apps));
+ }
+ if (DefaultSmsPreference.hasSmsPreference(mPackageName, getContext())) {
+ screen.addPreference(new ShortcutPreference(getPrefContext(),
+ AdvancedAppSettings.class, "default_sms_app", R.string.sms_application_title,
+ R.string.configure_apps));
+ }
+ boolean hasDrawOverOtherApps = hasPermission(permission.SYSTEM_ALERT_WINDOW);
+ boolean hasWriteSettings = hasPermission(permission.WRITE_SETTINGS);
+ if (hasDrawOverOtherApps || hasWriteSettings) {
+ PreferenceCategory category = new PreferenceCategory(getPrefContext());
+ category.setTitle(R.string.advanced_apps);
+ screen.addPreference(category);
+
+ if (hasDrawOverOtherApps) {
+ Preference pref = new Preference(getPrefContext());
+ pref.setTitle(R.string.draw_overlay);
+ pref.setKey("system_alert_window");
+ pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ startAppInfoFragment(DrawOverlayDetails.class,
+ getString(R.string.draw_overlay));
+ return true;
+ }
+ });
+ category.addPreference(pref);
+ }
+ if (hasWriteSettings) {
+ Preference pref = new Preference(getPrefContext());
+ pref.setTitle(R.string.write_settings);
+ pref.setKey("write_settings_apps");
+ pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ startAppInfoFragment(WriteSettingsDetails.class,
+ getString(R.string.write_settings));
+ return true;
+ }
+ });
+ category.addPreference(pref);
+ }
+ }
+ }
+
+ private boolean hasPermission(String permission) {
+ for (int i = 0; i < mPackageInfo.requestedPermissions.length; i++) {
+ if (mPackageInfo.requestedPermissions[i].equals(permission)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void updateDynamicPrefs() {
+ Preference pref = findPreference("default_home");
+ if (pref != null) {
+ pref.setSummary(DefaultHomePreference.isHomeDefault(mPackageName, getContext())
+ ? R.string.yes : R.string.no);
+ }
+ pref = findPreference("default_browser");
+ if (pref != null) {
+ pref.setSummary(DefaultBrowserPreference.isBrowserDefault(mPackageName, getContext())
+ ? R.string.yes : R.string.no);
+ }
+ pref = findPreference("default_phone_app");
+ if (pref != null) {
+ pref.setSummary(DefaultPhonePreference.isPhoneDefault(mPackageName, getContext())
+ ? R.string.yes : R.string.no);
+ }
+ pref = findPreference("default_emergency_app");
+ if (pref != null) {
+ pref.setSummary(DefaultEmergencyPreference.isEmergencyDefault(mPackageName,
+ getContext()) ? R.string.yes : R.string.no);
+ }
+ pref = findPreference("default_sms_app");
+ if (pref != null) {
+ pref.setSummary(DefaultSmsPreference.isSmsDefault(mPackageName, getContext())
+ ? R.string.yes : R.string.no);
+ }
+ pref = findPreference("system_alert_window");
+ if (pref != null) {
+ pref.setSummary(DrawOverlayDetails.getSummary(getContext(), mAppEntry));
+ }
+ pref = findPreference("write_settings_apps");
+ if (pref != null) {
+ pref.setSummary(WriteSettingsDetails.getSummary(getContext(), mAppEntry));
+ }
+ }
+
public static void setupAppSnippet(View appSnippet, CharSequence label, Drawable icon,
CharSequence versionName) {
LayoutInflater.from(appSnippet.getContext()).inflate(R.layout.widget_text_views,
diff --git a/src/com/android/settings/applications/ManageAssist.java b/src/com/android/settings/applications/ManageAssist.java
index 5a17a31..7af967c 100644
--- a/src/com/android/settings/applications/ManageAssist.java
+++ b/src/com/android/settings/applications/ManageAssist.java
@@ -18,20 +18,15 @@
import android.app.AlertDialog;
import android.content.ComponentName;
-import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
-import android.os.UserManager;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
-
import com.android.internal.logging.MetricsProto.MetricsEvent;
-import com.android.settings.PreferenceAvailabilityProvider;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
-import com.android.settings.Utils;
import com.android.settings.voice.VoiceInputListPreference;
/**
@@ -179,11 +174,4 @@
mDefaultAssitPref.setValue(assistPackage);
updateUi();
}
-
- public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
- @Override
- public boolean isAvailable(Context context) {
- return !Utils.isManagedProfile(UserManager.get(context));
- }
- }
}
diff --git a/src/com/android/settings/applications/ManageDefaultApps.java b/src/com/android/settings/applications/ManageDefaultApps.java
deleted file mode 100644
index 327c98b..0000000
--- a/src/com/android/settings/applications/ManageDefaultApps.java
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * 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.settings.applications;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.UserHandle;
-import android.provider.SearchIndexableResource;
-import android.provider.Settings;
-import android.support.v4.util.ArrayMap;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
-import android.text.TextUtils;
-import android.util.Log;
-
-import com.android.internal.content.PackageMonitor;
-import com.android.internal.logging.MetricsProto.MetricsEvent;
-import com.android.settings.PreferenceAvailabilityProvider;
-import com.android.settings.R;
-import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settings.search.Index;
-import com.android.settings.search.Indexable;
-import com.android.settings.utils.ProfileSettingsPreferenceFragment;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-public class ManageDefaultApps extends ProfileSettingsPreferenceFragment
- implements Preference.OnPreferenceClickListener, Indexable {
-
- private static final String TAG = ManageDefaultApps.class.getSimpleName();
-
- private static final String KEY_DEFAULT_HOME = "default_home";
- private static final String KEY_ASSIST_AND_VOICE_INPUT = "assist_and_voice_input";
- private static final String KEY_DEFAULT_BROWSER = "default_browser";
- private static final String KEY_DEFAULT_PHONE_APP = "default_phone_app";
- private static final String KEY_DEFAULT_EMERGENCY_APP = "default_emergency_app";
- private static final String KEY_SMS_APPLICATION = "default_sms_app";
- private static final String KEY_DEFAULT_NOTIFICATION_ASST = "default_notification_asst_app";
- private static final String[] PREFERENCE_KEYS = new String[] {
- KEY_DEFAULT_HOME, KEY_ASSIST_AND_VOICE_INPUT, KEY_DEFAULT_BROWSER,
- KEY_DEFAULT_PHONE_APP, KEY_DEFAULT_EMERGENCY_APP, KEY_SMS_APPLICATION,
- KEY_DEFAULT_NOTIFICATION_ASST
- };
-
- private DefaultBrowserPreference mDefaultBrowserPreference;
- private PackageManager mPm;
- private int myUserId;
-
- private static final long DELAY_UPDATE_BROWSER_MILLIS = 500;
-
- private final Handler mHandler = new Handler();
-
- private final Runnable mUpdateRunnable = new Runnable() {
- @Override
- public void run() {
- updateDefaultBrowserPreference();
- }
- };
-
- private final PackageMonitor mPackageMonitor = new PackageMonitor() {
- @Override
- public void onPackageAdded(String packageName, int uid) {
- sendUpdate();
- }
-
- @Override
- public void onPackageAppeared(String packageName, int reason) {
- sendUpdate();
- }
-
- @Override
- public void onPackageDisappeared(String packageName, int reason) {
- sendUpdate();
- }
-
- @Override
- public void onPackageRemoved(String packageName, int uid) {
- sendUpdate();
- }
-
- private void sendUpdate() {
- mHandler.postDelayed(mUpdateRunnable, DELAY_UPDATE_BROWSER_MILLIS);
- }
- };
-
- private void updateDefaultBrowserPreference() {
- mDefaultBrowserPreference.refreshBrowserApps();
-
- final PackageManager pm = getPackageManager();
-
- String packageName = pm.getDefaultBrowserPackageNameAsUser(UserHandle.myUserId());
- if (!TextUtils.isEmpty(packageName)) {
- // Check if the default Browser package is still there
- Intent intent = new Intent();
- intent.setPackage(packageName);
- intent.setAction(Intent.ACTION_VIEW);
- intent.addCategory(Intent.CATEGORY_BROWSABLE);
- intent.setData(Uri.parse("http:"));
-
- ResolveInfo info = mPm.resolveActivityAsUser(intent, 0, myUserId);
- if (info != null) {
- mDefaultBrowserPreference.setValue(packageName);
- CharSequence label = info.loadLabel(pm);
- mDefaultBrowserPreference.setSummary(label);
- } else {
- mDefaultBrowserPreference.setSummary(R.string.default_browser_title_none);
- }
- } else {
- mDefaultBrowserPreference.setSummary(R.string.default_browser_title_none);
- Log.d(TAG, "Cannot set empty default Browser value!");
- }
- }
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
-
- addPreferencesFromResource(R.xml.default_apps);
-
- mPm = getPackageManager();
- myUserId = UserHandle.myUserId();
-
-
- mDefaultBrowserPreference = (DefaultBrowserPreference) findPreference(KEY_DEFAULT_BROWSER);
- mDefaultBrowserPreference.setOnPreferenceChangeListener(
- new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
-
- if (newValue == null) {
- return false;
- }
- final CharSequence packageName = (CharSequence) newValue;
- if (TextUtils.isEmpty(packageName)) {
- return false;
- }
- boolean result = mPm.setDefaultBrowserPackageNameAsUser(
- packageName.toString(), myUserId);
- if (result) {
- mDefaultBrowserPreference.setValue(packageName.toString());
- final CharSequence appName = mDefaultBrowserPreference.getEntry();
- mDefaultBrowserPreference.setSummary(appName);
- }
- return result;
- }
- });
-
- updatePreferenceVisibility();
- // Update the index.
- Index.getInstance(getActivity()).updateFromClassNameResource(
- ManageDefaultApps.class.getName(), true, true);
- }
-
- /**
- * Iterate all preferences and hide it if it is unavailable.
- */
- private void updatePreferenceVisibility() {
- PreferenceScreen preferenceScreen = getPreferenceScreen();
- int count = preferenceScreen.getPreferenceCount();
- List<String> preferenceKeys = new ArrayList<>();
- for (int i = 0; i < count; i++) {
- String preferenceKey = preferenceScreen.getPreference(i).getKey();
- if (!TextUtils.isEmpty(preferenceKey)) {
- preferenceKeys.add(preferenceKey);
- }
- }
- for (String preferenceKey : preferenceKeys) {
- boolean isAvailable = getPreferenceAvailability(getContext(), preferenceKey);
- if (!isAvailable) {
- Preference preference = preferenceScreen.findPreference(preferenceKey);
- preferenceScreen.removePreference(preference);
- }
- }
- }
-
- /**
- * Get availability of preference from {@link PreferenceAvailabilityProvider}.
- */
- private static boolean getPreferenceAvailability(Context context,
- String preferenceKey) {
- // Consider the preference is unavailable if no corresponding provider is found.
- PreferenceAvailabilityProvider provider = getPreferenceAvailabilityProvider(preferenceKey);
- return (provider == null) ? false : provider.isAvailable(context);
- }
-
- private static PreferenceAvailabilityProvider getPreferenceAvailabilityProvider(
- String preferenceKey) {
- switch (preferenceKey) {
- case KEY_ASSIST_AND_VOICE_INPUT:
- return new ManageAssist.AvailabilityProvider();
- case KEY_DEFAULT_BROWSER:
- return new DefaultBrowserPreference.AvailabilityProvider();
- case KEY_DEFAULT_EMERGENCY_APP:
- return new DefaultEmergencyPreference.AvailabilityProvider();
- case KEY_DEFAULT_HOME:
- return new DefaultHomePreference.AvailabilityProvider();
- case KEY_DEFAULT_NOTIFICATION_ASST:
- return new DefaultNotificationAssistantPreference.AvailabilityProvider();
- case KEY_DEFAULT_PHONE_APP:
- return new DefaultPhonePreference.AvailabilityProvider();
- case KEY_SMS_APPLICATION:
- return new DefaultSmsPreference.AvailabilityProvider();
- }
- Log.w(TAG, "getPreferenceAvailabilityProvider: Cannot find provider for " + preferenceKey);
- return null;
- }
-
- @Override
- public void onResume() {
- super.onResume();
- updateDefaultBrowserPreference();
- mPackageMonitor.register(getActivity(), getActivity().getMainLooper(), false);
- }
-
- @Override
- public void onPause() {
- super.onPause();
-
- mPackageMonitor.unregister();
- }
-
- @Override
- protected int getMetricsCategory() {
- return MetricsEvent.APPLICATIONS_DEFAULT_APPS;
- }
-
- @Override
- public boolean onPreferenceClick(Preference preference) {
- return false;
- }
-
- public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider() {
- @Override
- public List<SearchIndexableResource> getXmlResourcesToIndex(
- Context context, boolean enabled) {
- SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = R.xml.default_apps;
- return Arrays.asList(sir);
- }
-
- @Override
- public List<String> getNonIndexableKeys(Context context) {
- // Iterate all preferences to see which is not available.
- final ArrayList<String> result = new ArrayList<>();
- for (String key : PREFERENCE_KEYS) {
- boolean isAvailable = getPreferenceAvailability(context, key);
- if (!isAvailable) {
- result.add(key);
- }
- }
- return result;
- }
- };
-
- protected String getIntentActionString() {
- return Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS;
- }
-
-}
diff --git a/src/com/android/settings/applications/ShortcutPreference.java b/src/com/android/settings/applications/ShortcutPreference.java
new file mode 100644
index 0000000..e3db57a
--- /dev/null
+++ b/src/com/android/settings/applications/ShortcutPreference.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2016 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.settings.applications;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.support.v7.preference.Preference;
+import com.android.settings.SettingsActivity;
+import com.android.settings.Utils;
+
+public class ShortcutPreference extends Preference {
+
+ private final Class mTarget;
+ private final String mPrefKey;
+ private final int mTitle;
+
+ public ShortcutPreference(Context context, Class target, String prefKey, int prefTitle,
+ int title) {
+ super(context);
+ mTarget = target;
+ mPrefKey = prefKey;
+ mTitle = title;
+ setTitle(prefTitle);
+ setKey(mPrefKey);
+ }
+
+ @Override
+ public void performClick() {
+ super.performClick();
+ Bundle bundle = new Bundle();
+ bundle.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, mPrefKey);
+ Utils.startWithFragment(getContext(), mTarget.getName(), bundle, null, 0,
+ mTitle, null);
+ }
+}
diff --git a/src/com/android/settings/applications/SpecialAccessSettings.java b/src/com/android/settings/applications/SpecialAccessSettings.java
new file mode 100644
index 0000000..8320b29
--- /dev/null
+++ b/src/com/android/settings/applications/SpecialAccessSettings.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2016 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.settings.applications;
+
+import android.os.Bundle;
+import com.android.settings.InstrumentedFragment;
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+public class SpecialAccessSettings extends SettingsPreferenceFragment {
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ addPreferencesFromResource(R.xml.special_access);
+ }
+
+ @Override
+ protected int getMetricsCategory() {
+ return InstrumentedFragment.SPECIAL_ACCESS;
+ }
+}
diff --git a/src/com/android/settings/applications/WriteSettingsDetails.java b/src/com/android/settings/applications/WriteSettingsDetails.java
index a4200d7..d310d2b 100644
--- a/src/com/android/settings/applications/WriteSettingsDetails.java
+++ b/src/com/android/settings/applications/WriteSettingsDetails.java
@@ -158,13 +158,17 @@
}
public static CharSequence getSummary(Context context, AppEntry entry) {
- if (entry.extraInfo != null) {
- return getSummary(context, new WriteSettingsState((PermissionState)entry
- .extraInfo));
+ WriteSettingsState state;
+ if (entry.extraInfo instanceof WriteSettingsState) {
+ state = (WriteSettingsState) entry.extraInfo;
+ } else if (entry.extraInfo instanceof PermissionState) {
+ state = new WriteSettingsState((PermissionState) entry.extraInfo);
+ } else {
+ state = new AppStateWriteSettingsBridge(context, null, null).getWriteSettingsInfo(
+ entry.info.packageName, entry.info.uid);
}
- // fallback if entry.extrainfo is null - although this should not happen
- return getSummary(context, entry.info.packageName);
+ return getSummary(context, state);
}
public static CharSequence getSummary(Context context, WriteSettingsState writeSettingsState) {
diff --git a/src/com/android/settings/fuelgauge/BatteryActiveView.java b/src/com/android/settings/fuelgauge/BatteryActiveView.java
new file mode 100644
index 0000000..4856b3d
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/BatteryActiveView.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2016 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.settings.fuelgauge;
+
+import android.annotation.Nullable;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.util.AttributeSet;
+import android.util.SparseIntArray;
+import android.view.View;
+
+public class BatteryActiveView extends View {
+
+ private final Paint mPaint = new Paint();
+ private BatteryActiveProvider mProvider;
+
+ public BatteryActiveView(Context context, @Nullable AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public void setProvider(BatteryActiveProvider provider) {
+ mProvider = provider;
+ if (getWidth() != 0) {
+ postInvalidate();
+ }
+ }
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ super.onSizeChanged(w, h, oldw, oldh);
+ if (getWidth() != 0) {
+ postInvalidate();
+ }
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ if (mProvider == null) {
+ return;
+ }
+ SparseIntArray array = mProvider.getColorArray();
+ float period = mProvider.getPeriod();
+ for (int i = 0; i < array.size() - 1; i++) {
+ drawColor(canvas, array.keyAt(i), array.keyAt(i + 1), array.valueAt(i), period);
+ }
+ }
+
+ private void drawColor(Canvas canvas, int start, int end, int color, float period) {
+ if (color == 0) {
+ return;
+ }
+ mPaint.setColor(color);
+ canvas.drawRect(start / period * getWidth(), 0, end / period * getWidth(), getHeight(),
+ mPaint);
+ }
+
+ public interface BatteryActiveProvider {
+ boolean hasData();
+ long getPeriod();
+ SparseIntArray getColorArray();
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/BatteryCellParser.java b/src/com/android/settings/fuelgauge/BatteryCellParser.java
new file mode 100644
index 0000000..aaac024f
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/BatteryCellParser.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2016 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.settings.fuelgauge;
+
+import android.os.BatteryStats.HistoryItem;
+import android.telephony.ServiceState;
+import android.util.SparseIntArray;
+import com.android.settings.Utils;
+import com.android.settings.fuelgauge.BatteryActiveView.BatteryActiveProvider;
+import com.android.settingslib.BatteryInfo;
+
+public class BatteryCellParser implements BatteryInfo.BatteryDataParser, BatteryActiveProvider {
+
+ private final SparseIntArray mData = new SparseIntArray();
+
+ private int mLastValue;
+ private long mLength;
+ private long mLastTime;
+
+ protected int getValue(HistoryItem rec) {
+ int bin;
+ if (((rec.states & HistoryItem.STATE_PHONE_STATE_MASK)
+ >> HistoryItem.STATE_PHONE_STATE_SHIFT)
+ == ServiceState.STATE_POWER_OFF) {
+ bin = 0;
+ } else if ((rec.states & HistoryItem.STATE_PHONE_SCANNING_FLAG) != 0) {
+ bin = 1;
+ } else {
+ bin = (rec.states & HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK)
+ >> HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
+ bin += 2;
+ }
+ return bin;
+ }
+
+ @Override
+ public void onParsingStarted(long startTime, long endTime) {
+ mLength = endTime - startTime;
+ }
+
+ @Override
+ public void onDataPoint(long time, HistoryItem record) {
+ int value = getValue(record);
+ if (value != mLastValue) {
+ mData.put((int) time, value);
+ mLastValue = value;
+ }
+ mLastTime = time;
+ }
+
+ @Override
+ public void onDataGap() {
+ if (mLastValue != 0) {
+ mData.put((int) mLastTime, 0);
+ mLastValue = 0;
+ }
+ }
+
+ @Override
+ public void onParsingDone() {
+ if (mLastValue != 0) {
+ mData.put((int) mLastTime, 0);
+ mLastValue = 0;
+ }
+ }
+
+ @Override
+ public long getPeriod() {
+ return mLength;
+ }
+
+ @Override
+ public boolean hasData() {
+ return mData.size() > 1;
+ }
+
+ @Override
+ public SparseIntArray getColorArray() {
+ SparseIntArray ret = new SparseIntArray();
+ for (int i = 0; i < mData.size(); i++) {
+ ret.put(mData.keyAt(i), getColor(mData.valueAt(i)));
+ }
+ return ret;
+ }
+
+ private int getColor(int i) {
+ return Utils.BADNESS_COLORS[i];
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/BatteryFlagParser.java b/src/com/android/settings/fuelgauge/BatteryFlagParser.java
new file mode 100644
index 0000000..cd5d89b
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/BatteryFlagParser.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2016 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.settings.fuelgauge;
+
+import android.os.BatteryStats.HistoryItem;
+import android.util.SparseBooleanArray;
+import android.util.SparseIntArray;
+import com.android.settings.fuelgauge.BatteryActiveView.BatteryActiveProvider;
+import com.android.settingslib.BatteryInfo;
+
+public class BatteryFlagParser implements BatteryInfo.BatteryDataParser, BatteryActiveProvider {
+
+ private final SparseBooleanArray mData = new SparseBooleanArray();
+ private final int mFlag;
+ private final boolean mState2;
+ private final int mAccentColor;
+
+ private boolean mLastSet;
+ private long mLength;
+ private long mLastTime;
+
+ public BatteryFlagParser(int accent, boolean state2, int flag) {
+ mAccentColor = accent;
+ mFlag = flag;
+ mState2 = state2;
+ }
+
+ protected boolean isSet(HistoryItem record) {
+ return ((mState2 ? record.states2 : record.states) & mFlag) != 0;
+ }
+
+ @Override
+ public void onParsingStarted(long startTime, long endTime) {
+ mLength = endTime - startTime;
+ }
+
+ @Override
+ public void onDataPoint(long time, HistoryItem record) {
+ boolean isSet = isSet(record);
+ if (isSet != mLastSet) {
+ mData.put((int) time, isSet);
+ mLastSet = isSet;
+ }
+ mLastTime = time;
+ }
+
+ @Override
+ public void onDataGap() {
+ if (mLastSet) {
+ mData.put((int) mLastTime, false);
+ mLastSet = false;
+ }
+ }
+
+ @Override
+ public void onParsingDone() {
+ if (mLastSet) {
+ mData.put((int) mLastTime, false);
+ mLastSet = false;
+ }
+ }
+
+ @Override
+ public long getPeriod() {
+ return mLength;
+ }
+
+ @Override
+ public boolean hasData() {
+ return mData.size() > 1;
+ }
+
+ @Override
+ public SparseIntArray getColorArray() {
+ SparseIntArray ret = new SparseIntArray();
+ for (int i = 0; i < mData.size(); i++) {
+ ret.put(mData.keyAt(i), getColor(mData.valueAt(i)));
+ }
+ return ret;
+ }
+
+ private int getColor(boolean b) {
+ if (b) {
+ return mAccentColor;
+ }
+ return 0;
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryDetail.java b/src/com/android/settings/fuelgauge/BatteryHistoryDetail.java
index af13551..b2cb73a 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryDetail.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryDetail.java
@@ -18,15 +18,21 @@
import android.content.Intent;
import android.os.BatteryStats;
+import android.os.BatteryStats.HistoryItem;
import android.os.Bundle;
+import android.os.SystemClock;
+import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-
+import android.widget.TextView;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.InstrumentedFragment;
import com.android.settings.R;
+import com.android.settings.fuelgauge.BatteryActiveView.BatteryActiveProvider;
+import com.android.settingslib.BatteryInfo;
+import com.android.settingslib.graph.UsageView;
public class BatteryHistoryDetail extends InstrumentedFragment {
public static final String EXTRA_STATS = "stats";
@@ -35,21 +41,80 @@
private BatteryStats mStats;
private Intent mBatteryBroadcast;
+ private BatteryFlagParser mChargingParser;
+ private BatteryFlagParser mScreenOn;
+ private BatteryFlagParser mGpsParser;
+ private BatteryFlagParser mFlashlightParser;
+ private BatteryFlagParser mCameraParser;
+ private BatteryWifiParser mWifiParser;
+ private BatteryFlagParser mCpuParser;
+ private BatteryCellParser mPhoneParser;
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
String histFile = getArguments().getString(EXTRA_STATS);
mStats = BatteryStatsHelper.statsFromFile(getActivity(), histFile);
mBatteryBroadcast = getArguments().getParcelable(EXTRA_BROADCAST);
+
+ TypedValue value = new TypedValue();
+ getContext().getTheme().resolveAttribute(android.R.attr.colorAccent, value, true);
+ int accentColor = getContext().getColor(value.resourceId);
+
+ mChargingParser = new BatteryFlagParser(accentColor, false,
+ HistoryItem.STATE_BATTERY_PLUGGED_FLAG);
+ mScreenOn = new BatteryFlagParser(accentColor, false,
+ HistoryItem.STATE_SCREEN_ON_FLAG);
+ mGpsParser = new BatteryFlagParser(accentColor, false,
+ HistoryItem.STATE_GPS_ON_FLAG);
+ mFlashlightParser = new BatteryFlagParser(accentColor, true,
+ HistoryItem.STATE2_FLASHLIGHT_FLAG);
+ mCameraParser = new BatteryFlagParser(accentColor, true,
+ HistoryItem.STATE2_CAMERA_FLAG);
+ mWifiParser = new BatteryWifiParser(accentColor);
+ mCpuParser = new BatteryFlagParser(accentColor, false,
+ HistoryItem.STATE_CPU_RUNNING_FLAG);
+ mPhoneParser = new BatteryCellParser();
}
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.battery_history_chart, null);
- BatteryHistoryChart chart = (BatteryHistoryChart)view.findViewById(
- R.id.battery_history_chart);
- chart.setStats(mStats, mBatteryBroadcast);
- return view;
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.battery_history_detail, container, false);
+ }
+
+ @Override
+ public void onViewCreated(View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ updateEverything();
+ }
+
+ private void updateEverything() {
+ BatteryInfo info = BatteryInfo.getBatteryInfo(getContext(), mBatteryBroadcast, mStats,
+ SystemClock.elapsedRealtime() * 1000);
+ final View view = getView();
+ info.bindHistory((UsageView) view.findViewById(R.id.battery_usage), mChargingParser,
+ mScreenOn, mGpsParser, mFlashlightParser, mCameraParser, mWifiParser, mCpuParser,
+ mPhoneParser);
+ ((TextView) view.findViewById(R.id.charge)).setText(info.batteryPercentString);
+ ((TextView) view.findViewById(R.id.estimation)).setText(info.remainingLabel);
+
+ bindData(mChargingParser, R.string.battery_stats_charging_label, R.id.charging_group);
+ bindData(mScreenOn, R.string.battery_stats_screen_on_label, R.id.screen_on_group);
+ bindData(mGpsParser, R.string.battery_stats_gps_on_label, R.id.gps_group);
+ bindData(mFlashlightParser, R.string.battery_stats_flashlight_on_label,
+ R.id.flashlight_group);
+ bindData(mCameraParser, R.string.battery_stats_camera_on_label, R.id.camera_group);
+ bindData(mWifiParser, R.string.battery_stats_wifi_running_label, R.id.wifi_group);
+ bindData(mCpuParser, R.string.battery_stats_wake_lock_label, R.id.cpu_group);
+ bindData(mPhoneParser, R.string.battery_stats_phone_signal_label, R.id.cell_network_group);
+ }
+
+ private void bindData(BatteryActiveProvider provider, int label, int groupId) {
+ View group = getView().findViewById(groupId);
+ group.setVisibility(provider.hasData() ? View.VISIBLE : View.GONE);
+ ((TextView) group.findViewById(android.R.id.title)).setText(label);
+ ((BatteryActiveView) group.findViewById(R.id.battery_active)).setProvider(provider);
}
@Override
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java b/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
index 7aafeba..ba93f98 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
@@ -44,10 +44,11 @@
public BatteryHistoryPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setLayoutResource(R.layout.battery_usage_graph);
+ setSelectable(true);
}
@Override
- protected void onClick() {
+ public void performClick() {
mHelper.storeStatsHistoryInFile(BATTERY_HISTORY_FILE);
Bundle args = new Bundle();
args.putString(BatteryHistoryDetail.EXTRA_STATS, BATTERY_HISTORY_FILE);
@@ -66,9 +67,11 @@
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
+ super.onBindViewHolder(view);
if (mBatteryInfo == null) {
return;
}
+ view.itemView.setClickable(true);
view.setDividerAllowedAbove(true);
((TextView) view.findViewById(R.id.charge)).setText(mBatteryInfo.batteryPercentString);
((TextView) view.findViewById(R.id.estimation)).setText(mBatteryInfo.remainingLabel);
diff --git a/src/com/android/settings/fuelgauge/BatteryWifiParser.java b/src/com/android/settings/fuelgauge/BatteryWifiParser.java
new file mode 100644
index 0000000..014c069
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/BatteryWifiParser.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2016 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.settings.fuelgauge;
+
+import android.os.BatteryStats;
+import android.os.BatteryStats.HistoryItem;
+
+public class BatteryWifiParser extends BatteryFlagParser {
+
+ public BatteryWifiParser(int accentColor) {
+ super(accentColor, false, 0);
+ }
+
+ @Override
+ protected boolean isSet(HistoryItem record) {
+ switch ((record.states2 & HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK)
+ >> HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT) {
+ case BatteryStats.WIFI_SUPPL_STATE_DISCONNECTED:
+ case BatteryStats.WIFI_SUPPL_STATE_DORMANT:
+ case BatteryStats.WIFI_SUPPL_STATE_INACTIVE:
+ case BatteryStats.WIFI_SUPPL_STATE_INTERFACE_DISABLED:
+ case BatteryStats.WIFI_SUPPL_STATE_INVALID:
+ case BatteryStats.WIFI_SUPPL_STATE_UNINITIALIZED:
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index a0d276f..bc44eeb 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -116,7 +116,7 @@
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (!(preference instanceof PowerGaugePreference)) {
- return false;
+ return super.onPreferenceTreeClick(preference);
}
PowerGaugePreference pgp = (PowerGaugePreference) preference;
BatteryEntry entry = pgp.getInfo();
diff --git a/src/com/android/settings/search/Ranking.java b/src/com/android/settings/search/Ranking.java
index 59f83ec..e961474 100644
--- a/src/com/android/settings/search/Ranking.java
+++ b/src/com/android/settings/search/Ranking.java
@@ -32,7 +32,7 @@
import com.android.settings.accessibility.AccessibilitySettings;
import com.android.settings.accounts.AccountSettings;
import com.android.settings.applications.AdvancedAppSettings;
-import com.android.settings.applications.ManageDefaultApps;
+import com.android.settings.applications.SpecialAccessSettings;
import com.android.settings.bluetooth.BluetoothSettings;
import com.android.settings.datausage.DataUsageMeteredSettings;
import com.android.settings.datausage.DataUsageSummary;
@@ -148,7 +148,7 @@
// Advanced app settings
sRankMap.put(AdvancedAppSettings.class.getName(), RANK_APPS);
- sRankMap.put(ManageDefaultApps.class.getName(), RANK_APPS);
+ sRankMap.put(SpecialAccessSettings.class.getName(), RANK_APPS);
// Users
sRankMap.put(UserSettings.class.getName(), RANK_USERS);
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 1d55b55..6aeb2a6 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -16,6 +16,7 @@
package com.android.settings.search;
+import android.provider.SearchIndexableResource;
import com.android.settings.DateTimeSettings;
import com.android.settings.DevelopmentSettings;
import com.android.settings.DeviceInfoSettings;
@@ -32,7 +33,7 @@
import com.android.settings.accessibility.AccessibilitySettings;
import com.android.settings.accounts.AccountSettings;
import com.android.settings.applications.AdvancedAppSettings;
-import com.android.settings.applications.ManageDefaultApps;
+import com.android.settings.applications.SpecialAccessSettings;
import com.android.settings.bluetooth.BluetoothSettings;
import com.android.settings.datausage.DataUsageMeteredSettings;
import com.android.settings.datausage.DataUsageSummary;
@@ -56,8 +57,6 @@
import com.android.settings.wifi.SavedAccessPointsWifiSettings;
import com.android.settings.wifi.WifiSettings;
-import android.provider.SearchIndexableResource;
-
import java.util.Collection;
import java.util.HashMap;
@@ -212,15 +211,15 @@
sResMap.put(AdvancedAppSettings.class.getName(),
new SearchIndexableResource(
Ranking.getRankForClassName(AdvancedAppSettings.class.getName()),
- R.xml.advanced_apps,
+ NO_DATA_RES_ID,
AdvancedAppSettings.class.getName(),
R.drawable.ic_settings_applications));
- sResMap.put(ManageDefaultApps.class.getName(),
+ sResMap.put(SpecialAccessSettings.class.getName(),
new SearchIndexableResource(
- Ranking.getRankForClassName(ManageDefaultApps.class.getName()),
- NO_DATA_RES_ID,
- ManageDefaultApps.class.getName(),
+ Ranking.getRankForClassName(SpecialAccessSettings.class.getName()),
+ R.xml.special_access,
+ SpecialAccessSettings.class.getName(),
R.drawable.ic_settings_applications));
sResMap.put(UserSettings.class.getName(),