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

Commit 827f3d30 authored by Tyler Gunn's avatar Tyler Gunn Committed by Android (Google) Code Review
Browse files

Merge "Un-registering phone accounts for packages which are uninstalled." into lmp-dev

parents acb91eb8 d900ce60
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -182,6 +182,13 @@
            </intent-filter>
        </receiver>

        <receiver android:name="PhoneAccountBroadcastReceiver">
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_REMOVED" />
                <data android:scheme="package" />
            </intent-filter>
        </receiver>

        <activity android:name=".RespondViaSmsSettings$Settings"
                  android:label="@string/respond_via_sms_setting_title"
                  android:configChanges="orientation|screenSize|keyboardHidden">
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.telecomm;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import java.lang.String;

/**
 * Captures {@code android.intent.action.PACKAGE_REMOVED} intents and triggers the removal of
 * associated {@link android.telecomm.PhoneAccount}s via the
 * {@link com.android.telecomm.PhoneAccountRegistrar}.
 */
public class PhoneAccountBroadcastReceiver extends BroadcastReceiver {
    /**
     * Receives the intents the class is configured to received.
     *
     * @param context The Context in which the receiver is running.
     * @param intent The Intent being received.
     */
    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
            Uri uri = intent.getData();
            if (uri == null) {
                return;
            }

            String packageName = uri.getSchemeSpecificPart();
            handlePackageRemoved(context, packageName);
        }
    }

    /**
     * Handles the removal of a package by calling upon the {@link PhoneAccountRegistrar} to
     * un-register any {@link android.telecomm.PhoneAccount}s associated with the package.
     *
     * @param packageName The name of the removed package.
     */
    private void handlePackageRemoved(Context context, String packageName) {
        TelecommApp telecommApp = TelecommApp.getInstance();
        if (telecommApp == null) {
            return;
        }

        PhoneAccountRegistrar registrar = telecommApp.getPhoneAccountRegistrar();
        if (registrar == null) {
            return;
        }

        registrar.clearAccounts(packageName);
    }
}
+19 −6
Original line number Diff line number Diff line
@@ -45,7 +45,9 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.String;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -256,19 +258,30 @@ public final class PhoneAccountRegistrar {
        fireAccountsChanged();
    }

    /**
     * Un-registers all phone accounts associated with a specified package.
     *
     * @param packageName The package for which phone accounts will be removed.
     */
    public void clearAccounts(String packageName) {
        for (int i = 0; i < mState.accounts.size(); i++) {
        boolean accountsRemoved = false;
        Iterator<PhoneAccount> it = mState.accounts.iterator();
        while (it.hasNext()) {
            PhoneAccount phoneAccount = it.next();
            if (Objects.equals(
                    packageName,
                    mState.accounts.get(i).getAccountHandle()
                            .getComponentName().getPackageName())) {
                mState.accounts.remove(i);
                    phoneAccount.getAccountHandle().getComponentName().getPackageName())) {
                Log.i(this, "Removing phone account " + phoneAccount.getLabel());
                it.remove();
                accountsRemoved = true;
            }
        }

        if (accountsRemoved) {
            write();
            fireAccountsChanged();
        }
    }

    public void addListener(Listener l) {
        mListeners.add(l);