Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security Patches :D #4

Open
wants to merge 35 commits into
base: eleven
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
58affb5
Add caller check to com.android.credentials.RESET
Jan 5, 2022
4f47540
Do not let guest user disable secure nfc
Jan 14, 2022
634ff01
Hide private DNS settings UI in Guest mode
Mar 9, 2022
4491d43
Prevent exfiltration of system files via user image settings.
Feb 25, 2022
b8937a7
[DO NOT MERGE] Verify ringtone from ringtone picker is audio
ArcWangInGoogle May 6, 2022
cef248f
Do not let guest user disable secuer nfc via SettingsSlice
May 4, 2022
2ca801a
RESTRICT AUTOMERGE Fix: policy enforcement for location wifi scanning
Jun 1, 2022
196c187
[DO NOT MERGE] Fix Settings crash when setting a null ringtone
ArcWangInGoogle May 16, 2022
7705906
[DO NOT MERGE] Fix can't change notification sound for work profile.
May 27, 2022
c1a16ca
Extract app label from component name in notification access confirma…
Apr 22, 2022
5b6f85e
Validate config activities with their rule owners
Jun 16, 2021
bf751bb
Revert "Prevent exfiltration of system files via user image settings."
Jul 27, 2022
8f834ce
Prevent exfiltration of system files via avatar picker.
Aug 26, 2022
189da23
Add FLAG_SECURE for ChooseLockPassword and Pattern
Aug 8, 2022
3f64f86
Rephrase dialog message of clear storage dialog for security concern
Oct 14, 2021
d9118be
Import translations. DO NOT MERGE ANYWHERE
Nov 4, 2021
2eca3da
Add non system overlay flag to InstallCaCertificateWarning
Nov 29, 2021
d00d678
RESTRICT AUTOMERGE Make bluetooth switch not discoverable via SliceDe…
Nov 7, 2022
901ce0a
[DO NOT MERGE] FRP bypass defense in the settings app
Jan 3, 2022
1b7e686
Add DISALLOW_APPS_CONTROL check into uninstall app for all users
Jan 4, 2023
8f9d4db
Only primary user is allowed to control secure nfc
Jul 28, 2022
6db393c
[DO NO MERGE] Enforce INTERACT_ACROSS_USERS_FULL permission for Notif…
Feb 6, 2023
e6fe218
RESTRICT AUTOMERGE Fix make Bluetooth discoverable without additional…
Oct 28, 2021
1143c0b
RESTRICT AUTOMERGE Make bluetooth not discoverable via SliceDeepLinkT…
May 10, 2022
eee68f9
Fix bypass CALL_PRIVILEGED permission in AppRestrictionsFragment
Jan 6, 2022
ee3da90
Fix LaunchAnyWhere in AppRestrictionsFragment
Apr 6, 2022
779cb71
[Settings] Move display of VPN version into summary text
Nov 18, 2021
73db739
Import translations. DO NOT MERGE ANYWHERE
Apr 28, 2022
c008af1
Convert argument to intent in AddAccountSettings.
Mar 7, 2023
9b21265
Don't show NLSes with excessively long component names
Mar 7, 2023
2df6c8e
DO NOT MERGE Don't hide approved NLSes in Settings
Jun 5, 2023
789a5d9
Settings: don't try to allow NLSes with too-long component names
Jun 15, 2023
47e900e
DO NOT MERGE: Prevent non-system IME from becoming device admin
May 19, 2023
5aca2a9
[RESTRICT AUTOMERGE] Restrict ApnEditor settings
Jul 7, 2023
afcc0a1
RESTRICT AUTOMERGE: Catch exceptions from setLockCredential()
ebiggers Jul 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Validate config activities with their rule owners
Test: RoboTests
Bug: 189332346
Bug: 235823407
Change-Id: Iee1b1caca4d6eb2729feb872c3e4954b6c16519c
Merged-In: Iee1b1caca4d6eb2729feb872c3e4954b6c16519c
(cherry picked from commit b161a3b)
Merged-In: Iee1b1caca4d6eb2729feb872c3e4954b6c16519c
Julia Reynolds authored and Meghthedev committed Jun 6, 2023
commit 5b6f85e174c97fd8d3ab25473ac49bf139d760e5
Original file line number Diff line number Diff line change
@@ -26,8 +26,11 @@
import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.os.Binder;
import android.provider.Settings;
import android.service.notification.ConditionProviderService;
import android.util.Log;
import android.util.Slog;

import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
@@ -36,6 +39,7 @@
import com.android.settingslib.core.lifecycle.Lifecycle;

