diff options
Diffstat (limited to 'java/com/android/dialer/app')
3 files changed, 20 insertions, 143 deletions
diff --git a/java/com/android/dialer/app/voicemail/error/AndroidManifest.xml b/java/com/android/dialer/app/voicemail/error/AndroidManifest.xml index bb6c55f5c..07cb77f58 100644 --- a/java/com/android/dialer/app/voicemail/error/AndroidManifest.xml +++ b/java/com/android/dialer/app/voicemail/error/AndroidManifest.xml @@ -18,12 +18,4 @@ <uses-permission android:name="android.permission.CALL_PHONE"/> - <application> - <receiver android:name=".PackageReplacedReceiver" android:exported="false"> - <intent-filter> - <action android:name="android.intent.action.MY_PACKAGE_REPLACED" /> - </intent-filter> - </receiver> - </application> - </manifest> diff --git a/java/com/android/dialer/app/voicemail/error/PackageReplacedReceiver.java b/java/com/android/dialer/app/voicemail/error/PackageReplacedReceiver.java deleted file mode 100644 index 64d72b18f..000000000 --- a/java/com/android/dialer/app/voicemail/error/PackageReplacedReceiver.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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.dialer.app.voicemail.error; - -import android.annotation.TargetApi; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.database.Cursor; -import android.net.Uri; -import android.preference.PreferenceManager; -import android.provider.CallLog.Calls; -import android.provider.VoicemailContract.Voicemails; -import com.android.dialer.common.LogUtil; -import com.android.dialer.common.concurrent.DialerExecutor.Worker; -import com.android.dialer.common.concurrent.DialerExecutorComponent; - -/** Receives MY_PACKAGE_REPLACED to check for legacy voicemail users. */ -public class PackageReplacedReceiver extends BroadcastReceiver { - - @Override - public void onReceive(Context context, Intent intent) { - LogUtil.enterBlock("PackageReplacedReceiver.onReceive"); - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - if (!prefs.contains(VoicemailTosMessageCreator.PREF_DIALER_FEATURE_VERSION_ACKNOWLEDGED_KEY)) { - setVoicemailFeatureVersionAsync(context); - } - } - - private void setVoicemailFeatureVersionAsync(Context context) { - LogUtil.enterBlock("PackageReplacedReceiver.setVoicemailFeatureVersionAsync"); - - // Check if user is already using voicemail (ie do they have any voicemails), and set the - // acknowledged feature value accordingly. - PendingResult pendingResult = goAsync(); - DialerExecutorComponent.get(context) - .dialerExecutorFactory() - .createNonUiTaskBuilder(new ExistingVoicemailCheck(context)) - .onSuccess( - output -> { - LogUtil.i("PackageReplacedReceiver.setVoicemailFeatureVersionAsync", "success"); - pendingResult.finish(); - }) - .onFailure( - throwable -> { - LogUtil.i("PackageReplacedReceiver.setVoicemailFeatureVersionAsync", "failure"); - pendingResult.finish(); - }) - .build() - .executeParallel(null); - } - - private static class ExistingVoicemailCheck implements Worker<Void, Void> { - private static final String[] PROJECTION = new String[] {Voicemails._ID}; - - private final Context context; - - ExistingVoicemailCheck(Context context) { - this.context = context; - } - - @TargetApi(android.os.Build.VERSION_CODES.M) // used for try with resources - @Override - public Void doInBackground(Void arg) throws Throwable { - LogUtil.i("PackageReplacedReceiver.ExistingVoicemailCheck.doInBackground", ""); - - // Check the database for existing voicemails. - boolean hasVoicemails = false; - Uri uri = Voicemails.buildSourceUri(context.getPackageName()); - String whereClause = Calls.TYPE + " = " + Calls.VOICEMAIL_TYPE; - try (Cursor cursor = - context.getContentResolver().query(uri, PROJECTION, whereClause, null, null)) { - if (cursor == null) { - LogUtil.e( - "PackageReplacedReceiver.ExistingVoicemailCheck.doInBackground", - "failed to check for existing voicemails"); - } else if (cursor.moveToNext()) { - hasVoicemails = true; - } - } - - LogUtil.i( - "PackageReplacedReceiver.ExistingVoicemailCheck.doInBackground", - "has voicemails: " + hasVoicemails); - int version = hasVoicemails ? VoicemailTosMessageCreator.LEGACY_VOICEMAIL_FEATURE_VERSION : 0; - PreferenceManager.getDefaultSharedPreferences(context) - .edit() - .putInt(VoicemailTosMessageCreator.PREF_DIALER_FEATURE_VERSION_ACKNOWLEDGED_KEY, version) - .apply(); - return null; - } - } -} diff --git a/java/com/android/dialer/app/voicemail/error/VoicemailTosMessageCreator.java b/java/com/android/dialer/app/voicemail/error/VoicemailTosMessageCreator.java index 3e4321309..b7c8ed721 100644 --- a/java/com/android/dialer/app/voicemail/error/VoicemailTosMessageCreator.java +++ b/java/com/android/dialer/app/voicemail/error/VoicemailTosMessageCreator.java @@ -48,6 +48,7 @@ import com.android.dialer.voicemail.settings.VoicemailSettingsFragment; import com.android.voicemail.VisualVoicemailTypeExtensions; import com.android.voicemail.VoicemailClient; import com.android.voicemail.VoicemailComponent; +import com.android.voicemail.VoicemailVersionConstants; import java.util.Locale; /** @@ -55,22 +56,6 @@ import java.util.Locale; * terms of service for Verizon and for other carriers. */ public class VoicemailTosMessageCreator { - // Preference key to check which version of the Verizon ToS that the user has accepted. - static final String PREF_VVM3_TOS_VERSION_ACCEPTED_KEY = "vvm3_tos_version_accepted"; - - // Preference key to check which version of the Google Dialer ToS that the user has accepted. - static final String PREF_DIALER_TOS_VERSION_ACCEPTED_KEY = "dialer_tos_version_accepted"; - - // Preference key to check which feature version the user has acknowledged - static final String PREF_DIALER_FEATURE_VERSION_ACKNOWLEDGED_KEY = - "dialer_feature_version_acknowledged"; - - static final int CURRENT_VVM3_TOS_VERSION = 2; - static final int CURRENT_DIALER_TOS_VERSION = 1; - static final int LEGACY_VOICEMAIL_FEATURE_VERSION = 1; // original visual voicemail - static final int TRANSCRIPTION_VOICEMAIL_FEATURE_VERSION = 2; // adds voicemail transcription - static final int CURRENT_VOICEMAIL_FEATURE_VERSION = TRANSCRIPTION_VOICEMAIL_FEATURE_VERSION; - private static final String ISO639_SPANISH = "es"; private final Context context; @@ -328,10 +313,11 @@ public class VoicemailTosMessageCreator { private boolean hasAcceptedTos() { if (isVvm3()) { - return preferences.getInt(PREF_VVM3_TOS_VERSION_ACCEPTED_KEY, 0) >= CURRENT_VVM3_TOS_VERSION; + return preferences.getInt(VoicemailVersionConstants.PREF_VVM3_TOS_VERSION_ACCEPTED_KEY, 0) + >= VoicemailVersionConstants.CURRENT_VVM3_TOS_VERSION; } else { - return preferences.getInt(PREF_DIALER_TOS_VERSION_ACCEPTED_KEY, 0) - >= CURRENT_DIALER_TOS_VERSION; + return preferences.getInt(VoicemailVersionConstants.PREF_DIALER_TOS_VERSION_ACCEPTED_KEY, 0) + >= VoicemailVersionConstants.CURRENT_DIALER_TOS_VERSION; } } @@ -339,12 +325,16 @@ public class VoicemailTosMessageCreator { if (isVvm3()) { preferences .edit() - .putInt(PREF_VVM3_TOS_VERSION_ACCEPTED_KEY, CURRENT_VVM3_TOS_VERSION) + .putInt( + VoicemailVersionConstants.PREF_VVM3_TOS_VERSION_ACCEPTED_KEY, + VoicemailVersionConstants.CURRENT_VVM3_TOS_VERSION) .apply(); } else { preferences .edit() - .putInt(PREF_DIALER_TOS_VERSION_ACCEPTED_KEY, CURRENT_DIALER_TOS_VERSION) + .putInt( + VoicemailVersionConstants.PREF_DIALER_TOS_VERSION_ACCEPTED_KEY, + VoicemailVersionConstants.CURRENT_DIALER_TOS_VERSION) .apply(); } @@ -360,20 +350,24 @@ public class VoicemailTosMessageCreator { return true; } - return preferences.getInt(PREF_DIALER_FEATURE_VERSION_ACKNOWLEDGED_KEY, 0) - >= CURRENT_VOICEMAIL_FEATURE_VERSION; + return preferences.getInt( + VoicemailVersionConstants.PREF_DIALER_FEATURE_VERSION_ACKNOWLEDGED_KEY, 0) + >= VoicemailVersionConstants.CURRENT_VOICEMAIL_FEATURE_VERSION; } private void recordFeatureAcknowledgement() { preferences .edit() - .putInt(PREF_DIALER_FEATURE_VERSION_ACKNOWLEDGED_KEY, CURRENT_VOICEMAIL_FEATURE_VERSION) + .putInt( + VoicemailVersionConstants.PREF_DIALER_FEATURE_VERSION_ACKNOWLEDGED_KEY, + VoicemailVersionConstants.CURRENT_VOICEMAIL_FEATURE_VERSION) .apply(); } private boolean isLegacyVoicemailUser() { - return preferences.getInt(PREF_DIALER_FEATURE_VERSION_ACKNOWLEDGED_KEY, 0) - == LEGACY_VOICEMAIL_FEATURE_VERSION; + return preferences.getInt( + VoicemailVersionConstants.PREF_DIALER_FEATURE_VERSION_ACKNOWLEDGED_KEY, 0) + == VoicemailVersionConstants.LEGACY_VOICEMAIL_FEATURE_VERSION; } private void logTosCreatedImpression() { |