diff options
author | Eric Erfanian <erfanian@google.com> | 2017-05-23 18:14:13 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-05-23 18:14:13 +0000 |
commit | 15528d8d010d2bc6509bd8cc62f2d8972ed199b7 (patch) | |
tree | 63ec5f9548751bd40b02a7bb255e3c0e556a8f7f /java/com/android/voicemail/impl/VvmPackageInstallHandler.java | |
parent | 27b5eaeb2d0cdffb0b89db4971894548da8afdd4 (diff) | |
parent | 651d758b594202ab62704462b48910445a381b17 (diff) |
Update Dialer to v10 RC39 am: 3ed0c281a1
am: 651d758b59
Change-Id: Ie6d59b702b6504c3957836597445c9b7c1bf7f72
Diffstat (limited to 'java/com/android/voicemail/impl/VvmPackageInstallHandler.java')
-rw-r--r-- | java/com/android/voicemail/impl/VvmPackageInstallHandler.java | 89 |
1 files changed, 1 insertions, 88 deletions
diff --git a/java/com/android/voicemail/impl/VvmPackageInstallHandler.java b/java/com/android/voicemail/impl/VvmPackageInstallHandler.java index 8d1fb2289..07900c26f 100644 --- a/java/com/android/voicemail/impl/VvmPackageInstallHandler.java +++ b/java/com/android/voicemail/impl/VvmPackageInstallHandler.java @@ -19,17 +19,10 @@ 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 @@ -45,91 +38,11 @@ import java.util.Set; @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) { + public 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 : |