From cd7f4a6229a033c7879788db0768fefacfb47b2b Mon Sep 17 00:00:00 2001 From: twyen Date: Tue, 21 Nov 2017 17:50:08 -0800 Subject: Force disable VVM if carrier app is preloaded This CL checks if the carrier app is installed on the system image. If so, VVM will be force disabled (user can't turn it on, can't even see the switch as if they are on a unsupported carrier). Otherwise, VVM will only be disabled by default if the carrier app is present (User can still turn it on in settings). Bug: 67496592 Test: OmtpCarrierConfigHelperTest / manual - move carrier app to /system/app PiperOrigin-RevId: 176586849 Change-Id: Idf79bdf61c600423062ca54d1b4c6e77cfcd8033 --- .../voicemail/impl/OmtpVvmCarrierConfigHelper.java | 38 +++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/java/com/android/voicemail/impl/OmtpVvmCarrierConfigHelper.java b/java/com/android/voicemail/impl/OmtpVvmCarrierConfigHelper.java index f8dc4bd79..0b63e8658 100644 --- a/java/com/android/voicemail/impl/OmtpVvmCarrierConfigHelper.java +++ b/java/com/android/voicemail/impl/OmtpVvmCarrierConfigHelper.java @@ -18,6 +18,7 @@ package com.android.voicemail.impl; import android.annotation.TargetApi; import android.app.PendingIntent; import android.content.Context; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Build.VERSION_CODES; import android.os.Bundle; @@ -174,7 +175,13 @@ public class OmtpVvmCarrierConfigHelper { * known protocol. */ public boolean isValid() { - return mProtocol != null; + if (mProtocol == null) { + return false; + } + if (isCarrierAppPreloaded()) { + return false; + } + return true; } @Nullable @@ -197,6 +204,11 @@ public class OmtpVvmCarrierConfigHelper { @Nullable public Set getCarrierVvmPackageNames() { Assert.checkArgument(isValid()); + return getCarrierVvmPackageNamesWithoutValidation(); + } + + @Nullable + private Set getCarrierVvmPackageNamesWithoutValidation() { Set names = getCarrierVvmPackageNames(mOverrideConfig); if (names != null) { return names; @@ -498,4 +510,28 @@ public class OmtpVvmCarrierConfigHelper { public static void setOverrideConfigForTest(PersistableBundle config) { sOverrideConfigForTest = config; } + + private boolean isCarrierAppPreloaded() { + Set carrierPackages = getCarrierVvmPackageNamesWithoutValidation(); + if (carrierPackages == null) { + return false; + } + for (String packageName : carrierPackages) { + try { + ApplicationInfo info = getContext().getPackageManager().getApplicationInfo(packageName, 0); + if (!info.enabled) { + continue; + } + if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0 + || (info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { + VvmLog.i(TAG, packageName + " preloaded, force disabling dialer vvm"); + return true; + } + + } catch (NameNotFoundException e) { + continue; + } + } + return false; + } } -- cgit v1.2.3