Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7b1c6cda authored by Matt Pape's avatar Matt Pape
Browse files

Update DeviceConfigService to pass Settings.AUTHORITY to IContentProvider.call invocations.

Also update SettingsProvider to resolve calling packages based on uids
when receiving calls to put or reset values in the config table. This
was necessary because the command line tool calls the DeviceConfig API,
which calls through to SettingsProvider. That was resulting in a
shell uid with an android package prior to this change.

Test: atest SettingsProviderTest:DeviceConfigServiceTest
Bug: 122304633

Change-Id: Ic80c734eb75dcaac688507c241b0995b7488a84f
parent 12278ded
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -14070,11 +14070,10 @@ public final class Settings {
            try {
                Bundle arg = new Bundle();
                arg.putInt(CALL_METHOD_USER_KEY, resolver.getUserId());
                arg.putInt(Settings.CALL_METHOD_RESET_MODE_KEY, resetMode);
                arg.putInt(CALL_METHOD_RESET_MODE_KEY, resetMode);
                if (prefix != null) {
                    arg.putString(Settings.CALL_METHOD_PREFIX_KEY, prefix);
                }
                arg.putInt(CALL_METHOD_RESET_MODE_KEY, resetMode);
                IContentProvider cp = sProviderHolder.getProvider(resolver);
                cp.call(resolver.getPackageName(), sProviderHolder.mUri.getAuthority(),
                        CALL_METHOD_RESET_CONFIG, null, arg);
+2 −2
Original line number Diff line number Diff line
@@ -242,7 +242,7 @@ public final class DeviceConfigService extends Binder {
                Bundle args = new Bundle();
                args.putInt(Settings.CALL_METHOD_USER_KEY,
                        ActivityManager.getService().getCurrentUser().id);
                Bundle b = provider.call(resolveCallingPackage(),
                Bundle b = provider.call(resolveCallingPackage(), Settings.AUTHORITY,
                        Settings.CALL_METHOD_DELETE_CONFIG, compositeKey, args);
                success = (b != null && b.getInt(SettingsProvider.RESULT_ROWS_DELETED) == 1);
            } catch (RemoteException e) {
@@ -261,7 +261,7 @@ public final class DeviceConfigService extends Binder {
                if (namespace != null) {
                    args.putString(Settings.CALL_METHOD_PREFIX_KEY, namespace);
                }
                Bundle b = provider.call(resolveCallingPackage(),
                Bundle b = provider.call(resolveCallingPackage(), Settings.AUTHORITY,
                        Settings.CALL_METHOD_LIST_CONFIG, null, args);
                if (b != null) {
                    Map<String, String> flagsToValues =
+18 −2
Original line number Diff line number Diff line
@@ -1097,7 +1097,7 @@ public class SettingsProvider extends ContentProvider {
                case MUTATION_OPERATION_INSERT: {
                    return mSettingsRegistry.insertSettingLocked(SETTINGS_TYPE_CONFIG,
                            UserHandle.USER_SYSTEM, name, value, null, makeDefault, true,
                            getCallingPackage(), false, null);
                            resolveCallingPackage(), false, null);
                }

                case MUTATION_OPERATION_DELETE: {
@@ -1107,7 +1107,7 @@ public class SettingsProvider extends ContentProvider {

                case MUTATION_OPERATION_RESET: {
                    mSettingsRegistry.resetSettingsLocked(SETTINGS_TYPE_CONFIG,
                            UserHandle.USER_SYSTEM, getCallingPackage(), mode, null, prefix);
                            UserHandle.USER_SYSTEM, resolveCallingPackage(), mode, null, prefix);
                } return true;
            }
        }
@@ -2247,6 +2247,22 @@ public class SettingsProvider extends ContentProvider {
        return !(TextUtils.isEmpty(key) || SettingsState.isBinary(key));
    }

    private String resolveCallingPackage() {
        switch (Binder.getCallingUid()) {
            case Process.ROOT_UID: {
                return "root";
            }

            case Process.SHELL_UID: {
                return "com.android.shell";
            }

            default: {
                return getCallingPackage();
            }
        }
    }

    private static final class Arguments {
        private static final Pattern WHERE_PATTERN_WITH_PARAM_NO_BRACKETS =
                Pattern.compile("[\\s]*name[\\s]*=[\\s]*\\?[\\s]*");