Merge "Fix crash on rotation" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
3bdd65e255
@@ -2743,6 +2743,7 @@
|
|||||||
|
|
||||||
<!-- Show channel-level notification settings (channel passed in as extras) -->
|
<!-- Show channel-level notification settings (channel passed in as extras) -->
|
||||||
<activity android:name="Settings$ChannelNotificationSettingsActivity"
|
<activity android:name="Settings$ChannelNotificationSettingsActivity"
|
||||||
|
android:label="@string/notification_channel_title"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter android:priority="1">
|
<intent-filter android:priority="1">
|
||||||
<action android:name="android.settings.CHANNEL_NOTIFICATION_SETTINGS" />
|
<action android:name="android.settings.CHANNEL_NOTIFICATION_SETTINGS" />
|
||||||
|
@@ -31,15 +31,32 @@
|
|||||||
|
|
||||||
<!-- Channels/Channel groups added here -->
|
<!-- Channels/Channel groups added here -->
|
||||||
|
|
||||||
|
<!-- Importance toggle -->
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="allow_sound"
|
||||||
|
android:title="@string/allow_interruption"
|
||||||
|
android:summary="@string/allow_interruption_summary" />
|
||||||
|
|
||||||
|
<!-- Visibility Override -->
|
||||||
|
<com.android.settings.RestrictedListPreference
|
||||||
|
android:key="visibility_override"
|
||||||
|
android:title="@string/app_notification_visibility_override_title"/>
|
||||||
|
|
||||||
<!-- Show badge -->
|
<!-- Show badge -->
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
android:key="badge"
|
android:key="badge"
|
||||||
android:title="@string/notification_badge_title"
|
android:title="@string/notification_badge_title"
|
||||||
android:order="501"
|
android:order="501"
|
||||||
settings:useAdditionalSummary="true"
|
settings:useAdditionalSummary="true"
|
||||||
settings:allowDividerAbove="true"
|
|
||||||
settings:restrictedSwitchSummary="@string/enabled_by_admin" />
|
settings:restrictedSwitchSummary="@string/enabled_by_admin" />
|
||||||
|
|
||||||
|
<!-- Bypass DND -->
|
||||||
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
android:key="bypass_dnd"
|
||||||
|
android:title="@string/app_notification_override_dnd_title"
|
||||||
|
android:summary="@string/app_notification_override_dnd_summary"
|
||||||
|
settings:useAdditionalSummary="true"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="app_link"
|
android:key="app_link"
|
||||||
android:title="@string/app_settings_link"
|
android:title="@string/app_settings_link"
|
||||||
|
@@ -14,9 +14,12 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen
|
||||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
settings:initialExpandedChildrenCount="3">
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:key="channel_settings"
|
||||||
|
android:title="@string/notification_channel_title"
|
||||||
|
settings:initialExpandedChildrenCount="3" >
|
||||||
|
|
||||||
<com.android.settings.applications.LayoutPreference
|
<com.android.settings.applications.LayoutPreference
|
||||||
android:key="pref_app_header"
|
android:key="pref_app_header"
|
||||||
|
@@ -68,10 +68,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
mDynamicPreferences.clear();
|
mDynamicPreferences.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mShowLegacyChannelConfig) {
|
if (!mShowLegacyChannelConfig) {
|
||||||
addPreferencesFromResource(R.xml.channel_notification_settings);
|
|
||||||
} else {
|
|
||||||
addPreferencesFromResource(R.xml.app_notification_settings);
|
|
||||||
// Load channel settings
|
// Load channel settings
|
||||||
new AsyncTask<Void, Void, Void>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -106,7 +103,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getPreferenceScreenResId() {
|
protected int getPreferenceScreenResId() {
|
||||||
return R.xml.notification_settings;
|
return R.xml.app_notification_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -18,6 +18,8 @@ package com.android.settings.notification;
|
|||||||
|
|
||||||
import static com.android.settings.widget.EntityHeaderController.PREF_KEY_APP_HEADER;
|
import static com.android.settings.widget.EntityHeaderController.PREF_KEY_APP_HEADER;
|
||||||
|
|
||||||
|
import android.arch.lifecycle.LifecycleObserver;
|
||||||
|
import android.arch.lifecycle.OnLifecycleEvent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v14.preference.PreferenceFragment;
|
import android.support.v14.preference.PreferenceFragment;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
@@ -30,13 +32,16 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.applications.LayoutPreference;
|
import com.android.settings.applications.LayoutPreference;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settings.widget.EntityHeaderController;
|
import com.android.settings.widget.EntityHeaderController;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class HeaderPreferenceController extends NotificationPreferenceController
|
public class HeaderPreferenceController extends NotificationPreferenceController
|
||||||
implements PreferenceControllerMixin {
|
implements PreferenceControllerMixin, LifecycleObserver {
|
||||||
|
|
||||||
private final PreferenceFragment mFragment;
|
private final PreferenceFragment mFragment;
|
||||||
|
private EntityHeaderController mHeaderController;
|
||||||
|
|
||||||
public HeaderPreferenceController(Context context, PreferenceFragment fragment) {
|
public HeaderPreferenceController(Context context, PreferenceFragment fragment) {
|
||||||
super(context, null);
|
super(context, null);
|
||||||
@@ -57,10 +62,9 @@ public class HeaderPreferenceController extends NotificationPreferenceController
|
|||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow != null && mFragment != null) {
|
if (mAppRow != null && mFragment != null) {
|
||||||
LayoutPreference pref = (LayoutPreference) preference;
|
LayoutPreference pref = (LayoutPreference) preference;
|
||||||
EntityHeaderController controller = EntityHeaderController
|
mHeaderController = EntityHeaderController.newInstance(
|
||||||
.newInstance(mFragment.getActivity(), mFragment,
|
mFragment.getActivity(), mFragment, pref.findViewById(R.id.entity_header));
|
||||||
pref.findViewById(R.id.entity_header));
|
pref = mHeaderController.setIcon(mAppRow.icon)
|
||||||
pref = controller.setIcon(mAppRow.icon)
|
|
||||||
.setLabel(getLabel())
|
.setLabel(getLabel())
|
||||||
.setSummary(getSummary())
|
.setSummary(getSummary())
|
||||||
.setPackageName(mAppRow.pkg)
|
.setPackageName(mAppRow.pkg)
|
||||||
@@ -68,7 +72,7 @@ public class HeaderPreferenceController extends NotificationPreferenceController
|
|||||||
.setButtonActions(EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE,
|
.setButtonActions(EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE,
|
||||||
EntityHeaderController.ActionType.ACTION_NONE)
|
EntityHeaderController.ActionType.ACTION_NONE)
|
||||||
.setHasAppInfoLink(true)
|
.setHasAppInfoLink(true)
|
||||||
.done(mFragment.getActivity(), mContext);
|
.done(null, mContext);
|
||||||
pref.findViewById(R.id.entity_header).setVisibility(View.VISIBLE);
|
pref.findViewById(R.id.entity_header).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,4 +105,11 @@ public class HeaderPreferenceController extends NotificationPreferenceController
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
|
public void onStart() {
|
||||||
|
if (mHeaderController != null) {
|
||||||
|
mHeaderController.styleActionBar(mFragment.getActivity());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -96,7 +96,7 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
|
|||||||
if (preference != null) {
|
if (preference != null) {
|
||||||
mPreference = preference;
|
mPreference = preference;
|
||||||
}
|
}
|
||||||
if (this instanceof Preference.OnPreferenceChangeListener) {
|
if (mPreference != null && this instanceof Preference.OnPreferenceChangeListener) {
|
||||||
mPreference.setOnPreferenceChangeListener(
|
mPreference.setOnPreferenceChangeListener(
|
||||||
(Preference.OnPreferenceChangeListener) this);
|
(Preference.OnPreferenceChangeListener) this);
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,7 @@ import static android.app.NotificationManager.IMPORTANCE_LOW;
|
|||||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationChannelGroup;
|
import android.app.NotificationChannelGroup;
|
||||||
@@ -81,28 +82,25 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
|||||||
protected List<Preference> mDynamicPreferences = new ArrayList<>();
|
protected List<Preference> mDynamicPreferences = new ArrayList<>();
|
||||||
protected ImportanceListener mImportanceListener = new ImportanceListener();
|
protected ImportanceListener mImportanceListener = new ImportanceListener();
|
||||||
|
|
||||||
|
protected Intent mIntent;
|
||||||
|
protected Bundle mArgs;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onAttach(Context context) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onAttach(context);
|
||||||
mContext = getActivity();
|
mContext = getActivity();
|
||||||
Intent intent = getActivity().getIntent();
|
mIntent = getActivity().getIntent();
|
||||||
Bundle args = getArguments();
|
mArgs = getArguments();
|
||||||
if (DEBUG) Log.d(TAG, "onCreate getIntent()=" + intent);
|
|
||||||
if (intent == null && args == null) {
|
|
||||||
Log.w(TAG, "No intent");
|
|
||||||
toastAndFinish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mPm = getPackageManager();
|
mPm = getPackageManager();
|
||||||
mNm = NotificationManager.from(mContext);
|
mNm = NotificationManager.from(mContext);
|
||||||
|
|
||||||
mPkg = args != null && args.containsKey(AppInfoBase.ARG_PACKAGE_NAME)
|
mPkg = mArgs != null && mArgs.containsKey(AppInfoBase.ARG_PACKAGE_NAME)
|
||||||
? args.getString(AppInfoBase.ARG_PACKAGE_NAME)
|
? mArgs.getString(AppInfoBase.ARG_PACKAGE_NAME)
|
||||||
: intent.getStringExtra(Settings.EXTRA_APP_PACKAGE);
|
: mIntent.getStringExtra(Settings.EXTRA_APP_PACKAGE);
|
||||||
mUid = args != null && args.containsKey(AppInfoBase.ARG_PACKAGE_UID)
|
mUid = mArgs != null && mArgs.containsKey(AppInfoBase.ARG_PACKAGE_UID)
|
||||||
? args.getInt(AppInfoBase.ARG_PACKAGE_UID)
|
? mArgs.getInt(AppInfoBase.ARG_PACKAGE_UID)
|
||||||
: intent.getIntExtra(Settings.EXTRA_APP_UID, -1);
|
: mIntent.getIntExtra(Settings.EXTRA_APP_UID, -1);
|
||||||
|
|
||||||
if (mUid < 0) {
|
if (mUid < 0) {
|
||||||
try {
|
try {
|
||||||
@@ -113,13 +111,38 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
|||||||
|
|
||||||
mPkgInfo = findPackageInfo(mPkg, mUid);
|
mPkgInfo = findPackageInfo(mPkg, mUid);
|
||||||
|
|
||||||
|
mUserId = UserHandle.getUserId(mUid);
|
||||||
|
mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
|
||||||
|
mContext, mPkg, mUserId);
|
||||||
|
|
||||||
|
loadChannel();
|
||||||
|
loadAppRow();
|
||||||
|
loadChannelGroup();
|
||||||
|
collectConfigActivities();
|
||||||
|
|
||||||
|
getLifecycle().addObserver(use(HeaderPreferenceController.class));
|
||||||
|
|
||||||
|
for (NotificationPreferenceController controller : mControllers) {
|
||||||
|
controller.onResume(mAppRow, mChannel, mChannelGroup, mSuspendedAppsAdmin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
if (mIntent == null && mArgs == null) {
|
||||||
|
Log.w(TAG, "No intent");
|
||||||
|
toastAndFinish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
|
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
|
||||||
Log.w(TAG, "Missing package or uid or packageinfo");
|
Log.w(TAG, "Missing package or uid or packageinfo");
|
||||||
toastAndFinish();
|
toastAndFinish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mUserId = UserHandle.getUserId(mUid);
|
|
||||||
startListeningToPackageRemove();
|
startListeningToPackageRemove();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,18 +155,26 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
|
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mAppRow == null) {
|
||||||
Log.w(TAG, "Missing package or uid or packageinfo");
|
Log.w(TAG, "Missing package or uid or packageinfo");
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mAppRow = mBackend.loadAppRow(mContext, mPm, mPkgInfo);
|
// Reload app, channel, etc onResume in case they've changed. A little wasteful if we've
|
||||||
|
// just done onAttach but better than making every preference controller reload all
|
||||||
|
// the data
|
||||||
|
loadAppRow();
|
||||||
if (mAppRow == null) {
|
if (mAppRow == null) {
|
||||||
Log.w(TAG, "Can't load package");
|
Log.w(TAG, "Can't load package");
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
loadChannel();
|
||||||
|
loadChannelGroup();
|
||||||
collectConfigActivities();
|
collectConfigActivities();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadChannel() {
|
||||||
Intent intent = getActivity().getIntent();
|
Intent intent = getActivity().getIntent();
|
||||||
String channelId = intent != null ? intent.getStringExtra(Settings.EXTRA_CHANNEL_ID) : null;
|
String channelId = intent != null ? intent.getStringExtra(Settings.EXTRA_CHANNEL_ID) : null;
|
||||||
if (channelId == null && intent != null) {
|
if (channelId == null && intent != null) {
|
||||||
@@ -151,12 +182,13 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
|||||||
channelId = args != null ? args.getString(Settings.EXTRA_CHANNEL_ID) : null;
|
channelId = args != null ? args.getString(Settings.EXTRA_CHANNEL_ID) : null;
|
||||||
}
|
}
|
||||||
mChannel = mBackend.getChannel(mPkg, mUid, channelId);
|
mChannel = mBackend.getChannel(mPkg, mUid, channelId);
|
||||||
|
}
|
||||||
|
|
||||||
NotificationChannelGroup group = null;
|
private void loadAppRow() {
|
||||||
|
mAppRow = mBackend.loadAppRow(mContext, mPm, mPkgInfo);
|
||||||
mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
|
}
|
||||||
mContext, mPkg, mUserId);
|
|
||||||
|
|
||||||
|
private void loadChannelGroup() {
|
||||||
mShowLegacyChannelConfig = mBackend.onlyHasDefaultChannel(mAppRow.pkg, mAppRow.uid)
|
mShowLegacyChannelConfig = mBackend.onlyHasDefaultChannel(mAppRow.pkg, mAppRow.uid)
|
||||||
|| (mChannel != null
|
|| (mChannel != null
|
||||||
&& NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId()));
|
&& NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId()));
|
||||||
@@ -166,7 +198,7 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
|||||||
mAppRow.pkg, mAppRow.uid, NotificationChannel.DEFAULT_CHANNEL_ID);
|
mAppRow.pkg, mAppRow.uid, NotificationChannel.DEFAULT_CHANNEL_ID);
|
||||||
}
|
}
|
||||||
if (mChannel != null && !TextUtils.isEmpty(mChannel.getGroup())) {
|
if (mChannel != null && !TextUtils.isEmpty(mChannel.getGroup())) {
|
||||||
group = mBackend.getGroup(mPkg, mUid, mChannel.getGroup());
|
NotificationChannelGroup group = mBackend.getGroup(mPkg, mUid, mChannel.getGroup());
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
mChannelGroup = group;
|
mChannelGroup = group;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user