diff options
Diffstat (limited to 'java/com/android/incallui/telecomeventui')
3 files changed, 154 insertions, 42 deletions
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(); + } } } |