Apply restricted settings to notification access.

Bug: 202130031
Test: Able to boot without error
Test: When app is installed by PackageInstaller app, notification
access is being restricted. The restriction is being removed after
turing it restricted settings off for that app.

Change-Id: I9c1fbc80dd2ca4cc483a60dfa9d043aaa99cde87
This commit is contained in:
Ricky Wai
2022-02-09 15:32:57 +00:00
parent bf576a628c
commit a137158f2c
4 changed files with 54 additions and 6 deletions

View File

@@ -27,10 +27,10 @@ import android.os.AsyncTask;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.RestrictedSwitchPreference;
public class ApprovalPreferenceController extends BasePreferenceController {
@@ -78,9 +78,11 @@ public class ApprovalPreferenceController extends BasePreferenceController {
@Override
public void updateState(Preference pref) {
final SwitchPreference preference = (SwitchPreference) pref;
final RestrictedSwitchPreference preference =
(RestrictedSwitchPreference) pref;
final CharSequence label = mPkgInfo.applicationInfo.loadLabel(mPm);
preference.setChecked(isServiceEnabled(mCn));
final boolean isEnabled = isServiceEnabled(mCn);
preference.setChecked(isEnabled);
preference.setOnPreferenceChangeListener((p, newValue) -> {
final boolean access = (Boolean) newValue;
if (!access) {
@@ -103,6 +105,7 @@ public class ApprovalPreferenceController extends BasePreferenceController {
return false;
}
});
preference.updateState(mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isEnabled);
}
public void disable(final ComponentName cn) {