import java.util.Map;
import java.util.Objects;

abstract public class AbstractZenModeAutomaticRulePreferenceController extends
AbstractZenModePreferenceController implements PreferenceControllerMixin {
@@ -92,7 +96,7 @@ public static ZenRuleInfo getRuleInfo(PackageManager pm, ComponentInfo ci) {
? ci.metaData.getString(ConditionProviderService.META_DATA_RULE_TYPE)
: ci.metaData.getString(NotificationManager.META_DATA_AUTOMATIC_RULE_TYPE);

final ComponentName configurationActivity = getSettingsActivity(null, ci);
final ComponentName configurationActivity = getSettingsActivity(pm, null, ci);
if (ruleType != null && !ruleType.trim().isEmpty() && configurationActivity != null) {
final ZenRuleInfo ri = new ZenRuleInfo();
ri.serviceComponent =
@@ -110,28 +114,44 @@ public static ZenRuleInfo getRuleInfo(PackageManager pm, ComponentInfo ci) {
return null;
}

protected static ComponentName getSettingsActivity(AutomaticZenRule rule, ComponentInfo ci) {
protected static ComponentName getSettingsActivity(PackageManager pm, AutomaticZenRule rule,
ComponentInfo ci) {
String owner = rule != null ? rule.getPackageName() : ci.packageName;
ComponentName settingsActivity = null;
// prefer config activity on the rule itself; fallback to manifest definition
if (rule != null && rule.getConfigurationActivity() != null) {
return rule.getConfigurationActivity();
}
if (ci == null) {
return null;
settingsActivity = rule.getConfigurationActivity();
} else {
if (ci == null) {
settingsActivity = null;
} else if (ci instanceof ActivityInfo) {
// new activity backed rule
settingsActivity = new ComponentName(ci.packageName, ci.name);
} else if (ci.metaData != null) {
// old service backed rule
final String configurationActivity = ci.metaData.getString(
ConditionProviderService.META_DATA_CONFIGURATION_ACTIVITY);
if (configurationActivity != null) {
settingsActivity = ComponentName.unflattenFromString(configurationActivity);
}
}
}
// new activity backed rule
if (ci instanceof ActivityInfo) {
return new ComponentName(ci.packageName, ci.name);
if (settingsActivity == null || owner == null) {
return settingsActivity;
}
// old service backed rule
if (ci.metaData != null) {
final String configurationActivity = ci.metaData.getString(
ConditionProviderService.META_DATA_CONFIGURATION_ACTIVITY);
if (configurationActivity != null) {
return ComponentName.unflattenFromString(configurationActivity);
try {
int ownerUid = pm.getPackageUid(owner, 0);
int configActivityOwnerUid = pm.getPackageUid(settingsActivity.getPackageName(), 0);
if (ownerUid == configActivityOwnerUid) {
return settingsActivity;
} else {
Log.w(TAG, "Config activity not in owner package for " + rule.getName());
return null;
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Failed to find config activity");
return null;
}

return null;
}

public class RuleNameChangeListener implements ZenRuleNameDialog.PositiveClickListener {
Original file line number Diff line number Diff line change
@@ -168,7 +168,7 @@ protected void setAttributes(AutomaticZenRule rule) {
: isEvent ? ZenModeEventRuleSettings.ACTION : "";
ComponentInfo si = mServiceListing.findService(rule.getOwner());
ComponentName settingsActivity = AbstractZenModeAutomaticRulePreferenceController.
getSettingsActivity(rule, si);
getSettingsActivity(mPm, rule, si);
mIntent = AbstractZenModeAutomaticRulePreferenceController.getRuleIntent(action,
settingsActivity, mId);
if (mIntent.resolveActivity(mPm) == null) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
* Copyright (C) 2021 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.notification.zen;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.when;

import android.app.AutomaticZenRule;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.service.notification.ConditionProviderService;
import android.service.notification.ZenPolicy;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

@RunWith(RobolectricTestRunner.class)
public class AbstractZenModeAutomaticRulePreferenceControllerTest {

@Mock
private PackageManager mPm;
private Context mContext;

@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
}

@Test
public void testGetSettingsActivity_configActivity() throws Exception {
AutomaticZenRule rule = new AutomaticZenRule("name", null,
new ComponentName(mContext.getPackageName(), "test"), Uri.EMPTY,
new ZenPolicy(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
rule.setPackageName(mContext.getPackageName());

when(mPm.getPackageUid(null, 0)).thenReturn(-1);
when(mPm.getPackageUid(mContext.getPackageName(), 0)).thenReturn(1);

ComponentName actual = AbstractZenModeAutomaticRulePreferenceController
.getSettingsActivity(mPm, rule, null);

assertThat(actual).isEqualTo(new ComponentName(mContext.getPackageName(), "test"));
}

@Test
public void testGetSettingsActivity_configActivity_wrongPackage() throws Exception {
AutomaticZenRule rule = new AutomaticZenRule("name", null,
new ComponentName("another", "test"), Uri.EMPTY,
new ZenPolicy(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
rule.setPackageName(mContext.getPackageName());

when(mPm.getPackageUid(null, 0)).thenReturn(-1);
when(mPm.getPackageUid(mContext.getPackageName(), 0)).thenReturn(1);

ComponentName actual = AbstractZenModeAutomaticRulePreferenceController
.getSettingsActivity(mPm, rule, null);

assertThat(actual).isNull();
}

@Test
public void testGetSettingsActivity_configActivity_unspecifiedOwner() throws Exception {
AutomaticZenRule rule = new AutomaticZenRule("name", null,
new ComponentName("another", "test"), Uri.EMPTY,
new ZenPolicy(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);

when(mPm.getPackageUid(null, 0)).thenReturn(-1);
when(mPm.getPackageUid(mContext.getPackageName(), 0)).thenReturn(1);

ComponentName actual = AbstractZenModeAutomaticRulePreferenceController
.getSettingsActivity(mPm, rule, null);

assertThat(actual).isEqualTo(new ComponentName("another", "test"));
}

@Test
public void testGetSettingsActivity_cps() throws Exception {
AutomaticZenRule rule = new AutomaticZenRule("name",
new ComponentName(mContext.getPackageName(), "service"), null, Uri.EMPTY,
new ZenPolicy(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
rule.setPackageName(mContext.getPackageName());

ComponentInfo ci = new ComponentInfo();
ci.packageName = mContext.getPackageName();
ci.metaData = new Bundle();
ci.metaData.putString(ConditionProviderService.META_DATA_CONFIGURATION_ACTIVITY,
ComponentName.flattenToShortString(
new ComponentName(mContext.getPackageName(), "activity")));

when(mPm.getPackageUid(null, 0)).thenReturn(-1);
when(mPm.getPackageUid(mContext.getPackageName(), 0)).thenReturn(1);

ComponentName actual = AbstractZenModeAutomaticRulePreferenceController
.getSettingsActivity(mPm, rule, ci);

assertThat(actual).isEqualTo(new ComponentName(mContext.getPackageName(), "activity"));
}

@Test
public void testGetSettingsActivity_cps_wrongPackage() throws Exception {
AutomaticZenRule rule = new AutomaticZenRule("name",
new ComponentName(mContext.getPackageName(), "service"), null, Uri.EMPTY,
new ZenPolicy(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
rule.setPackageName("other");

ComponentInfo ci = new ComponentInfo();
ci.packageName = mContext.getPackageName();
ci.metaData = new Bundle();
ci.metaData.putString(ConditionProviderService.META_DATA_CONFIGURATION_ACTIVITY,
ComponentName.flattenToShortString(
new ComponentName(mContext.getPackageName(), "activity")));

when(mPm.getPackageUid(null, 0)).thenReturn(-1);
when(mPm.getPackageUid(mContext.getPackageName(), 0)).thenReturn(1);

ComponentName actual = AbstractZenModeAutomaticRulePreferenceController
.getSettingsActivity(mPm, rule, ci);

assertThat(actual).isNull();
}

@Test
public void testGetSettingsActivity_cps_unspecifiedPackage() throws Exception {
AutomaticZenRule rule = new AutomaticZenRule("name",
new ComponentName(mContext.getPackageName(), "service"), null, Uri.EMPTY,
new ZenPolicy(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);

ComponentInfo ci = new ComponentInfo();
ci.packageName = mContext.getPackageName();
ci.metaData = new Bundle();
ci.metaData.putString(ConditionProviderService.META_DATA_CONFIGURATION_ACTIVITY,
ComponentName.flattenToShortString(
new ComponentName(mContext.getPackageName(), "activity")));

when(mPm.getPackageUid(null, 0)).thenReturn(-1);
when(mPm.getPackageUid(mContext.getPackageName(), 0)).thenReturn(1);

ComponentName actual = AbstractZenModeAutomaticRulePreferenceController
.getSettingsActivity(mPm, rule, ci);

assertThat(actual).isEqualTo(new ComponentName(mContext.getPackageName(), "activity"));
}
}