• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.dialer.voicemail;
18 
19 import android.app.Activity;
20 import android.database.Cursor;
21 import android.net.Uri;
22 import android.os.AsyncTask;
23 import android.os.Bundle;
24 import android.util.Log;
25 import com.android.dialer.calllog.CallLogAsyncTaskUtil;
26 import com.android.dialer.database.VoicemailArchiveContract;
27 import java.io.FileNotFoundException;
28 import java.util.concurrent.TimeUnit;
29 
30 /**
31  * Similar to the {@link VoicemailPlaybackPresenter}, but for the archive voicemail tab. It checks
32  * whether the voicemail file exists locally before preparing it.
33  */
34 public class VoicemailArchivePlaybackPresenter extends VoicemailPlaybackPresenter {
35     private static final String TAG = "VMPlaybackPresenter";
36     private static VoicemailPlaybackPresenter sInstance;
37 
VoicemailArchivePlaybackPresenter(Activity activity)38     public VoicemailArchivePlaybackPresenter(Activity activity) {
39         super(activity);
40     }
41 
getInstance( Activity activity, Bundle savedInstanceState)42     public static VoicemailPlaybackPresenter getInstance(
43             Activity activity, Bundle savedInstanceState) {
44         if (sInstance == null) {
45             sInstance = new VoicemailArchivePlaybackPresenter(activity);
46         }
47 
48         sInstance.init(activity, savedInstanceState);
49         return sInstance;
50     }
51 
52     @Override
checkForContent(final OnContentCheckedListener callback)53     protected void checkForContent(final OnContentCheckedListener callback) {
54         mAsyncTaskExecutor.submit(Tasks.CHECK_FOR_CONTENT, new AsyncTask<Void, Void, Boolean>() {
55             @Override
56             public Boolean doInBackground(Void... params) {
57                 try {
58                     // Check if the _data column of the archived voicemail is valid
59                     if (mVoicemailUri != null) {
60                         mContext.getContentResolver().openInputStream(mVoicemailUri);
61                         return true;
62                     }
63                 } catch (FileNotFoundException e) {
64                     Log.d(TAG, "Voicemail file not found for " + mVoicemailUri);
65                 }
66                 return false;
67             }
68 
69             @Override
70             public void onPostExecute(Boolean hasContent) {
71                 callback.onContentChecked(hasContent);
72             }
73         });
74     }
75 
76     @Override
startArchiveVoicemailTask(final Uri voicemailUri, final boolean archivedByUser)77     protected void startArchiveVoicemailTask(final Uri voicemailUri, final boolean archivedByUser) {
78         // If a user wants to share an archived voicemail, no need for archiving, just go straight
79         // to share intent.
80         if (!archivedByUser) {
81             sendShareIntent(voicemailUri);
82         }
83     }
84 
85     @Override
requestContent(int code)86     protected boolean requestContent(int code) {
87         handleError(new FileNotFoundException("Voicemail archive file does not exist"));
88         return false;       // No way for archive tab to request content
89     }
90 }
91