NAS Setting Migration
Change NAS setting to a toggle setting and move the settings to Notifications/General Bug: 173106358 Test: tested manually on device, make RunSettingsRoboTests Change-Id: I1ba1214511dceea6faf5fb39692d920e761b33d8
This commit is contained in:
@@ -18,44 +18,72 @@ package com.android.settings.notification;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
import com.android.settingslib.widget.CandidateInfo;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
public class NotificationAssistantPreferenceController extends BasePreferenceController {
|
||||
public class NotificationAssistantPreferenceController extends TogglePreferenceController {
|
||||
private static final String TAG = "NASPreferenceController";
|
||||
private static final int AVAILABLE = 1;
|
||||
private Fragment mFragment;
|
||||
private int mUserId = UserHandle.myUserId();
|
||||
|
||||
@VisibleForTesting
|
||||
protected NotificationBackend mNotificationBackend;
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
public NotificationAssistantPreferenceController(Context context, String preferenceKey) {
|
||||
public NotificationAssistantPreferenceController(Context context, NotificationBackend backend,
|
||||
Fragment fragment, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mNotificationBackend = new NotificationBackend();
|
||||
mPackageManager = mContext.getPackageManager();
|
||||
mNotificationBackend = backend;
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return BasePreferenceController.AVAILABLE;
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
CandidateInfo appSelected = new NotificationAssistantPicker.CandidateNone(mContext);
|
||||
ComponentName assistant = mNotificationBackend.getAllowedNotificationAssistant();
|
||||
if (assistant != null) {
|
||||
appSelected = createCandidateInfo(assistant);
|
||||
}
|
||||
return appSelected.loadLabel();
|
||||
public boolean isChecked() {
|
||||
ComponentName acn = mNotificationBackend.getAllowedNotificationAssistant();
|
||||
ComponentName dcn = mNotificationBackend.getDefaultNotificationAssistant();
|
||||
return (acn != null && acn.equals(dcn));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected CandidateInfo createCandidateInfo(ComponentName cn) {
|
||||
return new DefaultAppInfo(mContext, mPackageManager, UserHandle.myUserId(), cn);
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
ComponentName cn = isChecked
|
||||
? mNotificationBackend.getDefaultNotificationAssistant() : null;
|
||||
if (isChecked) {
|
||||
if (mFragment == null) {
|
||||
throw new IllegalStateException("No fragment to start activity");
|
||||
}
|
||||
showDialog(cn);
|
||||
return false;
|
||||
} else {
|
||||
setNotificationAssistantGranted(null);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void setNotificationAssistantGranted(ComponentName cn) {
|
||||
if (Settings.Secure.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.NAS_SETTINGS_UPDATED, 0, mUserId) == 0) {
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.NAS_SETTINGS_UPDATED, 1, mUserId);
|
||||
mNotificationBackend.resetDefaultNotificationAssistant(cn != null);
|
||||
}
|
||||
mNotificationBackend.setNotificationAssistantGranted(cn);
|
||||
}
|
||||
|
||||
protected void showDialog(ComponentName cn) {
|
||||
NotificationAssistantDialogFragment dialogFragment =
|
||||
NotificationAssistantDialogFragment.newInstance(mFragment, cn);
|
||||
dialogFragment.show(mFragment.getFragmentManager(), TAG);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user