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

Commit 50fcfe78 authored by “riyaghai”'s avatar “riyaghai”
Browse files

Refactor out PackageConfigurationUpdaterImpl

Test: Build + Manual testing

Bug: 199815981
Change-Id: I71e050f2141dda5b6de7b4510d8a5575e038771e
parent e8af7876
Loading
Loading
Loading
Loading
+2 −54
Original line number Original line Diff line number Diff line
@@ -6554,7 +6554,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {


        @Override
        @Override
        public PackageConfigurationUpdater createPackageConfigurationUpdater() {
        public PackageConfigurationUpdater createPackageConfigurationUpdater() {
            return new PackageConfigurationUpdaterImpl(Binder.getCallingPid());
            return new PackageConfigurationUpdaterImpl(Binder.getCallingPid(),
                    ActivityTaskManagerService.this);
        }
        }


        @Override
        @Override
@@ -6571,57 +6572,4 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                    null /* trigger */, mRootWindowContainer.getDefaultDisplay());
                    null /* trigger */, mRootWindowContainer.getDefaultDisplay());
        }
        }
    }
    }

    final class PackageConfigurationUpdaterImpl implements
            ActivityTaskManagerInternal.PackageConfigurationUpdater {
        private final int mPid;
        private Integer mNightMode;
        private LocaleList mLocales;

        PackageConfigurationUpdaterImpl(int pid) {
            mPid = pid;
        }

        @Override
        public ActivityTaskManagerInternal.PackageConfigurationUpdater setNightMode(int nightMode) {
            mNightMode = nightMode;
            return this;
        }

        @Override
        public ActivityTaskManagerInternal.PackageConfigurationUpdater
                setLocales(LocaleList locales) {
            mLocales = locales;
            return this;
        }

        @Override
        public void commit() {
            synchronized (mGlobalLock) {
                final long ident = Binder.clearCallingIdentity();
                try {
                    final WindowProcessController wpc = mProcessMap.getProcess(mPid);
                    if (wpc == null) {
                        Slog.w(TAG, "Override application configuration: cannot find pid " + mPid);
                        return;
                    }
                    LocaleList localesOverride = LocaleOverlayHelper.combineLocalesIfOverlayExists(
                            mLocales, getGlobalConfiguration().getLocales());
                    wpc.applyAppSpecificConfig(mNightMode, localesOverride);
                    wpc.updateAppSpecificSettingsForAllActivities(mNightMode, localesOverride);
                    mPackageConfigPersister.updateFromImpl(wpc.mName, wpc.mUserId, this);
                } finally {
                    Binder.restoreCallingIdentity(ident);
                }
            }
        }

        Integer getNightMode() {
            return mNightMode;
        }

        LocaleList getLocales() {
            return mLocales;
        }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -173,7 +173,7 @@ public class PackageConfigPersister {


    @GuardedBy("mLock")
    @GuardedBy("mLock")
    void updateFromImpl(String packageName, int userId,
    void updateFromImpl(String packageName, int userId,
            ActivityTaskManagerService.PackageConfigurationUpdaterImpl impl) {
            PackageConfigurationUpdaterImpl impl) {
        synchronized (mLock) {
        synchronized (mLock) {
            PackageConfigRecord record = findRecordOrCreate(mModified, packageName, userId);
            PackageConfigRecord record = findRecordOrCreate(mModified, packageName, userId);
            if (impl.getNightMode() != null) {
            if (impl.getNightMode() != null) {
+86 −0
Original line number Original line Diff line number Diff line
/*
 * 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.server.wm;

import android.os.Binder;
import android.os.LocaleList;
import android.util.Slog;

/**
 * An implementation of {@link ActivityTaskManagerInternal.PackageConfigurationUpdater}.
 */
final class PackageConfigurationUpdaterImpl implements
        ActivityTaskManagerInternal.PackageConfigurationUpdater {
    private static final String TAG = "PackageConfigurationUpdaterImpl";
    private final int mPid;
    private Integer mNightMode;
    private LocaleList mLocales;
    private ActivityTaskManagerService mAtm;

    PackageConfigurationUpdaterImpl(int pid, ActivityTaskManagerService atm) {
        mPid = pid;
        mAtm = atm;
    }

    @Override
    public ActivityTaskManagerInternal.PackageConfigurationUpdater setNightMode(int nightMode) {
        synchronized (this) {
            mNightMode = nightMode;
        }
        return this;
    }

    @Override
    public ActivityTaskManagerInternal.PackageConfigurationUpdater
            setLocales(LocaleList locales) {
        synchronized (this) {
            mLocales = locales;
        }
        return this;
    }

    @Override
    public void commit() {
        synchronized (this) {
            synchronized (mAtm.mGlobalLock) {
                final long ident = Binder.clearCallingIdentity();
                try {
                    final WindowProcessController wpc = mAtm.mProcessMap.getProcess(mPid);
                    if (wpc == null) {
                        Slog.w(TAG, "Override application configuration: cannot find pid " + mPid);
                        return;
                    }
                    LocaleList localesOverride = LocaleOverlayHelper.combineLocalesIfOverlayExists(
                            mLocales, mAtm.getGlobalConfiguration().getLocales());
                    wpc.applyAppSpecificConfig(mNightMode, localesOverride);
                    wpc.updateAppSpecificSettingsForAllActivities(mNightMode, localesOverride);
                    mAtm.mPackageConfigPersister.updateFromImpl(wpc.mName, wpc.mUserId, this);
                } finally {
                    Binder.restoreCallingIdentity(ident);
                }
            }
        }
    }

    Integer getNightMode() {
        return mNightMode;
    }

    LocaleList getLocales() {
        return mLocales;
    }
}