summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/callrecord/CallRecordingDataStore.java
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2018-07-09 11:19:24 +0200
committerMichael Bestas <mkbestas@lineageos.org>2020-12-12 01:23:35 +0200
commita6593be278cc0f94387289f99607a050efe7878b (patch)
tree4f12054f303f309215de552aabb97e2cfb9d7937 /java/com/android/dialer/callrecord/CallRecordingDataStore.java
parent399647dde74e8fbf152c98b36657944fd5369eea (diff)
Re-add call recording.
Author: Danny Baumann <dannybaumann@web.de> Date: Mon Jul 9 11:19:24 2018 +0200 Re-add call recording. Change-Id: I53fadf5754b5b6cc3e9920d57480e470e2305ac0 Author: Markus Gruber <gruberma@outlook.at> Date: Sat Oct 13 09:17:01 2018 +0200 Allow call recording for Austria * Call recording is legal in Austria, so it should be available in the UI Change-Id: Iaae0b222d2a1108572832732471e7e063f84dd1f Author: Alexandre Pary <alexandre.pary@gmail.com> Date: Wed Oct 17 11:33:35 2018 +0200 Allow call recording for Belgium * Call recording is legal in Belgium, so it should be available in the UI Change-Id: I0d18c5c31aa5fbde08a849932ac0c8088508dbd8 Author: Arekusu Rin <alexmatteotv@gmail.com> Date: Thu Oct 18 10:20:42 2018 +0200 Allow call recording for Bulgaria. * Call recording is legal, subject to certain restrictions, in Bulgaria. Call recording without notification or one side's consent is not a criminal offense, and only affects the admissibility of said call recording as evidence. Change-Id: Ie35f23056914fb2e7639ea509675e21e7fdfab26 (cherry picked from commit 4cec325c31dbe5894ab576b6161065ad0458612d) Author: Bruno Martins <bgcngm@gmail.com> Date: Tue Oct 23 21:03:47 2018 +0100 res: Fix malformed XML * The legal precedent source URL includes double dashes and breaks aapt2 compilation. Replace it by a shortened one. Change-Id: Ic1cb1b6af16d27649e36478ca7597b78b93b1338 Author: Arekusu Rin <alexmatteotv@gmail.com> Date: Thu Oct 25 12:50:57 2018 +0200 Enable or disable call recording for numerous countries via MCC. * This change handles call recording within the Dialer. Changes were made to the template of all of the XML files, and all links were changed to https, where possible. Quotes of the precedents and/or laws can be found within each country's XML file. Countries' whose status was not changed are not explicitly mentioned below, despite any changes to their files. * Call recording is disabled for: Andorra, Iceland, Indonesia, Monaco, Switzerland, the United States of America and some of its territories - Guam, Northern Mariana Islands, Puerto Rico and the United States Virgin Islands. * Call recording is enabled for: Albania, American Samoa, Argentina, Armenia, Aruba, Belarus, Bonaire, Bosnia and Herzegovina, Brazil, Canada, Chile, Croatia, Curaçao, Cyprus, Estonia, Faroe Islands, French Guiana, French Polynesia, Georgia, Greece, Greenland, Guadeloupe, Hungary, India, Ireland, Israel, Japan, Kosovo, Latvia, Liechtenstein, Lithuania, Luxembourg, Malta, Martinique, Mayotte, Moldova, Montenegro, Morocco, New Caledonia, New Zealand, North Macedonia, Peru, Russia, Réunion, Saba, Saint Barthélemy, Saint-Martin, Saint-Pierre-et-Miquelon, Serbia, Singapore, Sint Eustatius, Sint Maarten, Slovakia, Slovenia, South Africa, South Korea, Turkey, Ukraine and Wallis-et-Futuna. Change-Id: Iba5b7028d26cac281099f81bf3d5c21e2ee4d1a9 Author: Arekusu Rin <alexmatteotv@gmail.com> Date: Wed Jun 12 09:58:05 2019 +0200 Enable Call Recording for Sri Lanka and Costa Rica. * Call recording is enabled for: Sri Lanka (413) and Costa Rica (712). * Fixes: Removed newline from Belgium (206) and space from Russia (250). Change-Id: I4c9ecf41e9fd472b97fff5cd03800414737be87a Author: Danny Baumann <dannybaumann@web.de> Date: Thu Nov 7 08:34:44 2019 +0100 Base 'call recording allowed' decision on current country. Selection of resources by MCC happens via the SIM MCC, but what matters for legislation is the current country, not the country the SIM origins from. Because of that, move the decision about whether call recording is allowed or not to the current country instead of SIM MCC. Change-Id: I0ee365d7af8e3392716318e5a51e12e0efe7029a Author: Han Wang <416810799@qq.com> Date: Wed Nov 20 13:27:00 2019 +0200 Enable call recording for China Change-Id: Id51a2e6a119e99ff50696b50513aed323c61565c Author: mhkjahromi <m.h.k.jahromi@gmail.com> Date: Sat Dec 7 18:32:20 2019 +0330 Enable call recording for Iran Change-Id: I5640405d9bd38ac3d83fd618543190c1b0d800fb Author: Danny Baumann <dannybaumann@web.de> Date: Thu Feb 20 13:19:27 2020 +0100 Refactor call recording to use MediaProvider. Change-Id: Id53d43d8bf10715a1597ff754f6c38a992302190 Author: Danny Baumann <dannybaumann@web.de> Date: Fri Jun 5 13:19:46 2020 +0200 Iterate old recordings properly when migrating call recording data. SparseArray.get() expects a key, not an index. Change-Id: I0ba40180dc9df9f8a8f4036ccbe47cc59a50cfbb Change-Id: Ie9e0af8ccadb1bab1c52a5d905344d0c8fcab92c
Diffstat (limited to 'java/com/android/dialer/callrecord/CallRecordingDataStore.java')
-rw-r--r--java/com/android/dialer/callrecord/CallRecordingDataStore.java224
1 files changed, 224 insertions, 0 deletions
diff --git a/java/com/android/dialer/callrecord/CallRecordingDataStore.java b/java/com/android/dialer/callrecord/CallRecordingDataStore.java
new file mode 100644
index 000000000..88b603b54
--- /dev/null
+++ b/java/com/android/dialer/callrecord/CallRecordingDataStore.java
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 2014 The CyanogenMod 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.callrecord;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteException;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.database.sqlite.SQLiteStatement;
+import android.provider.BaseColumns;
+import android.util.Log;
+import android.util.SparseArray;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Persistent data store for call recordings. Usage:
+ * open()
+ * read/write operations
+ * close()
+ */
+public class CallRecordingDataStore {
+ private static final String TAG = "CallRecordingStore";
+ private SQLiteOpenHelper mOpenHelper = null;
+ private SQLiteDatabase mDatabase = null;
+
+ /**
+ * Open before reading/writing. Will not open handle if one is already open.
+ */
+ public void open(Context context) {
+ if (mDatabase == null) {
+ mOpenHelper = new CallRecordingSQLiteOpenHelper(context);
+ mDatabase = mOpenHelper.getWritableDatabase();
+ }
+ }
+
+ /**
+ * close when finished reading/writing
+ */
+ public void close() {
+ if (mDatabase != null) {
+ mDatabase.close();
+ }
+ if (mOpenHelper != null) {
+ mOpenHelper.close();
+ }
+ mDatabase = null;
+ mOpenHelper = null;
+ }
+
+ /**
+ * Save a recording in the data store
+ *
+ * @param recording the recording to store
+ */
+ public void putRecording(CallRecording recording) {
+ final String insertSql = "INSERT INTO " +
+ CallRecordingsContract.CallRecording.TABLE_NAME + " (" +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_PHONE_NUMBER + ", " +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_CALL_DATE + ", " +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_RECORDING_FILENAME + ", " +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_CREATION_DATE + ", " +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_MEDIA_ID + ") " +
+ " VALUES (?, ?, ?, ?, ?)";
+
+ try {
+ SQLiteStatement stmt = mDatabase.compileStatement(insertSql);
+ int idx = 1;
+ stmt.bindString(idx++, recording.phoneNumber);
+ stmt.bindLong(idx++, recording.creationTime);
+ stmt.bindString(idx++, recording.fileName);
+ stmt.bindLong(idx++, System.currentTimeMillis());
+ stmt.bindLong(idx++, recording.mediaId);
+ long id = stmt.executeInsert();
+ Log.i(TAG, "Saved recording " + recording + " with id " + id);
+ } catch (SQLiteException e) {
+ Log.w(TAG, "Failed to save recording " + recording, e);
+ }
+ }
+
+ /**
+ * Get all recordings associated with a phone call
+ *
+ * @param phoneNumber phone number no spaces
+ * @param callCreationDate time that the call was created
+ * @return list of recordings
+ */
+ public List<CallRecording> getRecordings(String phoneNumber, long callCreationDate) {
+ List<CallRecording> resultList = new ArrayList<CallRecording>();
+
+ final String query = "SELECT " +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_RECORDING_FILENAME + "," +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_CREATION_DATE + "," +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_MEDIA_ID +
+ " FROM " + CallRecordingsContract.CallRecording.TABLE_NAME +
+ " WHERE " + CallRecordingsContract.CallRecording.COLUMN_NAME_PHONE_NUMBER + " = ?" +
+ " AND " + CallRecordingsContract.CallRecording.COLUMN_NAME_CALL_DATE + " = ?" +
+ " AND " + CallRecordingsContract.CallRecording.COLUMN_NAME_MEDIA_ID + " != 0" +
+ " ORDER BY " + CallRecordingsContract.CallRecording.COLUMN_NAME_CREATION_DATE;
+
+ String args[] = {
+ phoneNumber, String.valueOf(callCreationDate)
+ };
+
+ try {
+ Cursor cursor = mDatabase.rawQuery(query, args);
+ while (cursor.moveToNext()) {
+ String fileName = cursor.getString(0);
+ long creationDate = cursor.getLong(1);
+ long mediaId = cursor.getLong(2);
+ // FIXME: need to check whether media entry still exists?
+ resultList.add(
+ new CallRecording(phoneNumber, callCreationDate, fileName, creationDate, mediaId));
+ }
+ cursor.close();
+ } catch (SQLiteException e) {
+ Log.w(TAG, "Failed to fetch recordings for number " + phoneNumber +
+ ", date " + callCreationDate, e);
+ }
+
+ return resultList;
+ }
+
+ public SparseArray<CallRecording> getUnmigratedRecordingData() {
+ final String query = "SELECT " +
+ CallRecordingsContract.CallRecording._ID + "," +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_PHONE_NUMBER + "," +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_RECORDING_FILENAME + "," +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_CREATION_DATE +
+ " FROM " + CallRecordingsContract.CallRecording.TABLE_NAME +
+ " WHERE " + CallRecordingsContract.CallRecording.COLUMN_NAME_MEDIA_ID + " == 0";
+ final SparseArray<CallRecording> result = new SparseArray<>();
+
+ try {
+ Cursor cursor = mDatabase.rawQuery(query, null);
+ while (cursor.moveToNext()) {
+ int id = cursor.getInt(0);
+ String phoneNumber = cursor.getString(1);
+ String fileName = cursor.getString(2);
+ long creationDate = cursor.getLong(3);
+ CallRecording recording = new CallRecording(
+ phoneNumber, creationDate, fileName, creationDate, 0);
+ result.put(id, recording);
+ }
+ cursor.close();
+ } catch (SQLiteException e) {
+ Log.w(TAG, "Failed to fetch recordings for migration", e);
+ }
+
+ return result;
+ }
+
+ public void updateMigratedRecording(int id, int mediaId) {
+ ContentValues cv = new ContentValues(1);
+ cv.put(CallRecordingsContract.CallRecording.COLUMN_NAME_MEDIA_ID, mediaId);
+ mDatabase.update(CallRecordingsContract.CallRecording.TABLE_NAME, cv,
+ CallRecordingsContract.CallRecording._ID + " = ?", new String[] { String.valueOf(id) });
+ }
+
+ static class CallRecordingsContract {
+ static interface CallRecording extends BaseColumns {
+ static final String TABLE_NAME = "call_recordings";
+ static final String COLUMN_NAME_PHONE_NUMBER = "phone_number";
+ static final String COLUMN_NAME_CALL_DATE = "call_date";
+ static final String COLUMN_NAME_RECORDING_FILENAME = "recording_filename";
+ static final String COLUMN_NAME_CREATION_DATE = "creation_date";
+ static final String COLUMN_NAME_MEDIA_ID = "media_id";
+ }
+ }
+
+ static class CallRecordingSQLiteOpenHelper extends SQLiteOpenHelper {
+ private static final int VERSION = 2;
+ private static final String DB_NAME = "callrecordings.db";
+
+ public CallRecordingSQLiteOpenHelper(Context context) {
+ super(context, DB_NAME, null, VERSION);
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+ db.execSQL("CREATE TABLE " + CallRecordingsContract.CallRecording.TABLE_NAME + " (" +
+ CallRecordingsContract.CallRecording._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_PHONE_NUMBER + " TEXT," +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_CALL_DATE + " LONG," +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_RECORDING_FILENAME + " TEXT, " +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_CREATION_DATE + " LONG," +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_MEDIA_ID + " INTEGER DEFAULT 0" +
+ ");"
+ );
+
+ db.execSQL("CREATE INDEX IF NOT EXISTS phone_number_call_date_index ON " +
+ CallRecordingsContract.CallRecording.TABLE_NAME + " (" +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_PHONE_NUMBER + ", " +
+ CallRecordingsContract.CallRecording.COLUMN_NAME_CALL_DATE + ");"
+ );
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ if (oldVersion < 2) {
+ db.execSQL("ALTER TABLE " + CallRecordingsContract.CallRecording.TABLE_NAME +
+ " ADD COLUMN " + CallRecordingsContract.CallRecording.COLUMN_NAME_MEDIA_ID +
+ " INTEGER DEFAULT 0;");
+ }
+ }
+ }
+}