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

Commit 364e0d26 authored by Thomas Stuart's avatar Thomas Stuart Committed by Android (Google) Code Review
Browse files

Merge "Created a listener for ACTION_MANAGED_PROFILE_REMOVED"

parents eb4ff4c6 969c8427
Loading
Loading
Loading
Loading
+33 −4
Original line number Original line Diff line number Diff line
@@ -19,9 +19,11 @@ package com.android.server.telecom;
import android.Manifest;
import android.Manifest;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.ServiceInfo;
@@ -132,6 +134,26 @@ public class PhoneAccountRegistrar {
                PhoneAccount phoneAccount) {}
                PhoneAccount phoneAccount) {}
    }
    }


    /**
     * Receiver for detecting when a managed profile has been removed so that PhoneAccountRegistrar
     * can clean up orphan {@link PhoneAccount}s
     */
    private final BroadcastReceiver mManagedProfileReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.startSession("PARbR.oR");
            try {
                synchronized (mLock) {
                    if (intent.getAction().equals(Intent.ACTION_MANAGED_PROFILE_REMOVED)) {
                        cleanupOrphanedPhoneAccounts();
                    }
                }
            } finally {
                Log.endSession();
            }
        }
    };

    public static final String FILE_NAME = "phone-account-registrar-state.xml";
    public static final String FILE_NAME = "phone-account-registrar-state.xml";
    @VisibleForTesting
    @VisibleForTesting
    public static final int EXPECTED_STATE_VERSION = 9;
    public static final int EXPECTED_STATE_VERSION = 9;
@@ -147,6 +169,7 @@ public class PhoneAccountRegistrar {
    private final SubscriptionManager mSubscriptionManager;
    private final SubscriptionManager mSubscriptionManager;
    private final DefaultDialerCache mDefaultDialerCache;
    private final DefaultDialerCache mDefaultDialerCache;
    private final AppLabelProxy mAppLabelProxy;
    private final AppLabelProxy mAppLabelProxy;
    private final TelecomSystem.SyncRoot mLock;
    private State mState;
    private State mState;
    private UserHandle mCurrentUserHandle;
    private UserHandle mCurrentUserHandle;
    private String mTestPhoneAccountPackageNameFilter;
    private String mTestPhoneAccountPackageNameFilter;
@@ -155,24 +178,30 @@ public class PhoneAccountRegistrar {
            new PhoneAccountRegistrarWriteLock() {};
            new PhoneAccountRegistrarWriteLock() {};


    @VisibleForTesting
    @VisibleForTesting
    public PhoneAccountRegistrar(Context context, DefaultDialerCache defaultDialerCache,
    public PhoneAccountRegistrar(Context context, TelecomSystem.SyncRoot lock,
                                 AppLabelProxy appLabelProxy) {
            DefaultDialerCache defaultDialerCache, AppLabelProxy appLabelProxy) {
        this(context, FILE_NAME, defaultDialerCache, appLabelProxy);
        this(context, lock, FILE_NAME, defaultDialerCache, appLabelProxy);
    }
    }


    @VisibleForTesting
    @VisibleForTesting
    public PhoneAccountRegistrar(Context context, String fileName,
    public PhoneAccountRegistrar(Context context, TelecomSystem.SyncRoot lock, String fileName,
            DefaultDialerCache defaultDialerCache, AppLabelProxy appLabelProxy) {
            DefaultDialerCache defaultDialerCache, AppLabelProxy appLabelProxy) {


        mAtomicFile = new AtomicFile(new File(context.getFilesDir(), fileName));
        mAtomicFile = new AtomicFile(new File(context.getFilesDir(), fileName));


        mState = new State();
        mState = new State();
        mContext = context;
        mContext = context;
        mLock = lock;
        mUserManager = UserManager.get(context);
        mUserManager = UserManager.get(context);
        mDefaultDialerCache = defaultDialerCache;
        mDefaultDialerCache = defaultDialerCache;
        mSubscriptionManager = SubscriptionManager.from(mContext);
        mSubscriptionManager = SubscriptionManager.from(mContext);
        mAppLabelProxy = appLabelProxy;
        mAppLabelProxy = appLabelProxy;
        mCurrentUserHandle = Process.myUserHandle();
        mCurrentUserHandle = Process.myUserHandle();

        // register context based receiver to clean up orphan phone accounts
        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MANAGED_PROFILE_REMOVED);
        mContext.registerReceiver(mManagedProfileReceiver, intentFilter);

        read();
        read();
    }
    }


+1 −1
Original line number Original line Diff line number Diff line
@@ -220,7 +220,7 @@ public class TelecomSystem {
        Log.startSession("TS.init");
        Log.startSession("TS.init");
        // Wrap this in a try block to ensure session cleanup occurs in the case of error.
        // Wrap this in a try block to ensure session cleanup occurs in the case of error.
        try {
        try {
            mPhoneAccountRegistrar = new PhoneAccountRegistrar(mContext, defaultDialerCache,
            mPhoneAccountRegistrar = new PhoneAccountRegistrar(mContext, mLock, defaultDialerCache,
                    packageName -> AppLabelProxy.Util.getAppLabel(
                    packageName -> AppLabelProxy.Util.getAppLabel(
                            mContext.getPackageManager(), packageName));
                            mContext.getPackageManager(), packageName));


+3 −1
Original line number Original line Diff line number Diff line
@@ -63,6 +63,7 @@ import com.android.server.telecom.AppLabelProxy;
import com.android.server.telecom.DefaultDialerCache;
import com.android.server.telecom.DefaultDialerCache;
import com.android.server.telecom.PhoneAccountRegistrar;
import com.android.server.telecom.PhoneAccountRegistrar;
import com.android.server.telecom.PhoneAccountRegistrar.DefaultPhoneAccountHandle;
import com.android.server.telecom.PhoneAccountRegistrar.DefaultPhoneAccountHandle;
import com.android.server.telecom.TelecomSystem;


import org.junit.After;
import org.junit.After;
import org.junit.Before;
import org.junit.Before;
@@ -95,6 +96,7 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase {
    private final String PACKAGE_1 = "PACKAGE_1";
    private final String PACKAGE_1 = "PACKAGE_1";
    private final String PACKAGE_2 = "PACKAGE_2";
    private final String PACKAGE_2 = "PACKAGE_2";
    private final String COMPONENT_NAME = "com.android.server.telecom.tests.MockConnectionService";
    private final String COMPONENT_NAME = "com.android.server.telecom.tests.MockConnectionService";
    private final TelecomSystem.SyncRoot mLock = new TelecomSystem.SyncRoot() { };
    private PhoneAccountRegistrar mRegistrar;
    private PhoneAccountRegistrar mRegistrar;
    @Mock private TelecomManager mTelecomManager;
    @Mock private TelecomManager mTelecomManager;
    @Mock private DefaultDialerCache mDefaultDialerCache;
    @Mock private DefaultDialerCache mDefaultDialerCache;
@@ -116,7 +118,7 @@ public class PhoneAccountRegistrarTest extends TelecomTestCase {
                .thenReturn(TEST_LABEL);
                .thenReturn(TEST_LABEL);
        mRegistrar = new PhoneAccountRegistrar(
        mRegistrar = new PhoneAccountRegistrar(
                mComponentContextFixture.getTestDouble().getApplicationContext(),
                mComponentContextFixture.getTestDouble().getApplicationContext(),
                FILE_NAME, mDefaultDialerCache, mAppLabelProxy);
                mLock, FILE_NAME, mDefaultDialerCache, mAppLabelProxy);
    }
    }


    @Override
    @Override