diff options
| author | Eric Erfanian <erfanian@google.com> | 2017-05-04 08:23:17 -0700 |
|---|---|---|
| committer | Eric Erfanian <erfanian@google.com> | 2017-05-04 14:04:39 -0700 |
| commit | 10b34a5ebf12e97ecba0caf3c8e30b476b038a96 (patch) | |
| tree | 3a325b0effac02fbd228b8ddf2f96589e5df72cd /java/com/android/voicemail/impl/VvmPackageInstallHandler.java | |
| parent | 8369df095a73a77b3715f8ae7ba06089cebca4ce (diff) | |
Update Dialer to V10 RC16
This release was created following the instructions at:
go/dialer-aosp-release
Subsequent dialer releases will follow as O bugs are
fixed, until we reach our final RC.
Version: 10
Candidate: RC16
Branch: dialer-android_release_branch/153304843.1
dialer-android/dialer-android_20170416.00/dialer-android_20170416.00_RC16
This release contains the following bug fixes since RC00:
Bug: 37324705 35304403 36067503 35304446 33203808 37280992
37346084 35766990 37481880 37424493 36470282 37347691
37519015 37168472 35805360 37545472 27704934 36515614
35766990 37577470 34739750 35801628 36788693 35264204
36708536 37628370 36904650 37314436 37642171 37530847
37637799 37666625 37548549 37648036 37636412 37323529
37630507 35919141 37198343 37548572 36178218 37640315
37663896 37720467 37275944 37710497 31634477 37744796
37348506 37744796 37568534 37672424 34872683 34873026
37681461 34873295 37748373 37526812 37618638 37663896
37536088 37727455 37165687 36651204 36900708 37323529
36902926 37256480 37328353 37432034 37436952 34093562
37720889 37321935 37780300 37781115 37755902 36588206
34258266 37290464 37698062 37618638 37473004 37432034
37918676 37870494 37722091
Test: make, on device
Change-Id: I99e1a484ccd578c1f8a13e7a6a4b4952f0791297
Diffstat (limited to 'java/com/android/voicemail/impl/VvmPackageInstallHandler.java')
| -rw-r--r-- | java/com/android/voicemail/impl/VvmPackageInstallHandler.java | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/java/com/android/voicemail/impl/VvmPackageInstallHandler.java b/java/com/android/voicemail/impl/VvmPackageInstallHandler.java new file mode 100644 index 000000000..8d1fb2289 --- /dev/null +++ b/java/com/android/voicemail/impl/VvmPackageInstallHandler.java @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2017 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.voicemail.impl; + +import android.annotation.SuppressLint; +import android.annotation.TargetApi; +import android.content.Context; +import android.content.SharedPreferences; +import android.content.pm.ChangedPackages; +import android.os.Build.VERSION_CODES; +import android.preference.PreferenceManager; +import android.provider.Settings.Global; +import android.telecom.PhoneAccountHandle; +import android.telecom.TelecomManager; +import android.util.ArraySet; +import com.android.dialer.common.PackageUtils; +import com.android.voicemail.impl.settings.VisualVoicemailSettingsUtil; +import java.util.Set; + +/** + * When a new package is installed, check if it matches any of the vvm carrier apps of the currently + * enabled dialer VVM sources. The dialer VVM client will be disabled upon carrier VVM app + * installation, unless it was explicitly enabled by the user. + * + * <p>The ACTION_PACKAGE_ADDED broadcast can no longer be received. (see + * https://developer.android.com/preview/features/background.html#broadcasts) New apps are scanned + * when a VVM SMS is received instead, as it can be a result of the carrier VVM app trying to run + * activation. + */ +@SuppressLint("AndroidApiChecker") // forEach +@TargetApi(VERSION_CODES.O) +public final class VvmPackageInstallHandler { + + private static final String LAST_BOOT_COUNT = + "com.android.voicemail.impl.VvmPackageInstallHandler.LAST_BOOT_COUNT"; + + private static final String CHANGED_PACKAGES_SEQUENCE_NUMBER = + "com.android.voicemail.impl.VvmPackageInstallHandler.CHANGED_PACKAGES_SEQUENCE_NUMBER"; + + private static final String INSTALLED_CARRIER_PACKAGES = + "com.android.voicemail.impl.VvmPackageInstallHandler.INSTALLED_CARRIER_PACKAGES"; + + /** + * Perform a scan of all changed apps since the last invocation to see if the carrier VVM app is + * installed. + */ + public static void scanNewPackages(Context context) { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + int sequenceNumber = sharedPreferences.getInt(CHANGED_PACKAGES_SEQUENCE_NUMBER, 0); + int lastBootCount = sharedPreferences.getInt(LAST_BOOT_COUNT, 0); + int bootCount = Global.getInt(context.getContentResolver(), Global.BOOT_COUNT, 0); + if (lastBootCount != bootCount) { + VvmLog.i( + "VvmPackageInstallHandler.scanNewPackages", "reboot detected, resetting sequence number"); + sequenceNumber = 0; + sharedPreferences.edit().putInt(LAST_BOOT_COUNT, bootCount).apply(); + } + + ChangedPackages changedPackages = + context.getPackageManager().getChangedPackages(sequenceNumber); + if (changedPackages == null) { + VvmLog.i("VvmPackageInstallHandler.scanNewPackages", "no package has changed"); + return; + } + sharedPreferences + .edit() + .putInt(CHANGED_PACKAGES_SEQUENCE_NUMBER, changedPackages.getSequenceNumber()) + .apply(); + + Set<String> installedPackages = + sharedPreferences.getStringSet(INSTALLED_CARRIER_PACKAGES, new ArraySet<>()); + + Set<String> monitoredPackage = getMonitoredPackages(context); + installedPackages.removeIf((packageName) -> !monitoredPackage.contains(packageName)); + + for (String packageName : changedPackages.getPackageNames()) { + if (!monitoredPackage.contains(packageName)) { + continue; + } + if (PackageUtils.isPackageEnabled(packageName, context)) { + if (!installedPackages.contains(packageName)) { + VvmLog.i("VvmPackageInstallHandler.scanNewPackages", "new package found: " + packageName); + installedPackages.add(packageName); + handlePackageInstalled(context, packageName); + } + } else { + installedPackages.remove(packageName); + } + } + sharedPreferences.edit().putStringSet(INSTALLED_CARRIER_PACKAGES, installedPackages).apply(); + } + + private static Set<String> getMonitoredPackages(Context context) { + Set<String> result = new ArraySet<>(); + context + .getSystemService(TelecomManager.class) + .getCallCapablePhoneAccounts() + .forEach( + (phoneAccountHandle -> { + OmtpVvmCarrierConfigHelper carrierConfigHelper = + new OmtpVvmCarrierConfigHelper(context, phoneAccountHandle); + if (!carrierConfigHelper.isValid()) { + return; + } + if (carrierConfigHelper.getCarrierVvmPackageNames() == null) { + return; + } + result.addAll(carrierConfigHelper.getCarrierVvmPackageNames()); + })); + + return result; + }; + + /** + * Iterates through all phone account and disable VVM on a account if {@code packageName} is + * listed as a carrier VVM package. + */ + private static void handlePackageInstalled(Context context, String packageName) { + // This get called every time an app is installed and will be noisy. Don't log until the app + // is identified as a carrier VVM app. + for (PhoneAccountHandle phoneAccount : + context.getSystemService(TelecomManager.class).getCallCapablePhoneAccounts()) { + OmtpVvmCarrierConfigHelper carrierConfigHelper = + new OmtpVvmCarrierConfigHelper(context, phoneAccount); + if (!carrierConfigHelper.isValid()) { + continue; + } + if (carrierConfigHelper.getCarrierVvmPackageNames() == null) { + continue; + } + if (!carrierConfigHelper.getCarrierVvmPackageNames().contains(packageName)) { + continue; + } + + VvmLog.i("VvmPackageInstallHandler.handlePackageInstalled", "Carrier app installed"); + if (VisualVoicemailSettingsUtil.isEnabledUserSet(context, phoneAccount)) { + // Skip the check if this voicemail source's setting is overridden by the user. + VvmLog.i( + "VvmPackageInstallHandler.handlePackageInstalled", + "VVM enabled by user, not disabling"); + continue; + } + + // Force deactivate the client. The user can re-enable it in the settings. + // There is no need to update the settings for deactivation. At this point, if the + // default value is used it should be false because a carrier package is present. + VvmLog.i( + "VvmPackageInstallHandler.handlePackageInstalled", + "Carrier VVM package installed, disabling system VVM client"); + VisualVoicemailSettingsUtil.setEnabled(context, phoneAccount, false); + } + } +} |
