Skip to content

Commit

Permalink
Merge tag 'android-13.0.0_r82' into thirteen
Browse files Browse the repository at this point in the history
Android 13.0.0 release 82

# -----BEGIN PGP SIGNATURE-----
#
# iF0EABECAB0WIQRDQNE1cO+UXoOBCWTorT+BmrEOeAUCZQiT6wAKCRDorT+BmrEO
# eGpGAJwNesNh/7GMAONbmY7tcneHGWDCYACfeoh+GL2ZLoQFJr/wnY9IsryUVBI=
# =mF4Z
# -----END PGP SIGNATURE-----
# gpg: Signature made Mon 18 Sep 2023 08:16:11 PM CEST
# gpg:                using DSA key 4340D13570EF945E83810964E8AD3F819AB10E78
# gpg: Can't check signature: No public key

* tag 'android-13.0.0_r82' of https://android.googlesource.com/platform/packages/apps/Settings:
  DO NOT MERGE: Prevent non-system IME from becoming device admin
  Settings: don't try to allow NLSes with too-long component names
  Don't hide approved NLSes in Settings
Change-Id: I452837c675fa931cc22041e008b9628899aef037
  • Loading branch information
whyredfire committed Sep 18, 2023
2 parents b8f997e + bfb2482 commit 98d2143
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 75 deletions.
Expand Up @@ -66,6 +66,7 @@
import android.util.EventLog;
import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -156,12 +157,12 @@ protected void onCreate(Bundle icicle) {

mHandler = new Handler(getMainLooper());

mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mAppOps = (AppOpsManager)getSystemService(Context.APP_OPS_SERVICE);
mDPM = getSystemService(DevicePolicyManager.class);
mAppOps = getSystemService(AppOpsManager.class);
mLayoutInflaternflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
PackageManager packageManager = getPackageManager();

if ((getIntent().getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
Log.w(TAG, "Cannot start ADD_DEVICE_ADMIN as a new task");
finish();
return;
Expand All @@ -171,7 +172,7 @@ protected void onCreate(Bundle icicle) {
EXTRA_CALLED_FROM_SUPPORT_DIALOG, false);

String action = getIntent().getAction();
ComponentName who = (ComponentName)getIntent().getParcelableExtra(
ComponentName who = (ComponentName) getIntent().getParcelableExtra(
DevicePolicyManager.EXTRA_DEVICE_ADMIN);
if (who == null) {
String packageName = getIntent().getStringExtra(EXTRA_DEVICE_ADMIN_PACKAGE_NAME);
Expand Down Expand Up @@ -229,7 +230,7 @@ protected void onCreate(Bundle icicle) {
PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS);
int count = avail == null ? 0 : avail.size();
boolean found = false;
for (int i=0; i<count; i++) {
for (int i = 0; i < count; i++) {
ResolveInfo ri = avail.get(i);
if (ai.packageName.equals(ri.activityInfo.packageName)
&& ai.name.equals(ri.activityInfo.name)) {
Expand Down Expand Up @@ -345,22 +346,22 @@ public void onDismiss(DialogInterface dialogInterface) {
mAdminWarning = dialog.findViewById(R.id.admin_warning_simplified);
mAdminWarning.setText(
mDPM.getResources().getString(NEW_DEVICE_ADMIN_WARNING_SIMPLIFIED, () ->
getString(R.string.device_admin_warning_simplified,
mProfileOwnerName), mProfileOwnerName));
getString(R.string.device_admin_warning_simplified,
mProfileOwnerName), mProfileOwnerName));
return;
}
setContentView(R.layout.device_admin_add);

mAdminIcon = (ImageView)findViewById(R.id.admin_icon);
mAdminName = (TextView)findViewById(R.id.admin_name);
mAdminDescription = (TextView)findViewById(R.id.admin_description);
mAdminIcon = (ImageView) findViewById(R.id.admin_icon);
mAdminName = (TextView) findViewById(R.id.admin_name);
mAdminDescription = (TextView) findViewById(R.id.admin_description);
mProfileOwnerWarning = (TextView) findViewById(R.id.profile_owner_warning);

mProfileOwnerWarning.setText(
mDPM.getResources().getString(SET_PROFILE_OWNER_POSTSETUP_WARNING,
() -> getString(R.string.adding_profile_owner_warning)));

mAddMsg = (TextView)findViewById(R.id.add_msg);
mAddMsg = (TextView) findViewById(R.id.add_msg);
mAddMsgExpander = (ImageView) findViewById(R.id.add_msg_expander);
final View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
Expand All @@ -381,7 +382,7 @@ public void onGlobalLayout() {
boolean hideMsgExpander = mAddMsg.getLineCount() <= maxLines;
mAddMsgExpander.setVisibility(hideMsgExpander ? View.GONE : View.VISIBLE);
if (hideMsgExpander) {
((View)mAddMsgExpander.getParent()).invalidate();
((View) mAddMsgExpander.getParent()).invalidate();
}
mAddMsg.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
Expand All @@ -399,7 +400,7 @@ public void onGlobalLayout() {
mCancelButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EventLog.writeEvent(EventLogTags.EXP_DET_DEVICE_ADMIN_DECLINED_BY_USER,
mDeviceAdmin.getActivityInfo().applicationInfo.uid);
mDeviceAdmin.getActivityInfo().applicationInfo.uid);
finish();
}
});
Expand All @@ -421,58 +422,64 @@ public void onClick(View v) {

final View restrictedAction = findViewById(R.id.restricted_action);
restrictedAction.setFilterTouchesWhenObscured(true);
restrictedAction.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (!mActionButton.isEnabled()) {
showPolicyTransparencyDialogIfRequired();
return;
}
if (mAdding) {
addAndFinish();
} else if (isManagedProfile(mDeviceAdmin)
&& mDeviceAdmin.getComponent().equals(mDPM.getProfileOwner())) {
final int userId = UserHandle.myUserId();
UserDialogs.createRemoveDialog(DeviceAdminAdd.this, userId,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
UserManager um = UserManager.get(DeviceAdminAdd.this);
um.removeUser(userId);
finish();
}

final View.OnClickListener restrictedActionClickListener = v -> {
if (!mActionButton.isEnabled()) {
showPolicyTransparencyDialogIfRequired();
return;
}
if (mAdding) {
addAndFinish();
} else if (isManagedProfile(mDeviceAdmin)
&& mDeviceAdmin.getComponent().equals(mDPM.getProfileOwner())) {
final int userId = UserHandle.myUserId();
UserDialogs.createRemoveDialog(DeviceAdminAdd.this, userId,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
UserManager um = UserManager.get(DeviceAdminAdd.this);
um.removeUser(userId);
finish();
}
).show();
} else if (mUninstalling) {
mDPM.uninstallPackageWithActiveAdmins(mDeviceAdmin.getPackageName());
finish();
} else if (!mWaitingForRemoveMsg) {
try {
// Don't allow the admin to put a dialog up in front
// of us while we interact with the user.
ActivityManager.getService().stopAppSwitches();
} catch (RemoteException e) {
}
mWaitingForRemoveMsg = true;
mDPM.getRemoveWarning(mDeviceAdmin.getComponent(),
new RemoteCallback(new RemoteCallback.OnResultListener() {
@Override
public void onResult(Bundle result) {
CharSequence msg = result != null
? result.getCharSequence(
DeviceAdminReceiver.EXTRA_DISABLE_WARNING)
: null;
continueRemoveAction(msg);
}
}, mHandler));
// Don't want to wait too long.
getWindow().getDecorView().getHandler().postDelayed(new Runnable() {
@Override public void run() {
continueRemoveAction(null);
}
}, 2*1000);
).show();
} else if (mUninstalling) {
mDPM.uninstallPackageWithActiveAdmins(mDeviceAdmin.getPackageName());
finish();
} else if (!mWaitingForRemoveMsg) {
try {
// Don't allow the admin to put a dialog up in front
// of us while we interact with the user.
ActivityManager.getService().stopAppSwitches();
} catch (RemoteException e) {
}
mWaitingForRemoveMsg = true;
mDPM.getRemoveWarning(mDeviceAdmin.getComponent(),
new RemoteCallback(new RemoteCallback.OnResultListener() {
@Override
public void onResult(Bundle result) {
CharSequence msg = result != null
? result.getCharSequence(
DeviceAdminReceiver.EXTRA_DISABLE_WARNING)
: null;
continueRemoveAction(msg);
}
}, mHandler));
// Don't want to wait too long.
getWindow().getDecorView().getHandler().postDelayed(
() -> continueRemoveAction(null), 2 * 1000);
}
};
restrictedAction.setOnKeyListener((view, keyCode, keyEvent) -> {
if ((keyEvent.getFlags() & KeyEvent.FLAG_FROM_SYSTEM) == 0) {
Log.e(TAG, "Can not activate device-admin with KeyEvent from non-system app.");
// Consume event to suppress click.
return true;
}
// Fallback to view click handler.
return false;
});
restrictedAction.setOnClickListener(restrictedActionClickListener);
}

/**
Expand Down
Expand Up @@ -81,6 +81,8 @@ public void updateState(Preference pref) {
final RestrictedSwitchPreference preference =
(RestrictedSwitchPreference) pref;
final CharSequence label = mPkgInfo.applicationInfo.loadLabel(mPm);
final boolean isAllowedCn = mCn.flattenToShortString().length()
<= NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH;
final boolean isEnabled = isServiceEnabled(mCn);
preference.setChecked(isEnabled);
preference.setOnPreferenceChangeListener((p, newValue) -> {
Expand All @@ -105,7 +107,8 @@ public void updateState(Preference pref) {
return false;
}
});
preference.updateState(mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isEnabled);
preference.updateState(
mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isAllowedCn, isEnabled);
}

public void disable(final ComponentName cn) {
Expand Down
Expand Up @@ -67,7 +67,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL);
CharSequence mAppLabel;

if (mComponentName == null || mComponentName.getPackageName() == null) {
if (mComponentName == null || mComponentName.getPackageName() == null
|| mComponentName.flattenToString().length()
> NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) {
finish();
return;
}
Expand Down
Expand Up @@ -43,6 +43,7 @@
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.applications.AppInfoBase;
Expand All @@ -63,9 +64,8 @@
@SearchIndexable
public class NotificationAccessSettings extends EmptyTextSettings {
private static final String TAG = "NotifAccessSettings";
private static final String ALLOWED_KEY = "allowed";
private static final String NOT_ALLOWED_KEY = "not_allowed";
private static final int MAX_CN_LENGTH = 500;
static final String ALLOWED_KEY = "allowed";
static final String NOT_ALLOWED_KEY = "not_allowed";

private static final ManagedServiceSettings.Config CONFIG =
new ManagedServiceSettings.Config.Builder()
Expand All @@ -80,9 +80,9 @@ public class NotificationAccessSettings extends EmptyTextSettings {
.setEmptyText(R.string.no_notification_listeners)
.build();

private NotificationManager mNm;
@VisibleForTesting NotificationManager mNm;
protected Context mContext;
private PackageManager mPm;
@VisibleForTesting PackageManager mPm;
private DevicePolicyManager mDpm;
private ServiceListing mServiceListing;
private IconDrawableFactory mIconDrawableFactory;
Expand All @@ -102,12 +102,6 @@ public void onCreate(Bundle icicle) {
.setNoun(CONFIG.noun)
.setSetting(CONFIG.setting)
.setTag(CONFIG.tag)
.setValidator(info -> {
if (info.getComponentName().flattenToString().length() > MAX_CN_LENGTH) {
return false;
}
return true;
})
.build();
mServiceListing.addCallback(this::updateList);

Expand Down Expand Up @@ -140,7 +134,8 @@ public void onPause() {
mServiceListing.setListening(false);
}

private void updateList(List<ServiceInfo> services) {
@VisibleForTesting
void updateList(List<ServiceInfo> services) {
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
final int managedProfileId = Utils.getManagedProfileId(um, UserHandle.myUserId());

Expand All @@ -153,6 +148,12 @@ private void updateList(List<ServiceInfo> services) {
services.sort(new PackageItemInfo.DisplayNameComparator(mPm));
for (ServiceInfo service : services) {
final ComponentName cn = new ComponentName(service.packageName, service.name);
boolean isAllowed = mNm.isNotificationListenerAccessGranted(cn);
if (!isAllowed && cn.flattenToString().length()
> NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) {
continue;
}

CharSequence title = null;
try {
title = mPm.getApplicationInfoAsUser(
Expand Down Expand Up @@ -200,7 +201,7 @@ private void updateList(List<ServiceInfo> services) {
return true;
});
pref.setKey(cn.flattenToString());
if (mNm.isNotificationListenerAccessGranted(cn)) {
if (isAllowed) {
allowedCategory.addPreference(pref);
} else {
notAllowedCategory.addPreference(pref);
Expand Down
Expand Up @@ -134,6 +134,9 @@ void recordCanBeBlocked(PackageInfo app, AppRow row) {

static public CharSequence getDeviceList(ICompanionDeviceManager cdm, LocalBluetoothManager lbm,
String pkg, int userId) {
if (cdm == null) {
return "";
}
boolean multiple = false;
StringBuilder sb = new StringBuilder();

Expand Down

0 comments on commit 98d2143

Please sign in to comment.