summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryueg <yueg@google.com>2018-04-24 12:12:57 -0700
committerCopybara-Service <copybara-piper@google.com>2018-04-25 11:43:21 -0700
commitb47528e0ed4260fd72b163e2e5dfb0668ea5ca15 (patch)
tree8fae9a47cb6a6dd6a08c1bd6b76c2bb420f6302e
parent27c3718f9e3c3297376cfa45f6a67d83a4bb7bcc (diff)
Show international call on wifi dialog without InCallActivity.
Bug: 74022483 Test: InCallPresenterTest PiperOrigin-RevId: 194125192 Change-Id: Ie7c50554079fe3a0a23b18ac44fc81b913c3e619
-rw-r--r--java/com/android/incallui/InCallActivity.java42
-rw-r--r--java/com/android/incallui/InCallPresenter.java16
-rw-r--r--java/com/android/incallui/telecomeventui/AndroidManifest.xml13
-rw-r--r--java/com/android/incallui/telecomeventui/InternationalCallOnWifiDialogActivity.java101
-rw-r--r--java/com/android/incallui/telecomeventui/InternationalCallOnWifiDialogFragment.java82
5 files changed, 171 insertions, 83 deletions
diff --git a/java/com/android/incallui/InCallActivity.java b/java/com/android/incallui/InCallActivity.java
index 91f557bd5..86799bfe4 100644
--- a/java/com/android/incallui/InCallActivity.java
+++ b/java/com/android/incallui/InCallActivity.java
@@ -129,9 +129,6 @@ public class InCallActivity extends TransactionSafeFragmentActivity
private static Optional<Integer> audioRouteForTesting = Optional.absent();
- private final InternationalCallOnWifiCallback internationalCallOnWifiCallback =
- new InternationalCallOnWifiCallback();
-
private SelectPhoneAccountListener selectPhoneAccountListener;
private Animation dialpadSlideInAnimation;
@@ -245,13 +242,6 @@ public class InCallActivity extends TransactionSafeFragmentActivity
}
}
- InternationalCallOnWifiDialogFragment existingInternationalCallOnWifiDialogFragment =
- (InternationalCallOnWifiDialogFragment)
- getSupportFragmentManager().findFragmentByTag(Tags.INTERNATIONAL_CALL_ON_WIFI);
- if (existingInternationalCallOnWifiDialogFragment != null) {
- existingInternationalCallOnWifiDialogFragment.setCallback(internationalCallOnWifiCallback);
- }
-
inCallOrientationEventListener = new InCallOrientationEventListener(this);
getWindow()
@@ -1201,16 +1191,8 @@ public class InCallActivity extends TransactionSafeFragmentActivity
}
public void showDialogForInternationalCallOnWifi(@NonNull DialerCall call) {
- if (!InternationalCallOnWifiDialogFragment.shouldShow(this)) {
- LogUtil.i(
- "InCallActivity.showDialogForInternationalCallOnWifi",
- "InternationalCallOnWifiDialogFragment.shouldShow returned false");
- return;
- }
-
InternationalCallOnWifiDialogFragment fragment =
- InternationalCallOnWifiDialogFragment.newInstance(
- call.getId(), internationalCallOnWifiCallback);
+ InternationalCallOnWifiDialogFragment.newInstance(call.getId());
fragment.show(getSupportFragmentManager(), Tags.INTERNATIONAL_CALL_ON_WIFI);
}
@@ -1785,28 +1767,6 @@ public class InCallActivity extends TransactionSafeFragmentActivity
static final String ANSWER_AND_RELEASE_ENABLED = "answer_and_release_enabled";
}
- private static final class InternationalCallOnWifiCallback
- implements InternationalCallOnWifiDialogFragment.Callback {
- private static final String TAG = InternationalCallOnWifiCallback.class.getCanonicalName();
-
- @Override
- public void continueCall(@NonNull String callId) {
- LogUtil.i(TAG, "Continuing call with ID: %s", callId);
- }
-
- @Override
- public void cancelCall(@NonNull String callId) {
- DialerCall call = CallList.getInstance().getCallById(callId);
- if (call == null) {
- LogUtil.i(TAG, "Call destroyed before the dialog is closed");
- return;
- }
-
- LogUtil.i(TAG, "Disconnecting international call on WiFi");
- call.disconnect();
- }
- }
-
private static final class SelectPhoneAccountListener
extends SelectPhoneAccountDialogFragment.SelectPhoneAccountListener {
private static final String TAG = SelectPhoneAccountListener.class.getCanonicalName();
diff --git a/java/com/android/incallui/InCallPresenter.java b/java/com/android/incallui/InCallPresenter.java
index a67dab513..526cc64d3 100644
--- a/java/com/android/incallui/InCallPresenter.java
+++ b/java/com/android/incallui/InCallPresenter.java
@@ -71,6 +71,8 @@ import com.android.incallui.latencyreport.LatencyReport;
import com.android.incallui.legacyblocking.BlockedNumberContentObserver;
import com.android.incallui.spam.SpamCallListListener;
import com.android.incallui.speakeasy.SpeakEasyCallManager;
+import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogActivity;
+import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment;
import com.android.incallui.videosurface.bindings.VideoSurfaceBindings;
import com.android.incallui.videosurface.protocol.VideoSurfaceTexture;
import com.android.incallui.videotech.utils.VideoUtils;
@@ -775,8 +777,22 @@ public class InCallPresenter implements CallList.Listener, AudioModeProvider.Aud
@Override
public void onInternationalCallOnWifi(@NonNull DialerCall call) {
LogUtil.enterBlock("InCallPresenter.onInternationalCallOnWifi");
+
+ if (!InternationalCallOnWifiDialogFragment.shouldShow(context)) {
+ LogUtil.i(
+ "InCallPresenter.onInternationalCallOnWifi",
+ "InternationalCallOnWifiDialogFragment.shouldShow returned false");
+ return;
+ }
+
if (inCallActivity != null) {
inCallActivity.showDialogForInternationalCallOnWifi(call);
+ } else {
+ Intent intent = new Intent(context, InternationalCallOnWifiDialogActivity.class);
+ // Prevent showing MainActivity with InternationalCallOnWifiDialogActivity on above
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
+ intent.putExtra(InternationalCallOnWifiDialogActivity.EXTRA_CALL_ID, call.getId());
+ context.startActivity(intent);
}
}
diff --git a/java/com/android/incallui/telecomeventui/AndroidManifest.xml b/java/com/android/incallui/telecomeventui/AndroidManifest.xml
index 861b9368a..a2134a3bd 100644
--- a/java/com/android/incallui/telecomeventui/AndroidManifest.xml
+++ b/java/com/android/incallui/telecomeventui/AndroidManifest.xml
@@ -12,4 +12,15 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<manifest package="com.android.incallui.telecomeventui"/> \ No newline at end of file
+<manifest
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.incallui.telecomeventui">
+ <application>
+ <activity
+ android:excludeFromRecents="true"
+ android:exported="true"
+ android:name="com.android.incallui.telecomeventui.InternationalCallOnWifiDialogActivity"
+ android:noHistory="true"
+ android:theme="@style/Theme.Incall.DialogHolder"/>
+ </application>
+</manifest>
diff --git a/java/com/android/incallui/telecomeventui/InternationalCallOnWifiDialogActivity.java b/java/com/android/incallui/telecomeventui/InternationalCallOnWifiDialogActivity.java
new file mode 100644
index 000000000..192c1603a
--- /dev/null
+++ b/java/com/android/incallui/telecomeventui/InternationalCallOnWifiDialogActivity.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2018 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.incallui.telecomeventui;
+
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v7.app.AppCompatActivity;
+import android.text.TextUtils;
+import com.android.incallui.call.CallList;
+import com.android.incallui.call.DialerCall;
+
+/**
+ * Activity containing dialog that may be shown when users place an outgoing call to an
+ * international number while on Wifi.
+ */
+public class InternationalCallOnWifiDialogActivity extends AppCompatActivity
+ implements CallList.Listener {
+
+ public static final String EXTRA_CALL_ID = "extra_call_id";
+ private static final String TAG_INTERNATIONAL_CALL_ON_WIFI = "tag_international_call_on_wifi";
+
+ private String callId;
+
+ @Override
+ protected void onCreate(@Nullable Bundle bundle) {
+ super.onCreate(bundle);
+
+ callId = getIntent().getStringExtra(EXTRA_CALL_ID);
+ if (TextUtils.isEmpty(callId)) {
+ finish();
+ return;
+ }
+
+ InternationalCallOnWifiDialogFragment fragment =
+ InternationalCallOnWifiDialogFragment.newInstance(callId);
+ fragment.show(getSupportFragmentManager(), TAG_INTERNATIONAL_CALL_ON_WIFI);
+
+ CallList.getInstance().addListener(this);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ CallList.getInstance().removeListener(this);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ // We don't expect the activity to resume, except for orientation change.
+ if (!isChangingConfigurations()) {
+ finish();
+ }
+ }
+
+ @Override
+ public void onDisconnect(DialerCall call) {
+ if (callId.equals(call.getId())) {
+ finish();
+ }
+ }
+
+ @Override
+ public void onIncomingCall(DialerCall call) {}
+
+ @Override
+ public void onUpgradeToVideo(DialerCall call) {}
+
+ @Override
+ public void onUpgradeToRtt(DialerCall call, int rttRequestId) {}
+
+ @Override
+ public void onSessionModificationStateChange(DialerCall call) {}
+
+ @Override
+ public void onCallListChange(CallList callList) {}
+
+ @Override
+ public void onWiFiToLteHandover(DialerCall call) {}
+
+ @Override
+ public void onHandoverToWifiFailed(DialerCall call) {}
+
+ @Override
+ public void onInternationalCallOnWifi(@NonNull DialerCall call) {}
+}
diff --git a/java/com/android/incallui/telecomeventui/InternationalCallOnWifiDialogFragment.java b/java/com/android/incallui/telecomeventui/InternationalCallOnWifiDialogFragment.java
index 2b602f876..71a8be483 100644
--- a/java/com/android/incallui/telecomeventui/InternationalCallOnWifiDialogFragment.java
+++ b/java/com/android/incallui/telecomeventui/InternationalCallOnWifiDialogFragment.java
@@ -21,16 +21,18 @@ import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.support.v4.app.DialogFragment;
import android.support.v4.os.UserManagerCompat;
import android.view.View;
import android.widget.CheckBox;
import com.android.dialer.common.Assert;
+import com.android.dialer.common.FragmentUtils;
import com.android.dialer.common.LogUtil;
+import com.android.dialer.storage.StorageComponent;
+import com.android.incallui.call.CallList;
+import com.android.incallui.call.DialerCall;
/**
* Dialog that may be shown when users place an outgoing call to an international number while on
@@ -53,7 +55,7 @@ public class InternationalCallOnWifiDialogFragment extends DialogFragment {
return false;
}
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+ SharedPreferences preferences = StorageComponent.get(context).unencryptedSharedPrefs();
boolean shouldShow = preferences.getBoolean(ALWAYS_SHOW_WARNING_PREFERENCE_KEY, true);
LogUtil.i("InternationalCallOnWifiDialogFragment.shouldShow", "result: %b", shouldShow);
@@ -61,27 +63,13 @@ public class InternationalCallOnWifiDialogFragment extends DialogFragment {
}
/**
- * Called in response to user interaction with the {@link InternationalCallOnWifiDialogFragment}.
- */
- public interface Callback {
-
- /** Indicates that the user wishes to proceed with the call represented by the given call id. */
- void continueCall(@NonNull String callId);
-
- /** Indicates that the user wishes to cancel the call represented by the given call id. */
- void cancelCall(@NonNull String callId);
- }
-
- /**
* Returns a new instance of {@link InternationalCallOnWifiDialogFragment} with the given
* callback.
*
* <p>Prefer this method over the default constructor.
*/
- public static InternationalCallOnWifiDialogFragment newInstance(
- @NonNull String callId, @NonNull Callback callback) {
+ public static InternationalCallOnWifiDialogFragment newInstance(@NonNull String callId) {
InternationalCallOnWifiDialogFragment fragment = new InternationalCallOnWifiDialogFragment();
- fragment.setCallback(callback);
Bundle args = new Bundle();
args.putString(ARG_CALL_ID, Assert.isNotNull(callId));
fragment.setArguments(args);
@@ -93,31 +81,12 @@ public class InternationalCallOnWifiDialogFragment extends DialogFragment {
* InternationalCallOnWifiDialogFragment InternationalCallOnWifiDialogFragments}.
*/
@VisibleForTesting
- static final String ALWAYS_SHOW_WARNING_PREFERENCE_KEY =
+ public static final String ALWAYS_SHOW_WARNING_PREFERENCE_KEY =
"ALWAYS_SHOW_INTERNATIONAL_CALL_ON_WIFI_WARNING";
/** Key in the arguments bundle for call id. */
private static final String ARG_CALL_ID = "call_id";
- /**
- * Callback which will receive information about user interactions with this dialog.
- *
- * <p>This is Nullable in the event that the dialog is destroyed by the framework, but doesn't
- * have a callback reattached. Ideally, the InCallActivity would implement the callback and we
- * would use FragmentUtils.getParentUnsafe instead of holding onto the callback here, but that's
- * not possible with the existing InCallActivity/InCallActivityCommon implementation.
- */
- @Nullable private Callback callback;
-
- /**
- * Sets the callback for this dialog.
- *
- * <p>Used to reset the callback after state changes.
- */
- public void setCallback(@NonNull Callback callback) {
- this.callback = Assert.isNotNull(callback);
- }
-
@NonNull
@Override
public Dialog onCreateDialog(Bundle bundle) {
@@ -134,7 +103,7 @@ public class InternationalCallOnWifiDialogFragment extends DialogFragment {
CheckBox alwaysWarn = dialogView.findViewById(R.id.always_warn);
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
+ SharedPreferences preferences = StorageComponent.get(getActivity()).unencryptedSharedPrefs();
// The default is set to false in this case to ensure that the first time the dialog opens,
// the checkbox is unchecked.
alwaysWarn.setChecked(preferences.getBoolean(ALWAYS_SHOW_WARNING_PREFERENCE_KEY, false));
@@ -163,7 +132,7 @@ public class InternationalCallOnWifiDialogFragment extends DialogFragment {
preferences.edit().putBoolean(ALWAYS_SHOW_WARNING_PREFERENCE_KEY, alwaysWarn).apply();
// Neither callback nor callId are null in normal circumstances. See comments on callback
- callback.continueCall(getArguments().getString(ARG_CALL_ID));
+ continueCall(getArguments().getString(ARG_CALL_ID));
}
private void onNegativeButtonClick(@NonNull SharedPreferences preferences, boolean alwaysWarn) {
@@ -174,6 +143,37 @@ public class InternationalCallOnWifiDialogFragment extends DialogFragment {
preferences.edit().putBoolean(ALWAYS_SHOW_WARNING_PREFERENCE_KEY, alwaysWarn).apply();
// Neither callback nor callId are null in normal circumstances. See comments on callback
- callback.cancelCall(getArguments().getString(ARG_CALL_ID));
+ cancelCall(getArguments().getString(ARG_CALL_ID));
+ }
+
+ private void continueCall(@NonNull String callId) {
+ LogUtil.i(
+ "InternationalCallOnWifiDialogFragment.continueCall",
+ "Continuing call with ID: %s",
+ callId);
+ InternationalCallOnWifiDialogActivity activity =
+ FragmentUtils.getParent(this, InternationalCallOnWifiDialogActivity.class);
+ if (activity != null) {
+ activity.finish();
+ }
+ }
+
+ private void cancelCall(@NonNull String callId) {
+ DialerCall call = CallList.getInstance().getCallById(callId);
+ if (call == null) {
+ LogUtil.i(
+ "InternationalCallOnWifiDialogFragment.cancelCall",
+ "Call destroyed before the dialog is closed");
+ } else {
+ LogUtil.i(
+ "InternationalCallOnWifiDialogFragment.cancelCall",
+ "Disconnecting international call on WiFi");
+ call.disconnect();
+ }
+ InternationalCallOnWifiDialogActivity activity =
+ FragmentUtils.getParent(this, InternationalCallOnWifiDialogActivity.class);
+ if (activity != null) {
+ activity.finish();
+ }
}
}