diff options
author | Danny Baumann <dannybaumann@web.de> | 2019-11-07 08:34:44 +0100 |
---|---|---|
committer | Danny Baumann <dannybaumann@web.de> | 2019-11-18 11:14:23 +0100 |
commit | 248db27d1c5d2bff2b1a8e9dd43fab657a7e95cd (patch) | |
tree | 3b14e47eef6ee850b4292f97ee1860c3966def9f /java/com/android/incallui/call/CallRecorder.java | |
parent | 6fbf058e87d2d69212ed29d73b8a6272245825bf (diff) | |
download | android_packages_apps_Dialer-248db27d1c5d2bff2b1a8e9dd43fab657a7e95cd.tar.gz android_packages_apps_Dialer-248db27d1c5d2bff2b1a8e9dd43fab657a7e95cd.tar.bz2 android_packages_apps_Dialer-248db27d1c5d2bff2b1a8e9dd43fab657a7e95cd.zip |
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
Diffstat (limited to 'java/com/android/incallui/call/CallRecorder.java')
-rw-r--r-- | java/com/android/incallui/call/CallRecorder.java | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/java/com/android/incallui/call/CallRecorder.java b/java/com/android/incallui/call/CallRecorder.java index 0525c40b2..867d5a57c 100644 --- a/java/com/android/incallui/call/CallRecorder.java +++ b/java/com/android/incallui/call/CallRecorder.java @@ -20,6 +20,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; +import android.content.res.XmlResourceParser; import android.os.Handler; import android.os.IBinder; import android.os.Looper; @@ -34,10 +35,17 @@ import com.android.dialer.callrecord.CallRecordingDataStore; import com.android.dialer.callrecord.CallRecording; import com.android.dialer.callrecord.ICallRecorderService; import com.android.dialer.callrecord.impl.CallRecorderService; +import com.android.dialer.location.GeoUtil; import com.android.incallui.call.state.DialerCallState; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +import java.io.IOException; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; +import java.util.Locale; /** * InCall UI's interface to the call recorder @@ -52,9 +60,9 @@ public class CallRecorder implements CallList.Listener { android.Manifest.permission.RECORD_AUDIO, android.Manifest.permission.WRITE_EXTERNAL_STORAGE }; + private static final HashMap<String, Boolean> RECORD_ALLOWED_STATE_BY_COUNTRY = new HashMap<>(); private static CallRecorder instance = null; - private Context context; private boolean initialized = false; private ICallRecorderService service = null; @@ -86,6 +94,20 @@ public class CallRecorder implements CallList.Listener { return CallRecorderService.isEnabled(context); } + public boolean canRecordInCurrentCountry() { + if (!isEnabled()) { + return false; + } + if (RECORD_ALLOWED_STATE_BY_COUNTRY.isEmpty()) { + loadAllowedStates(); + } + + String currentCountryIso = GeoUtil.getCurrentCountryIso(context); + Boolean allowedState = RECORD_ALLOWED_STATE_BY_COUNTRY.get(currentCountryIso); + + return allowedState != null && allowedState; + } + private CallRecorder() { CallList.getInstance().addListener(this); } @@ -277,4 +299,38 @@ public class CallRecorder implements CallList.Listener { handler.postDelayed(this, UPDATE_INTERVAL); } }; + + private void loadAllowedStates() { + XmlResourceParser parser = context.getResources().getXml(R.xml.call_record_states); + try { + // Consume all START_DOCUMENT which can appear more than once. + while (parser.next() == XmlPullParser.START_DOCUMENT) {} + + parser.require(XmlPullParser.START_TAG, null, "call-record-allowed-flags"); + + while (parser.next() != XmlPullParser.END_DOCUMENT) { + if (parser.getEventType() != XmlPullParser.START_TAG) { + continue; + } + parser.require(XmlPullParser.START_TAG, null, "country"); + + String iso = parser.getAttributeValue(null, "iso"); + String allowed = parser.getAttributeValue(null, "allowed"); + if (iso != null && ("true".equals(allowed) || "false".equals(allowed))) { + for (String splittedIso : iso.split(",")) { + RECORD_ALLOWED_STATE_BY_COUNTRY.put( + splittedIso.toUpperCase(Locale.US), Boolean.valueOf(allowed)); + } + } else { + throw new XmlPullParserException("Unexpected country specification", parser, null); + } + } + Log.d(TAG, "Loaded " + RECORD_ALLOWED_STATE_BY_COUNTRY.size() + " country records"); + } catch (XmlPullParserException | IOException e) { + Log.e(TAG, "Could not parse allowed country list", e); + RECORD_ALLOWED_STATE_BY_COUNTRY.clear(); + } finally { + parser.close(); + } + } } |